diff --git a/src/babel/transformation/transformers/es6/classes.js b/src/babel/transformation/transformers/es6/classes.js index 1a63e8ad8b..9b33376ebf 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; } } } @@ -170,15 +170,27 @@ class ClassTransformer { this.buildBody(); + var decorators = this.node.decorators; + var classCheckRef = classRef; + + if (decorators) { + classCheckRef = this.scope.generateUidIdentifier(classRef); + } + constructorBody.body.unshift(t.expressionStatement(t.callExpression(file.addHelper("class-call-check"), [ t.thisExpression(), - classRef + classCheckRef ]))); // - var decorators = this.node.decorators; if (decorators) { + if (this.className) { + body.push(t.variableDeclaration("var", [ + t.variableDeclarator(classCheckRef, classRef) + ])); + } + for (var i = 0; i < decorators.length; i++) { var decorator = decorators[i]; body.push(util.template("class-decorator", { diff --git a/test/core/fixtures/transformation/es7.decorators/class/actual.js b/test/core/fixtures/transformation/es7.decorators/class/actual.js index d7af40351a..96ced15a45 100644 --- a/test/core/fixtures/transformation/es7.decorators/class/actual.js +++ b/test/core/fixtures/transformation/es7.decorators/class/actual.js @@ -12,3 +12,10 @@ 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 cb9c85c166..e60d87aba8 100644 --- a/test/core/fixtures/transformation/es7.decorators/class/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/class/expected.js @@ -2,18 +2,20 @@ var Foo = (function () { function Foo() { - babelHelpers.classCallCheck(this, Foo); + babelHelpers.classCallCheck(this, _Foo); } + var _Foo = Foo; Foo = foo(Foo) || Foo; return Foo; })(); var Bar = (function () { function Bar() { - babelHelpers.classCallCheck(this, Bar); + babelHelpers.classCallCheck(this, _Bar); } + var _Bar = Bar; Bar = foo(Bar) || Bar; Bar = bar(Bar) || Bar; return Bar; @@ -21,19 +23,33 @@ var Bar = (function () { var Foo2 = (function () { function Foo() { - babelHelpers.classCallCheck(this, Foo); + babelHelpers.classCallCheck(this, _Foo2); } + var _Foo2 = Foo; Foo = bar(Foo) || Foo; return Foo; })(); var Bar2 = (function () { function Bar() { - babelHelpers.classCallCheck(this, Bar); + babelHelpers.classCallCheck(this, _Bar2); } + var _Bar2 = Bar; Bar = foo(Bar) || Bar; Bar = bar(Bar) || Bar; return Bar; -})(); \ No newline at end of file +})(); + +var Baz = (function () { + function Baz(baz) { + babelHelpers.classCallCheck(this, _Baz); + + this.baz = baz; + } + + var _Baz = Baz; + Baz = foo(Baz) || Baz; + return Baz; +})();