mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-19 03:44:23 -05:00
Throwing proper error when "constructor" is not a function within a class body.
This commit is contained in:
@@ -821,6 +821,9 @@
|
|||||||
pvar = prop.variable;
|
pvar = prop.variable;
|
||||||
if (pvar && pvar.base.value === 'constructor') {
|
if (pvar && pvar.base.value === 'constructor') {
|
||||||
func = prop.value;
|
func = prop.value;
|
||||||
|
if (!(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 {
|
||||||
|
|||||||
@@ -601,6 +601,7 @@ exports.ClassNode: class ClassNode extends BaseNode
|
|||||||
pvar: prop.variable
|
pvar: prop.variable
|
||||||
if pvar and pvar.base.value is 'constructor'
|
if pvar and pvar.base.value is 'constructor'
|
||||||
func: prop.value
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user