add isFalsyExpression check to superName and make classes a closure if they're inheriting

This commit is contained in:
Sebastian McKenzie 2014-12-31 11:54:39 +11:00
parent 46632e1a97
commit aee1ca45b0
2 changed files with 13 additions and 1 deletions

View File

@ -102,6 +102,7 @@ Class.prototype.run = function () {
// //
if (superName) { if (superName) {
this.closure = true;
body.push(t.expressionStatement(t.callExpression(file.addDeclaration("inherits"), [className, superName]))); body.push(t.expressionStatement(t.callExpression(file.addDeclaration("inherits"), [className, superName])));
} }
@ -153,7 +154,7 @@ Class.prototype.buildBody = function () {
} }
} }
if (!this.hasConstructor && superName) { if (!this.hasConstructor && superName && !t.isFalsyExpression(superName)) {
constructor.body.body.push(util.template("class-super-constructor-call", { constructor.body.body.push(util.template("class-super-constructor-call", {
SUPER_NAME: superName SUPER_NAME: superName
}, true)); }, true));

View File

@ -74,6 +74,17 @@ addAssert("Expression", t.isExpression);
// //
t.isFalsyExpression = function (node) {
if (t.isLiteral(node)) {
return !node.value;
} else if (t.isIdentifier(node)) {
return node.name === "undefined";
}
return false;
};
//
t.toSequenceExpression = function (nodes, scope) { t.toSequenceExpression = function (nodes, scope) {
var exprs = []; var exprs = [];