Fix incorrect property ordering with obj rest spread on nested (#5750)

This commit is contained in:
Brian Ng 2017-05-20 08:08:23 -05:00 committed by Henry Zhu
parent 5f866f2d92
commit 9a92933589
5 changed files with 60 additions and 1 deletions

View File

@ -107,15 +107,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,

View File

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

View File

@ -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"]);

View File

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

View File

@ -0,0 +1,11 @@
const defunct = {
outer: {
inner: {
three: 'three',
four: 'four'
}
}
};
const { outer: { inner: { three } } } = defunct,
other = babelHelpers.objectWithoutProperties(defunct.outer.inner, ['three']);