Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix printing BigIntLiterals/DecimalLiterals with compact option #12424

Merged
merged 1 commit into from Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/babel-generator/src/generators/types.js
Expand Up @@ -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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolo-ribaudo @JLHwung we could also use this.number here if clearer (though there's logic in there for handling integer tokens), thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe let's add a comment explaining that we use word instead of number to avoid that additional logic?

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) {
Expand Down
@@ -0,0 +1,5 @@
function a() { return 100n; }
function b() { return 9223372036854775807n; }
function c() { return 0o16432n; }
function d() { return 0xFFF123n; }
function e() { return 0b101011101n; }
@@ -0,0 +1,3 @@
{
"compact": true
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -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; }
@@ -0,0 +1,4 @@
{
"compact": true,
"plugins": ["decimal"]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.