mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Back to naked constructors.
This commit is contained in:
34
lib/nodes.js
34
lib/nodes.js
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user