minimatch 7.2.0 → 7.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,148 @@
1
+ // translate the various posix character classes into unicode properties
2
+ // this works across all unicode locales
3
+ // { <posix class>: [<translation>, /u flag required, negated]
4
+ const posixClasses = {
5
+ '[:alnum:]': ['\\p{L}\\p{Nl}\\p{Nd}', true],
6
+ '[:alpha:]': ['\\p{L}\\p{Nl}', true],
7
+ '[:ascii:]': ['\\x' + '00-\\x' + '7f', false],
8
+ '[:blank:]': ['\\p{Zs}\\t', true],
9
+ '[:cntrl:]': ['\\p{Cc}', true],
10
+ '[:digit:]': ['\\p{Nd}', true],
11
+ '[:graph:]': ['\\p{Z}\\p{C}', true, true],
12
+ '[:lower:]': ['\\p{Ll}', true],
13
+ '[:print:]': ['\\p{C}', true],
14
+ '[:punct:]': ['\\p{P}', true],
15
+ '[:space:]': ['\\p{Z}\\t\\r\\n\\v\\f', true],
16
+ '[:upper:]': ['\\p{Lu}', true],
17
+ '[:word:]': ['\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}', true],
18
+ '[:xdigit:]': ['A-Fa-f0-9', false],
19
+ };
20
+ // only need to escape a few things inside of brace expressions
21
+ // escapes: [ \ ] -
22
+ const braceEscape = (s) => s.replace(/[[\]\\-]/g, '\\$&');
23
+ // escape all regexp magic characters
24
+ const regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
25
+ // everything has already been escaped, we just have to join
26
+ const rangesToString = (ranges) => ranges.join('');
27
+ // takes a glob string at a posix brace expression, and returns
28
+ // an equivalent regular expression source, and boolean indicating
29
+ // whether the /u flag needs to be applied, and the number of chars
30
+ // consumed to parse the character class.
31
+ // This also removes out of order ranges, and returns ($.) if the
32
+ // entire class just no good.
33
+ export const parseClass = (glob, position) => {
34
+ const pos = position;
35
+ /* c8 ignore start */
36
+ if (glob.charAt(pos) !== '[') {
37
+ throw new Error('not in a brace expression');
38
+ }
39
+ /* c8 ignore stop */
40
+ const ranges = [];
41
+ const negs = [];
42
+ let i = pos + 1;
43
+ let sawStart = false;
44
+ let uflag = false;
45
+ let escaping = false;
46
+ let negate = false;
47
+ let endPos = pos;
48
+ let rangeStart = '';
49
+ WHILE: while (i < glob.length) {
50
+ const c = glob.charAt(i);
51
+ if ((c === '!' || c === '^') && i === pos + 1) {
52
+ negate = true;
53
+ i++;
54
+ continue;
55
+ }
56
+ if (c === ']' && sawStart && !escaping) {
57
+ endPos = i + 1;
58
+ break;
59
+ }
60
+ sawStart = true;
61
+ if (c === '\\') {
62
+ if (!escaping) {
63
+ escaping = true;
64
+ i++;
65
+ continue;
66
+ }
67
+ // escaped \ char, fall through and treat like normal char
68
+ }
69
+ if (c === '[' && !escaping) {
70
+ // either a posix class, a collation equivalent, or just a [
71
+ for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
72
+ if (glob.startsWith(cls, i)) {
73
+ // invalid, [a-[] is fine, but not [a-[:alpha]]
74
+ if (rangeStart) {
75
+ return ['$.', false, glob.length - pos, true];
76
+ }
77
+ i += cls.length;
78
+ if (neg)
79
+ negs.push(unip);
80
+ else
81
+ ranges.push(unip);
82
+ uflag = uflag || u;
83
+ continue WHILE;
84
+ }
85
+ }
86
+ }
87
+ // now it's just a normal character, effectively
88
+ escaping = false;
89
+ if (rangeStart) {
90
+ // throw this range away if it's not valid, but others
91
+ // can still match.
92
+ if (c > rangeStart) {
93
+ ranges.push(braceEscape(rangeStart) + '-' + braceEscape(c));
94
+ }
95
+ else if (c === rangeStart) {
96
+ ranges.push(braceEscape(c));
97
+ }
98
+ rangeStart = '';
99
+ i++;
100
+ continue;
101
+ }
102
+ // now might be the start of a range.
103
+ // can be either c-d or c-] or c<more...>] or c] at this point
104
+ if (glob.startsWith('-]', i + 1)) {
105
+ ranges.push(braceEscape(c + '-'));
106
+ i += 2;
107
+ continue;
108
+ }
109
+ if (glob.startsWith('-', i + 1)) {
110
+ rangeStart = c;
111
+ i += 2;
112
+ continue;
113
+ }
114
+ // not the start of a range, just a single character
115
+ ranges.push(braceEscape(c));
116
+ i++;
117
+ }
118
+ if (endPos < i) {
119
+ // didn't see the end of the class, not a valid class,
120
+ // but might still be valid as a literal match.
121
+ return ['', false, 0, false];
122
+ }
123
+ // if we got no ranges and no negates, then we have a range that
124
+ // cannot possibly match anything, and that poisons the whole glob
125
+ if (!ranges.length && !negs.length) {
126
+ return ['$.', false, glob.length - pos, true];
127
+ }
128
+ // if we got one positive range, and it's a single character, then that's
129
+ // not actually a magic pattern, it's just that one literal character.
130
+ // we should not treat that as "magic", we should just return the literal
131
+ // character. [_] is a perfectly valid way to escape glob magic chars.
132
+ if (negs.length === 0 &&
133
+ ranges.length === 1 &&
134
+ /^\\?.$/.test(ranges[0]) &&
135
+ !negate) {
136
+ const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
137
+ return [regexpEscape(r), false, endPos - pos, false];
138
+ }
139
+ const sranges = '[' + (negate ? '^' : '') + rangesToString(ranges) + ']';
140
+ const snegs = '[' + (negate ? '' : '^') + rangesToString(negs) + ']';
141
+ const comb = ranges.length && negs.length
142
+ ? '(' + sranges + '|' + snegs + ')'
143
+ : ranges.length
144
+ ? sranges
145
+ : snegs;
146
+ return [comb, uflag, endPos - pos, true];
147
+ };
148
+ //# sourceMappingURL=brace-expressions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brace-expressions.js","sourceRoot":"","sources":["../../src/brace-expressions.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,wCAAwC;AAExC,8DAA8D;AAC9D,MAAM,YAAY,GAA0D;IAC1E,WAAW,EAAE,CAAC,sBAAsB,EAAE,IAAI,CAAC;IAC3C,WAAW,EAAE,CAAC,eAAe,EAAE,IAAI,CAAC;IACpC,WAAW,EAAE,CAAC,KAAK,GAAG,QAAQ,GAAG,IAAI,EAAE,KAAK,CAAC;IAC7C,WAAW,EAAE,CAAC,YAAY,EAAE,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CAAC,GAAG,cAAc,CAAC,IAAI,CAAC,GAAG,GAAG,CAAA;IACpE,MAAM,IAAI,GACR,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM;QAC1B,CAAC,CAAC,GAAG,GAAG,OAAO,GAAG,GAAG,GAAG,KAAK,GAAG,GAAG;QACnC,CAAC,CAAC,MAAM,CAAC,MAAM;YACf,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,KAAK,CAAA;IAEX,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,CAAA;AAC1C,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { MinimatchOptions } from './index.js';
2
+ /**
3
+ * Escape all magic characters in a glob pattern.
4
+ *
5
+ * If the {@link windowsPathsNoEscape | GlobOptions.windowsPathsNoEscape}
6
+ * option is used, then characters are escaped by wrapping in `[]`, because
7
+ * a magic character wrapped in a character class can only be satisfied by
8
+ * that exact character. In this mode, `\` is _not_ escaped, because it is
9
+ * not interpreted as a magic character, but instead as a path separator.
10
+ */
11
+ export declare const escape: (s: string, { windowsPathsNoEscape, }?: Pick<MinimatchOptions, 'windowsPathsNoEscape'>) => string;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Escape all magic characters in a glob pattern.
3
+ *
4
+ * If the {@link windowsPathsNoEscape | GlobOptions.windowsPathsNoEscape}
5
+ * option is used, then characters are escaped by wrapping in `[]`, because
6
+ * a magic character wrapped in a character class can only be satisfied by
7
+ * that exact character. In this mode, `\` is _not_ escaped, because it is
8
+ * not interpreted as a magic character, but instead as a path separator.
9
+ */
10
+ export const escape = (s, { windowsPathsNoEscape = false, } = {}) => {
11
+ // don't need to escape +@! because we escape the parens
12
+ // that make those magic, and escaping ! as [!] isn't valid,
13
+ // because [!]] is a valid glob class meaning not ']'.
14
+ return windowsPathsNoEscape
15
+ ? s.replace(/[?*()[\]]/g, '[$&]')
16
+ : s.replace(/[?*()[\]\\]/g, '\\$&');
17
+ };
18
+ //# sourceMappingURL=escape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"escape.js","sourceRoot":"","sources":["../../src/escape.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,CAAS,EACT,EACE,oBAAoB,GAAG,KAAK,MACsB,EAAE,EACtD,EAAE;IACF,wDAAwD;IACxD,4DAA4D;IAC5D,sDAAsD;IACtD,OAAO,oBAAoB;QACzB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC;QACjC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;AACvC,CAAC,CAAA"}
@@ -12,6 +12,7 @@ export interface MinimatchOptions {
12
12
  dot?: boolean;
13
13
  nocase?: boolean;
14
14
  nocaseMagicOnly?: boolean;
15
+ magicalBraces?: boolean;
15
16
  matchBase?: boolean;
16
17
  flipNegate?: boolean;
17
18
  preserveMultipleSlashes?: boolean;
@@ -29,6 +30,8 @@ export declare const minimatch: {
29
30
  makeRe: (pattern: string, options?: MinimatchOptions) => false | MMRegExp;
30
31
  match: (list: string[], pattern: string, options?: MinimatchOptions) => string[];
31
32
  Minimatch: typeof Minimatch;
33
+ escape: (s: string, { windowsPathsNoEscape, }?: Pick<MinimatchOptions, "windowsPathsNoEscape">) => string;
34
+ unescape: (s: string, { windowsPathsNoEscape, }?: Pick<MinimatchOptions, "windowsPathsNoEscape">) => string;
32
35
  };
33
36
  export default minimatch;
34
37
  type Sep = '\\' | '/';
@@ -37,7 +40,6 @@ export declare const GLOBSTAR: unique symbol;
37
40
  export declare const filter: (pattern: string, options?: MinimatchOptions) => (p: string) => boolean;
38
41
  export declare const defaults: (def: MinimatchOptions) => typeof minimatch;
39
42
  export declare const braceExpand: (pattern: string, options?: MinimatchOptions) => string[];
40
- declare const SUBPARSE: unique symbol;
41
43
  export declare const makeRe: (pattern: string, options?: MinimatchOptions) => false | MMRegExp;
42
44
  export declare const match: (list: string[], pattern: string, options?: MinimatchOptions) => string[];
43
45
  export type MMRegExp = RegExp & {
@@ -66,6 +68,7 @@ export declare class Minimatch {
66
68
  windowsNoMagicRoot: boolean;
67
69
  regexp: false | null | MMRegExp;
68
70
  constructor(pattern: string, options?: MinimatchOptions);
71
+ hasMagic(): boolean;
69
72
  debug(..._: any[]): void;
70
73
  make(): void;
71
74
  preprocess(globParts: string[][]): string[][];
@@ -78,9 +81,11 @@ export declare class Minimatch {
78
81
  parseNegate(): void;
79
82
  matchOne(file: string[], pattern: ParseReturn[], partial?: boolean): boolean;
80
83
  braceExpand(): string[];
81
- parse(pattern: string, isSub?: typeof SUBPARSE): ParseReturn | SubparseReturn;
84
+ parse(pattern: string): ParseReturn | SubparseReturn;
82
85
  makeRe(): false | MMRegExp;
83
86
  slashSplit(p: string): string[];
84
87
  match(f: string, partial?: boolean): boolean;
85
88
  static defaults(def: MinimatchOptions): typeof Minimatch;
86
89
  }
90
+ export { escape } from './escape.js';
91
+ export { unescape } from './unescape.js';
package/dist/mjs/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ import expand from 'brace-expansion';
2
+ import { parseClass } from './brace-expressions.js';
3
+ import { escape } from './escape.js';
4
+ import { unescape } from './unescape.js';
1
5
  export const minimatch = (p, pattern, options = {}) => {
2
6
  assertValidPattern(pattern);
3
7
  // shortcut: comments match nothing.
@@ -74,7 +78,6 @@ export const sep = defaultPlatform === 'win32' ? path.win32.sep : path.posix.sep
74
78
  minimatch.sep = sep;
75
79
  export const GLOBSTAR = Symbol('globstar **');
76
80
  minimatch.GLOBSTAR = GLOBSTAR;
77
- import expand from 'brace-expansion';
78
81
  const plTypes = {
79
82
  '!': { open: '(?:(?!(?:', close: '))[^/]*?)' },
80
83
  '?': { open: '(?:', close: ')?' },
@@ -121,6 +124,8 @@ export const defaults = (def) => {
121
124
  return orig.defaults(ext(def, options)).Minimatch;
122
125
  }
123
126
  },
127
+ unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
128
+ escape: (s, options = {}) => orig.escape(s, ext(def, options)),
124
129
  filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
125
130
  defaults: (options) => orig.defaults(ext(def, options)),
126
131
  makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)),
@@ -172,7 +177,6 @@ const assertValidPattern = (pattern) => {
172
177
  // when it is the *only* thing in a path portion. Otherwise, any series
173
178
  // of * is equivalent to a single *. Globstar behavior is enabled by
174
179
  // default, and can be disabled by setting options.noglobstar.
175
- const SUBPARSE = Symbol('subparse');
176
180
  export const makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe();
177
181
  minimatch.makeRe = makeRe;
178
182
  export const match = (list, pattern, options = {}) => {
@@ -187,9 +191,7 @@ minimatch.match = match;
187
191
  // replace stuff like \* with *
188
192
  const globUnescape = (s) => s.replace(/\\(.)/g, '$1');
189
193
  const globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
190
- const charUnescape = (s) => s.replace(/\\([^-\]])/g, '$1');
191
194
  const regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
192
- const braExpEscape = (s) => s.replace(/[[\]\\]/g, '\\$&');
193
195
  export class Minimatch {
194
196
  options;
195
197
  set;
@@ -238,6 +240,18 @@ export class Minimatch {
238
240
  // make the set of regexps etc.
239
241
  this.make();
240
242
  }
243
+ hasMagic() {
244
+ if (this.options.magicalBraces && this.set.length > 1) {
245
+ return true;
246
+ }
247
+ for (const pattern of this.set) {
248
+ for (const part of pattern) {
249
+ if (typeof part !== 'string')
250
+ return true;
251
+ }
252
+ }
253
+ return false;
254
+ }
241
255
  debug(..._) { }
242
256
  make() {
243
257
  const pattern = this.pattern;
@@ -787,7 +801,7 @@ export class Minimatch {
787
801
  braceExpand() {
788
802
  return braceExpand(this.pattern, this.options);
789
803
  }
790
- parse(pattern, isSub) {
804
+ parse(pattern) {
791
805
  assertValidPattern(pattern);
792
806
  const options = this.options;
793
807
  // shortcuts
@@ -799,34 +813,32 @@ export class Minimatch {
799
813
  // *, *.*, and *.<ext> Add a fast check method for those.
800
814
  let m;
801
815
  let fastTest = null;
802
- if (isSub !== SUBPARSE) {
803
- if ((m = pattern.match(starRE))) {
804
- fastTest = options.dot ? starTestDot : starTest;
805
- }
806
- else if ((m = pattern.match(starDotExtRE))) {
807
- fastTest = (options.nocase
808
- ? options.dot
809
- ? starDotExtTestNocaseDot
810
- : starDotExtTestNocase
811
- : options.dot
812
- ? starDotExtTestDot
813
- : starDotExtTest)(m[1]);
814
- }
815
- else if ((m = pattern.match(qmarksRE))) {
816
- fastTest = (options.nocase
817
- ? options.dot
818
- ? qmarksTestNocaseDot
819
- : qmarksTestNocase
820
- : options.dot
821
- ? qmarksTestDot
822
- : qmarksTest)(m);
823
- }
824
- else if ((m = pattern.match(starDotStarRE))) {
825
- fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
826
- }
827
- else if ((m = pattern.match(dotStarRE))) {
828
- fastTest = dotStarTest;
829
- }
816
+ if ((m = pattern.match(starRE))) {
817
+ fastTest = options.dot ? starTestDot : starTest;
818
+ }
819
+ else if ((m = pattern.match(starDotExtRE))) {
820
+ fastTest = (options.nocase
821
+ ? options.dot
822
+ ? starDotExtTestNocaseDot
823
+ : starDotExtTestNocase
824
+ : options.dot
825
+ ? starDotExtTestDot
826
+ : starDotExtTest)(m[1]);
827
+ }
828
+ else if ((m = pattern.match(qmarksRE))) {
829
+ fastTest = (options.nocase
830
+ ? options.dot
831
+ ? qmarksTestNocaseDot
832
+ : qmarksTestNocase
833
+ : options.dot
834
+ ? qmarksTestDot
835
+ : qmarksTest)(m);
836
+ }
837
+ else if ((m = pattern.match(starDotStarRE))) {
838
+ fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
839
+ }
840
+ else if ((m = pattern.match(dotStarRE))) {
841
+ fastTest = dotStarTest;
830
842
  }
831
843
  let re = '';
832
844
  let hasMagic = false;
@@ -835,12 +847,8 @@ export class Minimatch {
835
847
  const patternListStack = [];
836
848
  const negativeLists = [];
837
849
  let stateChar = false;
838
- let inClass = false;
839
- let reClassStart = -1;
840
- let classStart = -1;
841
- let cs;
850
+ let uflag = false;
842
851
  let pl;
843
- let sp;
844
852
  // . and .. never match anything that doesn't start with .,
845
853
  // even when options.dot is set. However, if the pattern
846
854
  // starts with ., then traversal patterns can match.
@@ -903,10 +911,6 @@ export class Minimatch {
903
911
  }
904
912
  /* c8 ignore stop */
905
913
  case '\\':
906
- if (inClass && pattern.charAt(i + 1) === '-') {
907
- re += c;
908
- continue;
909
- }
910
914
  clearStateChar();
911
915
  escaping = true;
912
916
  continue;
@@ -918,15 +922,6 @@ export class Minimatch {
918
922
  case '@':
919
923
  case '!':
920
924
  this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c);
921
- // all of those are literals inside a class, except that
922
- // the glob [!a] means [^a] in regexp
923
- if (inClass) {
924
- this.debug(' in class');
925
- if (c === '!' && i === classStart + 1)
926
- c = '^';
927
- re += c;
928
- continue;
929
- }
930
925
  // if we already have a stateChar, then it means
931
926
  // that there was something like ** or +? in there.
932
927
  // Handle the stateChar, then proceed with this one.
@@ -940,10 +935,6 @@ export class Minimatch {
940
935
  clearStateChar();
941
936
  continue;
942
937
  case '(': {
943
- if (inClass) {
944
- re += '(';
945
- continue;
946
- }
947
938
  if (!stateChar) {
948
939
  re += '\\(';
949
940
  continue;
@@ -970,7 +961,7 @@ export class Minimatch {
970
961
  }
971
962
  case ')': {
972
963
  const plEntry = patternListStack[patternListStack.length - 1];
973
- if (inClass || !plEntry) {
964
+ if (!plEntry) {
974
965
  re += '\\)';
975
966
  continue;
976
967
  }
@@ -989,7 +980,7 @@ export class Minimatch {
989
980
  }
990
981
  case '|': {
991
982
  const plEntry = patternListStack[patternListStack.length - 1];
992
- if (inClass || !plEntry) {
983
+ if (!plEntry) {
993
984
  re += '\\|';
994
985
  continue;
995
986
  }
@@ -1006,67 +997,27 @@ export class Minimatch {
1006
997
  case '[':
1007
998
  // swallow any state-tracking char before the [
1008
999
  clearStateChar();
1009
- if (inClass) {
1010
- re += '\\' + c;
1011
- continue;
1000
+ const [src, needUflag, consumed, magic] = parseClass(pattern, i);
1001
+ if (consumed) {
1002
+ re += src;
1003
+ uflag = uflag || needUflag;
1004
+ i += consumed - 1;
1005
+ hasMagic = hasMagic || magic;
1006
+ }
1007
+ else {
1008
+ re += '\\[';
1012
1009
  }
1013
- inClass = true;
1014
- classStart = i;
1015
- reClassStart = re.length;
1016
- re += c;
1017
1010
  continue;
1018
1011
  case ']':
1019
- // a right bracket shall lose its special
1020
- // meaning and represent itself in
1021
- // a bracket expression if it occurs
1022
- // first in the list. -- POSIX.2 2.8.3.2
1023
- if (i === classStart + 1 || !inClass) {
1024
- re += '\\' + c;
1025
- continue;
1026
- }
1027
- // split where the last [ was, make sure we don't have
1028
- // an invalid re. if so, re-walk the contents of the
1029
- // would-be class to re-translate any characters that
1030
- // were passed through as-is
1031
- // TODO: It would probably be faster to determine this
1032
- // without a try/catch and a new RegExp, but it's tricky
1033
- // to do safely. For now, this is safe and works.
1034
- cs = pattern.substring(classStart + 1, i);
1035
- try {
1036
- RegExp('[' + braExpEscape(charUnescape(cs)) + ']');
1037
- // looks good, finish up the class.
1038
- re += c;
1039
- }
1040
- catch (er) {
1041
- // out of order ranges in JS are errors, but in glob syntax,
1042
- // they're just a range that matches nothing.
1043
- re = re.substring(0, reClassStart) + '(?:$.)'; // match nothing ever
1044
- }
1045
- hasMagic = true;
1046
- inClass = false;
1012
+ re += '\\' + c;
1047
1013
  continue;
1048
1014
  default:
1049
1015
  // swallow any state char that wasn't consumed
1050
1016
  clearStateChar();
1051
- if (reSpecials[c] && !(c === '^' && inClass)) {
1052
- re += '\\';
1053
- }
1054
- re += c;
1017
+ re += regExpEscape(c);
1055
1018
  break;
1056
1019
  } // switch
1057
1020
  } // for
1058
- // handle the case where we left a class open.
1059
- // "[abc" is valid, equivalent to "\[abc"
1060
- if (inClass) {
1061
- // split where the last [ was, and escape it
1062
- // this is a huge pita. We now have to re-walk
1063
- // the contents of the would-be class to re-translate
1064
- // any characters that were passed through as-is
1065
- cs = pattern.slice(classStart + 1);
1066
- sp = this.parse(cs, SUBPARSE);
1067
- re = re.substring(0, reClassStart) + '\\[' + sp[0];
1068
- hasMagic = hasMagic || sp[1];
1069
- }
1070
1021
  // handle the case where we had a +( thing at the *end*
1071
1022
  // of the pattern.
1072
1023
  // each pattern list stack adds 3 chars, and we need to go through
@@ -1129,7 +1080,7 @@ export class Minimatch {
1129
1080
  cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
1130
1081
  }
1131
1082
  nlAfter = cleanAfter;
1132
- const dollar = nlAfter === '' && isSub !== SUBPARSE ? '(?:$|\\/)' : '';
1083
+ const dollar = nlAfter === '' ? '(?:$|\\/)' : '';
1133
1084
  re = nlBefore + nlFirst + nlAfter + dollar + nlLast;
1134
1085
  }
1135
1086
  // if the re is not "" at this point, then we need to make sure
@@ -1141,10 +1092,6 @@ export class Minimatch {
1141
1092
  if (addPatternStart) {
1142
1093
  re = patternStart() + re;
1143
1094
  }
1144
- // parsing just a piece of a larger pattern.
1145
- if (isSub === SUBPARSE) {
1146
- return [re, hasMagic];
1147
- }
1148
1095
  // if it's nocase, and the lcase/uppercase don't match, it's magic
1149
1096
  if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
1150
1097
  hasMagic = pattern.toUpperCase() !== pattern.toLowerCase();
@@ -1153,9 +1100,9 @@ export class Minimatch {
1153
1100
  // unescape anything in it, though, so that it'll be
1154
1101
  // an exact match against a file etc.
1155
1102
  if (!hasMagic) {
1156
- return globUnescape(pattern);
1103
+ return globUnescape(re);
1157
1104
  }
1158
- const flags = options.nocase ? 'i' : '';
1105
+ const flags = (options.nocase ? 'i' : '') + (uflag ? 'u' : '');
1159
1106
  try {
1160
1107
  const ext = fastTest
1161
1108
  ? {
@@ -1332,5 +1279,11 @@ export class Minimatch {
1332
1279
  return minimatch.defaults(def).Minimatch;
1333
1280
  }
1334
1281
  }
1282
+ /* c8 ignore start */
1283
+ export { escape } from './escape.js';
1284
+ export { unescape } from './unescape.js';
1285
+ /* c8 ignore stop */
1335
1286
  minimatch.Minimatch = Minimatch;
1287
+ minimatch.escape = escape;
1288
+ minimatch.unescape = unescape;
1336
1289
  //# sourceMappingURL=index.js.map