mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
No longer throw an error on get or set function calls to objects with dynamic property names (introduces a way to circumvent our check for trying to avoid the get or set keywords, but not worth the complications for this tiny edge case)
This commit is contained in:
@@ -232,7 +232,7 @@
|
||||
}
|
||||
|
||||
stringToken() {
|
||||
var $, attempt, delimiter, doc, end, heredoc, i, indent, indentRegex, match, prev, quote, ref, ref1, regex, token, tokens;
|
||||
var $, attempt, delimiter, doc, end, heredoc, i, indent, indentRegex, match, prev, quote, ref, regex, token, tokens;
|
||||
[quote] = STRING_START.exec(this.chunk) || [];
|
||||
if (!quote) {
|
||||
return 0;
|
||||
@@ -241,9 +241,6 @@
|
||||
if (prev && this.value() === 'from' && (this.seenImport || this.seenExport)) {
|
||||
prev[0] = 'FROM';
|
||||
}
|
||||
if (prev && prev.spaced && (ref = prev[0], indexOf.call(CALLABLE, ref) >= 0) && /^[gs]et$/.test(prev[1])) {
|
||||
this.error(`'${prev[1]}' cannot be used as a keyword, or as a function call without parentheses`, prev[2]);
|
||||
}
|
||||
regex = (function() {
|
||||
switch (quote) {
|
||||
case "'":
|
||||
@@ -278,7 +275,7 @@
|
||||
})()).join('#{}');
|
||||
while (match = HEREDOC_INDENT.exec(doc)) {
|
||||
attempt = match[1];
|
||||
if (indent === null || (0 < (ref1 = attempt.length) && ref1 < indent.length)) {
|
||||
if (indent === null || (0 < (ref = attempt.length) && ref < indent.length)) {
|
||||
indent = attempt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,16 +245,12 @@ exports.Lexer = class Lexer
|
||||
[quote] = STRING_START.exec(@chunk) || []
|
||||
return 0 unless quote
|
||||
|
||||
prev = @prev()
|
||||
|
||||
# If the preceding token is `from` and this is an import or export statement,
|
||||
# properly tag the `from`.
|
||||
prev = @prev()
|
||||
if prev and @value() is 'from' and (@seenImport or @seenExport)
|
||||
prev[0] = 'FROM'
|
||||
|
||||
if prev and prev.spaced and prev[0] in CALLABLE and /^[gs]et$/.test(prev[1])
|
||||
@error "'#{prev[1]}' cannot be used as a keyword, or as a function call without parentheses", prev[2]
|
||||
|
||||
regex = switch quote
|
||||
when "'" then STRING_SINGLE
|
||||
when '"' then STRING_DOUBLE
|
||||
|
||||
@@ -1476,23 +1476,3 @@ test "setter keyword before static method", ->
|
||||
set @foo = ->
|
||||
^^^
|
||||
'''
|
||||
|
||||
test "getter keyword with dynamic property name", ->
|
||||
assertErrorFormat '''
|
||||
class A
|
||||
get "#{'foo'}": ->
|
||||
''', '''
|
||||
[stdin]:2:3: error: 'get' cannot be used as a keyword, or as a function call without parentheses
|
||||
get "#{'foo'}": ->
|
||||
^^^
|
||||
'''
|
||||
|
||||
test "setter keyword with dynamic property name", ->
|
||||
assertErrorFormat '''
|
||||
class A
|
||||
set "#{'foo'}": ->
|
||||
''', '''
|
||||
[stdin]:2:3: error: 'set' cannot be used as a keyword, or as a function call without parentheses
|
||||
set "#{'foo'}": ->
|
||||
^^^
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user