Skip to content

Commit

Permalink
fix(lexer): fix regexp char class \u{hhhh} which requires the u flag
Browse files Browse the repository at this point in the history
closes #79
  • Loading branch information
3cp committed May 25, 2020
1 parent d1ec140 commit 1fdffb6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/lexer/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,9 @@ export function scanRegularExpression(parser: ParserState, context: Context): To
* @param flags Regexp flags
*/
function validate(parser: ParserState, pattern: string, flags: string): RegExp | null | Token {
try {
RegExp(pattern);
} catch (e) {
report(parser, Errors.UnterminatedRegExp);
}

try {
return new RegExp(pattern, flags);
} catch (e) {
return null;
report(parser, Errors.UnterminatedRegExp);
}
}
2 changes: 2 additions & 0 deletions test/lexer/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ describe('Lexer - Regular expressions', () => {
[Context.AllowRegExp, '/x\\udabcy/', 'x\\udabcy', ''],
[Context.AllowRegExp, '/\\udd00\\udd00y/', '\\udd00\\udd00y', ''],
[Context.AllowRegExp, '/\\ud900\\udd00\\ud900y/', '\\ud900\\udd00\\ud900y', ''],
[Context.AllowRegExp, '/[\\ufdd0-\\ufdef]/', '[\\ufdd0-\\ufdef]', ''],
[Context.AllowRegExp, '/[\\u{FDD0}-\\u{FDEF}]/u', '[\\u{FDD0}-\\u{FDEF}]', 'u'],
[Context.AllowRegExp, '/[i]/', '[i]', ''],
[Context.AllowRegExp, '/[j]/', '[j]', ''],
[Context.AllowRegExp, '/[s]/', '[s]', ''],
Expand Down

0 comments on commit 1fdffb6

Please sign in to comment.