Support ObjectExpression in static path evaluation (#4746)

This commit is contained in:
Moti Zilberman
2016-10-18 01:55:02 +03:00
committed by Henry Zhu
parent d9dd32860a
commit 6bc10b5573
2 changed files with 32 additions and 2 deletions

View File

@@ -231,7 +231,34 @@ export function evaluate(): { confident: boolean; value: any } {
}
if (path.isObjectExpression()) {
// todo
let obj = {};
let props: Array<NodePath> = path.get("properties");
for (let prop of props) {
if (prop.isObjectMethod() || prop.isSpreadProperty()) {
return deopt(prop);
}
const keyPath = prop.get("key");
let key = keyPath;
if (prop.node.computed) {
key = key.evaluate();
if (!key.confident) {
return deopt(keyPath);
}
key = key.value;
} else if (key.isIdentifier()) {
key = key.node.name;
} else {
key = key.node.value;
}
const valuePath = prop.get("value");
let value = valuePath.evaluate();
if (!value.confident) {
return deopt(valuePath);
}
value = value.value;
obj[key] = value;
}
return obj;
}
if (path.isLogicalExpression()) {