remove unnecessary hosting when using template strings (#13482)
This commit is contained in:
parent
dddb4133d2
commit
eb22659817
@ -190,7 +190,7 @@ export default declare((api, options) => {
|
|||||||
|
|
||||||
const keys = [];
|
const keys = [];
|
||||||
let allLiteral = true;
|
let allLiteral = true;
|
||||||
|
let hasTemplateLiteral = false;
|
||||||
for (let i = 0; i < pattern.properties.length; i++) {
|
for (let i = 0; i < pattern.properties.length; i++) {
|
||||||
const prop = pattern.properties[i];
|
const prop = pattern.properties[i];
|
||||||
|
|
||||||
@ -204,8 +204,9 @@ export default declare((api, options) => {
|
|||||||
const key = prop.key;
|
const key = prop.key;
|
||||||
if (t.isIdentifier(key) && !prop.computed) {
|
if (t.isIdentifier(key) && !prop.computed) {
|
||||||
keys.push(t.stringLiteral(key.name));
|
keys.push(t.stringLiteral(key.name));
|
||||||
} else if (t.isTemplateLiteral(prop.key)) {
|
} else if (t.isTemplateLiteral(key)) {
|
||||||
keys.push(t.cloneNode(prop.key));
|
keys.push(t.cloneNode(key));
|
||||||
|
hasTemplateLiteral = true;
|
||||||
} else if (t.isLiteral(key)) {
|
} else if (t.isLiteral(key)) {
|
||||||
keys.push(t.stringLiteral(String(key.value)));
|
keys.push(t.stringLiteral(String(key.value)));
|
||||||
} else {
|
} else {
|
||||||
@ -228,7 +229,7 @@ export default declare((api, options) => {
|
|||||||
t.memberExpression(keyExpression, t.identifier("map")),
|
t.memberExpression(keyExpression, t.identifier("map")),
|
||||||
[this.addHelper("toPropertyKey")],
|
[this.addHelper("toPropertyKey")],
|
||||||
);
|
);
|
||||||
} else if (!t.isProgram(this.scope.block)) {
|
} else if (!hasTemplateLiteral && !t.isProgram(this.scope.block)) {
|
||||||
// Hoist definition of excluded keys, so that it's not created each time.
|
// Hoist definition of excluded keys, so that it's not created each time.
|
||||||
const program = this.scope.path.findParent(path => path.isProgram());
|
const program = this.scope.path.findParent(path => path.isProgram());
|
||||||
const id = this.scope.generateUidIdentifier("excluded");
|
const id = this.scope.generateUidIdentifier("excluded");
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
const example = (obj) => {
|
||||||
|
const foo = 'foo';
|
||||||
|
const { [`prefix_${foo}`]: _, ...rest } = obj;
|
||||||
|
};
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
var example = obj => {
|
||||||
|
var foo = 'foo';
|
||||||
|
var _ = obj[`prefix_${foo}`],
|
||||||
|
rest = babelHelpers.objectWithoutProperties(obj, [`prefix_${foo}`]);
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user