fix destructuring of non string keys (#1989)

This commit is contained in:
kzc
2017-05-22 04:38:03 -04:00
committed by Alex Lam S.L
parent 5b22334f3b
commit a658cd84a5
2 changed files with 80 additions and 3 deletions

View File

@@ -2100,9 +2100,11 @@ merge(Compressor.prototype, {
else if (node.names[i] instanceof AST_Hole) { else if (node.names[i] instanceof AST_Hole) {
continue; continue;
} }
else if (node.names[i] instanceof AST_ObjectKeyVal && typeof node.names[i].key === "string") { else if (node.names[i] instanceof AST_ObjectKeyVal) {
if (typeof node.names[i].key === "string") {
initializations.add(node.names[i].key, destructuring_value); initializations.add(node.names[i].key, destructuring_value);
} }
}
else if (node.names[i] instanceof AST_Symbol) { else if (node.names[i] instanceof AST_Symbol) {
initializations.add(node.names[i].name, destructuring_value); initializations.add(node.names[i].name, destructuring_value);
} else { } else {

View File

@@ -328,5 +328,80 @@ issue_1886: {
let [a] = [1]; let [a] = [1];
console.log(a); console.log(a);
} }
expect_exact: "1" }
destructuring_decl_of_numeric_key: {
options = {
evaluate: true,
unused: true,
}
input: {
let { 3: x } = { [1 + 2]: 42 };
console.log(x);
}
expect: {
let { 3: x } = { [3]: 42 };
console.log(x);
}
expect_stdout: "42"
node_version: ">=6"
}
destructuring_decl_of_computed_key: {
options = {
evaluate: true,
unused: true,
}
input: {
let four = 4;
let { [7 - four]: x } = { [1 + 2]: 42 };
console.log(x);
}
expect: {
let four = 4;
let { [7 - four]: x } = { [3]: 42 };
console.log(x);
}
expect_stdout: "42"
node_version: ">=6"
}
destructuring_assign_of_numeric_key: {
options = {
evaluate: true,
unused: true,
}
input: {
let x;
({ 3: x } = { [1 + 2]: 42 });
console.log(x);
}
expect: {
let x;
({ 3: x } = { [3]: 42 });
console.log(x);
}
expect_stdout: "42"
node_version: ">=6"
}
destructuring_assign_of_computed_key: {
options = {
evaluate: true,
unused: true,
}
input: {
let x;
let four = 4;
({ [(5 + 2) - four]: x } = { [1 + 2]: 42 });
console.log(x);
}
expect: {
let x;
let four = 4;
({ [7 - four]: x } = { [3]: 42 });
console.log(x);
}
expect_stdout: "42"
node_version: ">=6"
} }