From 84fb9a101f3701678067a8e678fc17774d6f58e1 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Mon, 30 Nov 2020 15:32:32 -0600 Subject: [PATCH] Fix printing BigIntLiterals and DecimalLiterals with compact option --- packages/babel-generator/src/generators/types.js | 8 ++++---- .../test/fixtures/types/BigIntLiteral-compact/input.js | 5 +++++ .../fixtures/types/BigIntLiteral-compact/options.json | 3 +++ .../test/fixtures/types/BigIntLiteral-compact/output.js | 1 + .../test/fixtures/types/DecimalLiteral-compact/input.js | 5 +++++ .../fixtures/types/DecimalLiteral-compact/options.json | 4 ++++ .../test/fixtures/types/DecimalLiteral-compact/output.js | 1 + 7 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 packages/babel-generator/test/fixtures/types/BigIntLiteral-compact/input.js create mode 100644 packages/babel-generator/test/fixtures/types/BigIntLiteral-compact/options.json create mode 100644 packages/babel-generator/test/fixtures/types/BigIntLiteral-compact/output.js create mode 100644 packages/babel-generator/test/fixtures/types/DecimalLiteral-compact/input.js create mode 100644 packages/babel-generator/test/fixtures/types/DecimalLiteral-compact/options.json create mode 100644 packages/babel-generator/test/fixtures/types/DecimalLiteral-compact/output.js diff --git a/packages/babel-generator/src/generators/types.js b/packages/babel-generator/src/generators/types.js index 0b70c7a3d976..12054bad46ac 100644 --- a/packages/babel-generator/src/generators/types.js +++ b/packages/babel-generator/src/generators/types.js @@ -216,19 +216,19 @@ export function StringLiteral(node: Object) { export function BigIntLiteral(node: Object) { const raw = this.getPossibleRaw(node); if (!this.format.minified && raw != null) { - this.token(raw); + this.word(raw); return; } - this.token(node.value + "n"); + this.word(node.value + "n"); } export function DecimalLiteral(node: Object) { const raw = this.getPossibleRaw(node); if (!this.format.minified && raw != null) { - this.token(raw); + this.word(raw); return; } - this.token(node.value + "m"); + this.word(node.value + "m"); } export function PipelineTopicExpression(node: Object) { diff --git a/packages/babel-generator/test/fixtures/types/BigIntLiteral-compact/input.js b/packages/babel-generator/test/fixtures/types/BigIntLiteral-compact/input.js new file mode 100644 index 000000000000..33a5bc422ae0 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/BigIntLiteral-compact/input.js @@ -0,0 +1,5 @@ +function a() { return 100n; } +function b() { return 9223372036854775807n; } +function c() { return 0o16432n; } +function d() { return 0xFFF123n; } +function e() { return 0b101011101n; } diff --git a/packages/babel-generator/test/fixtures/types/BigIntLiteral-compact/options.json b/packages/babel-generator/test/fixtures/types/BigIntLiteral-compact/options.json new file mode 100644 index 000000000000..eb4e948bfaa5 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/BigIntLiteral-compact/options.json @@ -0,0 +1,3 @@ +{ + "compact": true +} diff --git a/packages/babel-generator/test/fixtures/types/BigIntLiteral-compact/output.js b/packages/babel-generator/test/fixtures/types/BigIntLiteral-compact/output.js new file mode 100644 index 000000000000..e36496116af3 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/BigIntLiteral-compact/output.js @@ -0,0 +1 @@ +function a(){return 100n;}function b(){return 9223372036854775807n;}function c(){return 0o16432n;}function d(){return 0xFFF123n;}function e(){return 0b101011101n;} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/DecimalLiteral-compact/input.js b/packages/babel-generator/test/fixtures/types/DecimalLiteral-compact/input.js new file mode 100644 index 000000000000..8c40bfa2d3ec --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/DecimalLiteral-compact/input.js @@ -0,0 +1,5 @@ +function a() { return 100m; } +function b() { return 9223372036854775807m; } +function c() { return 0.m; } +function d() { return 3.1415926535897932m; } +function e() { return 100.000m; } diff --git a/packages/babel-generator/test/fixtures/types/DecimalLiteral-compact/options.json b/packages/babel-generator/test/fixtures/types/DecimalLiteral-compact/options.json new file mode 100644 index 000000000000..2157de4fdfae --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/DecimalLiteral-compact/options.json @@ -0,0 +1,4 @@ +{ + "compact": true, + "plugins": ["decimal"] +} diff --git a/packages/babel-generator/test/fixtures/types/DecimalLiteral-compact/output.js b/packages/babel-generator/test/fixtures/types/DecimalLiteral-compact/output.js new file mode 100644 index 000000000000..c5ba781b93c2 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/DecimalLiteral-compact/output.js @@ -0,0 +1 @@ +function a(){return 100m;}function b(){return 9223372036854775807m;}function c(){return 0.m;}function d(){return 3.1415926535897932m;}function e(){return 100.000m;} \ No newline at end of file