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:
Siddhant N Trivedi 2020-03-17 03:36:32 +05:30 committed by GitHub
parent 4f394e30d2
commit f232d4d109
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 1 deletions

View File

@ -120,8 +120,11 @@ 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) {
if (opts.numbers) {
this.number(jsesc(node.value, opts));
} else if (raw == null) {
this.number(value); // normalize
} else if (this.format.minified) {
this.number(raw.length < value.length ? raw : value);

View File

@ -0,0 +1 @@
let x = 42

View File

@ -0,0 +1,6 @@
{
"jsescOption": {
"numbers": "hexadecimal",
"lowercaseHex": true
}
}

View File

@ -0,0 +1 @@
let x = 0x2a;