Skip to content

Commit 35787ef

Browse files
committed
Fixes #2567 -- optimize generated code with an existential is directly negated.
1 parent f029695 commit 35787ef

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/coffee-script/nodes.js

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

src/nodes.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,9 +1530,12 @@ exports.Op = class Op extends Base
15301530

15311531
# Compile a unary **Op**.
15321532
compileUnary: (o) ->
1533+
parts = [op = @operator]
1534+
if op is '!' and @first instanceof Existence
1535+
@first.negated = not @first.negated
1536+
return @first.compile o
15331537
if o.level >= LEVEL_ACCESS
15341538
return (new Parens this).compile o
1535-
parts = [op = @operator]
15361539
plusMinus = op in ['+', '-']
15371540
parts.push ' ' if op in ['new', 'typeof', 'delete'] or
15381541
plusMinus and @first instanceof Op and @first.operator is op

test/operators.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,10 @@ test "#2197: Existential existential double trouble", ->
281281
func = -> counter++
282282
func()? ? 100
283283
eq counter, 1
284+
285+
test "#2567: Optimization of negated existential produces correct result", ->
286+
a = 1
287+
ok !(!a?)
288+
ok !b?
289+
284290

0 commit comments

Comments
 (0)