Merge pull request #1184 from Dignifiedquire/class-decorators
Use a functionExpression with class decorators. Fixes #1161.
This commit is contained in:
commit
fc34d5a9b0
@ -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) {
|
||||
if (this.className && !this.node.decorators) {
|
||||
constructor = t.functionDeclaration(this.className, [], constructorBody);
|
||||
body.push(constructor);
|
||||
} else {
|
||||
@ -189,6 +189,14 @@ 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 {
|
||||
|
||||
@ -12,3 +12,10 @@ var Foo2 = @bar class Foo {
|
||||
var Bar2 = @foo @bar class Bar {
|
||||
|
||||
};
|
||||
|
||||
@foo
|
||||
class Baz{
|
||||
constructor(baz) {
|
||||
this.baz = baz;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
var Foo = function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
}
|
||||
};
|
||||
|
||||
Foo = foo(Foo) || Foo;
|
||||
return Foo;
|
||||
})();
|
||||
|
||||
var Bar = (function () {
|
||||
function Bar() {
|
||||
var Bar = function Bar() {
|
||||
babelHelpers.classCallCheck(this, Bar);
|
||||
}
|
||||
};
|
||||
|
||||
Bar = foo(Bar) || Bar;
|
||||
Bar = bar(Bar) || Bar;
|
||||
@ -20,20 +20,31 @@ var Bar = (function () {
|
||||
})();
|
||||
|
||||
var Foo2 = (function () {
|
||||
function Foo() {
|
||||
var Foo = function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
}
|
||||
};
|
||||
|
||||
Foo = bar(Foo) || Foo;
|
||||
return Foo;
|
||||
})();
|
||||
|
||||
var Bar2 = (function () {
|
||||
function Bar() {
|
||||
var 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;
|
||||
})();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user