Skip to content

Commit 6fe8c6a

Browse files
alexander-akaitclaude
authored andcommitted
fix(javascript): compress a function body outside the one pass, inside its function
Claude-Session: https://claude.ai/code/session_015gdnghKbLJ7VvJ5nNCNHhH
1 parent 0f826c7 commit 6fe8c6a

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9824,7 +9824,9 @@ const installMinify = (modules) => {
98249824
modules.onePass !== undefined &&
98259825
modules.onePass.enabled &&
98269826
Boolean(options.compress) &&
9827-
!(options.mangle && options.mangle.properties);
9827+
!(options.mangle && options.mangle.properties) &&
9828+
// A function's body compresses inside the function `wrapFunctionBody` builds.
9829+
!functionBody;
98289830
const printsNodes = nodesPrint && (options.mangle === false || onePass);
98299831
// A source printed as read is printed from a `SyntaxTree` of it.
98309832
const treeSource = sourcePrintedFromTree(

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15531,6 +15531,19 @@ describe("JavaScript minifier reading an event handler's body", () => {
1553115531
}
1553215532
});
1553315533

15534+
it("should compress a body inside its function with the one pass switched on", async () => {
15535+
const { minify, modules } = await load();
15536+
const source = "var v = 5; value = v; return value == null ? undefined : v";
15537+
const off = await minify(source, { sourceType: "event-handler" });
15538+
modules.onePass.enabled = true;
15539+
try {
15540+
const on = await minify(source, { sourceType: "event-handler" });
15541+
expect(on.code).toBe(off.code);
15542+
} finally {
15543+
modules.onePass.enabled = false;
15544+
}
15545+
});
15546+
1553415547
it("should refuse what a function's body cannot hold", async () => {
1553515548
const { minify } = await load();
1553615549
for (const source of ['import a from "b"', "#!x\n1"]) {

0 commit comments

Comments
 (0)