clean up default constructor in derived classes - fixes #1748
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
(function () {
|
||||
super(...arguments);
|
||||
})
|
||||
@@ -1,3 +0,0 @@
|
||||
if (SUPER_NAME != null) {
|
||||
SUPER_NAME.apply(this, arguments);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
if (SUPER_NAME != null) {
|
||||
SUPER_NAME.apply(this, arguments);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
if (SUPER_NAME != null) {
|
||||
var NATIVE_REF = new SUPER_NAME(...arguments);
|
||||
NATIVE_REF.__proto__ = CLASS_NAME.prototype;
|
||||
return NATIVE_REF;
|
||||
}
|
||||
@@ -251,20 +251,43 @@ class ClassTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://www.youtube.com/watch?v=fWNaR-rxAic
|
||||
*/
|
||||
|
||||
constructorMeMaybe() {
|
||||
if (!this.hasSuper) return;
|
||||
|
||||
var hasConstructor = false;
|
||||
var paths = this.path.get("body.body");
|
||||
|
||||
for (var path of (paths: Array)) {
|
||||
hasConstructor = path.equals("kind", "constructor");
|
||||
if (hasConstructor) break;
|
||||
}
|
||||
|
||||
if (!hasConstructor) {
|
||||
this.path.get("body").unshiftContainer("body", t.methodDefinition(
|
||||
t.identifier("constructor"),
|
||||
util.template("class-derived-default-constructor"),
|
||||
"constructor"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
buildBody() {
|
||||
this.constructorMeMaybe();
|
||||
|
||||
var constructorBody = this.constructorBody;
|
||||
var classBody = this.node.body.body;
|
||||
var classBodyPaths = this.path.get("body.body");
|
||||
var body = this.body;
|
||||
|
||||
var classBodyPaths = this.path.get("body").get("body");
|
||||
|
||||
for (var i = 0; i < classBody.length; i++) {
|
||||
var node = classBody[i];
|
||||
var path = classBodyPaths[i];
|
||||
for (var path of (classBodyPaths: Array)) {
|
||||
var node = path.node;
|
||||
|
||||
if (node.decorators) {
|
||||
memoiseDecorators(node.decorators, this.scope);
|
||||
@@ -297,16 +320,6 @@ class ClassTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
// we have no constructor, but we're a derived class
|
||||
if (!this.hasConstructor && this.hasSuper) {
|
||||
var helperName = "class-super-constructor-call";
|
||||
if (this.isLoose) helperName += "-loose";
|
||||
constructorBody.body.push(util.template(helperName, {
|
||||
CLASS_NAME: this.classRef,
|
||||
SUPER_NAME: this.superName
|
||||
}, true));
|
||||
}
|
||||
|
||||
//
|
||||
this.placePropertyInitializers();
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ export function insertBefore(nodes) {
|
||||
} else if (this.isNodeType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
|
||||
if (this.node) nodes.push(this.node);
|
||||
this.replaceExpressionWithStatements(nodes);
|
||||
} else if (this.isNodeType("Statement") || !this.type) {
|
||||
} else {
|
||||
this._maybePopFromStatements(nodes);
|
||||
if (Array.isArray(this.container)) {
|
||||
return this._containerInsertBefore(nodes);
|
||||
@@ -26,8 +26,6 @@ export function insertBefore(nodes) {
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
} else {
|
||||
throw new Error("No clue what to do with this node type.");
|
||||
}
|
||||
|
||||
return [this];
|
||||
@@ -94,7 +92,7 @@ export function insertAfter(nodes) {
|
||||
nodes.push(t.expressionStatement(temp));
|
||||
}
|
||||
this.replaceExpressionWithStatements(nodes);
|
||||
} else if (this.isNodeType("Statement") || !this.type) {
|
||||
} else {
|
||||
this._maybePopFromStatements(nodes);
|
||||
if (Array.isArray(this.container)) {
|
||||
return this._containerInsertAfter(nodes);
|
||||
@@ -104,8 +102,6 @@ export function insertAfter(nodes) {
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
} else {
|
||||
throw new Error("No clue what to do with this node type.");
|
||||
}
|
||||
|
||||
return [this];
|
||||
|
||||
Reference in New Issue
Block a user