Fix path.evaluate for references before declarations (#4875)

This commit is contained in:
Boopathi Rajaa 2016-11-21 04:44:56 +01:00 committed by Henry Zhu
parent 3a27f49c57
commit 7e020272c1
2 changed files with 16 additions and 0 deletions

View File

@ -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 {

View File

@ -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
);
});
});