Skip to content

Commit 7c6f378

Browse files
Fix jashkenas#4836: functions named get or set can be used without parentheses when attached to @ (jashkenas#4837)
1 parent 12fcbfc commit 7c6f378

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

lib/coffeescript/lexer.js

Lines changed: 2 additions & 2 deletions
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
@@ -197,7 +197,7 @@ exports.Lexer = class Lexer
197197
else
198198
prevprev = @tokens[@tokens.length - 2]
199199
if prev[0] in ['@', 'THIS'] and prevprev and prevprev.spaced and /^[gs]et$/.test(prevprev[1]) and
200-
@tokens[@tokens.length - 3][0] isnt '.'
200+
@tokens[@tokens.length - 3][0] not in ['.', '@']
201201
@error "'#{prevprev[1]}' cannot be used as a keyword, or as a function call without parentheses", prevprev[2]
202202

203203
if tag is 'IDENTIFIER' and id in RESERVED

test/function_invocation.coffee

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ test "get and set can be used as class method names", ->
795795
eq 4, B.get()
796796
eq 5, B.set()
797797

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

837837
eq 16, b.get value: @ten
838838
eq 17, b.set value: @ten
839+
840+
test "#4836: functions named get or set can be used without parentheses when attached to this or @", ->
841+
@get = (x) -> x + 2
842+
@set = (x) -> x + 3
843+
@a = 4
844+
845+
eq 12, this.get 10
846+
eq 13, this.set 10
847+
eq 6, this.get @a
848+
eq 7, this.set @a
849+
850+
eq 12, @get 10
851+
eq 13, @set 10
852+
eq 6, @get @a
853+
eq 7, @set @a

0 commit comments

Comments
 (0)