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

@@ -228,6 +228,18 @@ export default declare((api, options) => {
t.memberExpression(keyExpression, t.identifier("map")),
[this.addHelper("toPropertyKey")],
);
} else if (!t.isProgram(this.scope.block)) {
// Hoist definition of excluded keys, so that it's not created each time.
const program = this.scope.path.findParent(path => path.isProgram());
const id = this.scope.generateUidIdentifier("excluded");
program.scope.push({
id,
init: keyExpression,
kind: "const",
});
keyExpression = t.cloneNode(id);
}
value = t.callExpression(

View File

@@ -1,3 +1,4 @@
var _excluded = ["x"];
var z = {};
var _z = z,
x = Object.assign({}, _z);
@@ -10,7 +11,7 @@ var _z3 = z,
(function (_ref) {
var x = _ref.x,
y = babelHelpers.objectWithoutProperties(_ref, ["x"]);
y = babelHelpers.objectWithoutProperties(_ref, _excluded);
});
var _o = o;

View File

@@ -1,3 +1,4 @@
const _excluded = ["x"];
var z = {};
var _z = z,
x = babelHelpers.extends({}, _z);
@@ -10,7 +11,7 @@ var _z3 = z,
(function (_ref) {
let x = _ref.x,
y = babelHelpers.objectWithoutPropertiesLoose(_ref, ["x"]);
y = babelHelpers.objectWithoutPropertiesLoose(_ref, _excluded);
});
var _o = o;

View File

@@ -1,3 +1,4 @@
var _excluded = ["x"];
var z = {};
var _z = z,
x = babelHelpers.extends({}, _z);
@@ -10,7 +11,7 @@ var _z3 = z,
(function (_ref) {
var x = _ref.x,
y = babelHelpers.objectWithoutProperties(_ref, ["x"]);
y = babelHelpers.objectWithoutProperties(_ref, _excluded);
});
var _o = o;