Make sure syntax errors in regular expressions raise conforming exceptions
Just letting the error from new RegExp through creates an exception missing the pos/loc/raisedAt properties. Issue #82 Issue #81
This commit is contained in:
8
acorn.js
8
acorn.js
@@ -767,7 +767,13 @@
|
||||
// here (don't ask).
|
||||
var mods = readWord1();
|
||||
if (mods && !/^[gmsiy]*$/.test(mods)) raise(start, "Invalid regexp flag");
|
||||
return finishToken(_regexp, new RegExp(content, mods));
|
||||
try {
|
||||
var value = new RegExp(content, mods);
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) raise(start, e.message);
|
||||
raise(e);
|
||||
}
|
||||
return finishToken(_regexp, value);
|
||||
}
|
||||
|
||||
// Read an integer in the given radix. Return null if zero digits
|
||||
|
||||
Reference in New Issue
Block a user