Skip to content

Commit

Permalink
Use computed memberExpression for literal keys with object rest (#11550)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitos committed May 12, 2020
1 parent 0734754 commit 9a52019
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Expand Up @@ -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 =>
Expand Down
@@ -0,0 +1,7 @@
let useState = [{ some: 42 }, () => null];

let {
0: { numeric,...rest1 },
'2': { str,...rest2 },
1: setState,
} = useState;
@@ -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"]);

0 comments on commit 9a52019

Please sign in to comment.