Back to naked constructors.

This commit is contained in:
Jeremy Ashkenas
2010-11-13 15:22:18 -05:00
parent f0b73dc9f5
commit 2aedbc2e42
12 changed files with 74 additions and 82 deletions

View File

@@ -851,25 +851,10 @@
base = assign.variable.base;
delete assign.context;
func = assign.value;
if (base.value === 'constructor') {
if (ctor) {
throw new Error('cannot define more than one constructor in a class');
}
if (func.bound) {
throw new Error('cannot define a constructor as a bound function');
}
if (func instanceof Code) {
ctor = func;
} else {
ctor = new Assign(new Value(lname), func);
}
assign = null;
} else {
assign.variable = new Value(lname, [new Accessor(base, 'proto')]);
if (func instanceof Code && func.bound) {
boundFuncs.push(base);
func.bound = false;
}
assign.variable = new Value(lname, [new Accessor(base, 'proto')]);
if (func instanceof Code && func.bound) {
boundFuncs.push(base);
func.bound = false;
}
}
_results.push(assign);
@@ -883,6 +868,15 @@
node = _ref[i];
if (node instanceof Value && node.isObject(true)) {
exps[i] = compact(convert(node));
} else if (node instanceof Code) {
if (ctor) {
throw new Error('cannot define more than one constructor in a class');
}
if (node.bound) {
throw new Error('cannot define a constructor as a bound function');
}
ctor = node;
exps[i] = null;
} else {
others.push(node);
}
@@ -906,7 +900,7 @@
other = others[_i];
_fn(other);
}
this.body.expressions = exps = flatten(exps);
this.body.expressions = exps = compact(flatten(exps));
if (!ctor) {
ctor = new Code;
if (this.parent) {