Skip to content

Commit 8f38980

Browse files
author
Guy Bedford
authored
fix: handle fallthrough of regex parser bugs (#447)
1 parent ce4be9c commit 8f38980

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/precompile.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ function findRegexLiterals(source) {
1616
const pattern = m.captures[0].node.text;
1717
const flags = m.captures[1]?.node.text || "";
1818
// transpile unicode property escapes
19-
const patternTranspiled = regexpuc(pattern, flags, { unicodePropertyEscapes: 'transform' });
19+
let patternTranspiled;
20+
try {
21+
patternTranspiled = regexpuc(pattern, flags, { unicodePropertyEscapes: 'transform' });
22+
} catch {
23+
// swallow regex parse errors here to instead throw them at the engine level
24+
// this then also avoids regex parser bugs being thrown unnecessarily
25+
patternTranspiled = pattern;
26+
}
2027
regexLiterals.push({
2128
patternStart: m.captures[0].node.startIndex,
2229
patternEnd: m.captures[0].node.endIndex,

0 commit comments

Comments
 (0)