Skip to content

Commit

Permalink
fix(lexer): \8 \9 are acceptable in web compatibility mode
Browse files Browse the repository at this point in the history
closes #137
  • Loading branch information
3cp committed Oct 29, 2020
1 parent 756d990 commit 26a19a8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/lexer/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ export function parseEscape(parser: ParserState, context: Context, first: number
return code;
}

// `8`, `9` (invalid escapes)
case Chars.Eight:
case Chars.Nine:
return Escape.EightOrNine;

// HexEscapeSequence
// \x HexDigit HexDigit
case Chars.LowerX: {
Expand Down Expand Up @@ -215,6 +210,11 @@ export function parseEscape(parser: ParserState, context: Context, first: number
}
}

// `8`, `9` (invalid escapes)
case Chars.Eight:
case Chars.Nine:
if ((context & Context.OptionsWebCompat) === 0) return Escape.EightOrNine;

default:
return first;
}
Expand Down
7 changes: 6 additions & 1 deletion test/lexer/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ describe('Lexer - String', () => {
[Context.None, Token.StringLiteral, '"\\302"', 'Â'],
[Context.None, Token.StringLiteral, '"\\000"', '\u0000'],
[Context.None, Token.StringLiteral, '"\\104"', 'D'],
[Context.None, Token.StringLiteral, '"\\221"', '‘']
[Context.None, Token.StringLiteral, '"\\221"', '‘'],

// \8 \9 are acceptable in web compatibility mode
[Context.OptionsWebCompat, Token.StringLiteral, '"\\8"', '8'],
[Context.OptionsWebCompat, Token.StringLiteral, '"\\9"', '9'],
[Context.OptionsWebCompat, Token.StringLiteral, '"\\9999"', '9999']
];

for (const [ctx, token, op, value] of tokens) {
Expand Down
2 changes: 0 additions & 2 deletions test/parser/miscellaneous/failure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,6 @@ describe('Miscellaneous - Failure', () => {
'"use strict";\n"\\011"',
'"use strict"; "\\08"',
'"use strict"; "\\09"',
'"use strict"; "\\8"',
'"use strict"; "\\9"',
'await ~123',
'async () => class await {}',
'{_ => {}/123/g;}',
Expand Down
1 change: 0 additions & 1 deletion test/parser/miscellaneous/literals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ describe('Miscellaneous - Literal', () => {
"'use strict'; ('\\123')",
"('\\x')",
'(")',
"('\\9')",
'\\0009',
'("\\u{FFFFFFF}")',
"'",
Expand Down
7 changes: 6 additions & 1 deletion test/test262-parser-tests/parser-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ const expectations = {
'e3fbcf63d7e43ead.js',
'15a6123f6b825c38.js',
'147fa078a7436e0e.js',
'fd2a45941e114896.js'
'fd2a45941e114896.js',
// https://github.com/tc39/test262-parser-tests/issues/25
'0d5e450f1da8a92a.js',
'748656edbfb2d0bb.js',
'79f882da06f88c9f.js',
'92b6af54adef3624.js'
],
early: [
'eeb5ffaafa815bb2.js',
Expand Down

0 comments on commit 26a19a8

Please sign in to comment.