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:
Jason Quense 2018-08-23 09:53:31 -04:00 committed by Mateusz Burzyński
parent c5e3b6d4bc
commit 47e05d70f3
4 changed files with 34 additions and 2 deletions

View File

@ -96,10 +96,14 @@ export default declare((api, opts) => {
const bindings = path.getOuterBindingIdentifierPaths(); const bindings = path.getOuterBindingIdentifierPaths();
Object.keys(bindings).forEach(bindingName => { 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; return;
} }
bindings[bindingName].parentPath.remove(); bindingParentPath.remove();
}); });
} }

View File

@ -0,0 +1,8 @@
const get = () => {
fireTheMissiles();
return 3;
};
const f = ({ a = get(), b, c, ...z }) => {
const v = b + 3;
};

View File

@ -0,0 +1,4 @@
{
"presets": [ [ "env", { "targets": { "node": "8" } } ] ],
"plugins": [ [ "proposal-object-rest-spread", { "loose": true } ] ]
}

View 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;
};