Skip to content

Commit 58cf99d

Browse files
fix(minifier): read a case's class by its id when keeping a switch
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
1 parent 1f562ea commit 58cf99d

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38064,7 +38064,7 @@ const installStatementOptimizers = (modules, helpers) => {
3806438064
for (const statement of /** @type {Node[]} */ (branch.consequent)) {
3806538065
if (canBeExtractedFromIfBlock(statement)) continue;
3806638066
const names = A.isClassNode(statement)
38067-
? [statement.name]
38067+
? [statement.id]
3806838068
: /** @type {Node[]} */ (statement.declarations).map(
3806938069
(/** @type {Node} */ declaration) => declaration.id
3807038070
);

‎test/unitCases/syntax-printer.unittest.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3046,6 +3046,11 @@ const CORRECTED_CASES = [
30463046
'function f() { switch (1) { case 0: let s = 1; console.log(s); break; case 1: console.log(typeof s); default: console.log("d"); } } try { f(); } catch (e) { console.log(e.name); }',
30473047
{ compress: {}, mangle: false }
30483048
],
3049+
[
3050+
"a class of a case a constant `switch` skips, which a reached case reads in its dead zone",
3051+
'try { switch (1) { case 0: class C {} console.log("no"); case 1: console.log(typeof C); } } catch (e) { console.log(e.name); }',
3052+
{ compress: {}, mangle: false }
3053+
],
30493054
[
30503055
"a `var` of two names in a `default` before a calling case",
30513056
'var b = "outer"; function f(x) { switch (0) { default: var c, b; case x(): } for (var i = 0; i < 2; i++) b = x(b); return b; } console.log(f(function (v) { return v + 1; }), b);',

0 commit comments

Comments
 (0)