Skip to content

Commit

Permalink
Merge pull request #957 from rhendric/fix/anaphorization
Browse files Browse the repository at this point in the history
fix bug in anaphorization logic
  • Loading branch information
gkz authored Mar 10, 2017
2 parents aa4216b + dce6d07 commit 47ad4eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/ast.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/ast.ls
Original file line number Diff line number Diff line change
Expand Up @@ -1863,10 +1863,11 @@ class exports.Existence extends Node implements Negatable
compile-node: (o) ->
node = @it.unwrap! <<< {@front}
code = [(node.compile o, LEVEL_OP + PREC\==)]
if @do-anaphorize
o.scope.declare \that Var \that
if node instanceof Var and not o.scope.check code.join(""), true
[op, eq] = if @negated then <[ || = ]> else <[ && ! ]>
if @do-anaphorize
o.scope.declare 'that' Var \that
[anaph-pre, anaph-post] = if @negated
then [["(that = undefined) || "], []]
else [[], [" && (that = ", ...code, ", true)"]]
Expand Down
3 changes: 3 additions & 0 deletions test/existence.ls
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,6 @@ val = do ->
while existent? and i--
that
eq val.join(' '), '5 4 3 2 1'

# Ensure `var that` is declared even if the tested variable exists
eq 'var a, that, b;\na = 0;\nif ((that = a) != null) {\n b = that;\n}', LiveScript.compile 'a = 0; b = that if a?' {+bare,-header}

0 comments on commit 47ad4eb

Please sign in to comment.