Skip to content

Commit ebb4f5d

Browse files
fix(javascript): print a conditional's assignments in the one pass with mangle off (#22972)
With `mangle: false` the one pass has no definitions, so hoisting an assignment out of a conditional's branches threw reading them. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC
1 parent 420e8e1 commit ebb4f5d

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64616,7 +64616,7 @@ const createNodePrinter = (modules) => {
6461664616
) {
6461764617
return null;
6461864618
}
64619-
const definition = /** @type {TreeDefinition[]} */ (mangledNames)[target];
64619+
const definition = mangledNames === null ? null : mangledNames[target];
6462064620
return isMinifierVariable(definition) && !definition.undeclared
6462164621
? [operator, definition]
6462264622
: null;

‎test/unitCases/javascript/printer.unittest.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15310,6 +15310,12 @@ describe("JavaScript minifier printing a SyntaxTree", () => {
1531015310
{},
1531115311
"function f(n){return[(n=>n)(/*! a */n),function(){/*! b */return n}(),function(n){return n.a}(/*! c */n)]}"
1531215312
],
15313+
// Not mangled, no definition reads a name an assignment sets.
15314+
[
15315+
"function f(c) { var a; c ? a = 1 : a = 2; return a }",
15316+
{ mangle: false },
15317+
"function f(c){var a;c?a=1:a=2;return a}"
15318+
],
1531315319
[
1531415320
"function f(a){ if (0) x(); Math.PI }",
1531515321
{ compress: {toplevel: false,builtins_ecma: 2020},format: {comments: false} },

0 commit comments

Comments
 (0)