File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7971,6 +7971,8 @@ const installMinify = (modules) => {
79717971 } else {
79727972 const next = /** @type {Token} */ (tables.of(sorted[low]));
79737973 next.comments_before = [...important, ...next.comments_before];
7974+ // The line break after them moves too, as in `keepCommentsOf`.
7975+ if (/** @type {Token} */ (tables.of(token)).nlb) next.nlb = true;
79747976 }
79757977 for (const comment of important) {
79767978 comments.splice(comments.indexOf(comment), 1);
@@ -28165,6 +28167,9 @@ const createTightenBody = (modules) => {
2816528167 if (!from || !to || from.comments_before.length === 0) return;
2816628168 to.comments_before = [...from.comments_before, ...to.comments_before];
2816728169 from.comments_before = [];
28170+ // The line break after them moves too: a banner before a dropped `;`
28171+ // still ends its line, as terser prints it.
28172+ if (from.nlb) to.nlb = true;
2816828173 }
2816928174
2817028175 /**
Original file line number Diff line number Diff line change @@ -6332,6 +6332,28 @@ describe("syntax-printer", () => {
63326332 ).toBe(reference.code);
63336333 });
63346334
6335+ it("should keep the line break after a banner before a dropped `;`, as terser prints it", async () => {
6336+ const { minify } = await load();
6337+ const code = "/*! license\n */\n;(function () { f(); })();";
6338+ const { code: printed } = await minify(code, {});
6339+ expect(printed).toBe("/*! license\n */\nf();");
6340+ expect((await minify(/** @type {string} */ (printed), formatOnly)).code).toBe(
6341+ printed
6342+ );
6343+ expect((await terserReference().minify(code, {})).code).toBe(printed);
6344+ });
6345+
6346+ it("should keep the line break after a license whose code was dropped, wherever it moves", async () => {
6347+ const { minify } = await load();
6348+ const code =
6349+ "function g() {\n/*! license\n */\nvar n = 50; return h(0, n); }\ng();";
6350+ const { code: printed } = await minify(code, {});
6351+ expect(printed).toBe("function g(){return h(0,\n/*! license\n */\n50)}g();");
6352+ expect((await minify(/** @type {string} */ (printed), formatOnly)).code).toBe(
6353+ printed
6354+ );
6355+ });
6356+
63356357 it("should print a directive as it is spelled, where an encoding doubled each backslash", async () => {
63366358 /**
63376359 * @param {string} code a program
You can’t perform that action at this time.
0 commit comments