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:
Geoffrey Booth
2017-04-06 15:23:14 -07:00
parent 7129f8347e
commit 0576eb3a10
3 changed files with 3 additions and 30 deletions

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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'}": ->
^^^
'''