Skip to content

Commit 75d376f

Browse files
Fix: comprehension as postfix conditional (#5310)
Co-authored-by: Geoffrey Booth <[email protected]>
1 parent 3136bde commit 75d376f

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

lib/coffeescript/nodes.js

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

src/nodes.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4527,7 +4527,7 @@ exports.Elision = class Elision extends Base
45274527
# it, all other loops can be manufactured. Useful in cases where you need more
45284528
# flexibility or more speed than a comprehension can provide.
45294529
exports.While = class While extends Base
4530-
constructor: (@condition, {@invert, @guard, @isLoop} = {}) ->
4530+
constructor: (@condition, {invert: @inverted, @guard, @isLoop} = {}) ->
45314531
super()
45324532

45334533
children: ['condition', 'guard', 'body']
@@ -4578,7 +4578,7 @@ exports.While = class While extends Base
45784578
answer
45794579

45804580
processedCondition: ->
4581-
@processedConditionCache ?= if @invert then @condition.invert() else @condition
4581+
@processedConditionCache ?= if @inverted then @condition.invert() else @condition
45824582

45834583
astType: -> 'WhileStatement'
45844584

@@ -4587,7 +4587,7 @@ exports.While = class While extends Base
45874587
test: @condition.ast o, LEVEL_PAREN
45884588
body: @body.ast o, LEVEL_TOP
45894589
guard: @guard?.ast(o) ? null
4590-
inverted: !!@invert
4590+
inverted: !!@inverted
45914591
postfix: !!@postfix
45924592
loop: !!@isLoop
45934593

test/comprehensions.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,3 +613,8 @@ test "for pattern variables can linebreak/indent", ->
613613
anotherNonexistentElement
614614
] in listOfArrays
615615
eq a, 2
616+
617+
test "#5309: comprehension as postfix condition", ->
618+
doesNotThrowCompileError """
619+
throw new Error "DOOM was called with a null element" unless elm? for elm in elms
620+
"""

0 commit comments

Comments
 (0)