Merge pull request #1185 from Dignifiedquire/class-decorators-scope
Take 2: Fix class decorator scoping.
This commit is contained in:
commit
ed747f88bd
@ -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", {
|
||||
|
||||
@ -12,3 +12,10 @@ var Foo2 = @bar class Foo {
|
||||
var Bar2 = @foo @bar class Bar {
|
||||
|
||||
};
|
||||
|
||||
@foo
|
||||
class Baz{
|
||||
constructor(baz) {
|
||||
this.baz = baz;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
})();
|
||||
})();
|
||||
|
||||
var Baz = (function () {
|
||||
function Baz(baz) {
|
||||
babelHelpers.classCallCheck(this, _Baz);
|
||||
|
||||
this.baz = baz;
|
||||
}
|
||||
|
||||
var _Baz = Baz;
|
||||
Baz = foo(Baz) || Baz;
|
||||
return Baz;
|
||||
})();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user