Fix incorrect property ordering with obj rest spread on nested (#5750)
This commit is contained in:
parent
5f866f2d92
commit
9a92933589
@ -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,
|
||||
|
||||
15
packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/nested-2/actual.js
vendored
Normal file
15
packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/nested-2/actual.js
vendored
Normal 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;
|
||||
@ -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"]);
|
||||
10
packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/nested/actual.js
vendored
Normal file
10
packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/nested/actual.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
const defunct = {
|
||||
outer: {
|
||||
inner: {
|
||||
three: 'three',
|
||||
four: 'four'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const { outer: { inner: { three, ...other } } } = defunct
|
||||
11
packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/nested/expected.js
vendored
Normal file
11
packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/nested/expected.js
vendored
Normal 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']);
|
||||
Loading…
x
Reference in New Issue
Block a user