Skip to content

Commit

Permalink
Fix incorrect property ordering with obj rest spread on nested
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism committed May 1, 2017
1 parent 7ca8170 commit 8b55a58
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/babel-plugin-transform-object-rest-spread/src/index.js
Expand Up @@ -117,15 +117,27 @@ export default function ({ types: t }) {
}

let ref = this.originalPath.node.init;
let refProperty = null;

path.findParent((path) => {
if (path.isObjectProperty()) {
ref = t.memberExpression(ref, t.identifier(path.node.key.name));
const id = t.identifier(path.node.key.name);

if (refProperty) {
ref = t.memberExpression(ref, id);
} else {
refProperty = id;
}

} else if (path.isVariableDeclarator()) {
return true;
}
});

if (refProperty) {
ref = t.memberExpression(ref, refProperty);
}

const [ argument, callExpression ] = createObjectSpread(
file,
path.parentPath.node.properties,
Expand Down
@@ -0,0 +1,10 @@
const defunct = {
outer: {
inner: {
three: 'three',
four: 'four'
}
}
}

const { outer: { inner: { three, ...other } } } = defunct
@@ -0,0 +1,11 @@
const defunct = {
outer: {
inner: {
three: 'three',
four: 'four'
}
}
};

const { outer: { inner: { three } } } = defunct,
other = babelHelpers.objectWithoutProperties(defunct.outer.inner, ['three']);

0 comments on commit 8b55a58

Please sign in to comment.