Skip to content

Commit

Permalink
Allow get or set parentheses-less function calls when first argum…
Browse files Browse the repository at this point in the history
…ent is a string without a colon (so a plain string, not a property accessor)
  • Loading branch information
GeoffreyBooth committed Apr 6, 2017
1 parent 962374a commit 2d1addf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/coffeescript/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ exports.Lexer = class Lexer
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])
if prev and prev.spaced and prev[0] in CALLABLE and /^[gs]et$/.test(prev[1]) and /^\S*:\s/.test(@chunk)
@error "'#{prev[1]}' cannot be used as a keyword, or as a function call without parentheses", prev[2]

regex = switch quote
Expand Down
8 changes: 8 additions & 0 deletions test/function_invocation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -712,15 +712,23 @@ test "get and set can be used as function names when not ambiguous with `get`/`s
set = (val) -> val
eq 2, get(2)
eq 3, set(3)
eq 2, get 2
eq 3, set 3
eq 'a', get('a')
eq 'b', set('b')
eq 'a', get 'a'
eq 'b', set 'b'

get = ({val}) -> val
set = ({val}) -> val
eq 4, get({val: 4})
eq 5, set({val: 5})
eq 4, get {val: 4}
eq 5, set {val: 5}
eq 'c', get({val: 'c'})
eq 'd', set({val: 'd'})
eq 'c', get {val: 'c'}
eq 'd', set {val: 'd'}

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

0 comments on commit 2d1addf

Please sign in to comment.