mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
merging non-func-constructor-fix, but a little more forgiving.
This commit is contained in:
14
lib/nodes.js
14
lib/nodes.js
@@ -810,7 +810,7 @@
|
||||
// equivalent syntax tree and compile that, in pieces. You can see the
|
||||
// constructor, property assignments, and inheritance getting built out below.
|
||||
ClassNode.prototype.compile_node = function compile_node(o) {
|
||||
var _a, _b, _c, access, applied, construct, extension, func, prop, props, pvar, returns, val;
|
||||
var _a, _b, _c, _d, access, applied, construct, extension, func, prop, props, pvar, returns, val;
|
||||
extension = this.parent && new ExtendsNode(this.variable, this.parent);
|
||||
constructor = null;
|
||||
props = new Expressions();
|
||||
@@ -818,19 +818,17 @@
|
||||
_b = this.properties;
|
||||
for (_a = 0, _c = _b.length; _a < _c; _a++) {
|
||||
prop = _b[_a];
|
||||
pvar = prop.variable;
|
||||
if (pvar && pvar.base.value === 'constructor') {
|
||||
func = prop.value;
|
||||
if (!(func instanceof CodeNode)) {
|
||||
throw new Error("'" + (pvar.base.value) + "' must be a function in 'class " + (this.variable.base.value) + "'.");
|
||||
}
|
||||
_d = [prop.variable, prop.value];
|
||||
pvar = _d[0];
|
||||
func = _d[1];
|
||||
if (pvar && pvar.base.value === 'constructor' && func instanceof CodeNode) {
|
||||
func.body.push(new ReturnNode(literal('this')));
|
||||
constructor = new AssignNode(this.variable, func);
|
||||
} else {
|
||||
if (pvar) {
|
||||
access = prop.context === 'this' ? pvar.base.properties[0] : new AccessorNode(pvar, 'prototype');
|
||||
val = new ValueNode(this.variable, [access]);
|
||||
prop = new AssignNode(val, prop.value);
|
||||
prop = new AssignNode(val, func);
|
||||
}
|
||||
props.push(prop);
|
||||
}
|
||||
|
||||
@@ -598,17 +598,15 @@ exports.ClassNode: class ClassNode extends BaseNode
|
||||
o.top: true
|
||||
|
||||
for prop in @properties
|
||||
pvar: prop.variable
|
||||
if pvar and pvar.base.value is 'constructor'
|
||||
func: prop.value
|
||||
throw new Error("'${ pvar.base.value }' must be a function in 'class ${ @variable.base.value }'.") if not (func instanceof CodeNode)
|
||||
[pvar, func]: [prop.variable, prop.value]
|
||||
if pvar and pvar.base.value is 'constructor' and func instanceof CodeNode
|
||||
func.body.push(new ReturnNode(literal('this')))
|
||||
constructor: new AssignNode(@variable, func)
|
||||
else
|
||||
if pvar
|
||||
access: if prop.context is 'this' then pvar.base.properties[0] else new AccessorNode(pvar, 'prototype')
|
||||
val: new ValueNode(@variable, [access])
|
||||
prop: new AssignNode(val, prop.value)
|
||||
prop: new AssignNode(val, func)
|
||||
props.push prop
|
||||
|
||||
if not constructor
|
||||
|
||||
Reference in New Issue
Block a user