mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 19:34:27 -05:00
throw a syntax error if you try to use the fat arrow to define a class constructor.
This commit is contained in:
@@ -739,6 +739,9 @@
|
|||||||
pvar = _e[0];
|
pvar = _e[0];
|
||||||
func = _e[1];
|
func = _e[1];
|
||||||
if (pvar && pvar.base.value === 'constructor' && func instanceof CodeNode) {
|
if (pvar && pvar.base.value === 'constructor' && func instanceof CodeNode) {
|
||||||
|
if (func.bound) {
|
||||||
|
throw new Error("cannot define a constructor as a bound function.");
|
||||||
|
}
|
||||||
func.name = className;
|
func.name = className;
|
||||||
func.body.push(new ReturnNode(literal('this')));
|
func.body.push(new ReturnNode(literal('this')));
|
||||||
this.variable = new ValueNode(this.variable);
|
this.variable = new ValueNode(this.variable);
|
||||||
|
|||||||
@@ -647,6 +647,7 @@ exports.ClassNode: class ClassNode extends BaseNode
|
|||||||
for prop in @properties
|
for prop in @properties
|
||||||
[pvar, func]: [prop.variable, prop.value]
|
[pvar, func]: [prop.variable, prop.value]
|
||||||
if pvar and pvar.base.value is 'constructor' and func instanceof CodeNode
|
if pvar and pvar.base.value is 'constructor' and func instanceof CodeNode
|
||||||
|
throw new Error "cannot define a constructor as a bound function." if func.bound
|
||||||
func.name: className
|
func.name: className
|
||||||
func.body.push new ReturnNode literal 'this'
|
func.body.push new ReturnNode literal 'this'
|
||||||
@variable: new ValueNode @variable
|
@variable: new ValueNode @variable
|
||||||
|
|||||||
Reference in New Issue
Block a user