mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
#1534 class then "use strict": herecomments fix
This commit is contained in:
@@ -1248,12 +1248,15 @@
|
||||
};
|
||||
|
||||
Class.prototype.checkStrict = function() {
|
||||
var node;
|
||||
if ((node = this.body.expressions[0]) instanceof Value) {
|
||||
if (/^['"]use strict['"]$/.test(node.unwrapAll().value)) {
|
||||
this.strict = true;
|
||||
return this.body.expressions.shift();
|
||||
}
|
||||
var i, node, _i, _len, _ref2;
|
||||
_ref2 = this.body.expressions;
|
||||
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
||||
node = _ref2[i];
|
||||
if (!(!(node instanceof Comment))) continue;
|
||||
if (!(node instanceof Value)) return;
|
||||
if (!/^['"]use strict['"]$/.test(node.unwrapAll().value)) return;
|
||||
this.body.expressions.splice(i, 1);
|
||||
return this.strict = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -917,10 +917,11 @@ exports.Class = class Class extends Base
|
||||
child.expressions = exps = flatten exps
|
||||
|
||||
checkStrict: ->
|
||||
if (node = @body.expressions[0]) instanceof Value
|
||||
if /^['"]use strict['"]$/.test node.unwrapAll().value
|
||||
@strict = yes
|
||||
@body.expressions.shift()
|
||||
for node,i in @body.expressions when node not instanceof Comment
|
||||
return unless node instanceof Value
|
||||
return unless /^['"]use strict['"]$/.test node.unwrapAll().value
|
||||
@body.expressions.splice i,1
|
||||
return @strict = yes
|
||||
|
||||
# Make sure that a constructor is defined for the class, and properly
|
||||
# configured.
|
||||
|
||||
@@ -625,9 +625,35 @@ test "#1534: class then 'use strict'", ->
|
||||
# function expression/declaration or Global code
|
||||
nonce = {}
|
||||
strictTest = 'do ->"use strict";arguments.callee'
|
||||
strictEnv = (try CoffeeScript.run strictTest, bare: yes catch e then nonce) is nonce
|
||||
return unless strictEnv
|
||||
throws (-> CoffeeScript.run "class then 'use strict';arguments.callee", bare: yes)
|
||||
doesNotThrow (-> CoffeeScript.run "class then arguments.callee", bare: yes)
|
||||
doesNotThrow (-> CoffeeScript.run 'class then arguments.callee;"use strict"', bare: yes)
|
||||
return unless (try CoffeeScript.run strictTest, bare: yes catch e then nonce) is nonce
|
||||
|
||||
class then arguments.callee
|
||||
class then arguments.callee;"use strict"
|
||||
throws -> CoffeeScript.run "class then 'use strict';arguments.callee", bare: yes
|
||||
|
||||
comments = ['''
|
||||
class
|
||||
### comment ###
|
||||
'use strict'
|
||||
arguments.callee''',
|
||||
'''
|
||||
class
|
||||
### comment 1 ###
|
||||
### comment 2 ###
|
||||
'use strict'
|
||||
arguments.callee''',
|
||||
'''
|
||||
class
|
||||
### comment 1 ###
|
||||
### comment 2 ###
|
||||
'use strict'
|
||||
arguments.callee
|
||||
### comment 3 ###''']
|
||||
throws (-> CoffeeScript.run comment, bare: yes) for comment in comments
|
||||
|
||||
class
|
||||
### comment 1 ###
|
||||
'unrestricted'
|
||||
'use strict'
|
||||
arguments.callee
|
||||
|
||||
|
||||
Reference in New Issue
Block a user