Fixed issue with non-simple property paths in object-rest-spread loose mode (#8514)
* fix: object rest with default values bug fixes #8323 * rename variable
This commit is contained in:
parent
c5e3b6d4bc
commit
47e05d70f3
@ -96,10 +96,14 @@ export default declare((api, opts) => {
|
||||
const bindings = path.getOuterBindingIdentifierPaths();
|
||||
|
||||
Object.keys(bindings).forEach(bindingName => {
|
||||
if (path.scope.getBinding(bindingName).references > 1) {
|
||||
const bindingParentPath = bindings[bindingName].parentPath;
|
||||
if (
|
||||
path.scope.getBinding(bindingName).references > 1 ||
|
||||
!bindingParentPath.isObjectProperty()
|
||||
) {
|
||||
return;
|
||||
}
|
||||
bindings[bindingName].parentPath.remove();
|
||||
bindingParentPath.remove();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
8
packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-8323/input.js
vendored
Normal file
8
packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-8323/input.js
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
const get = () => {
|
||||
fireTheMissiles();
|
||||
return 3;
|
||||
};
|
||||
|
||||
const f = ({ a = get(), b, c, ...z }) => {
|
||||
const v = b + 3;
|
||||
};
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"presets": [ [ "env", { "targets": { "node": "8" } } ] ],
|
||||
"plugins": [ [ "proposal-object-rest-spread", { "loose": true } ] ]
|
||||
}
|
||||
16
packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-8323/output.js
vendored
Normal file
16
packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-8323/output.js
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
|
||||
const get = () => {
|
||||
fireTheMissiles();
|
||||
return 3;
|
||||
};
|
||||
|
||||
const f = (_ref) => {
|
||||
let {
|
||||
a = get(),
|
||||
b
|
||||
} = _ref,
|
||||
z = _objectWithoutPropertiesLoose(_ref, ["a", "b", "c"]);
|
||||
|
||||
const v = b + 3;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user