Skip to content

Commit

Permalink
fix corner case in properties (#4830)
Browse files Browse the repository at this point in the history
fixes #4829
  • Loading branch information
alexlamsl committed Mar 31, 2021
1 parent 6335b5f commit 1947a21
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/compress.js
Expand Up @@ -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;
props = props.map(function(prop) {
return prop.value;
});
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.map(function(prop) {
return prop.value;
})
}),
property: make_node(AST_Number, this, {
value: i
})
expression: make_node(AST_Array, expr, { elements: props }),
property: make_node(AST_Number, this, { value: i }),
});
}
}
Expand Down
24 changes: 24 additions & 0 deletions test/compress/classes.js
Expand Up @@ -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"
}

0 comments on commit 1947a21

Please sign in to comment.