Skip to content

Commit 14b99f3

Browse files
alexander-akaitclaude
authored andcommitted
fix(javascript): wrap a handler body around enclose, not inside it
Claude-Session: https://claude.ai/code/session_015gdnghKbLJ7VvJ5nNCNHhH
1 parent f0f9a95 commit 14b99f3

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9917,11 +9917,11 @@ const installMinify = (modules) => {
99179917
annotatedProperties = findAnnotatedProperties(toplevel);
99189918
}
99199919
if (options.wrap) toplevel = ast.wrapCommonjs(toplevel, options.wrap);
9920+
if (options.enclose) toplevel = ast.wrapEnclose(toplevel, options.enclose);
99209921
// Compressed inside a function, so every rule a function's body reads by
9921-
// holds; printed without it.
9922+
// holds; printed without it, so it wraps every other wrapper.
99229923
const wrapsBody = functionBody && Boolean(options.compress);
99239924
if (wrapsBody) toplevel = ast.wrapFunctionBody(toplevel);
9924-
if (options.enclose) toplevel = ast.wrapEnclose(toplevel, options.enclose);
99259925
if (
99269926
!options.wrap &&
99279927
!options.enclose &&

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14991,6 +14991,17 @@ describe("JavaScript minifier reading an event handler's body", () => {
1499114991
}
1499214992
});
1499314993

14994+
it("should wrap a body as `wrap` and `enclose` ask, inside its function", async () => {
14995+
const { minify } = await load();
14996+
for (const given of [{ enclose: true }, { wrap: "lib" }]) {
14997+
const { code } = await minify("x(); return 1", {
14998+
...given,
14999+
sourceType: "event-handler"
15000+
});
15001+
expect(code).toMatch(/x\(\)/);
15002+
}
15003+
});
15004+
1499415005
it("should refuse what a function's body cannot hold", async () => {
1499515006
const { minify } = await load();
1499615007
for (const source of ['import a from "b"', "#!x\n1"]) {

0 commit comments

Comments
 (0)