Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,11 @@ export class Tokenizer extends DiagnosticEmitter {
: DiagnosticCode.Multiple_consecutive_numeric_separators_are_not_permitted,
this.range(pos)
);
} else if (pos - 1 == start && text.charCodeAt(pos - 1) == CharCode._0) {
this.error(
DiagnosticCode.Numeric_separators_are_not_allowed_here,
this.range(pos)
);
}
sepEnd = pos + 1;
} else {
Expand Down Expand Up @@ -1497,9 +1502,7 @@ export class Tokenizer extends DiagnosticEmitter {
var text = this.source.text;
var end = this.end;
var start = this.pos;
var sepCount = 0;

sepCount += this.readDecimalFloatPartial(false);
var sepCount = this.readDecimalFloatPartial(false);
if (this.pos < end && text.charCodeAt(this.pos) == CharCode.DOT) {
++this.pos;
sepCount += this.readDecimalFloatPartial();
Expand All @@ -1518,7 +1521,7 @@ export class Tokenizer extends DiagnosticEmitter {
}
}
let result = text.substring(start, this.pos);
if (sepCount > 0) result = result.replaceAll("_", "");
if (sepCount) result = result.replaceAll("_", "");
return parseFloat(result);
}

Expand Down Expand Up @@ -1553,7 +1556,6 @@ export class Tokenizer extends DiagnosticEmitter {
} else if (!isDecimalDigit(c)) {
break;
}

++pos;
}

Expand Down
7 changes: 6 additions & 1 deletion tests/parser/numeric-separators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
1e2_; // 6188
1e-1__0; // 6189

0_0; // 6188
0_0.0; // 6188
0_0.0_0; // 6188
0_0e0_0; // 6188
0_0e0_0; // 6188

0x_11_11; // 6188
0o_11_11; // 6188
0b_11_11; // 6188
8 changes: 8 additions & 0 deletions tests/parser/numeric-separators.ts.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
0;
0;
0;
0;
4369;
585;
15;
// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(14,9+0)
// ERROR 6189: "Multiple consecutive numeric separators are not permitted." in numeric-separators.ts(15,4+0)
// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(17,11+0)
Expand All @@ -48,3 +52,7 @@
// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(38,2+0)
// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(39,2+0)
// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(40,2+0)
// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(41,2+0)
// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(43,3+0)
// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(44,3+0)
// ERROR 6188: "Numeric separators are not allowed here." in numeric-separators.ts(45,3+0)