Hoist omitted keys from object spread operator (#13384)

This commit is contained in:
Alan Orozco
2021-05-28 09:32:30 -07:00
committed by GitHub
parent 612f19fbdc
commit f35513fbaa
21 changed files with 110 additions and 35 deletions

View File

@@ -178,6 +178,20 @@ export default declare((api, opts) => {
);
} else {
keyExpression = t.arrayExpression(keys);
if (!t.isProgram(path.scope.block)) {
// Hoist definition of excluded keys, so that it's not created each time.
const program = path.findParent(path => path.isProgram());
const id = path.scope.generateUidIdentifier("excluded");
program.scope.push({
id,
init: keyExpression,
kind: "const",
});
keyExpression = t.cloneNode(id);
}
}
return [