Skip to content

Commit 6c7fc0c

Browse files
fix(javascript): keep a call whose argument prints as a value in the one pass
A call printed as its function's value prints each parameter as the name passed for it, which a moved function, a folded value or an inlined constant no longer declares: such a call prints as written. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC
1 parent cf4369e commit 6c7fc0c

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64526,6 +64526,31 @@ const createNodePrinter = (modules) => {
6452664526
}
6452764527
}
6452864528
}
64529+
// A parameter prints as the name passed, so a call prints as its value
64530+
// only where each name passed prints as itself, not what it is read as.
64531+
for (const [call, fn] of reducedCalls) {
64532+
const count = tree.fieldCount(Field.arguments, call);
64533+
for (let i = 0; i < count; i++) {
64534+
const argument = itemOf(i, Field.arguments, call);
64535+
if (
64536+
moveReads.has(argument) ||
64537+
collapsed.has(argument) ||
64538+
isInlinedRead(argument)
64539+
) {
64540+
reducing.delete(fn);
64541+
reducedCalls.delete(call);
64542+
const params = tree.fieldCount(Field.params, fn);
64543+
for (let j = 0; j < params; j++) {
64544+
substituted.delete(
64545+
/** @type {TreeDefinition[]} */ (mangledNames)[
64546+
tree.field(j, Field.params, fn)
64547+
]
64548+
);
64549+
}
64550+
break;
64551+
}
64552+
}
64553+
}
6452964554
};
6453064555

6453164556
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15365,6 +15365,12 @@ describe("JavaScript minifier printing a SyntaxTree", () => {
1536515365
{},
1536615366
"function f(n){return[(n=>n)(/*! a */n),function(){/*! b */return n}(),function(n){return n.a}(/*! c */n)]}"
1536715367
],
15368+
// A call prints as its value only where what it passes prints as named.
15369+
[
15370+
"(function () { var x = 7; function h(k) { return k() } function f(a) { var g = function () { return x }; return h(g) + a } g(f(3)) })(); (function () { function h(k) { return k + 1 } function f(a) { var c = 5; return h(c) + a } g(f(3)) })(); (function () { function h(k) { return k.v } function f(a) { var c = { v: 5 }; return h(c) + a } g(f(3)) })()",
15371+
{},
15372+
"(function(){g(function(n){return function(n){return n()}(function(){return 7})+n}(3))})();(function(){g(function(n){return function(n){return n+1}(5)+n}(3))})();(function(){g(function(n){return function(n){return n.v}({v:5})+n}(3))})();"
15373+
],
1536815374
[
1536915375
"function f(a){ if (0) x(); Math.PI }",
1537015376
{ compress: {toplevel: false,builtins_ecma: 2020},format: {comments: false} },

0 commit comments

Comments
 (0)