Skip to content

Commit

Permalink
Fix jashkenas#4836: functions named get or set can be used without pa…
Browse files Browse the repository at this point in the history
…rentheses when attached to @ (jashkenas#4837)
  • Loading branch information
GeoffreyBooth authored Jan 6, 2018
1 parent 12fcbfc commit 7c6f378
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions 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 @@ -197,7 +197,7 @@ exports.Lexer = class Lexer
else
prevprev = @tokens[@tokens.length - 2]
if prev[0] in ['@', 'THIS'] and prevprev and prevprev.spaced and /^[gs]et$/.test(prevprev[1]) and
@tokens[@tokens.length - 3][0] isnt '.'
@tokens[@tokens.length - 3][0] not in ['.', '@']
@error "'#{prevprev[1]}' cannot be used as a keyword, or as a function call without parentheses", prevprev[2]

if tag is 'IDENTIFIER' and id in RESERVED
Expand Down
17 changes: 16 additions & 1 deletion test/function_invocation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ test "get and set can be used as class method names", ->
eq 4, B.get()
eq 5, B.set()

test "functions named get or set can be used without parentheses when attached to an object; #4524", ->
test "#4524: functions named get or set can be used without parentheses when attached to an object", ->
obj =
get: (x) -> x + 2
set: (x) -> x + 3
Expand Down Expand Up @@ -836,3 +836,18 @@ test "functions named get or set can be used without parentheses when attached t

eq 16, b.get value: @ten
eq 17, b.set value: @ten

test "#4836: functions named get or set can be used without parentheses when attached to this or @", ->
@get = (x) -> x + 2
@set = (x) -> x + 3
@a = 4

eq 12, this.get 10
eq 13, this.set 10
eq 6, this.get @a
eq 7, this.set @a

eq 12, @get 10
eq 13, @set 10
eq 6, @get @a
eq 7, @set @a

0 comments on commit 7c6f378

Please sign in to comment.