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