Skip to content

Commit 7cb3001

Browse files
fix(javascript): keep a license whose code the minifier drops where comments are left unset
Claude-Session: https://claude.ai/code/session_01UgQAw35dRJd9GKMF9p5CcQ
1 parent a9f16c7 commit 7cb3001

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8286,12 +8286,16 @@ const installMinify = (modules) => {
82868286
});
82878287
assignNativeLookups(compressor, modules.nativeObjects);
82888288
toplevel = compressor.compress(toplevel);
8289+
// Unset, the printer keeps what "some" does.
8290+
const comments = hasOwn(options.format, "comments")
8291+
? options.format.comments
8292+
: "some";
82898293
if (
8290-
options.format.comments &&
8294+
comments &&
82918295
modules.corrections !== undefined &&
82928296
modules.corrections.enabled
82938297
) {
8294-
keepImportantComments(toplevel, options.format.comments === "all");
8298+
keepImportantComments(toplevel, comments === "all");
82958299
}
82968300
}
82978301

‎test/unitCases/syntax-printer.unittest.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6793,7 +6793,9 @@ describe("syntax-printer", () => {
67936793
{ toplevel: true, format: { comments: "some" } },
67946794
"keep",
67956795
true
6796-
]
6796+
],
6797+
// Unset, `comments` keeps what "some" does.
6798+
["foo();\n/*! license */\nfunction unused() {}", { toplevel: true }, "license", true]
67976799
];
67986800
for (const [input, options, comment, terserDrops] of cases) {
67996801
const { code } = await minify(input, options);

0 commit comments

Comments
 (0)