From 0cb5a7c91e505ba1d4767224f17465d0673b13c6 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 7 Apr 2015 04:40:39 -0700 Subject: [PATCH] Revert "Use a functionExpression with class decorators. Fixes #1161." This reverts commit f8d56d961207153c5b259c1666cd9fff2d03d817. --- .../transformers/es6/classes.js | 12 ++------ .../es7.decorators/class/actual.js | 7 ----- .../es7.decorators/class/expected.js | 29 ++++++------------- 3 files changed, 11 insertions(+), 37 deletions(-) diff --git a/src/babel/transformation/transformers/es6/classes.js b/src/babel/transformation/transformers/es6/classes.js index f15233451b..1a63e8ad8b 100644 --- a/src/babel/transformation/transformers/es6/classes.js +++ b/src/babel/transformation/transformers/es6/classes.js @@ -30,7 +30,7 @@ var collectPropertyReferencesVisitor = { } if (this.isReferenced() && scope.getBinding(node.name) === state.scope.getBinding(node.name)) { - state.references[node.name] = true; + state.references[node.name] = true;; } } } @@ -140,7 +140,7 @@ class ClassTransformer { var constructorBody = this.constructorBody = t.blockStatement([]); var constructor; - if (this.className && !this.node.decorators) { + if (this.className) { constructor = t.functionDeclaration(this.className, [], constructorBody); body.push(constructor); } else { @@ -189,14 +189,6 @@ class ClassTransformer { } if (this.className) { - if (decorators) { - constructor = t.functionExpression(this.className, constructor.params, constructorBody); - - body.unshift(t.variableDeclaration("var", [ - t.variableDeclarator(classRef, constructor) - ])); - } - // named class with only a constructor if (body.length === 1) return t.toExpression(body[0]); } else { diff --git a/test/core/fixtures/transformation/es7.decorators/class/actual.js b/test/core/fixtures/transformation/es7.decorators/class/actual.js index 96ced15a45..d7af40351a 100644 --- a/test/core/fixtures/transformation/es7.decorators/class/actual.js +++ b/test/core/fixtures/transformation/es7.decorators/class/actual.js @@ -12,10 +12,3 @@ var Foo2 = @bar class Foo { var Bar2 = @foo @bar class Bar { }; - -@foo -class Baz{ - constructor(baz) { - this.baz = baz; - } -} diff --git a/test/core/fixtures/transformation/es7.decorators/class/expected.js b/test/core/fixtures/transformation/es7.decorators/class/expected.js index d0388c5577..cb9c85c166 100644 --- a/test/core/fixtures/transformation/es7.decorators/class/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/class/expected.js @@ -1,18 +1,18 @@ "use strict"; var Foo = (function () { - var Foo = function Foo() { + function Foo() { babelHelpers.classCallCheck(this, Foo); - }; + } Foo = foo(Foo) || Foo; return Foo; })(); var Bar = (function () { - var Bar = function Bar() { + function Bar() { babelHelpers.classCallCheck(this, Bar); - }; + } Bar = foo(Bar) || Bar; Bar = bar(Bar) || Bar; @@ -20,31 +20,20 @@ var Bar = (function () { })(); var Foo2 = (function () { - var Foo = function Foo() { + function Foo() { babelHelpers.classCallCheck(this, Foo); - }; + } Foo = bar(Foo) || Foo; return Foo; })(); var Bar2 = (function () { - var Bar = function Bar() { + function Bar() { babelHelpers.classCallCheck(this, Bar); - }; + } Bar = foo(Bar) || Bar; Bar = bar(Bar) || Bar; return Bar; -})(); - -var Baz = (function () { - var Baz = function Baz(baz) { - babelHelpers.classCallCheck(this, Baz); - - this.baz = baz; - }; - - Baz = foo(Baz) || Baz; - return Baz; -})(); +})(); \ No newline at end of file