Preserve separators in numeric literals with target=ES2021+ (#57144)

This commit is contained in:
Dan Vanderkam 2024-02-15 17:26:42 -05:00 committed by GitHub
parent da5f0fe9d4
commit f41a5f5986
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 198 additions and 1 deletions

View File

@ -5657,7 +5657,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
const flags = (neverAsciiEscape ? GetLiteralTextFlags.NeverAsciiEscape : 0)
| (jsxAttributeEscape ? GetLiteralTextFlags.JsxAttributeEscape : 0)
| (printerOptions.terminateUnterminatedLiterals ? GetLiteralTextFlags.TerminateUnterminatedLiterals : 0)
| (printerOptions.target && printerOptions.target === ScriptTarget.ESNext ? GetLiteralTextFlags.AllowNumericSeparator : 0);
| (printerOptions.target && printerOptions.target >= ScriptTarget.ES2021 ? GetLiteralTextFlags.AllowNumericSeparator : 0);
return getLiteralText(node, currentSourceFile, flags);
}

View File

@ -0,0 +1,34 @@
//// [tests/cases/conformance/parser/ecmascript2021/numericSeparators/parser.numericSeparators.decimal.ts] ////
//// [parser.numericSeparators.decimal.ts]
1_000_000_000
1.1_00_01
1e1_0
1e+1_0
1e-1_0
1.1e10_0
1.1e+10_0
1.1e-10_0
12_34_56
1_22_333
1_2.3_4
1_2.3_4e5_6
1_2.3_4e+5_6
1_2.3_4e-5_6
//// [parser.numericSeparators.decimal.js]
1_000_000_000;
1.1_00_01;
1e1_0;
1e+1_0;
1e-1_0;
1.1e10_0;
1.1e+10_0;
1.1e-10_0;
12_34_56;
1_22_333;
1_2.3_4;
1_2.3_4e5_6;
1_2.3_4e+5_6;
1_2.3_4e-5_6;

View File

@ -0,0 +1,19 @@
//// [tests/cases/conformance/parser/ecmascript2021/numericSeparators/parser.numericSeparators.decimal.ts] ////
=== parser.numericSeparators.decimal.ts ===
1_000_000_000
1.1_00_01
1e1_0
1e+1_0
1e-1_0
1.1e10_0
1.1e+10_0
1.1e-10_0
12_34_56
1_22_333
1_2.3_4
1_2.3_4e5_6
1_2.3_4e+5_6
1_2.3_4e-5_6

View File

@ -0,0 +1,45 @@
//// [tests/cases/conformance/parser/ecmascript2021/numericSeparators/parser.numericSeparators.decimal.ts] ////
=== parser.numericSeparators.decimal.ts ===
1_000_000_000
>1_000_000_000 : 1000000000
1.1_00_01
>1.1_00_01 : 1.10001
1e1_0
>1e1_0 : 10000000000
1e+1_0
>1e+1_0 : 10000000000
1e-1_0
>1e-1_0 : 1e-10
1.1e10_0
>1.1e10_0 : 1.1e+100
1.1e+10_0
>1.1e+10_0 : 1.1e+100
1.1e-10_0
>1.1e-10_0 : 1.1e-100
12_34_56
>12_34_56 : 123456
1_22_333
>1_22_333 : 122333
1_2.3_4
>1_2.3_4 : 12.34
1_2.3_4e5_6
>1_2.3_4e5_6 : 1.234e+57
1_2.3_4e+5_6
>1_2.3_4e+5_6 : 1.234e+57
1_2.3_4e-5_6
>1_2.3_4e-5_6 : 1.234e-55

View File

@ -0,0 +1,34 @@
//// [tests/cases/conformance/parser/ecmascript2021/numericSeparators/parser.numericSeparators.decimal.ts] ////
//// [parser.numericSeparators.decimal.ts]
1_000_000_000
1.1_00_01
1e1_0
1e+1_0
1e-1_0
1.1e10_0
1.1e+10_0
1.1e-10_0
12_34_56
1_22_333
1_2.3_4
1_2.3_4e5_6
1_2.3_4e+5_6
1_2.3_4e-5_6
//// [parser.numericSeparators.decimal.js]
1000000000;
1.10001;
10000000000;
10000000000;
1e-10;
1.1e+100;
1.1e+100;
1.1e-100;
123456;
122333;
12.34;
1.234e+57;
1.234e+57;
1.234e-55;

View File

@ -0,0 +1,19 @@
//// [tests/cases/conformance/parser/ecmascript2021/numericSeparators/parser.numericSeparators.decimal.ts] ////
=== parser.numericSeparators.decimal.ts ===
1_000_000_000
1.1_00_01
1e1_0
1e+1_0
1e-1_0
1.1e10_0
1.1e+10_0
1.1e-10_0
12_34_56
1_22_333
1_2.3_4
1_2.3_4e5_6
1_2.3_4e+5_6
1_2.3_4e-5_6

View File

@ -0,0 +1,45 @@
//// [tests/cases/conformance/parser/ecmascript2021/numericSeparators/parser.numericSeparators.decimal.ts] ////
=== parser.numericSeparators.decimal.ts ===
1_000_000_000
>1_000_000_000 : 1000000000
1.1_00_01
>1.1_00_01 : 1.10001
1e1_0
>1e1_0 : 10000000000
1e+1_0
>1e+1_0 : 10000000000
1e-1_0
>1e-1_0 : 1e-10
1.1e10_0
>1.1e10_0 : 1.1e+100
1.1e+10_0
>1.1e+10_0 : 1.1e+100
1.1e-10_0
>1.1e-10_0 : 1.1e-100
12_34_56
>12_34_56 : 123456
1_22_333
>1_22_333 : 122333
1_2.3_4
>1_2.3_4 : 12.34
1_2.3_4e5_6
>1_2.3_4e5_6 : 1.234e+57
1_2.3_4e+5_6
>1_2.3_4e+5_6 : 1.234e+57
1_2.3_4e-5_6
>1_2.3_4e-5_6 : 1.234e-55

View File

@ -1,3 +1,4 @@
// @target: es5, es2020, es2021
1_000_000_000
1.1_00_01
1e1_0