| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5354af3 commit 8914a52
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -403,7 +403,7 @@ var require_ast = __commonJS({ | |||
| 403 | 403 | var unescape_js_12 = require_unescape(); | |
| 404 | 404 | var types = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]); | |
| 405 | 405 | var isExtglobType = (c) => types.has(c); | |
| 406 | - var startNoTraversal = "(?!\\.\\.?(?:$|/))"; | ||
| 406 | + var startNoTraversal = "(?!(?:^|/)\\.\\.?(?:$|/))"; | ||
| 407 | 407 | var startNoDot = "(?!\\.)"; | |
| 408 | 408 | var addPatternStart = /* @__PURE__ */ new Set(["[", "."]); | |
| 409 | 409 | var justDots = /* @__PURE__ */ new Set(["..", "."]); | |
@@ -412,10 +412,11 @@ var require_ast = __commonJS({ | |||
| 412 | 412 | var qmark2 = "[^/]"; | |
| 413 | 413 | var star2 = qmark2 + "*?"; | |
| 414 | 414 | var starNoEmpty = qmark2 + "+?"; | |
| 415 | - var _root, _hasMagic, _uflag, _parts, _parent, _parentIndex, _negs, _filledNegs, _options, _toString, _emptyExt, _fillNegs, fillNegs_fn, _parseAST, parseAST_fn, _parseGlob, parseGlob_fn; | ||
| 415 | + var _root, _hasMagic, _uflag, _parts, _parent, _parentIndex, _negs, _filledNegs, _options, _toString, _emptyExt, _fillNegs, fillNegs_fn, _parseAST, parseAST_fn, _partsToRegExp, partsToRegExp_fn, _parseGlob, parseGlob_fn; | ||
| 416 | 416 | var _AST = class { | |
| 417 | 417 | constructor(type, parent, options = {}) { | |
| 418 | 418 | __privateAdd(this, _fillNegs); | |
| 419 | + __privateAdd(this, _partsToRegExp); | ||
| 419 | 420 | __publicField(this, "type"); | |
| 420 | 421 | __privateAdd(this, _root, void 0); | |
| 421 | 422 | __privateAdd(this, _hasMagic, void 0); | |
@@ -614,14 +615,15 @@ var require_ast = __commonJS({ | |||
| 614 | 615 | // - Since the start for a join is eg /(?!\.) and the start for a part | |
| 615 | 616 | // is ^(?!\.), we can just prepend (?!\.) to the pattern (either root | |
| 616 | 617 | // or start or whatever) and prepend ^ or / at the Regexp construction. | |
| 617 | - toRegExpSource() { | ||
| 618 | + toRegExpSource(allowDot) { | ||
| 619 | + const dot = allowDot ?? !!__privateGet(this, _options).dot; | ||
| 618 | 620 | if (__privateGet(this, _root) === this) | |
| 619 | 621 | __privateMethod(this, _fillNegs, fillNegs_fn).call(this); | |
| 620 | 622 | if (!this.type) { | |
| 621 | 623 | const noEmpty = this.isStart() && this.isEnd(); | |
| 622 | 624 | const src = __privateGet(this, _parts).map((p) => { | |
| 623 | 625 | var _a; | |
| 624 | - const [re, _, hasMagic, uflag] = typeof p === "string" ? __privateMethod(_a = _AST, _parseGlob, parseGlob_fn).call(_a, p, __privateGet(this, _hasMagic), noEmpty) : p.toRegExpSource(); | ||
| 626 | + const [re, _, hasMagic, uflag] = typeof p === "string" ? __privateMethod(_a = _AST, _parseGlob, parseGlob_fn).call(_a, p, __privateGet(this, _hasMagic), noEmpty) : p.toRegExpSource(allowDot); | ||
| 625 | 627 | __privateSet(this, _hasMagic, __privateGet(this, _hasMagic) || hasMagic); | |
| 626 | 628 | __privateSet(this, _uflag, __privateGet(this, _uflag) || uflag); | |
| 627 | 629 | return re; | |
@@ -634,11 +636,11 @@ var require_ast = __commonJS({ | |||
| 634 | 636 | const aps = addPatternStart; | |
| 635 | 637 | const needNoTrav = ( | |
| 636 | 638 | // dots are allowed, and the pattern starts with [ or . | |
| 637 | - __privateGet(this, _options).dot && aps.has(src.charAt(0)) || // the pattern starts with \., and then [ or . | ||
| 639 | + dot && aps.has(src.charAt(0)) || // the pattern starts with \., and then [ or . | ||
| 638 | 640 | src.startsWith("\\.") && aps.has(src.charAt(2)) || // the pattern starts with \.\., and then [ or . | |
| 639 | 641 | src.startsWith("\\.\\.") && aps.has(src.charAt(4)) | |
| 640 | 642 | ); | |
| 641 | - const needNoDot = !__privateGet(this, _options).dot && aps.has(src.charAt(0)); | ||
| 643 | + const needNoDot = !dot && !allowDot && aps.has(src.charAt(0)); | ||
| 642 | 644 | start2 = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : ""; | |
| 643 | 645 | } | |
| 644 | 646 | } | |
@@ -655,30 +657,31 @@ var require_ast = __commonJS({ | |||
| 655 | 657 | __privateGet(this, _uflag) | |
| 656 | 658 | ]; | |
| 657 | 659 | } | |
| 660 | + const repeated = this.type === "*" || this.type === "+"; | ||
| 658 | 661 | const start = this.type === "!" ? "(?:(?!(?:" : "(?:"; | |
| 659 | - const body = __privateGet(this, _parts).map((p) => { | ||
| 660 | - if (typeof p === "string") { | ||
| 661 | - throw new Error("string type in extglob ast??"); | ||
| 662 | - } | ||
| 663 | - const [re, _, _hasMagic2, uflag] = p.toRegExpSource(); | ||
| 664 | - __privateSet(this, _uflag, __privateGet(this, _uflag) || uflag); | ||
| 665 | - return re; | ||
| 666 | - }).filter((p) => !(this.isStart() && this.isEnd()) || !!p).join("|"); | ||
| 662 | + let body = __privateMethod(this, _partsToRegExp, partsToRegExp_fn).call(this, dot); | ||
| 667 | 663 | if (this.isStart() && this.isEnd() && !body && this.type !== "!") { | |
| 668 | 664 | const s = this.toString(); | |
| 669 | 665 | __privateSet(this, _parts, [s]); | |
| 670 | 666 | this.type = null; | |
| 671 | 667 | __privateSet(this, _hasMagic, void 0); | |
| 672 | 668 | return [s, (0, unescape_js_12.unescape)(this.toString()), false, false]; | |
| 673 | 669 | } | |
| 670 | + let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot ? "" : __privateMethod(this, _partsToRegExp, partsToRegExp_fn).call(this, true); | ||
| 671 | + if (bodyDotAllowed === body) { | ||
| 672 | + bodyDotAllowed = ""; | ||
| 673 | + } | ||
| 674 | + if (bodyDotAllowed) { | ||
| 675 | + body = `(?:${body})(?:${bodyDotAllowed})*?`; | ||
| 676 | + } | ||
| 674 | 677 | let final = ""; | |
| 675 | 678 | if (this.type === "!" && __privateGet(this, _emptyExt)) { | |
| 676 | - final = (this.isStart() && !__privateGet(this, _options).dot ? startNoDot : "") + starNoEmpty; | ||
| 679 | + final = (this.isStart() && !dot ? startNoDot : "") + starNoEmpty; | ||
| 677 | 680 | } else { | |
| 678 | 681 | const close = this.type === "!" ? ( | |
| 679 | 682 | // !() must match something,but !(x) can match '' | |
| 680 | - "))" + (this.isStart() && !__privateGet(this, _options).dot ? startNoDot : "") + star2 + ")" | ||
| 681 | - ) : this.type === "@" ? ")" : `)${this.type}`; | ||
| 683 | + "))" + (this.isStart() && !dot && !allowDot ? startNoDot : "") + star2 + ")" | ||
| 684 | + ) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && bodyDotAllowed ? ")" : this.type === "*" && bodyDotAllowed ? `)?` : `)${this.type}`; | ||
| 682 | 685 | final = start + body + close; | |
| 683 | 686 | } | |
| 684 | 687 | return [ | |
@@ -836,6 +839,17 @@ var require_ast = __commonJS({ | |||
| 836 | 839 | __privateSet(ast, _parts, [str.substring(pos - 1)]); | |
| 837 | 840 | return i; | |
| 838 | 841 | }; | |
| 842 | + _partsToRegExp = new WeakSet(); | ||
| 843 | + partsToRegExp_fn = function(dot) { | ||
| 844 | + return __privateGet(this, _parts).map((p) => { | ||
| 845 | + if (typeof p === "string") { | ||
| 846 | + throw new Error("string type in extglob ast??"); | ||
| 847 | + } | ||
| 848 | + const [re, _, _hasMagic2, uflag] = p.toRegExpSource(dot); | ||
| 849 | + __privateSet(this, _uflag, __privateGet(this, _uflag) || uflag); | ||
| 850 | + return re; | ||
| 851 | + }).filter((p) => !(this.isStart() && this.isEnd()) || !!p).join("|"); | ||
| 852 | + }; | ||
| 839 | 853 | _parseGlob = new WeakSet(); | |
| 840 | 854 | parseGlob_fn = function(glob, hasMagic, noEmpty = false) { | |
| 841 | 855 | let escaping = false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,11 +14,6 @@ export declare class AST { | |||
| 14 | 14 | clone(parent: AST): AST; | |
| 15 | 15 | static fromGlob(pattern: string, options?: MinimatchOptions): AST; | |
| 16 | 16 | toMMPattern(): MMRegExp | string; | |
| 17 | - toRegExpSource(): [ | ||
| 18 | - re: string, | ||
| 19 | - body: string, | ||
| 20 | - hasMagic: boolean, | ||
| 21 | - uflag: boolean | ||
| 22 | - ]; | ||
| 17 | + toRegExpSource(allowDot?: boolean): [re: string, body: string, hasMagic: boolean, uflag: boolean]; | ||
| 23 | 18 | } | |
| 24 | 19 | //# sourceMappingURL=ast.d.ts.map | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,11 +14,6 @@ export declare class AST { | |||
| 14 | 14 | clone(parent: AST): AST; | |
| 15 | 15 | static fromGlob(pattern: string, options?: MinimatchOptions): AST; | |
| 16 | 16 | toMMPattern(): MMRegExp | string; | |
| 17 | - toRegExpSource(): [ | ||
| 18 | - re: string, | ||
| 19 | - body: string, | ||
| 20 | - hasMagic: boolean, | ||
| 21 | - uflag: boolean | ||
| 22 | - ]; | ||
| 17 | + toRegExpSource(allowDot?: boolean): [re: string, body: string, hasMagic: boolean, uflag: boolean]; | ||
| 23 | 18 | } | |
| 24 | 19 | //# sourceMappingURL=ast.d.ts.map | |
| Back | FazBrowse Home | New Git URL |
0 commit comments