Fix bug where path.evaluate treats repeated identifiers as undefined (#3557)
* babel-traverse: add test to demonstrate repeated identifiers being evaluated to `false` * fix typo: `value` -> `val` * path.evaluate: only mark item as resolved if we're confident
This commit is contained in:
parent
d0c82f0d8a
commit
aeb42c2228
@ -90,8 +90,10 @@ export function evaluate(): { confident: boolean; value: any } {
|
||||
seen.set(node, item);
|
||||
|
||||
let val = _evaluate(path);
|
||||
item.resolved = true;
|
||||
item.value = value;
|
||||
if (confident) {
|
||||
item.resolved = true;
|
||||
item.value = val;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,4 +37,18 @@ suite("evaluation", function () {
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
test("should work with repeated, indeterminate identifiers", function () {
|
||||
assert.strictEqual(
|
||||
getPath("var num = foo(); (num > 0 && num < 100);").get("body")[1].evaluateTruthy(),
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
test("should work with repeated, determinate identifiers", function () {
|
||||
assert.strictEqual(
|
||||
getPath("var num = 5; (num > 0 && num < 100);").get("body")[1].evaluateTruthy(),
|
||||
true
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user