Hoist omitted keys from object spread operator (#13384)
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user