1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Fix #4836: functions named get or set can be used without parentheses when attached to @ (#4837)

This commit is contained in:
Geoffrey Booth 2018-01-06 13:58:43 -08:00 committed by GitHub
parent 12fcbfc654
commit 7c6f3788ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View file

@ -111,7 +111,7 @@
// referenced as property names here, so you can still do `jQuery.is()` even
// though `is` means `===` otherwise.
identifierToken() {
var alias, colon, colonOffset, colonToken, id, idLength, inCSXTag, input, match, poppedToken, prev, prevprev, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, regExSuper, regex, sup, tag, tagToken;
var alias, colon, colonOffset, colonToken, id, idLength, inCSXTag, input, match, poppedToken, prev, prevprev, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, regExSuper, regex, sup, tag, tagToken;
inCSXTag = this.atCSXTag();
regex = inCSXTag ? CSX_ATTRIBUTE : IDENTIFIER;
if (!(match = regex.exec(this.chunk))) {
@ -203,7 +203,7 @@
this.error(`'${prev[1]}' cannot be used as a keyword, or as a function call without parentheses`, prev[2]);
} else {
prevprev = this.tokens[this.tokens.length - 2];
if (((ref8 = prev[0]) === '@' || ref8 === 'THIS') && prevprev && prevprev.spaced && /^[gs]et$/.test(prevprev[1]) && this.tokens[this.tokens.length - 3][0] !== '.') {
if (((ref8 = prev[0]) === '@' || ref8 === 'THIS') && prevprev && prevprev.spaced && /^[gs]et$/.test(prevprev[1]) && ((ref9 = this.tokens[this.tokens.length - 3][0]) !== '.' && ref9 !== '@')) {
this.error(`'${prevprev[1]}' cannot be used as a keyword, or as a function call without parentheses`, prevprev[2]);
}
}

View file

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

View file

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