Skip to content

Commit 8fa60d8

Browse files
Add comment
1 parent 0f211b7 commit 8fa60d8

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@
15491549
"category": "Error",
15501550
"code": 1484
15511551
},
1552-
"'{0}' is not allowed.": {
1552+
"Escape sequence '{0}' is not allowed.": {
15531553
"category": "Error",
15541554
"code": 1485
15551555
},

src/compiler/scanner.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,21 @@ export function createScanner(languageVersion: ScriptTarget,
14151415
return resultingToken;
14161416
}
14171417

1418+
// Extract from Section A.1
1419+
// EscapeSequence ::
1420+
// | CharacterEscapeSequence
1421+
// | 0 (?![0-9])
1422+
// | LegacyOctalEscapeSequence
1423+
// | NonOctalDecimalEscapeSequence
1424+
// | HexEscapeSequence
1425+
// | UnicodeEscapeSequence
1426+
// LegacyOctalEscapeSequence ::=
1427+
// | '0' (?=[89])
1428+
// | [1-7] (?![0-7])
1429+
// | [0-3] [0-7] (?![0-7])
1430+
// | [4-7] [0-7]
1431+
// | [0-3] [0-7] [0-7]
1432+
// NonOctalDecimalEscapeSequence ::= [89]
14181433
function scanEscapeSequence(shouldEmitInvalidEscapeError?: boolean): string {
14191434
const start = pos;
14201435
pos++;
@@ -1426,8 +1441,9 @@ export function createScanner(languageVersion: ScriptTarget,
14261441
pos++;
14271442
switch (ch) {
14281443
case CharacterCodes._0:
1429-
// '\08' is '\0' + '8' but is treated as an octal escape sequence, thus isDigit
1430-
if (!(pos < end && isDigit(text.charCodeAt(pos)))) {
1444+
// Although '0' preceding any digit is treated as LegacyOctalEscapeSequence,
1445+
// '\08' should separately be interpreted as '\0' + '8'.
1446+
if (pos >= end || !isDigit(text.charCodeAt(pos))) {
14311447
return "\0";
14321448
}
14331449
// '\01', '\011'
@@ -1462,7 +1478,7 @@ export function createScanner(languageVersion: ScriptTarget,
14621478
// the invalid '\8' and '\9'
14631479
tokenFlags |= TokenFlags.ContainsInvalidEscape;
14641480
if (shouldEmitInvalidEscapeError) {
1465-
error(Diagnostics._0_is_not_allowed, start, 2, text.substring(start, pos));
1481+
error(Diagnostics.Escape_sequence_0_is_not_allowed, start, pos - start, text.substring(start, pos));
14661482
return String.fromCharCode(ch);
14671483
}
14681484
return text.substring(start, pos);

0 commit comments

Comments
 (0)