Added jsescOptions to Numeric Literals (#11028)
* Added jsescOptions to Numeric Literals * Added tests and hexadecimal opts to NumericLiterals * Fixed the bug of every numeric literal being coverted to hex * Added conditions when jsesc should be applied * Removed numbers and lowercaseHex from format object * Added newline to test of jsonEscape (to exclude the change) * Modified conditions to apply jsesc * Made the required changes. * Using node.value instead of value
This commit is contained in:
parent
4f394e30d2
commit
f232d4d109
@ -120,8 +120,11 @@ export function NullLiteral() {
|
|||||||
|
|
||||||
export function NumericLiteral(node: Object) {
|
export function NumericLiteral(node: Object) {
|
||||||
const raw = this.getPossibleRaw(node);
|
const raw = this.getPossibleRaw(node);
|
||||||
|
const opts = this.format.jsescOption;
|
||||||
const value = node.value + "";
|
const value = node.value + "";
|
||||||
if (raw == null) {
|
if (opts.numbers) {
|
||||||
|
this.number(jsesc(node.value, opts));
|
||||||
|
} else if (raw == null) {
|
||||||
this.number(value); // normalize
|
this.number(value); // normalize
|
||||||
} else if (this.format.minified) {
|
} else if (this.format.minified) {
|
||||||
this.number(raw.length < value.length ? raw : value);
|
this.number(raw.length < value.length ? raw : value);
|
||||||
|
|||||||
1
packages/babel-generator/test/fixtures/escapes/numeric-literals/input.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/escapes/numeric-literals/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
let x = 42
|
||||||
6
packages/babel-generator/test/fixtures/escapes/numeric-literals/options.json
vendored
Normal file
6
packages/babel-generator/test/fixtures/escapes/numeric-literals/options.json
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"jsescOption": {
|
||||||
|
"numbers": "hexadecimal",
|
||||||
|
"lowercaseHex": true
|
||||||
|
}
|
||||||
|
}
|
||||||
1
packages/babel-generator/test/fixtures/escapes/numeric-literals/output.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/escapes/numeric-literals/output.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
let x = 0x2a;
|
||||||
Loading…
x
Reference in New Issue
Block a user