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

Added jsescOptions to Numeric Literals #11028

Merged
merged 9 commits into from Mar 16, 2020
24 changes: 21 additions & 3 deletions packages/babel-generator/src/generators/types.js
Expand Up @@ -120,13 +120,31 @@ export function NullLiteral() {

export function NumericLiteral(node: Object) {
const raw = this.getPossibleRaw(node);
const opts = this.format.jsescOption;
const value = node.value + "";
if (raw == null) {
this.number(value); // normalize
//normalize
if (this.format.jsescOption.numbers) {
this.number(jsesc(parseInt(value), opts));
} else {
this.number(value);
}
} else if (this.format.minified) {
this.number(raw.length < value.length ? raw : value);
if (this.format.jsescOption.numbers) {
this.number(
raw.length < value.length
? jsesc(parseInt(raw), opts)
: jsesc(parseInt(value), opts),
);
} else {
this.number(raw.length < value.length ? raw : value);
}
} else {
this.number(raw);
if (this.format.jsescOption.numbers) {
this.number(jsesc(parseInt(raw), opts));
} else {
this.number(raw);
}
}
}

Expand Down
@@ -0,0 +1 @@
let x = 42
@@ -0,0 +1,6 @@
{
"jsescOption": {
"numbers": "hexadecimal",
"lowercaseHex": true
}
}
@@ -0,0 +1 @@
let x = 0x2a;