Skip to content

Commit b84f46c

Browse files
alexander-akaitclaude
authored andcommitted
fix(javascript): let sourceType name the parse's production over parse.module
Claude-Session: https://claude.ai/code/session_015gdnghKbLJ7VvJ5nNCNHhH
1 parent 12bd33f commit b84f46c

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9712,7 +9712,11 @@ const installMinify = (modules) => {
97129712
const { sourceType } = options;
97139713
const functionBody =
97149714
sourceType === "event-handler" || sourceType === "commonjs";
9715-
if (sourceType !== undefined) options.module = sourceType === "module";
9715+
// It names the production over any `module` given, the parse's included.
9716+
if (sourceType !== undefined) {
9717+
options.module = sourceType === "module";
9718+
options.parse = { ...options.parse, module: options.module };
9719+
}
97169720
if (functionBody) {
97179721
options.parse = { ...options.parse, [PARSE_FUNCTION_BODY]: sourceType };
97189722
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15038,6 +15038,18 @@ describe("JavaScript minifier reading an event handler's body", () => {
1503815038
}
1503915039
});
1504015040

15041+
it("should read a body as `sourceType` says over a `module` given", async () => {
15042+
const { minify } = await load();
15043+
for (const sourceType of /** @type {const} */ (["event-handler", "commonjs"])) {
15044+
const { code } = await minify("x(); return 1", {
15045+
sourceType,
15046+
module: true,
15047+
parse: { module: true }
15048+
});
15049+
expect(code).toMatch(/^return x\(\),1;?$/);
15050+
}
15051+
});
15052+
1504115053
it("should refuse what a function's body cannot hold", async () => {
1504215054
const { minify } = await load();
1504315055
for (const source of ['import a from "b"', "#!x\n1"]) {

0 commit comments

Comments
 (0)