fix corner case in properties (#4830)

fixes #4829
This commit is contained in:
Alex Lam S.L
2021-04-01 00:05:50 +01:00
committed by GitHub
parent 6335b5fd8a
commit 1947a21824
2 changed files with 32 additions and 8 deletions

View File

@@ -11457,15 +11457,15 @@ merge(Compressor.prototype, {
if (prop.key != key) continue;
if (!all(props, can_hoist_property)) break;
if (!safe_to_flatten(prop.value, compressor)) break;
return make_node(AST_Sub, this, {
expression: make_node(AST_Array, expr, {
elements: props.map(function(prop) {
props = props.map(function(prop) {
return prop.value;
})
}),
property: make_node(AST_Number, this, {
value: i
})
});
if (prop instanceof AST_ObjectMethod && prop.value instanceof AST_Function) {
props[i] = make_node(AST_Arrow, prop.value, prop.value);
}
return make_node(AST_Sub, this, {
expression: make_node(AST_Array, expr, { elements: props }),
property: make_node(AST_Number, this, { value: i }),
});
}
}

View File

@@ -1344,3 +1344,27 @@ issue_4821_2: {
expect_stdout: "function"
node_version: ">=12"
}
issue_4829: {
options = {
properties: true,
}
input: {
"use strict";
try {
class A extends { f(){} }.f {}
} catch (e) {
console.log("PASS");
}
}
expect: {
"use strict";
try {
class A extends [ () => {} ][0] {}
} catch (e) {
console.log("PASS");
}
}
expect_stdout: "PASS"
node_version: ">=4"
}