Fix: `__extends` helper above directive prologue

This commit is contained in:
Marc Häfner 2013-10-26 06:54:54 +02:00
parent 5456bd5f89
commit 9ba1d41ec8
3 changed files with 12 additions and 2 deletions

View File

@ -1537,7 +1537,6 @@
this.body.expressions.unshift(this.ctor);
}
this.body.expressions.push(lname);
(_ref4 = this.body.expressions).unshift.apply(_ref4, this.directives);
call = Closure.wrap(this.body);
if (this.parent && call.args) {
this.superClass = new Literal(o.scope.freeVariable('super', false));
@ -1546,6 +1545,7 @@
params = call.variable.params || call.variable.base.params;
params.push(new Param(this.superClass));
}
(_ref4 = this.body.expressions).unshift.apply(_ref4, this.directives);
klass = new Parens(call, true);
if (this.variable) {
klass = new Assign(this.variable, klass);

View File

@ -1098,7 +1098,6 @@ exports.Class = class Class extends Base
@body.spaced = yes
@body.expressions.unshift @ctor unless @ctor instanceof Code
@body.expressions.push lname
@body.expressions.unshift @directives...
call = Closure.wrap @body
@ -1109,6 +1108,8 @@ exports.Class = class Class extends Base
params = call.variable.params or call.variable.base.params
params.push new Param @superClass
@body.expressions.unshift @directives...
klass = new Parens call, yes
klass = new Assign @variable, klass if @variable
klass.compileToFragments o

View File

@ -699,6 +699,15 @@ test "#2052: classes should work in strict mode", ->
catch e
ok no
test "directives in class with extends ", ->
strictTest = """
class extends Object
### comment ###
'use strict'
do -> eq this, undefined
"""
CoffeeScript.run strictTest, bare: yes
test "#2630: class bodies can't reference arguments", ->
throws ->
CoffeeScript.compile('class Test then arguments')