diff options
author | 2021-11-15 15:51:39 -0800 | |
---|---|---|
committer | 2021-11-15 15:51:39 -0800 | |
commit | 01d1f1d258a6706b4221028ed89c58ea94e0ec69 (patch) | |
tree | d2a1387bb6e8a74221ddb46a900850b2f0f57f7f | |
parent | 4e775d275c33ae67d583732d2c3649dc89a0002d (diff) | |
download | bun-01d1f1d258a6706b4221028ed89c58ea94e0ec69.tar.gz bun-01d1f1d258a6706b4221028ed89c58ea94e0ec69.tar.zst bun-01d1f1d258a6706b4221028ed89c58ea94e0ec69.zip |
Fix #66
embarassing!
-rw-r--r-- | integration/scripts/snippets.json | 3 | ||||
-rw-r--r-- | integration/snippets/number-literal-bug.js | 11 | ||||
-rw-r--r-- | src/js_printer.zig | 2 |
3 files changed, 14 insertions, 2 deletions
diff --git a/integration/scripts/snippets.json b/integration/scripts/snippets.json index a37394c1c..5d91a845e 100644 --- a/integration/scripts/snippets.json +++ b/integration/scripts/snippets.json @@ -23,5 +23,6 @@ "/jsx-spacing.jsx", "/jsx-entities.jsx", "/optional-chain-with-function.js", - "/template-literal.js" + "/template-literal.js", + "/number-literal-bug.js" ] diff --git a/integration/snippets/number-literal-bug.js b/integration/snippets/number-literal-bug.js new file mode 100644 index 000000000..cb6990348 --- /dev/null +++ b/integration/snippets/number-literal-bug.js @@ -0,0 +1,11 @@ +// test that we don't call functions on number literals +export function test() { + const precision = 10; + try { + parseFloat((0.0).toPrecision(precision) + "1"); + } catch (exception) { + throw new Error("Test Failed", exception); + } + + testDone(import.meta.url); +} diff --git a/src/js_printer.zig b/src/js_printer.zig index 584cc45be..5f994d5f5 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -1175,7 +1175,7 @@ pub fn NewPrinter( const isOptionalChain = (e.optional_chain orelse js_ast.OptionalChain.ccontinue) == js_ast.OptionalChain.start; if (p.canPrintIdentifier(e.name)) { - if (isOptionalChain and p.prev_num_end == p.writer.written) { + if (!isOptionalChain and p.prev_num_end == p.writer.written) { // "1.toString" is a syntax error, so print "1 .toString" instead p.print(" "); } |