Skip to content

Commit 2d1addf

Browse files
committed
Allow get or set parentheses-less function calls when first argument is a string without a colon (so a plain string, not a property accessor)
1 parent 962374a commit 2d1addf

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lib/coffeescript/lexer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ exports.Lexer = class Lexer
252252
if prev and @value() is 'from' and (@seenImport or @seenExport)
253253
prev[0] = 'FROM'
254254

255-
if prev and prev.spaced and prev[0] in CALLABLE and /^[gs]et$/.test(prev[1])
255+
if prev and prev.spaced and prev[0] in CALLABLE and /^[gs]et$/.test(prev[1]) and /^\S*:\s/.test(@chunk)
256256
@error "'#{prev[1]}' cannot be used as a keyword, or as a function call without parentheses", prev[2]
257257

258258
regex = switch quote

test/function_invocation.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,15 +712,23 @@ test "get and set can be used as function names when not ambiguous with `get`/`s
712712
set = (val) -> val
713713
eq 2, get(2)
714714
eq 3, set(3)
715+
eq 2, get 2
716+
eq 3, set 3
715717
eq 'a', get('a')
716718
eq 'b', set('b')
719+
eq 'a', get 'a'
720+
eq 'b', set 'b'
717721

718722
get = ({val}) -> val
719723
set = ({val}) -> val
720724
eq 4, get({val: 4})
721725
eq 5, set({val: 5})
726+
eq 4, get {val: 4}
727+
eq 5, set {val: 5}
722728
eq 'c', get({val: 'c'})
723729
eq 'd', set({val: 'd'})
730+
eq 'c', get {val: 'c'}
731+
eq 'd', set {val: 'd'}
724732

725733
test "get and set can be used as variable and property names", ->
726734
get = 2

0 commit comments

Comments
 (0)