clean up class decorators #1185
This commit is contained in:
parent
7e1a4be085
commit
27b6f804ce
@ -168,7 +168,6 @@ class ClassTransformer {
|
||||
var closureArgs = [];
|
||||
|
||||
//
|
||||
|
||||
if (this.hasSuper) {
|
||||
closureArgs.push(superName);
|
||||
|
||||
@ -180,30 +179,30 @@ class ClassTransformer {
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
this.buildBody();
|
||||
|
||||
var decorators = this.node.decorators;
|
||||
var classCheckRef = classRef;
|
||||
|
||||
if (decorators) {
|
||||
classCheckRef = this.scope.generateUidIdentifier(classRef);
|
||||
// create a class reference to use later on
|
||||
this.classRef = this.scope.generateUidIdentifier(classRef);
|
||||
|
||||
// this is so super calls and the decorators have access to the raw function
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(this.classRef, classRef)
|
||||
]));
|
||||
}
|
||||
|
||||
//
|
||||
this.buildBody();
|
||||
|
||||
// make sure this class isn't directly called
|
||||
constructorBody.body.unshift(t.expressionStatement(t.callExpression(file.addHelper("class-call-check"), [
|
||||
t.thisExpression(),
|
||||
classCheckRef
|
||||
this.classRef
|
||||
])));
|
||||
|
||||
//
|
||||
|
||||
if (decorators) {
|
||||
if (this.className) {
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(classCheckRef, classRef)
|
||||
]));
|
||||
}
|
||||
|
||||
// reverse the decorators so we execute them in the right order
|
||||
decorators = decorators.reverse();
|
||||
|
||||
for (var i = 0; i < decorators.length; i++) {
|
||||
@ -219,6 +218,8 @@ class ClassTransformer {
|
||||
}
|
||||
|
||||
if (this.isNativeSuper) {
|
||||
// we've determined this is inheriting from a native class so return the constructed
|
||||
// instance
|
||||
constructorBody.body.push(t.returnStatement(this.nativeSuperRef));
|
||||
}
|
||||
|
||||
|
||||
@ -9,11 +9,12 @@ var _foo = require("foo");
|
||||
var _foo2 = babelHelpers.interopRequireWildcard(_foo);
|
||||
|
||||
var Foo = (function () {
|
||||
var _Foo = Foo;
|
||||
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, _Foo);
|
||||
}
|
||||
|
||||
var _Foo = Foo;
|
||||
Foo = _foo2["default"](Foo) || Foo;
|
||||
return Foo;
|
||||
})();
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
@bar
|
||||
class Foo extends Bar {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
var Foo2 = @bar class extends Bar {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
var Foo = (function (_Bar) {
|
||||
var _Foo = Foo;
|
||||
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, _Foo);
|
||||
|
||||
babelHelpers.get(Object.getPrototypeOf(_Foo.prototype), "constructor", this).call(this);
|
||||
}
|
||||
|
||||
babelHelpers.inherits(Foo, _Bar);
|
||||
Foo = bar(Foo) || Foo;
|
||||
return Foo;
|
||||
})(Bar);
|
||||
|
||||
var Foo2 = (function (_Bar2) {
|
||||
var _class = function Foo2() {
|
||||
babelHelpers.classCallCheck(this, _class2);
|
||||
|
||||
babelHelpers.get(Object.getPrototypeOf(_class2.prototype), "constructor", this).call(this);
|
||||
};
|
||||
|
||||
var _class2 = _class;
|
||||
babelHelpers.inherits(_class, _Bar2);
|
||||
_class = bar(_class) || _class;
|
||||
return _class;
|
||||
})(Bar);
|
||||
@ -1,55 +1,60 @@
|
||||
"use strict";
|
||||
|
||||
var Foo = (function () {
|
||||
var _Foo = Foo;
|
||||
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, _Foo);
|
||||
}
|
||||
|
||||
var _Foo = Foo;
|
||||
Foo = foo(Foo) || Foo;
|
||||
return Foo;
|
||||
})();
|
||||
|
||||
var Bar = (function () {
|
||||
var _Bar = Bar;
|
||||
|
||||
function Bar() {
|
||||
babelHelpers.classCallCheck(this, _Bar);
|
||||
}
|
||||
|
||||
var _Bar = Bar;
|
||||
Bar = bar(Bar) || Bar;
|
||||
Bar = foo(Bar) || Bar;
|
||||
return Bar;
|
||||
})();
|
||||
|
||||
var Foo2 = (function () {
|
||||
var _Foo2 = Foo;
|
||||
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, _Foo2);
|
||||
}
|
||||
|
||||
var _Foo2 = Foo;
|
||||
Foo = bar(Foo) || Foo;
|
||||
return Foo;
|
||||
})();
|
||||
|
||||
var Bar2 = (function () {
|
||||
var _Bar2 = Bar;
|
||||
|
||||
function Bar() {
|
||||
babelHelpers.classCallCheck(this, _Bar2);
|
||||
}
|
||||
|
||||
var _Bar2 = Bar;
|
||||
Bar = bar(Bar) || Bar;
|
||||
Bar = foo(Bar) || Bar;
|
||||
return Bar;
|
||||
})();
|
||||
|
||||
var Baz = (function () {
|
||||
var _Baz = Baz;
|
||||
|
||||
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