diff options
author | 2023-05-06 18:16:21 -0700 | |
---|---|---|
committer | 2023-05-06 18:16:21 -0700 | |
commit | 5327940132ca29eb721afbeb4709311d3622b9c5 (patch) | |
tree | d905b3135f0edddfe7c1e643b8befbef82cd1056 | |
parent | 54d5f59f09a753e9df649c6a05f3e18840b12888 (diff) | |
download | bun-5327940132ca29eb721afbeb4709311d3622b9c5.tar.gz bun-5327940132ca29eb721afbeb4709311d3622b9c5.tar.zst bun-5327940132ca29eb721afbeb4709311d3622b9c5.zip |
Fixes https://github.com/oven-sh/bun/issues/2810
-rw-r--r-- | src/js_ast.zig | 4 | ||||
-rw-r--r-- | test/transpiler/transpiler.test.js | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/js_ast.zig b/src/js_ast.zig index 6d69ff622..8b27cd0a8 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -1695,8 +1695,8 @@ pub const E = struct { pub const Number = struct { value: f64, - const double_digit = [_]string{ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100" }; - const neg_double_digit = [_]string{ "-0", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19", "-20", "-21", "-22", "-23", "-24", "-25", "-26", "-27", "-28", "-29", "-30", "-31", "-32", "-33", "-34", "-35", "-36", "-37", "-38", "-39", "-40", "-41", "-42", "-43", "-44", "-45", "-46", "-47", "-48", "-49", "-50", "-51", "-52", "-53", "-54", "-55", "-56", "-57", "-58", "-59", "-60", "-61", "-62", "-63", "-64", "-65", "-66", "-67", "-68", "-69", "-70", "-71", "-72", "-73", "-74", "-75", "-76", "-77", "-78", "-79", "-80", "-81", "-82", "-83", "-84", "-85", "-86", "-87", "-88", "-89", "-90", "-91", "-92", "-93", "-94", "-95", "-96", "-97", "-98", "-99", "-100" }; + const double_digit = [_]string{ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100" }; + const neg_double_digit = [_]string{ "-0", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19", "-20", "-21", "-22", "-23", "-24", "-25", "-26", "-27", "-28", "-29", "-30", "-31", "-32", "-33", "-34", "-35", "-36", "-37", "-38", "-39", "-40", "-41", "-42", "-43", "-44", "-45", "-46", "-47", "-48", "-49", "-50", "-51", "-52", "-53", "-54", "-55", "-56", "-57", "-58", "-59", "-60", "-61", "-62", "-63", "-64", "-65", "-66", "-67", "-68", "-69", "-70", "-71", "-72", "-73", "-74", "-75", "-76", "-77", "-78", "-79", "-80", "-81", "-82", "-83", "-84", "-85", "-86", "-87", "-88", "-89", "-90", "-91", "-92", "-93", "-94", "-95", "-96", "-97", "-98", "-99", "-100" }; /// String concatenation with numbers is required by the TypeScript compiler for /// "constant expression" handling in enums. However, we don't want to introduce diff --git a/test/transpiler/transpiler.test.js b/test/transpiler/transpiler.test.js index 1fc599771..bf51adba8 100644 --- a/test/transpiler/transpiler.test.js +++ b/test/transpiler/transpiler.test.js @@ -2635,6 +2635,16 @@ console.log(foo, array); }); it("constant folding", () => { + // we have an optimization for numbers 0 - 100, -0 - -100 so we must test those specifically + // https://github.com/oven-sh/bun/issues/2810 + for (let i = 1; i < 120; i++) { + const inner = "${" + i + " * 1}"; + expectPrinted("console.log(`" + inner + "`)", 'console.log("' + i + '")'); + + const innerNeg = "${" + -i + " * 1}"; + expectPrinted("console.log(`" + innerNeg + "`)", 'console.log("' + -i + '")'); + } + expectPrinted("1 && 2", "2"); expectPrinted("1 || 2", "1"); expectPrinted("0 && 1", "0"); |