Skip to content

Commit 798f818

Browse files
alexander-akaitclaude
authored andcommitted
fix(javascript): write a computed number past plain digits in its shortest form under keep_numbers
Claude-Session: https://claude.ai/code/session_01UgQAw35dRJd9GKMF9p5CcQ
1 parent b877a84 commit 798f818

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39596,8 +39596,10 @@ const installEstreePrint = (modules) => {
3959639596
modules.corrections !== undefined &&
3959739597
modules.corrections.enabled
3959839598
) {
39599-
// A number the compressor computed has no source to keep, so it stays plain.
39600-
output.print(`${value}`);
39599+
// A number the compressor computed has no source to keep, so it stays
39600+
// plain unless only an exponent can write it, where the shortest one wins.
39601+
const plain = `${value}`;
39602+
output.print(plain.includes("e") ? makeNum(value) : plain);
3960139603
} else {
3960239604
output.print(makeNum(value));
3960339605
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6914,18 +6914,18 @@ describe("syntax-printer", () => {
69146914

69156915
it("should keep a number the compressor computes plain where keep_numbers is on", async () => {
69166916
const { minify, corrections } = await load();
6917-
const input = "var s = 1000; var m = s * 60; var h = m * 60; console.log(s, m, h, 0.5);";
6917+
const input = "var s = 1000; var m = s * 60; var h = m * 60; console.log(s, m, h, 0.5, 1e20 * 100);";
69186918
const options = { module: true, compress: {}, mangle: false, format: { keep_numbers: true } };
69196919
const { code } = await minify(input, options);
6920-
expect(code).toBe("console.log(1000,60000,3600000,0.5);");
6920+
expect(code).toBe("console.log(1000,60000,3600000,0.5,1e22);");
69216921

69226922
if (!corrections) throw new Error("the correct phase is not installed");
69236923
corrections.enabled = false;
69246924
try {
69256925
const uncorrected = await unimproved(() => minify(input, options));
69266926
const reference = await terserReference().minify(input, options);
69276927
expect(uncorrected.code).toBe(reference.code);
6928-
expect(reference.code).toBe("console.log(1e3,6e4,36e5,0.5);");
6928+
expect(reference.code).toBe("console.log(1e3,6e4,36e5,0.5,1e22);");
69296929
} finally {
69306930
corrections.enabled = true;
69316931
}

0 commit comments

Comments
 (0)