@@ -2183,7 +2183,7 @@ Compressor.prototype.compress = function(node) {
|
||||
can_replace = replace;
|
||||
return signal_abort(node);
|
||||
}
|
||||
return handle_custom_scan_order(node, scanner);
|
||||
if (handle_custom_scan_order(node, scanner)) return signal_abort(node);
|
||||
}, signal_abort);
|
||||
var multi_replacer = new TreeTransformer(function(node) {
|
||||
if (abort) return node;
|
||||
@@ -2345,14 +2345,28 @@ Compressor.prototype.compress = function(node) {
|
||||
}
|
||||
|
||||
function handle_custom_scan_order(node, tt) {
|
||||
if (!(node instanceof AST_BlockScope)) {
|
||||
if (!(node instanceof AST_ClassProperty && !node.static)) return;
|
||||
// Skip non-static class property values
|
||||
if (node.key instanceof AST_Node) node.key = node.key.transform(tt);
|
||||
return node;
|
||||
}
|
||||
if (!(node instanceof AST_BlockScope)) return;
|
||||
// Skip (non-executed) functions
|
||||
if (node instanceof AST_Scope) return node;
|
||||
// Scan computed keys, static fields & initializers in class
|
||||
if (node instanceof AST_Class) {
|
||||
if (node.name) node.name = node.name.transform(tt);
|
||||
if (node.extends) node.extends = node.extends.transform(tt);
|
||||
node.properties.reduce(function(props, prop) {
|
||||
if (prop.key instanceof AST_Node) prop.key = prop.key.transform(tt);
|
||||
if (prop.static) {
|
||||
if (prop instanceof AST_ClassField) {
|
||||
props.push(prop);
|
||||
} else if (prop instanceof AST_ClassInit) {
|
||||
props.unshift(prop);
|
||||
}
|
||||
}
|
||||
return props;
|
||||
}, []).forEach(function(prop) {
|
||||
prop.value = prop.value.transform(tt);
|
||||
});
|
||||
return node;
|
||||
}
|
||||
// Scan object only in a for-in/of statement
|
||||
if (node instanceof AST_ForEnumeration) {
|
||||
node.object = node.object.transform(tt);
|
||||
|
||||
@@ -3143,3 +3143,39 @@ issue_5489_strict: {
|
||||
]
|
||||
node_version: ">=16"
|
||||
}
|
||||
|
||||
issue_5502: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
var a = "FAIL";
|
||||
class A {
|
||||
static p = a;
|
||||
[a = "PASS"];
|
||||
}
|
||||
try {
|
||||
b++;
|
||||
} finally {
|
||||
var a, b = 42;
|
||||
}
|
||||
console.log(a, b);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
var a = "FAIL";
|
||||
class A {
|
||||
static p = a;
|
||||
[a = "PASS"];
|
||||
}
|
||||
try {
|
||||
b++;
|
||||
} finally {
|
||||
var a, b = 42;
|
||||
}
|
||||
console.log(a, b);
|
||||
}
|
||||
expect_stdout: "PASS 42"
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user