diff --git a/lib/lexer.js b/lib/lexer.js index d7e40ee1..b400f427 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -617,7 +617,7 @@ JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED); exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS); IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/; - NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i; + NUMBER = /^0x[\da-f]+|^\d*\.?\d+(?:e[+-]?\d+)?/i; HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/; OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/; WHITESPACE = /^[^\n\S]+/; diff --git a/lib/nodes.js b/lib/nodes.js index 8089e702..48629a27 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -589,7 +589,7 @@ throw SyntaxError('cannot call super outside of a function.'); } name = method.name; - if (!name) { + if (name == null) { throw SyntaxError('cannot call super on an anonymous function.'); } if (method.klass) { @@ -1140,7 +1140,7 @@ return unfoldSoak(o, this, 'variable'); }; Assign.prototype.compileNode = function(o) { - var isValue, match, name, val, _ref2, _ref3, _ref4; + var isValue, match, name, val, _ref2, _ref3, _ref4, _ref5; if (isValue = this.variable instanceof Value) { if (this.variable.isArray() || this.variable.isObject()) { return this.compilePatternMatch(o); @@ -1167,7 +1167,7 @@ if (match[1]) { this.value.klass = match[1]; } - this.value.name = (_ref3 = (_ref4 = match[2]) != null ? _ref4 : match[3]) != null ? _ref3 : match[4]; + this.value.name = (_ref3 = (_ref4 = (_ref5 = match[2]) != null ? _ref5 : match[3]) != null ? _ref4 : match[4]) != null ? _ref3 : match[5]; } val = this.value.compile(o, LEVEL_LIST); if (this.context === 'object') { @@ -2263,7 +2263,7 @@ IDENTIFIER_STR = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*"; IDENTIFIER = RegExp("^" + IDENTIFIER_STR + "$"); SIMPLENUM = /^[+-]?\d+$/; - METHOD_DEF = RegExp("^(?:(" + IDENTIFIER_STR + ")\\.prototype(?:\\.(" + IDENTIFIER_STR + ")|\\[(\"(?:[^\"\\r\\n]|\\\\\")*\"|'(?:[^'\\r\\n]|\\\\')*')\\]))|(" + IDENTIFIER_STR + ")$"); + METHOD_DEF = RegExp("^(?:(" + IDENTIFIER_STR + ")\\.prototype(?:\\.(" + IDENTIFIER_STR + ")|\\[(\"(?:[^\\\\\"\\r\\n]|\\\\.)*\"|'(?:[^\\\\'\\r\\n]|\\\\.)*')\\]|\\[(0x[\\da-fA-F]+|\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\]))|(" + IDENTIFIER_STR + ")$"); IS_STRING = /^['"]/; utility = function(name) { var ref; diff --git a/src/lexer.coffee b/src/lexer.coffee index 3b7f68c4..965181b8 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -554,7 +554,7 @@ IDENTIFIER = /// ^ NUMBER = /// ^ 0x[\da-f]+ | # hex - ^ (?: \d+(\.\d+)? | \.\d+ ) (?:e[+-]?\d+)? # decimal + ^ \d*\.?\d+ (?:e[+-]?\d+)? # decimal ///i HEREDOC = /// ^ ("""|''') ([\s\S]*?) (?:\n[^\n\S]*)? \1 /// diff --git a/src/nodes.coffee b/src/nodes.coffee index 5652c755..73a60dad 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -467,7 +467,7 @@ exports.Call = class Call extends Base {method} = o.scope throw SyntaxError 'cannot call super outside of a function.' unless method {name} = method - throw SyntaxError 'cannot call super on an anonymous function.' unless name + throw SyntaxError 'cannot call super on an anonymous function.' unless name? if method.klass (new Value (new Literal method.klass), [new Access(new Literal "__super__"), new Access new Literal name]).compile o else @@ -934,7 +934,7 @@ exports.Assign = class Assign extends Base o.scope.find name if @value instanceof Code and match = METHOD_DEF.exec name @value.klass = match[1] if match[1] - @value.name = match[2] ? match[3] ? match[4] + @value.name = match[2] ? match[3] ? match[4] ? match[5] val = @value.compile o, LEVEL_LIST return "#{name}: #{val}" if @context is 'object' val = name + " #{ @context or '=' } " + val @@ -1802,19 +1802,19 @@ IDENTIFIER_STR = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*" IDENTIFIER = /// ^ #{IDENTIFIER_STR} $ /// SIMPLENUM = /^[+-]?\d+$/ METHOD_DEF = /// - ^ - (?: - (#{IDENTIFIER_STR}) - \.prototype - (?: - \.(#{IDENTIFIER_STR}) - | - \[("(?:[^"\r\n]|\\")*"|'(?:[^'\r\n]|\\')*')\] - ) - ) - | - (#{IDENTIFIER_STR}) - $ + ^ + (?: + (#{IDENTIFIER_STR}) + \.prototype + (?: + \.(#{IDENTIFIER_STR}) + | \[("(?:[^\\"\r\n]|\\.)*"|'(?:[^\\'\r\n]|\\.)*')\] + | \[(0x[\da-fA-F]+ | \d*\.?\d+ (?:[eE][+-]?\d+)?)\] + ) + ) + | + (#{IDENTIFIER_STR}) + $ /// # Is a literal value a string? diff --git a/test/classes.coffee b/test/classes.coffee index ea6808b6..44f9e1d9 100644 --- a/test/classes.coffee +++ b/test/classes.coffee @@ -486,3 +486,7 @@ test "#1380: `super` with reserved names", -> class C do: -> super ok C::do + + class B + 0: -> super + ok B::[0]