Fix setting deopt properly after evaluating multiple expressions (#6882)
This commit is contained in:
parent
edbf5d33dc
commit
c583a04a55
@ -211,11 +211,11 @@ function _evaluate(path, state) {
|
|||||||
if (path.isArrayExpression()) {
|
if (path.isArrayExpression()) {
|
||||||
const arr = [];
|
const arr = [];
|
||||||
const elems: Array<NodePath> = path.get("elements");
|
const elems: Array<NodePath> = path.get("elements");
|
||||||
for (let elem of elems) {
|
for (const elem of elems) {
|
||||||
elem = elem.evaluate();
|
const elemValue = elem.evaluate();
|
||||||
|
|
||||||
if (elem.confident) {
|
if (elemValue.confident) {
|
||||||
arr.push(elem.value);
|
arr.push(elemValue.value);
|
||||||
} else {
|
} else {
|
||||||
return deopt(elem, state);
|
return deopt(elem, state);
|
||||||
}
|
}
|
||||||
@ -268,7 +268,7 @@ function _evaluate(path, state) {
|
|||||||
switch (node.operator) {
|
switch (node.operator) {
|
||||||
case "||":
|
case "||":
|
||||||
// TODO consider having a "truthy type" that doesn't bail on
|
// TODO consider having a "truthy type" that doesn't bail on
|
||||||
// left uncertainity but can still evaluate to truthy.
|
// left uncertainty but can still evaluate to truthy.
|
||||||
if (left && leftConfident) {
|
if (left && leftConfident) {
|
||||||
state.confident = true;
|
state.confident = true;
|
||||||
return left;
|
return left;
|
||||||
|
|||||||
@ -216,4 +216,48 @@ describe("evaluation", function() {
|
|||||||
"\\d",
|
"\\d",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("sets deopt properly when not confident after evaluating multiple expressions", () => {
|
||||||
|
const ast = parse(`
|
||||||
|
const parts = [foo, bar];
|
||||||
|
console.log(parts.join('-'));
|
||||||
|
`);
|
||||||
|
|
||||||
|
let result;
|
||||||
|
|
||||||
|
traverse(ast, {
|
||||||
|
MemberExpression: {
|
||||||
|
enter(path) {
|
||||||
|
result = path.get("object").evaluate();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(result.confident, false);
|
||||||
|
assert.strictEqual(result.deopt.type, "Identifier");
|
||||||
|
assert.strictEqual(result.deopt.node.name, "foo");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("sets deopt properly when confident after evaluating multiple expressions", () => {
|
||||||
|
const ast = parse(`
|
||||||
|
const foo = 'foo';
|
||||||
|
const bar = 'bar';
|
||||||
|
const parts = [foo, bar];
|
||||||
|
console.log(parts.join('-'))
|
||||||
|
`);
|
||||||
|
|
||||||
|
let result;
|
||||||
|
|
||||||
|
traverse(ast, {
|
||||||
|
MemberExpression: {
|
||||||
|
enter(path) {
|
||||||
|
result = path.get("object").evaluate();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(result.confident, true);
|
||||||
|
assert.strictEqual(result.deopt, null);
|
||||||
|
assert.deepStrictEqual(result.value, ["foo", "bar"]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user