Skip to content

Commit 9321c22

Browse files
authored
fix(2356): omit numeric separators when targeting es2020 (#2358)
1 parent 2df6436 commit 9321c22

File tree

39 files changed

+113
-495
lines changed

39 files changed

+113
-495
lines changed

internal/compiler/emitter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func (e *emitter) emitJSFile(sourceFile *ast.SourceFile, jsFilePath string, sour
163163
SourceMap: options.SourceMap.IsTrue(),
164164
InlineSourceMap: options.InlineSourceMap.IsTrue(),
165165
InlineSources: options.InlineSources.IsTrue(),
166+
Target: options.Target,
166167
// !!!
167168
}
168169

internal/printer/printer.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type PrinterOptions struct {
3737
NoEmitHelpers bool
3838
// Module core.ModuleKind
3939
// ModuleResolution core.ModuleResolutionKind
40-
// Target core.ScriptTarget
40+
Target core.ScriptTarget
4141
SourceMap bool
4242
InlineSourceMap bool
4343
InlineSources bool
@@ -206,12 +206,13 @@ func (p *Printer) getLiteralTextOfNode(node *ast.LiteralLikeNode, sourceFile *as
206206
}
207207
}
208208
}
209-
210209
// !!! Printer option to control whether to terminate unterminated literals
211-
// !!! If necessary, printer option to control whether to preserve numeric separators
212210
if p.emitContext.EmitFlags(node)&EFNoAsciiEscaping != 0 {
213211
flags |= getLiteralTextFlagsNeverAsciiEscape
214212
}
213+
if p.Options.Target >= core.ScriptTargetES2021 {
214+
flags |= getLiteralTextFlagsAllowNumericSeparator
215+
}
215216
return getLiteralText(node, core.Coalesce(sourceFile, p.currentSourceFile), flags)
216217
}
217218

@@ -999,7 +1000,7 @@ func (p *Printer) emitLiteral(node *ast.LiteralLikeNode, flags getLiteralTextFla
9991000

10001001
func (p *Printer) emitNumericLiteral(node *ast.NumericLiteral) {
10011002
state := p.enterNode(node.AsNode())
1002-
p.emitLiteral(node.AsNode(), getLiteralTextFlagsAllowNumericSeparator)
1003+
p.emitLiteral(node.AsNode(), getLiteralTextFlagsNone)
10031004
p.exitNode(node.AsNode(), state)
10041005
}
10051006

internal/printer/printer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestEmit(t *testing.T) {
2323
{title: "StringLiteral#1", input: `;"test"`, output: ";\n\"test\";"},
2424
{title: "StringLiteral#2", input: `;'test'`, output: ";\n'test';"},
2525
{title: "NumericLiteral#1", input: `0`, output: `0;`},
26-
{title: "NumericLiteral#2", input: `10_000`, output: `10_000;`},
26+
{title: "NumericLiteral#2", input: `10_000`, output: `10000;`},
2727
{title: "BigIntLiteral#1", input: `0n`, output: `0n;`},
2828
{title: "BigIntLiteral#2", input: `10_000n`, output: `10000n;`}, // TODO: Preserve numeric literal separators after Strada migration
2929
{title: "BooleanLiteral#1", input: `true`, output: `true;`},

testdata/baselines/reference/submodule/compiler/numberLiteralsWithLeadingZeros.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ e5;
119119
850000;
120120
850000;
121121
0;
122-
.5_5;
122+
0.55;
123123
0;
124-
.5_5;
124+
0.55;
125125
1;
126-
.5_5;
126+
0.55;
127127
1;
128-
.5_5;
128+
0.55;
129129
8.55;
130130
8.55;
131131
0;
@@ -139,13 +139,13 @@ e5_5;
139139
8e+55;
140140
8e+55;
141141
0;
142-
.5_5e5_5;
142+
5.5e+54;
143143
0;
144-
.5_5e5_5;
144+
5.5e+54;
145145
1;
146-
.5_5e5_5;
146+
5.5e+54;
147147
1;
148-
.5_5e5_5;
148+
5.5e+54;
149149
8.55e+55;
150150
8.55e+55;
151151
0.55;

testdata/baselines/reference/submodule/compiler/numberLiteralsWithLeadingZeros.js.diff

Lines changed: 0 additions & 63 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/numericUnderscoredSeparator(target=es2015).js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
//// [numericUnderscoredSeparator.js]
11-
1_000_000_000_000;
12-
0b1010_0001_1000_0101;
13-
0b1010_0001_1000_0101;
14-
0xA0_B0_C0;
11+
1000000000000;
12+
41349;
13+
41349;
14+
10531008;

testdata/baselines/reference/submodule/compiler/numericUnderscoredSeparator(target=es2015).js.diff

Lines changed: 0 additions & 14 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/numericUnderscoredSeparator(target=es2016).js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
//// [numericUnderscoredSeparator.js]
11-
1_000_000_000_000;
12-
0b1010_0001_1000_0101;
13-
0b1010_0001_1000_0101;
14-
0xA0_B0_C0;
11+
1000000000000;
12+
41349;
13+
41349;
14+
10531008;

testdata/baselines/reference/submodule/compiler/numericUnderscoredSeparator(target=es2016).js.diff

Lines changed: 0 additions & 14 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/numericUnderscoredSeparator(target=es2017).js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
//// [numericUnderscoredSeparator.js]
11-
1_000_000_000_000;
12-
0b1010_0001_1000_0101;
13-
0b1010_0001_1000_0101;
14-
0xA0_B0_C0;
11+
1000000000000;
12+
41349;
13+
41349;
14+
10531008;

0 commit comments

Comments
 (0)