Skip to content

Commit 792b8bb

Browse files
YuichiNukiyamaweswigham
authored andcommitted
Fix error messeage (microsoft#20601)
* Fix error messeage * delete extra lint
1 parent eba15b5 commit 792b8bb

6 files changed

Lines changed: 64 additions & 42 deletions

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3424,6 +3424,10 @@
34243424
"category": "Error",
34253425
"code": 6188
34263426
},
3427+
"Multiple consecutive numeric separators are not permitted.": {
3428+
"category": "Error",
3429+
"code": 6189
3430+
},
34273431
"Variable '{0}' implicitly has an '{1}' type.": {
34283432
"category": "Error",
34293433
"code": 7005

src/compiler/scanner.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,15 +866,20 @@ namespace ts {
866866
function scanNumberFragment(): string {
867867
let start = pos;
868868
let allowSeparator = false;
869+
let isPreviousTokenSeparator = false;
869870
let result = "";
870871
while (true) {
871872
const ch = text.charCodeAt(pos);
872873
if (ch === CharacterCodes._) {
873874
tokenFlags |= TokenFlags.ContainsSeparator;
874875
if (allowSeparator) {
875876
allowSeparator = false;
877+
isPreviousTokenSeparator = true;
876878
result += text.substring(start, pos);
877879
}
880+
else if (isPreviousTokenSeparator) {
881+
error(Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted, pos, 1);
882+
}
878883
else {
879884
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos, 1);
880885
}
@@ -884,6 +889,7 @@ namespace ts {
884889
}
885890
if (isDigit(ch)) {
886891
allowSeparator = true;
892+
isPreviousTokenSeparator = false;
887893
pos++;
888894
continue;
889895
}
@@ -962,12 +968,17 @@ namespace ts {
962968
let digits = 0;
963969
let value = 0;
964970
let allowSeparator = false;
971+
let isPreviousTokenSeparator = false;
965972
while (digits < minCount || scanAsManyAsPossible) {
966973
const ch = text.charCodeAt(pos);
967974
if (canHaveSeparators && ch === CharacterCodes._) {
968975
tokenFlags |= TokenFlags.ContainsSeparator;
969976
if (allowSeparator) {
970977
allowSeparator = false;
978+
isPreviousTokenSeparator = true;
979+
}
980+
else if (isPreviousTokenSeparator) {
981+
error(Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted, pos, 1);
971982
}
972983
else {
973984
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos, 1);
@@ -990,6 +1001,7 @@ namespace ts {
9901001
}
9911002
pos++;
9921003
digits++;
1004+
isPreviousTokenSeparator = false;
9931005
}
9941006
if (digits < minCount) {
9951007
value = -1;
@@ -1287,13 +1299,18 @@ namespace ts {
12871299
// Similarly valid octalIntegerLiteral must have at least one octal digit following o or O.
12881300
let numberOfDigits = 0;
12891301
let separatorAllowed = false;
1302+
let isPreviousTokenSeparator = false;
12901303
while (true) {
12911304
const ch = text.charCodeAt(pos);
12921305
// Numeric seperators are allowed anywhere within a numeric literal, except not at the beginning, or following another separator
12931306
if (ch === CharacterCodes._) {
12941307
tokenFlags |= TokenFlags.ContainsSeparator;
12951308
if (separatorAllowed) {
12961309
separatorAllowed = false;
1310+
isPreviousTokenSeparator = true;
1311+
}
1312+
else if (isPreviousTokenSeparator) {
1313+
error(Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted, pos, 1);
12971314
}
12981315
else {
12991316
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos, 1);
@@ -1309,6 +1326,7 @@ namespace ts {
13091326
value = value * base + valueOfCh;
13101327
pos++;
13111328
numberOfDigits++;
1329+
isPreviousTokenSeparator = false;
13121330
}
13131331
// Invalid binaryIntegerLiteral or octalIntegerLiteral
13141332
if (numberOfDigits === 0) {

tests/baselines/reference/parser.numericSeparators.binaryNegative.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ tests/cases/conformance/parser/ecmascriptnext/numericSeparators/2.ts(1,3): error
33
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,2): error TS6188: Numeric separators are not allowed here.
44
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,3): error TS1005: ';' expected.
55
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,3): error TS2304: Cannot find name 'B0101'.
6-
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/4.ts(1,6): error TS6188: Numeric separators are not allowed here.
7-
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/5.ts(1,13): error TS6188: Numeric separators are not allowed here.
6+
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/4.ts(1,6): error TS6189: Multiple consecutive numeric separators are not permitted.
7+
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/5.ts(1,13): error TS6189: Multiple consecutive numeric separators are not permitted.
88
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/6.ts(1,3): error TS6188: Numeric separators are not allowed here.
99
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/6.ts(1,4): error TS6188: Numeric separators are not allowed here.
1010
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/6.ts(1,5): error TS6188: Numeric separators are not allowed here.
@@ -32,12 +32,12 @@ tests/cases/conformance/parser/ecmascriptnext/numericSeparators/6.ts(1,5): error
3232
==== tests/cases/conformance/parser/ecmascriptnext/numericSeparators/4.ts (1 errors) ====
3333
0b01__11
3434
~
35-
!!! error TS6188: Numeric separators are not allowed here.
35+
!!! error TS6189: Multiple consecutive numeric separators are not permitted.
3636

3737
==== tests/cases/conformance/parser/ecmascriptnext/numericSeparators/5.ts (1 errors) ====
3838
0B0110_0110__
3939
~
40-
!!! error TS6188: Numeric separators are not allowed here.
40+
!!! error TS6189: Multiple consecutive numeric separators are not permitted.
4141

4242
==== tests/cases/conformance/parser/ecmascriptnext/numericSeparators/6.ts (3 errors) ====
4343
0b___0111010_0101_1

0 commit comments

Comments
 (0)