Use computed memberExpression for literal keys with object rest (#11550)

This commit is contained in:
Nikita Kirsanov 2020-05-12 22:56:03 +02:00 committed by GitHub
parent 07347544fd
commit 9a52019019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

@ -346,7 +346,11 @@ export default declare((api, opts) => {
);
refPropertyPath.forEach(prop => {
const { node } = prop;
ref = t.memberExpression(ref, t.cloneNode(node.key), node.computed);
ref = t.memberExpression(
ref,
t.cloneNode(node.key),
node.computed || t.isLiteral(node.key),
);
});
const objectPatternPath = path.findParent(path =>

View File

@ -0,0 +1,7 @@
let useState = [{ some: 42 }, () => null];
let {
0: { numeric,...rest1 },
'2': { str,...rest2 },
1: setState,
} = useState;

View File

@ -0,0 +1,14 @@
let useState = [{
some: 42
}, () => null];
let {
0: {
numeric
},
'2': {
str
},
1: setState
} = useState,
rest1 = babelHelpers.objectWithoutProperties(useState[0], ["numeric"]),
rest2 = babelHelpers.objectWithoutProperties(useState['2'], ["str"]);