From 69fb1854d79e25f63e0b7553ba966716397eb382 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Thu, 12 Nov 2015 01:49:01 -0800 Subject: [PATCH] add error for decorators not being implemented yet --- .../src/index.js | 8 +++++ .../fixtures/.decorators/class-decorator.js | 18 ---------- .../test/fixtures/.decorators/getters.js | 23 ------------- .../initialised-property-declarations.js | 8 ----- .../initialised-static-properties.js | 8 ----- ...itialized-properties-in-object-literals.js | 7 ---- .../test/fixtures/.decorators/methods.js | 33 ------------------- .../uninitialized-field-declaration.js | 17 ---------- ...itialized-properties-in-object-literals.js | 11 ------- .../unitialised-static-properties.js | 13 -------- .../{.decorators => exec}/options.json | 0 11 files changed, 8 insertions(+), 138 deletions(-) delete mode 100644 packages/babel-plugin-transform-decorators/test/fixtures/.decorators/class-decorator.js delete mode 100644 packages/babel-plugin-transform-decorators/test/fixtures/.decorators/getters.js delete mode 100644 packages/babel-plugin-transform-decorators/test/fixtures/.decorators/initialised-property-declarations.js delete mode 100644 packages/babel-plugin-transform-decorators/test/fixtures/.decorators/initialised-static-properties.js delete mode 100644 packages/babel-plugin-transform-decorators/test/fixtures/.decorators/initialized-properties-in-object-literals.js delete mode 100644 packages/babel-plugin-transform-decorators/test/fixtures/.decorators/methods.js delete mode 100644 packages/babel-plugin-transform-decorators/test/fixtures/.decorators/uninitialized-field-declaration.js delete mode 100644 packages/babel-plugin-transform-decorators/test/fixtures/.decorators/uninitialized-properties-in-object-literals.js delete mode 100644 packages/babel-plugin-transform-decorators/test/fixtures/.decorators/unitialised-static-properties.js rename packages/babel-plugin-transform-decorators/test/fixtures/{.decorators => exec}/options.json (100%) diff --git a/packages/babel-plugin-transform-decorators/src/index.js b/packages/babel-plugin-transform-decorators/src/index.js index dbad41c823..150e25e0f8 100644 --- a/packages/babel-plugin-transform-decorators/src/index.js +++ b/packages/babel-plugin-transform-decorators/src/index.js @@ -70,12 +70,18 @@ export default function ({ types: t }) { return false; } + function doError(path) { + throw path.buildCodeFrameError("Decorators are not supported yet in 6.x pending proposal update."); + } + return { inherits: require("babel-plugin-syntax-decorators"), visitor: { ClassExpression(path) { if (!hasDecorators(path)) return; + doError(path); + explodeClass(path); let ref = path.scope.generateDeclaredUidIdentifier("ref"); @@ -92,6 +98,7 @@ export default function ({ types: t }) { ClassDeclaration(path) { if (!hasDecorators(path)) return; + doError(path); explodeClass(path); let ref = path.node.id; @@ -105,6 +112,7 @@ export default function ({ types: t }) { ObjectExpression(path) { if (!hasDecorators(path)) return; + doError(path); } } }; diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/class-decorator.js b/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/class-decorator.js deleted file mode 100644 index 4333b596e3..0000000000 --- a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/class-decorator.js +++ /dev/null @@ -1,18 +0,0 @@ -function noop() {} - -function override() { - return "bar"; -} - -@override -class Foo {} - -@noop -class Bar { - constructor() { - this.foo = "bar"; - } -} - -assert.equal(Foo, "bar"); -assert.equal(new Bar().foo, "bar"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/getters.js b/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/getters.js deleted file mode 100644 index 6c613018af..0000000000 --- a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/getters.js +++ /dev/null @@ -1,23 +0,0 @@ -class Person { - @reader _first; - @reader last; - - constructor(first, last) { - this._first = first; - this._last = last; - } - - @reader get _fullName() { - return `${this._first} ${this._last}`; - } -} - -let jason = new Person("Jason", "Orendorff"); - -assert.equal(jason.first, "Jason"); -assert.equal(jason.last, "Orendorff"); -assert.equal(jason.fullName, "Jason Orendorff"); - -jason.update("JSON", "Orendorff") -assert.equal(jason.first, "JSON"); -assert.equal(jason.fullName, "JSON Orendorff"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/initialised-property-declarations.js b/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/initialised-property-declarations.js deleted file mode 100644 index 761ba3c538..0000000000 --- a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/initialised-property-declarations.js +++ /dev/null @@ -1,8 +0,0 @@ -class Person { - @reader _first = "Andreas"; - @reader _last = "Rossberg"; -} - -let andreas = new Person(); -assert.equal(andreas.first, "Andreas"); -assert.equal(andreas.last, "Rossberg"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/initialised-static-properties.js b/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/initialised-static-properties.js deleted file mode 100644 index e928cd349c..0000000000 --- a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/initialised-static-properties.js +++ /dev/null @@ -1,8 +0,0 @@ -class Person { - @reader static _first = "Brendan"; - @reader static _last = "Eich"; -} - -let brendan = Person; -assert.equal(brendan.first, "Brendan"); -assert.equal(brendan.last, "Eich"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/initialized-properties-in-object-literals.js b/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/initialized-properties-in-object-literals.js deleted file mode 100644 index e242da8ad2..0000000000 --- a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/initialized-properties-in-object-literals.js +++ /dev/null @@ -1,7 +0,0 @@ -let person = { - @reader _first: "Mark", - @reader _last: "Miller" -}; - -assert.equal(person.first, "Mark"); -assert.equal(person.last, "Miller"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/methods.js b/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/methods.js deleted file mode 100644 index c3d6a66bd7..0000000000 --- a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/methods.js +++ /dev/null @@ -1,33 +0,0 @@ -function reader(target, descriptor) { - let { enumerable, configurable, property: { name, get }, hint } = descriptor; - let publicName = extractPublicName(name()); - Object.defineProperty(target, publicName, { - enumerable, configurable, get: function() { return get(this, name); } - }); - return descriptor; -} - -function extractPublicName(name) { - // _first -> first - return name.slice(1); -} - -class Person { - @reader _first; - @reader _last; - - constructor(first, last) { - this._first = first; - this._last = last; - } - - @reader _update(first, last) { - this._first = first; - this._last = last; - } -} - -let alex = new Person("Alex", "Russell"); -assert.equal(alex.first, "Alex"); -alex.update("Alexander", "Russell"); -assert.equal(alex.first, "Alexander"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/uninitialized-field-declaration.js b/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/uninitialized-field-declaration.js deleted file mode 100644 index 71c118d267..0000000000 --- a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/uninitialized-field-declaration.js +++ /dev/null @@ -1,17 +0,0 @@ -class Person { - @reader _first; - @reader _last; - - constructor(first="Waldemar", last="Horwat") { - this._first = first; - this._last = last; - } -} - -let waldemar = new Person(); -assert.equal(waldemar.first, "Waldemar"); -assert.equal(waldemar.last, "Horwat"); - -let jeff = new Person("Jeff", "Morrison"); -assert.equal(jeff.first, "Jeff"); -assert.equal(jeff.last, "Morrison"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/uninitialized-properties-in-object-literals.js b/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/uninitialized-properties-in-object-literals.js deleted file mode 100644 index 9f577a129f..0000000000 --- a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/uninitialized-properties-in-object-literals.js +++ /dev/null @@ -1,11 +0,0 @@ -let person = { - @reader _first, - @reader _last -}; - -assert.equal(person.first, "undefined"); - -Object.assign(person, { _first: "Brian", _last: "Terlson" }); - -assert.equal(person.first, "Brian"); -assert.equal(person.last, "Terlson"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/unitialised-static-properties.js b/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/unitialised-static-properties.js deleted file mode 100644 index f57d08af44..0000000000 --- a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/unitialised-static-properties.js +++ /dev/null @@ -1,13 +0,0 @@ -class Person { - @reader static _first; - @reader static _last; -} - -let jonathan = Person; - -assert.equal(jonathan.first, undefined); - -Object.assign(jonathan, { _first: "Jonathan", _last: "Turner" }); - -assert.equal(jonathan.first, "Jonathan"); -assert.equal(jonathan.last, "Turner"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/.decorators/options.json b/packages/babel-plugin-transform-decorators/test/fixtures/exec/options.json similarity index 100% rename from packages/babel-plugin-transform-decorators/test/fixtures/.decorators/options.json rename to packages/babel-plugin-transform-decorators/test/fixtures/exec/options.json