Skip to content

Commit b3452c1

Browse files
committed
Fixes #2508 -- existential access of the prototype.
1 parent 47f0ea6 commit b3452c1

File tree

8 files changed

+139
-132
lines changed

8 files changed

+139
-132
lines changed

lib/coffee-script/grammar.js

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

lib/coffee-script/lexer.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/parser.js

Lines changed: 122 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/rewriter.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/grammar.coffee

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ grammar =
263263
Accessor: [
264264
o '. Identifier', -> new Access $2
265265
o '?. Identifier', -> new Access $2, 'soak'
266-
o ':: Identifier', -> [LOC(1)(new Access new Literal 'prototype'), LOC(2)(new Access $2)]
266+
o ':: Identifier', -> [LOC(1)(new Access new Literal('prototype')), LOC(2)(new Access $2)]
267+
o '?:: Identifier', -> [LOC(1)(new Access new Literal('prototype'), 'soak'), LOC(2)(new Access $2)]
267268
o '::', -> new Access new Literal 'prototype'
268269
o 'Index'
269270
]
@@ -576,7 +577,7 @@ grammar =
576577
#
577578
# (2 + 3) * 4
578579
operators = [
579-
['left', '.', '?.', '::']
580+
['left', '.', '?.', '::', '?::']
580581
['left', 'CALL_START', 'CALL_END']
581582
['nonassoc', '++', '--']
582583
['left', '?']

src/lexer.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ exports.Lexer = class Lexer
114114
@token 'OWN', id
115115
return id.length
116116
forcedIdentifier = colon or
117-
(prev = last @tokens) and (prev[0] in ['.', '?.', '::'] or
117+
(prev = last @tokens) and (prev[0] in ['.', '?.', '::', '?::'] or
118118
not prev.spaced and prev[0] is '@')
119119
tag = 'IDENTIFIER'
120120

@@ -678,7 +678,7 @@ exports.Lexer = class Lexer
678678
# Are we in the midst of an unfinished expression?
679679
unfinished: ->
680680
LINE_CONTINUER.test(@chunk) or
681-
@tag() in ['\\', '.', '?.', 'UNARY', 'MATH', '+', '-', 'SHIFT', 'RELATION'
681+
@tag() in ['\\', '.', '?.', '?::', 'UNARY', 'MATH', '+', '-', 'SHIFT', 'RELATION'
682682
'COMPARE', 'LOGIC', 'THROW', 'EXTENDS']
683683

684684
# Converts newlines for string literals.
@@ -771,7 +771,7 @@ OPERATOR = /// ^ (
771771
| >>>=? # zero-fill right shift
772772
| ([-+:])\1 # doubles
773773
| ([&|<>])\2=? # logic / shift
774-
| \?\. # soak access
774+
| \?(\.|::) # soak access
775775
| \.{2,3} # range or splat
776776
) ///
777777

src/rewriter.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class exports.Rewriter
270270
# .g b, ->
271271
# c
272272
# .h a
273-
if prevTag is 'OUTDENT' and inImplicitCall() and tag in ['.', '?.', '::']
273+
if prevTag is 'OUTDENT' and inImplicitCall() and tag in ['.', '?.', '::', '?::']
274274
endImplicitCall()
275275
return forward(1)
276276

test/operators.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,6 @@ test "#2567: Optimization of negated existential produces correct result", ->
293293
ok !(!a?)
294294
ok !b?
295295

296-
296+
test "#2508: Existential access of the prototype", ->
297+
eq NonExistent?::nothing, undefined
298+
ok Object?::toString

0 commit comments

Comments
 (0)