From c3fe29455bc26c842ce3ca04f5ffc46dfebe2499 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Thu, 11 Aug 2011 01:52:10 -0400 Subject: [PATCH] finishing up fix for #1009: class @do; it's a little bit ugly, but it makes sense to do it this way --- lib/coffee-script/lexer.js | 2 +- lib/coffee-script/nodes.js | 4 ++-- src/lexer.coffee | 2 +- src/nodes.coffee | 2 +- test/classes.coffee | 7 +++++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/coffee-script/lexer.js b/lib/coffee-script/lexer.js index cd50b75d..2c6b3917 100644 --- a/lib/coffee-script/lexer.js +++ b/lib/coffee-script/lexer.js @@ -63,7 +63,7 @@ } } } - if (__indexOf.call(JS_FORBIDDEN, id) >= 0) { + if (__indexOf.call(['eval', 'arguments'].concat(JS_FORBIDDEN), id) >= 0) { if (forcedIdentifier) { tag = 'IDENTIFIER'; id = new String(id); diff --git a/lib/coffee-script/nodes.js b/lib/coffee-script/nodes.js index c13bf0bc..507f196d 100644 --- a/lib/coffee-script/nodes.js +++ b/lib/coffee-script/nodes.js @@ -333,8 +333,8 @@ } }; Literal.prototype.compileNode = function(o) { - var code; - code = this.isUndefined ? o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0' : this.value.reserved ? "\"" + this.value + "\"" : this.value; + var code, _ref2; + code = this.isUndefined ? o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0' : this.value.reserved && ((_ref2 = "" + this.value) !== 'eval' && _ref2 !== 'arguments') ? "\"" + this.value + "\"" : this.value; if (this.isStatement()) { return "" + this.tab + code + ";"; } else { diff --git a/src/lexer.coffee b/src/lexer.coffee index 2f73c8b1..41c10c99 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -104,7 +104,7 @@ exports.Lexer = class Lexer @tokens.pop() id = '!' + id - if id in JS_FORBIDDEN + if id in ['eval', 'arguments'].concat JS_FORBIDDEN if forcedIdentifier tag = 'IDENTIFIER' id = new String id diff --git a/src/nodes.coffee b/src/nodes.coffee index 05e8ad29..27ae002c 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -301,7 +301,7 @@ exports.Literal = class Literal extends Base compileNode: (o) -> code = if @isUndefined if o.level >= LEVEL_ACCESS then '(void 0)' else 'void 0' - else if @value.reserved + else if @value.reserved and "#{@value}" not in ['eval', 'arguments'] "\"#{@value}\"" else @value diff --git a/test/classes.coffee b/test/classes.coffee index 57b8f01d..ce933d69 100644 --- a/test/classes.coffee +++ b/test/classes.coffee @@ -501,8 +501,11 @@ test "#1464: bound class methods should keep context", -> eq nonce, C.boundStaticColon().id eq nonce2, C.boundStaticEqual().id -test "#1009: classes with reserved words as determined names", -> - eq 'function', typeof (-> class @for).call {} +test "#1009: classes with reserved words as determined names", -> (-> + eq 'function', typeof (class @for) + ok not /\beval\b/.test (class @eval).toString() + ok not /\barguments\b/.test (class @arguments).toString() +).call {} test "#1482: classes can extend expressions", -> id = (x) -> x