diff --git a/lib/coffee-script/nodes.js b/lib/coffee-script/nodes.js index cea7a3f5..3d0a090d 100644 --- a/lib/coffee-script/nodes.js +++ b/lib/coffee-script/nodes.js @@ -1587,7 +1587,7 @@ }; Assign.prototype.compileNode = function(o) { - var answer, compiledName, isValue, match, name, val, varBase, _ref2, _ref3, _ref4, _ref5; + var answer, compiledName, isValue, match, name, val, varBase, _ref2, _ref3, _ref4; if (isValue = this.variable instanceof Value) { if (this.variable.isArray() || this.variable.isObject()) { return this.compilePatternMatch(o); @@ -1615,10 +1615,10 @@ } } if (this.value instanceof Code && (match = METHOD_DEF.exec(name))) { - if (match[1]) { + if (match[2]) { this.value.klass = match[1]; } - this.value.name = (_ref3 = (_ref4 = (_ref5 = match[2]) != null ? _ref5 : match[3]) != null ? _ref4 : match[4]) != null ? _ref3 : match[5]; + this.value.name = (_ref3 = (_ref4 = match[3]) != null ? _ref4 : match[4]) != null ? _ref3 : match[5]; } val = this.value.compileToFragments(o, LEVEL_LIST); if (this.context === 'object') { @@ -3025,7 +3025,7 @@ NUMBER = /^[+-]?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)$/i; - METHOD_DEF = RegExp("^(?:(" + IDENTIFIER_STR + ")\\.prototype(?:\\.(" + IDENTIFIER_STR + ")|\\[(\"(?:[^\\\\\"\\r\\n]|\\\\.)*\"|'(?:[^\\\\'\\r\\n]|\\\\.)*')\\]|\\[(0x[\\da-fA-F]+|\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\]))|(" + IDENTIFIER_STR + ")$"); + METHOD_DEF = RegExp("^(" + IDENTIFIER_STR + ")(\\.prototype)?(?:\\.(" + IDENTIFIER_STR + ")|\\[(\"(?:[^\\\\\"\\r\\n]|\\\\.)*\"|'(?:[^\\\\'\\r\\n]|\\\\.)*')\\]|\\[(0x[\\da-fA-F]+|\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\])$"); IS_STRING = /^['"]/; diff --git a/src/nodes.coffee b/src/nodes.coffee index 04b797df..591249c0 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1164,8 +1164,8 @@ exports.Assign = class Assign extends Base else 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] ? match[5] + @value.klass = match[1] if match[2] + @value.name = match[3] ? match[4] ? match[5] val = @value.compileToFragments o, LEVEL_LIST return (compiledName.concat @makeCode(": "), val) if @context is 'object' answer = compiledName.concat @makeCode(" #{ @context or '=' } "), val @@ -2141,21 +2141,14 @@ NUMBER = ///^[+-]?(?: \d*\.?\d+ (?:e[+-]?\d+)? # decimal )$///i -METHOD_DEF = /// - ^ - (?: - (#{IDENTIFIER_STR}) - \.prototype - (?: - \.(#{IDENTIFIER_STR}) - | \[("(?:[^\\"\r\n]|\\.)*"|'(?:[^\\'\r\n]|\\.)*')\] - | \[(0x[\da-fA-F]+ | \d*\.?\d+ (?:[eE][+-]?\d+)?)\] - ) - ) - | - (#{IDENTIFIER_STR}) - $ -/// +METHOD_DEF = /// ^ + (#{IDENTIFIER_STR}) + (\.prototype)? + (?: \.(#{IDENTIFIER_STR}) + | \[("(?:[^\\"\r\n]|\\.)*"|'(?:[^\\'\r\n]|\\.)*')\] + | \[(0x[\da-fA-F]+ | \d*\.?\d+ (?:[eE][+-]?\d+)?)\] + ) +$ /// # Is a literal value a string/regex? IS_STRING = /^['"]/ diff --git a/test/classes.coffee b/test/classes.coffee index ab8d78e4..f0db6d03 100644 --- a/test/classes.coffee +++ b/test/classes.coffee @@ -807,3 +807,12 @@ test "#3063: Class bodies cannot contain pure statements", -> return if S.f @f: => this """ + +test "#2949: super in static method with reserved name", -> + class Foo + @static: -> 'baz' + + class Bar extends Foo + @static: -> super + + eq Bar.static(), 'baz'