Added error for IdentifierStart immediately after a NumericLiteral

Fixes #4702.
This commit is contained in:
Josh Goldberg
2018-12-04 17:59:20 -08:00
parent 2103ed69e6
commit 174816fc26
18 changed files with 643 additions and 87 deletions

View File

@@ -1011,6 +1011,10 @@
"category": "Message",
"code": 1350
},
"An identifier cannot follow a numeric literal.": {
"category": "Error",
"code": 1351
},
"Duplicate identifier '{0}'.": {
"category": "Error",

View File

@@ -974,7 +974,10 @@ namespace ts {
else {
result = text.substring(start, end); // No need to use all the fragments; no _ removal needed
}
checkForIdentifierAfterNumericLiteral();
if (decimalFragment !== undefined || tokenFlags & TokenFlags.Scientific) {
checkForIdentifierAfterNumericLiteral();
return {
type: SyntaxKind.NumericLiteral,
value: "" + +result // if value is not an integer, it can be safely coerced to a number
@@ -983,10 +986,17 @@ namespace ts {
else {
tokenValue = result;
const type = checkBigIntSuffix(); // if value is an integer, check whether it is a bigint
checkForIdentifierAfterNumericLiteral();
return { type, value: tokenValue };
}
}
function checkForIdentifierAfterNumericLiteral() {
if (isIdentifierStart(text.charCodeAt(pos), languageVersion)) {
error(Diagnostics.An_identifier_cannot_follow_a_numeric_literal, pos, 1);
}
}
function scanOctalDigits(): number {
const start = pos;
while (isOctalDigit(text.charCodeAt(pos))) {