Skip to content

Commit 47ad4eb

Browse files
authored
Merge pull request #957 from rhendric/fix/anaphorization
fix bug in anaphorization logic
2 parents aa4216b + dce6d07 commit 47ad4eb

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lib/ast.js

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

src/ast.ls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1863,10 +1863,11 @@ class exports.Existence extends Node implements Negatable
18631863
compile-node: (o) ->
18641864
node = @it.unwrap! <<< {@front}
18651865
code = [(node.compile o, LEVEL_OP + PREC\==)]
1866+
if @do-anaphorize
1867+
o.scope.declare \that Var \that
18661868
if node instanceof Var and not o.scope.check code.join(""), true
18671869
[op, eq] = if @negated then <[ || = ]> else <[ && ! ]>
18681870
if @do-anaphorize
1869-
o.scope.declare 'that' Var \that
18701871
[anaph-pre, anaph-post] = if @negated
18711872
then [["(that = undefined) || "], []]
18721873
else [[], [" && (that = ", ...code, ", true)"]]

test/existence.ls

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,6 @@ val = do ->
266266
while existent? and i--
267267
that
268268
eq val.join(' '), '5 4 3 2 1'
269+
270+
# Ensure `var that` is declared even if the tested variable exists
271+
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 commit comments

Comments
 (0)