Exposed flags to the regex parser

This commit is contained in:
Napalys
2025-03-02 16:53:18 +01:00
parent 2f2c9f8943
commit cb448db3ce
3 changed files with 13 additions and 3 deletions

View File

@@ -600,7 +600,7 @@ public class ASTExtractor {
SourceMap sourceMap =
SourceMap.legacyWithStartPos(
SourceMap.fromString(nd.getRaw()).offsetBy(0, offsets), startPos);
regexpExtractor.extract(source.substring(1, source.lastIndexOf('/')), sourceMap, nd, false);
regexpExtractor.extract(source.substring(1, source.lastIndexOf('/')), sourceMap, nd, false, source.substring(source.lastIndexOf('/'), source.length()));
} else if (nd.isStringLiteral()
&& !c.isInsideType()
&& nd.getRaw().length() < 1000

View File

@@ -346,8 +346,8 @@ public class RegExpExtractor {
}
}
public void extract(String src, SourceMap sourceMap, Node parent, boolean isSpeculativeParsing) {
Result res = parser.parse(src);
public void extract(String src, SourceMap sourceMap, Node parent, boolean isSpeculativeParsing, String flags) {
Result res = parser.parse(src, flags);
if (isSpeculativeParsing && res.getErrors().size() > 0) {
return;
}
@@ -364,4 +364,8 @@ public class RegExpExtractor {
this.emitLocation(err, lbl);
}
}
public void extract(String src, SourceMap sourceMap, Node parent, boolean isSpeculativeParsing) {
extract(src, sourceMap, parent, isSpeculativeParsing, "");
}
}

View File

@@ -67,6 +67,7 @@ public class RegExpParser {
private List<Error> errors;
private List<BackReference> backrefs;
private int maxbackref;
private String flags;
/** Parse the given string as a regular expression. */
public Result parse(String src) {
@@ -82,6 +83,11 @@ public class RegExpParser {
return new Result(root, errors);
}
public Result parse(String src, String flags) {
this.flags = flags;
return parse(src);
}
private static String fromCodePoint(int codepoint) {
if (Character.isValidCodePoint(codepoint)) return new String(Character.toChars(codepoint));
// replacement character