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 da5e355
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
Expand Up @@ -117,15 +117,22 @@ export default function ({ types: t }) {
}

let ref = this.originalPath.node.init;
const refPropertyPath = [];

path.findParent((path) => {
if (path.isObjectProperty()) {
ref = t.memberExpression(ref, t.identifier(path.node.key.name));
refPropertyPath.unshift(path.node.key.name);
} else if (path.isVariableDeclarator()) {
return true;
}
});

if (refPropertyPath.length) {
refPropertyPath.forEach((prop) => {
ref = t.memberExpression(ref, t.identifier(prop));
});
}

const [ argument, callExpression ] = createObjectSpread(
file,
path.parentPath.node.properties,
Expand Down
@@ -0,0 +1,15 @@
const test = {
foo: {
bar: {
baz: {
a: {
x: 1,
y: 2,
z: 3,
},
},
},
},
};

const { foo: { bar: { baz: { a: { x, ...other } } } } } = test;
@@ -0,0 +1,16 @@
const test = {
foo: {
bar: {
baz: {
a: {
x: 1,
y: 2,
z: 3
}
}
}
}
};

const { foo: { bar: { baz: { a: { x } } } } } = test,
other = babelHelpers.objectWithoutProperties(test.foo.bar.baz.a, ["x"]);
@@ -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 da5e355

Please sign in to comment.