MCPcopy Index your code
hub / github.com/nodejs/node / toRegExpSource

Method toRegExpSource

deps/minimatch/index.js:869–946  ·  view source on GitHub ↗
(allowDot)

Source from the content-addressed store, hash-verified

867 // is ^(?!\.), we can just prepend (?!\.) to the pattern (either root
868 // or start or whatever) and prepend ^ or / at the Regexp construction.
869 toRegExpSource(allowDot) {
870 const dot = allowDot ?? !!this.#options.dot;
871 if (this.#root === this) {
872 this.#flatten();
873 this.#fillNegs();
874 }
875 if (!isExtglobAST(this)) {
876 const noEmpty = this.isStart() && this.isEnd() && !this.#parts.some((s) => typeof s !== "string");
877 const src = this.#parts.map((p) => {
878 const [re, _, hasMagic, uflag] = typeof p === "string" ? _a.#parseGlob(p, this.#hasMagic, noEmpty) : p.toRegExpSource(allowDot);
879 this.#hasMagic = this.#hasMagic || hasMagic;
880 this.#uflag = this.#uflag || uflag;
881 return re;
882 }).join("");
883 let start2 = "";
884 if (this.isStart()) {
885 if (typeof this.#parts[0] === "string") {
886 const dotTravAllowed = this.#parts.length === 1 && justDots.has(this.#parts[0]);
887 if (!dotTravAllowed) {
888 const aps = addPatternStart;
889 const needNoTrav = (
890 // dots are allowed, and the pattern starts with [ or .
891 dot && aps.has(src.charAt(0)) || // the pattern starts with \., and then [ or .
892 src.startsWith("\\.") && aps.has(src.charAt(2)) || // the pattern starts with \.\., and then [ or .
893 src.startsWith("\\.\\.") && aps.has(src.charAt(4))
894 );
895 const needNoDot = !dot && !allowDot && aps.has(src.charAt(0));
896 start2 = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : "";
897 }
898 }
899 }
900 let end = "";
901 if (this.isEnd() && this.#root.#filledNegs && this.#parent?.type === "!") {
902 end = "(?:$|\\/)";
903 }
904 const final2 = start2 + src + end;
905 return [
906 final2,
907 (0, unescape_js_12.unescape)(src),
908 this.#hasMagic = !!this.#hasMagic,
909 this.#uflag
910 ];
911 }
912 const repeated = this.type === "*" || this.type === "+";
913 const start = this.type === "!" ? "(?:(?!(?:" : "(?:";
914 let body = this.#partsToRegExp(dot);
915 if (this.isStart() && this.isEnd() && !body && this.type !== "!") {
916 const s = this.toString();
917 const me = this;
918 me.#parts = [s];
919 me.type = null;
920 me.#hasMagic = void 0;
921 return [s, (0, unescape_js_12.unescape)(this.toString()), false, false];
922 }
923 let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot ? "" : this.#partsToRegExp(true);
924 if (bodyDotAllowed === body) {
925 bodyDotAllowed = "";
926 }

Callers 2

toMMPatternMethod · 0.80
#partsToRegExpMethod · 0.80

Calls 12

isExtglobASTFunction · 0.85
#flattenMethod · 0.80
#fillNegsMethod · 0.80
isStartMethod · 0.80
isEndMethod · 0.80
someMethod · 0.80
#parseGlobMethod · 0.80
#partsToRegExpMethod · 0.80
mapMethod · 0.65
hasMethod · 0.65
joinMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected