Fix path.evaluate for references before declarations (#4875)
This commit is contained in:
parent
3a27f49c57
commit
7e020272c1
@ -173,6 +173,10 @@ export function evaluate(): { confident: boolean; value: any } {
|
||||
return deopt(binding.path);
|
||||
}
|
||||
|
||||
if (binding && path.node.start < binding.path.node.end) {
|
||||
return deopt(binding.path);
|
||||
}
|
||||
|
||||
if (binding && binding.hasValue) {
|
||||
return binding.value;
|
||||
} else {
|
||||
|
||||
@ -86,4 +86,16 @@ describe("evaluation", function () {
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it("should deopt ids that are referenced before the bindings", function () {
|
||||
assert.strictEqual(
|
||||
getPath("let x = y + 5; let y = 5;").get("body.0.declarations.0.init").evaluate().confident,
|
||||
false
|
||||
);
|
||||
assert.strictEqual(
|
||||
getPath("if (typeof x === 'undefined') var x = {}")
|
||||
.get("body.0.test").evaluate().confident,
|
||||
false
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user