From 37f6df6ec292b405d9f69d0f0cabbc6b0a002d65 Mon Sep 17 00:00:00 2001 From: isaacs Date: Fri, 23 Jun 2023 11:06:18 -0700 Subject: [PATCH] Prevent dots only at the start of repeat patterns A pattern like `+(?)` will note that the `?` matches the start of the pattern, and prevent it from matching a dot. However, this is not "anything other than a dot, repeating", but rather "repeating, where the first repetition doesn't start with a dot". With this change, repetitive extglob patterns in the start position are expanded such that the first instance of the pattern may not start with a dot, but any subsequent repetitions may begin with a dot. Fix: https://github.com/isaacs/minimatch/issues/211 --- src/ast.ts | 84 +++-- tap-snapshots/test/basic.js.test.cjs | 256 +++++++++++-- .../test/escape-has-magic.js.test.cjs | 132 +++++-- .../test/optimization-level-0.ts.test.cjs | 354 ++++++++++++++++-- .../test/optimization-level-2.ts.test.cjs | 256 +++++++++++-- test/patterns.js | 116 ++++++ 6 files changed, 1037 insertions(+), 161 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index e6d5bb0..4805010 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1,7 +1,7 @@ // parse a single path portion -import { MinimatchOptions, MMRegExp } from './index.js' import { parseClass } from './brace-expressions.js' +import { MinimatchOptions, MMRegExp } from './index.js' import { unescape } from './unescape.js' // classes [] are handled by the parseClass method @@ -50,7 +50,7 @@ const isExtglobType = (c: string): c is ExtglobType => // entire string, or just a single path portion, to prevent dots // and/or traversal patterns, when needed. // Exts don't need the ^ or / bit, because the root binds that already. -const startNoTraversal = '(?!\\.\\.?(?:$|/))' +const startNoTraversal = '(?!(?:^|/)\\.\\.?(?:$|/))' const startNoDot = '(?!\\.)' // characters that indicate a start of pattern needs the "no dots" bit, @@ -467,12 +467,10 @@ export class AST { // - Since the start for a join is eg /(?!\.) and the start for a part // is ^(?!\.), we can just prepend (?!\.) to the pattern (either root // or start or whatever) and prepend ^ or / at the Regexp construction. - toRegExpSource(): [ - re: string, - body: string, - hasMagic: boolean, - uflag: boolean - ] { + toRegExpSource( + allowDot?: boolean + ): [re: string, body: string, hasMagic: boolean, uflag: boolean] { + const dot = allowDot ?? !!this.#options.dot if (this.#root === this) this.#fillNegs() if (!this.type) { const noEmpty = this.isStart() && this.isEnd() @@ -481,7 +479,7 @@ export class AST { const [re, _, hasMagic, uflag] = typeof p === 'string' ? AST.#parseGlob(p, this.#hasMagic, noEmpty) - : p.toRegExpSource() + : p.toRegExpSource(allowDot) this.#hasMagic = this.#hasMagic || hasMagic this.#uflag = this.#uflag || uflag return re @@ -504,14 +502,14 @@ export class AST { // and prevent that. const needNoTrav = // dots are allowed, and the pattern starts with [ or . - (this.#options.dot && aps.has(src.charAt(0))) || + (dot && aps.has(src.charAt(0))) || // the pattern starts with \., and then [ or . (src.startsWith('\\.') && aps.has(src.charAt(2))) || // the pattern starts with \.\., and then [ or . (src.startsWith('\\.\\.') && aps.has(src.charAt(4))) // no need to prevent dots if it can't match a dot, or if a // sub-pattern will be preventing it anyway. - const needNoDot = !this.#options.dot && aps.has(src.charAt(0)) + const needNoDot = !dot && !allowDot && aps.has(src.charAt(0)) start = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : '' } @@ -536,23 +534,15 @@ export class AST { ] } + // We need to calculate the body *twice* if it's a repeat pattern + // at the start, once in nodot mode, then again in dot mode, so a + // pattern like *(?) can match 'x.y' + + const repeated = this.type === '*' || this.type === '+' // some kind of extglob const start = this.type === '!' ? '(?:(?!(?:' : '(?:' - const body = this.#parts - .map(p => { - // extglob ASTs should only contain parent ASTs - /* c8 ignore start */ - if (typeof p === 'string') { - throw new Error('string type in extglob ast??') - } - /* c8 ignore stop */ - // can ignore hasMagic, because extglobs are already always magic - const [re, _, _hasMagic, uflag] = p.toRegExpSource() - this.#uflag = this.#uflag || uflag - return re - }) - .filter(p => !(this.isStart() && this.isEnd()) || !!p) - .join('|') + let body = this.#partsToRegExp(dot) + if (this.isStart() && this.isEnd() && !body && this.type !== '!') { // invalid extglob, has to at least be *something* present, if it's // the entire path portion. @@ -562,21 +552,39 @@ export class AST { this.#hasMagic = undefined return [s, unescape(this.toString()), false, false] } + + // XXX abstract out this map method + let bodyDotAllowed = + !repeated || allowDot || dot || !startNoDot + ? '' + : this.#partsToRegExp(true) + if (bodyDotAllowed === body) { + bodyDotAllowed = '' + } + if (bodyDotAllowed) { + body = `(?:${body})(?:${bodyDotAllowed})*?` + } + // an empty !() is exactly equivalent to a starNoEmpty let final = '' if (this.type === '!' && this.#emptyExt) { - final = - (this.isStart() && !this.#options.dot ? startNoDot : '') + starNoEmpty + final = (this.isStart() && !dot ? startNoDot : '') + starNoEmpty } else { const close = this.type === '!' ? // !() must match something,but !(x) can match '' '))' + - (this.isStart() && !this.#options.dot ? startNoDot : '') + + (this.isStart() && !dot && !allowDot ? startNoDot : '') + star + ')' : this.type === '@' ? ')' + : this.type === '?' + ? ')?' + : this.type === '+' && bodyDotAllowed + ? ')' + : this.type === '*' && bodyDotAllowed + ? `)?` : `)${this.type}` final = start + body + close } @@ -588,6 +596,24 @@ export class AST { ] } + #partsToRegExp(dot: boolean) { + return this.#parts + .map(p => { + // extglob ASTs should only contain parent ASTs + /* c8 ignore start */ + if (typeof p === 'string') { + throw new Error('string type in extglob ast??') + } + /* c8 ignore stop */ + // can ignore hasMagic, because extglobs are already always magic + const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot) + this.#uflag = this.#uflag || uflag + return re + }) + .filter(p => !(this.isStart() && this.isEnd()) || !!p) + .join('|') + } + static #parseGlob( glob: string, hasMagic: boolean | undefined, diff --git a/tap-snapshots/test/basic.js.test.cjs b/tap-snapshots/test/basic.js.test.cjs index c5845a9..ea44e2f 100644 --- a/tap-snapshots/test/basic.js.test.cjs +++ b/tap-snapshots/test/basic.js.test.cjs @@ -259,6 +259,28 @@ Array [ ] ` +exports[`test/basic.js TAP basic tests > *(?) hasMagic known 1`] = ` +true +` + +exports[`test/basic.js TAP basic tests > *(?) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/basic.js TAP basic tests > *(?) parsed 1`] = ` +Array [ + Array [], + Array [ + "*", + Array [ + Array [], + "?", + ], + ], + Object {}, +] +` + exports[`test/basic.js TAP basic tests > *(a/b) hasMagic known 1`] = ` true ` @@ -852,6 +874,65 @@ Array [ ] ` +exports[`test/basic.js TAP basic tests > +(.|a|!(b)) hasMagic known 1`] = ` +true +` + +exports[`test/basic.js TAP basic tests > +(.|a|!(b)) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/basic.js TAP basic tests > +(.|a|!(b)) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + ".", + ], + Array [ + Array [], + "a", + ], + Array [ + Array [], + Array [ + "!", + Array [ + Array [], + "b", + Object {}, + ], + ], + ], + ], + Object {}, +] +` + +exports[`test/basic.js TAP basic tests > +(?) hasMagic known 1`] = ` +true +` + +exports[`test/basic.js TAP basic tests > +(?) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/basic.js TAP basic tests > +(?) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + "?", + ], + ], + Object {}, +] +` + exports[`test/basic.js TAP basic tests > +(a)!(b)+(c) hasMagic known 1`] = ` true ` @@ -893,6 +974,39 @@ Array [ ] ` +exports[`test/basic.js TAP basic tests > +(a|!(b)) hasMagic known 1`] = ` +true +` + +exports[`test/basic.js TAP basic tests > +(a|!(b)) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/basic.js TAP basic tests > +(a|!(b)) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + "a", + ], + Array [ + Array [], + Array [ + "!", + Array [ + Array [], + "b", + Object {}, + ], + ], + ], + ], + Object {}, +] +` + exports[`test/basic.js TAP basic tests > +(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g hasMagic known 1`] = ` true ` @@ -912,6 +1026,58 @@ Array [ ] ` +exports[`test/basic.js TAP basic tests > +(a|.) hasMagic known 1`] = ` +true +` + +exports[`test/basic.js TAP basic tests > +(a|.) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/basic.js TAP basic tests > +(a|.) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + "a", + ], + Array [ + Array [], + ".", + ], + ], + Object {}, +] +` + +exports[`test/basic.js TAP basic tests > +(a|?) hasMagic known 1`] = ` +true +` + +exports[`test/basic.js TAP basic tests > +(a|?) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/basic.js TAP basic tests > +(a|?) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + "a", + ], + Array [ + Array [], + "?", + ], + ], + Object {}, +] +` + exports[`test/basic.js TAP basic tests > +(x|a[^)]y) hasMagic known 1`] = ` true ` @@ -3027,7 +3193,7 @@ exports[`test/basic.js TAP basic tests > makeRe !()y 2`] = ` ` exports[`test/basic.js TAP basic tests > makeRe !(.a|js)@(.*) 1`] = ` -/^(?:(?!(?:\\.a(?:\\.[^/]*?)(?:$|\\/)|js(?:\\.[^/]*?)(?:$|\\/)))(?!\\.)[^/]*?)(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:(?!(?:\\.a(?:\\.[^/]*?)(?:$|\\/)|js(?:\\.[^/]*?)(?:$|\\/)))(?!\\.)[^/]*?)(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/basic.js TAP basic tests > makeRe !\\!a* 1`] = ` @@ -3051,7 +3217,7 @@ exports[`test/basic.js TAP basic tests > makeRe #* 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe * 1`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ ` exports[`test/basic.js TAP basic tests > makeRe * 2`] = ` @@ -3059,7 +3225,11 @@ exports[`test/basic.js TAP basic tests > makeRe * 2`] = ` ` exports[`test/basic.js TAP basic tests > makeRe * 3`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ +` + +exports[`test/basic.js TAP basic tests > makeRe *(?) 1`] = ` +/^(?:(?:(?!\\.)[^/])(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/])*?)?$/ ` exports[`test/basic.js TAP basic tests > makeRe *(a/b) 1`] = ` @@ -3127,7 +3297,7 @@ exports[`test/basic.js TAP basic tests > makeRe *.* 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe *.* 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.[^/]*?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.[^/]*?$/ ` exports[`test/basic.js TAP basic tests > makeRe *.Y 1`] = ` @@ -3135,7 +3305,7 @@ exports[`test/basic.js TAP basic tests > makeRe *.Y 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe *.Z 1`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.Z$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.Z$/i ` exports[`test/basic.js TAP basic tests > makeRe *.\\* 1`] = ` @@ -3147,7 +3317,7 @@ exports[`test/basic.js TAP basic tests > makeRe *.js 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe *.js 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.js$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.js$/ ` exports[`test/basic.js TAP basic tests > makeRe *.js 3`] = ` @@ -3155,7 +3325,7 @@ exports[`test/basic.js TAP basic tests > makeRe *.js 3`] = ` ` exports[`test/basic.js TAP basic tests > makeRe *.js 4`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.js$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.js$/i ` exports[`test/basic.js TAP basic tests > makeRe *.y 1`] = ` @@ -3163,7 +3333,7 @@ exports[`test/basic.js TAP basic tests > makeRe *.y 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe *.z 1`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.z$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.z$/ ` exports[`test/basic.js TAP basic tests > makeRe */man*/bash.* 1`] = ` @@ -3194,24 +3364,44 @@ exports[`test/basic.js TAP basic tests > makeRe +()*(x|a) 1`] = ` /^(?:)+(?:x|a)*$/ ` +exports[`test/basic.js TAP basic tests > makeRe +(.|a|!(b)) 1`] = ` +/^(?:(?:\\.|a|(?:(?!(?:b(?:$|\\/)))(?!\\.)[^/]*?))(?:\\.|a|(?:(?!(?:b(?:$|\\/)))[^/]*?))*?)$/ +` + +exports[`test/basic.js TAP basic tests > makeRe +(?) 1`] = ` +/^(?:(?:(?!\\.)[^/])(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/])*?)$/ +` + exports[`test/basic.js TAP basic tests > makeRe +(a)!(b)+(c) 1`] = ` /^(?:a)+(?:(?!(?:b(?:c)+(?:$|\\/)))[^/]*?)(?:c)+$/ ` +exports[`test/basic.js TAP basic tests > makeRe +(a|!(b)) 1`] = ` +/^(?:(?:a|(?:(?!(?:b(?:$|\\/)))(?!\\.)[^/]*?))(?:a|(?:(?!(?:b(?:$|\\/)))[^/]*?))*?)$/ +` + exports[`test/basic.js TAP basic tests > makeRe +(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g 1`] = ` /^\\+\\(a\\|[^/]*?|c\\\\\\|d\\\\|e\\\\\\\\\\|f\\\\\\\\|g$/ ` +exports[`test/basic.js TAP basic tests > makeRe +(a|.) 1`] = ` +/^(?:a|\\.)+$/ +` + +exports[`test/basic.js TAP basic tests > makeRe +(a|?) 1`] = ` +/^(?:(?:a|(?!\\.)[^/])(?:a|(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/])*?)$/ +` + exports[`test/basic.js TAP basic tests > makeRe +(x|a[^)]y) 1`] = ` /^(?:x|a[^)]y)+$/ ` exports[`test/basic.js TAP basic tests > makeRe .* 1`] = ` -/^(?!\\.\\.?(?:$|\\/))\\.[^/]*?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?$/ ` exports[`test/basic.js TAP basic tests > makeRe .* 2`] = ` -/^(?!\\.\\.?(?:$|\\/))\\.[^/]*?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?$/ ` exports[`test/basic.js TAP basic tests > makeRe .x/**/* 1`] = ` @@ -3219,7 +3409,7 @@ exports[`test/basic.js TAP basic tests > makeRe .x/**/* 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe .x/**/* 2`] = ` -/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ ` exports[`test/basic.js TAP basic tests > makeRe .x/**/**/* 1`] = ` @@ -3227,7 +3417,7 @@ exports[`test/basic.js TAP basic tests > makeRe .x/**/**/* 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe .x/**/**/* 2`] = ` -/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ ` exports[`test/basic.js TAP basic tests > makeRe .x/**/*/** 1`] = ` @@ -3235,7 +3425,7 @@ exports[`test/basic.js TAP basic tests > makeRe .x/**/*/** 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe .x/**/*/** 2`] = ` -/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ ` exports[`test/basic.js TAP basic tests > makeRe .x/*/** 1`] = ` @@ -3243,7 +3433,7 @@ exports[`test/basic.js TAP basic tests > makeRe .x/*/** 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe .x/*/** 2`] = ` -/^\\.x\\/(?!\\.\\.?(?:$|\\/))[^/]+?(?:\\/|(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)?$/ +/^\\.x\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?(?:\\/|(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)?$/ ` exports[`test/basic.js TAP basic tests > makeRe .x/*/**/** 1`] = ` @@ -3251,7 +3441,7 @@ exports[`test/basic.js TAP basic tests > makeRe .x/*/**/** 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe .x/*/**/** 2`] = ` -/^\\.x\\/(?!\\.\\.?(?:$|\\/))[^/]+?(?:\\/|(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)?$/ +/^\\.x\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?(?:\\/|(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)?$/ ` exports[`test/basic.js TAP basic tests > makeRe /^root:/{s/^[^:]*:[^:]*:([^:]*).*$// 1`] = ` @@ -3303,7 +3493,7 @@ exports[`test/basic.js TAP basic tests > makeRe ?.js 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe ?.js 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]\\.js$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]\\.js$/ ` exports[`test/basic.js TAP basic tests > makeRe ?.js 3`] = ` @@ -3311,7 +3501,7 @@ exports[`test/basic.js TAP basic tests > makeRe ?.js 3`] = ` ` exports[`test/basic.js TAP basic tests > makeRe ?.js 4`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]\\.js$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]\\.js$/i ` exports[`test/basic.js TAP basic tests > makeRe ?? 1`] = ` @@ -3319,11 +3509,11 @@ exports[`test/basic.js TAP basic tests > makeRe ?? 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe ?? 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/][^/]$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/][^/]$/ ` exports[`test/basic.js TAP basic tests > makeRe ?? 3`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/][^/]$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/][^/]$/i ` exports[`test/basic.js TAP basic tests > makeRe ?? 4`] = ` @@ -3343,7 +3533,7 @@ exports[`test/basic.js TAP basic tests > makeRe ??? 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe ??? 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/][^/][^/]$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/][^/][^/]$/ ` exports[`test/basic.js TAP basic tests > makeRe ?js 1`] = ` @@ -3351,35 +3541,35 @@ exports[`test/basic.js TAP basic tests > makeRe ?js 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe ?js 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]js$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]js$/ ` exports[`test/basic.js TAP basic tests > makeRe ?js 3`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]js$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]js$/i ` exports[`test/basic.js TAP basic tests > makeRe @(*|.*) 1`] = ` -/^(?:(?!\\.)[^/]+?|(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:(?!\\.)[^/]+?|(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/basic.js TAP basic tests > makeRe @(*|a) 1`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))[^/]+?|a)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?|a)$/ ` exports[`test/basic.js TAP basic tests > makeRe @(.*) 1`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/basic.js TAP basic tests > makeRe @(.*) 2`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/basic.js TAP basic tests > makeRe @(.*|*) 1`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?|(?!\\.)[^/]+?)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?|(?!\\.)[^/]+?)$/ ` exports[`test/basic.js TAP basic tests > makeRe @(.*|js) 1`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?|js)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?|js)$/ ` exports[`test/basic.js TAP basic tests > makeRe @(a|a[(])b 1`] = ` @@ -3391,7 +3581,7 @@ exports[`test/basic.js TAP basic tests > makeRe @(a|a[)])b 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe @(js|.*) 1`] = ` -/^(?:js|(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:js|(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/basic.js TAP basic tests > makeRe X* 1`] = ` @@ -3627,7 +3817,7 @@ exports[`test/basic.js TAP basic tests > makeRe a*cd**?**??k 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe a/*/b 1`] = ` -/^a\\/(?!\\.\\.?(?:$|\\/))[^/]+?\\/b$/ +/^a\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?\\/b$/ ` exports[`test/basic.js TAP basic tests > makeRe a/*/b 2`] = ` @@ -3635,11 +3825,11 @@ exports[`test/basic.js TAP basic tests > makeRe a/*/b 2`] = ` ` exports[`test/basic.js TAP basic tests > makeRe a/.*/b 1`] = ` -/^a\\/(?!\\.\\.?(?:$|\\/))\\.[^/]*?\\/b$/ +/^a\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?\\/b$/ ` exports[`test/basic.js TAP basic tests > makeRe a/.*/b 2`] = ` -/^a\\/(?!\\.\\.?(?:$|\\/))\\.[^/]*?\\/b$/ +/^a\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?\\/b$/ ` exports[`test/basic.js TAP basic tests > makeRe a/[2015-03-10T00:23:08.647Z\\]/z 1`] = ` @@ -3699,7 +3889,7 @@ exports[`test/basic.js TAP basic tests > makeRe man/man1/bash.1 1`] = ` ` exports[`test/basic.js TAP basic tests > makeRe s/\\..*// 1`] = ` -/^s\\/(?!\\.\\.?(?:$|\\/))\\.\\.[^/]*?\\/$/ +/^s\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.\\.[^/]*?\\/$/ ` exports[`test/basic.js TAP basic tests > makeRe x/*/../../a/b/c 1`] = ` diff --git a/tap-snapshots/test/escape-has-magic.js.test.cjs b/tap-snapshots/test/escape-has-magic.js.test.cjs index e907efb..2c1e25e 100644 --- a/tap-snapshots/test/escape-has-magic.js.test.cjs +++ b/tap-snapshots/test/escape-has-magic.js.test.cjs @@ -42,7 +42,7 @@ exports[`test/escape-has-magic.js TAP > !(.a|js)@(.*) 1`] = ` Array [ Array [ Array [ - /^(?:(?!(?:\\.a(?:\\.[^/]*?)(?:$|\\/)|js(?:\\.[^/]*?)(?:$|\\/)))(?!\\.)[^/]*?)(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/, + /^(?:(?!(?:\\.a(?:\\.[^/]*?)(?:$|\\/)|js(?:\\.[^/]*?)(?:$|\\/)))(?!\\.)[^/]*?)(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/, ], ], true, @@ -104,7 +104,7 @@ exports[`test/escape-has-magic.js TAP > * 1`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/]+?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/, ], ], true, @@ -126,7 +126,18 @@ exports[`test/escape-has-magic.js TAP > * 3`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/]+?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/, + ], + ], + true, +] +` + +exports[`test/escape-has-magic.js TAP > *(?) 1`] = ` +Array [ + Array [ + Array [ + /^(?:(?:(?!\\.)[^/])(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/])*?)?$/, ], ], true, @@ -330,7 +341,7 @@ exports[`test/escape-has-magic.js TAP > *.* 2`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/]*?\\.[^/]*?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.[^/]*?$/, ], ], true, @@ -352,7 +363,7 @@ exports[`test/escape-has-magic.js TAP > *.Z 1`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/]*?\\.Z$/i, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.Z$/i, ], ], true, @@ -385,7 +396,7 @@ exports[`test/escape-has-magic.js TAP > *.js 2`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/]*?\\.js$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.js$/, ], ], true, @@ -407,7 +418,7 @@ exports[`test/escape-has-magic.js TAP > *.js 4`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/]*?\\.js$/i, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.js$/i, ], ], true, @@ -429,7 +440,7 @@ exports[`test/escape-has-magic.js TAP > *.z 1`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/]*?\\.z$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.z$/, ], ], true, @@ -515,6 +526,28 @@ Array [ ] ` +exports[`test/escape-has-magic.js TAP > +(.|a|!(b)) 1`] = ` +Array [ + Array [ + Array [ + /^(?:(?:\\.|a|(?:(?!(?:b(?:$|\\/)))(?!\\.)[^/]*?))(?:\\.|a|(?:(?!(?:b(?:$|\\/)))[^/]*?))*?)$/, + ], + ], + true, +] +` + +exports[`test/escape-has-magic.js TAP > +(?) 1`] = ` +Array [ + Array [ + Array [ + /^(?:(?:(?!\\.)[^/])(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/])*?)$/, + ], + ], + true, +] +` + exports[`test/escape-has-magic.js TAP > +(a)!(b)+(c) 1`] = ` Array [ Array [ @@ -526,6 +559,17 @@ Array [ ] ` +exports[`test/escape-has-magic.js TAP > +(a|!(b)) 1`] = ` +Array [ + Array [ + Array [ + /^(?:(?:a|(?:(?!(?:b(?:$|\\/)))(?!\\.)[^/]*?))(?:a|(?:(?!(?:b(?:$|\\/)))[^/]*?))*?)$/, + ], + ], + true, +] +` + exports[`test/escape-has-magic.js TAP > +(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g 1`] = ` Array [ Array [ @@ -537,6 +581,28 @@ Array [ ] ` +exports[`test/escape-has-magic.js TAP > +(a|.) 1`] = ` +Array [ + Array [ + Array [ + /^(?:a|\\.)+$/, + ], + ], + true, +] +` + +exports[`test/escape-has-magic.js TAP > +(a|?) 1`] = ` +Array [ + Array [ + Array [ + /^(?:(?:a|(?!\\.)[^/])(?:a|(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/])*?)$/, + ], + ], + true, +] +` + exports[`test/escape-has-magic.js TAP > +(x|a[^)]y) 1`] = ` Array [ Array [ @@ -552,7 +618,7 @@ exports[`test/escape-has-magic.js TAP > .* 1`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))\\.[^/]*?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?$/, ], ], true, @@ -563,7 +629,7 @@ exports[`test/escape-has-magic.js TAP > .* 2`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))\\.[^/]*?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?$/, ], ], true, @@ -589,7 +655,7 @@ Array [ Array [ ".x", Symbol(globstar **), - /^(?!\\.\\.?(?:$|\\/))[^/]+?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/, ], ], true, @@ -615,7 +681,7 @@ Array [ Array [ ".x", Symbol(globstar **), - /^(?!\\.\\.?(?:$|\\/))[^/]+?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/, ], ], true, @@ -642,7 +708,7 @@ Array [ Array [ ".x", Symbol(globstar **), - /^(?!\\.\\.?(?:$|\\/))[^/]+?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/, Symbol(globstar **), ], ], @@ -668,7 +734,7 @@ Array [ Array [ Array [ ".x", - /^(?!\\.\\.?(?:$|\\/))[^/]+?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/, Symbol(globstar **), ], ], @@ -694,7 +760,7 @@ Array [ Array [ Array [ ".x", - /^(?!\\.\\.?(?:$|\\/))[^/]+?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/, Symbol(globstar **), ], ], @@ -848,7 +914,7 @@ exports[`test/escape-has-magic.js TAP > ?.js 2`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/]\\.js$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]\\.js$/, ], ], true, @@ -870,7 +936,7 @@ exports[`test/escape-has-magic.js TAP > ?.js 4`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/]\\.js$/i, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]\\.js$/i, ], ], true, @@ -892,7 +958,7 @@ exports[`test/escape-has-magic.js TAP > ?? 2`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/][^/]$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/][^/]$/, ], ], true, @@ -903,7 +969,7 @@ exports[`test/escape-has-magic.js TAP > ?? 3`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/][^/]$/i, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/][^/]$/i, ], ], true, @@ -958,7 +1024,7 @@ exports[`test/escape-has-magic.js TAP > ??? 2`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/][^/][^/]$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/][^/][^/]$/, ], ], true, @@ -980,7 +1046,7 @@ exports[`test/escape-has-magic.js TAP > ?js 2`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/]js$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]js$/, ], ], true, @@ -991,7 +1057,7 @@ exports[`test/escape-has-magic.js TAP > ?js 3`] = ` Array [ Array [ Array [ - /^(?!\\.\\.?(?:$|\\/))[^/]js$/i, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]js$/i, ], ], true, @@ -1002,7 +1068,7 @@ exports[`test/escape-has-magic.js TAP > @(*|.*) 1`] = ` Array [ Array [ Array [ - /^(?:(?!\\.)[^/]+?|(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/, + /^(?:(?!\\.)[^/]+?|(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/, ], ], true, @@ -1013,7 +1079,7 @@ exports[`test/escape-has-magic.js TAP > @(*|a) 1`] = ` Array [ Array [ Array [ - /^(?:(?!\\.\\.?(?:$|\\/))[^/]+?|a)$/, + /^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?|a)$/, ], ], true, @@ -1024,7 +1090,7 @@ exports[`test/escape-has-magic.js TAP > @(.*) 1`] = ` Array [ Array [ Array [ - /^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/, + /^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/, ], ], true, @@ -1035,7 +1101,7 @@ exports[`test/escape-has-magic.js TAP > @(.*) 2`] = ` Array [ Array [ Array [ - /^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/, + /^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/, ], ], true, @@ -1046,7 +1112,7 @@ exports[`test/escape-has-magic.js TAP > @(.*|*) 1`] = ` Array [ Array [ Array [ - /^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?|(?!\\.)[^/]+?)$/, + /^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?|(?!\\.)[^/]+?)$/, ], ], true, @@ -1057,7 +1123,7 @@ exports[`test/escape-has-magic.js TAP > @(.*|js) 1`] = ` Array [ Array [ Array [ - /^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?|js)$/, + /^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?|js)$/, ], ], true, @@ -1090,7 +1156,7 @@ exports[`test/escape-has-magic.js TAP > @(js|.*) 1`] = ` Array [ Array [ Array [ - /^(?:js|(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/, + /^(?:js|(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/, ], ], true, @@ -1742,7 +1808,7 @@ Array [ Array [ Array [ "a", - /^(?!\\.\\.?(?:$|\\/))[^/]+?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/, "b", ], ], @@ -1768,7 +1834,7 @@ Array [ Array [ Array [ "a", - /^(?!\\.\\.?(?:$|\\/))\\.[^/]*?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?$/, "b", ], ], @@ -1781,7 +1847,7 @@ Array [ Array [ Array [ "a", - /^(?!\\.\\.?(?:$|\\/))\\.[^/]*?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?$/, "b", ], ], @@ -1964,7 +2030,7 @@ Array [ Array [ Array [ "s", - /^(?!\\.\\.?(?:$|\\/))\\.\\.[^/]*?$/, + /^(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.\\.[^/]*?$/, "", ], ], diff --git a/tap-snapshots/test/optimization-level-0.ts.test.cjs b/tap-snapshots/test/optimization-level-0.ts.test.cjs index e8ed2cc..3f3c0fb 100644 --- a/tap-snapshots/test/optimization-level-0.ts.test.cjs +++ b/tap-snapshots/test/optimization-level-0.ts.test.cjs @@ -289,6 +289,23 @@ Array [ ] ` +exports[`test/optimization-level-0.ts TAP basic tests > "*(?)" ["a.a","a.b","aa","aa.","ab","ab.","b.a","b.b","ba","ba.","bb","bb."] 1`] = ` +Array [ + "a.a", + "a.b", + "aa", + "aa.", + "ab", + "ab.", + "b.a", + "b.b", + "ba", + "ba.", + "bb", + "bb.", +] +` + exports[`test/optimization-level-0.ts TAP basic tests > "*(a/b)" ["*(a/b)"] 1`] = ` Array [ "*(a/b)", @@ -561,6 +578,44 @@ Array [ ] ` +exports[`test/optimization-level-0.ts TAP basic tests > "+(.|a|!(b))" [".aa",".ab",".ba",".bb","a.a","a.b","aa","aa.","ab","ab.","b.a","b.b","ba","ba.","bb","bb."] 1`] = ` +Array [ + ".aa", + ".ab", + ".ba", + ".bb", + "a.a", + "a.b", + "aa", + "aa.", + "ab", + "ab.", + "b.a", + "b.b", + "ba", + "ba.", + "bb", + "bb.", +] +` + +exports[`test/optimization-level-0.ts TAP basic tests > "+(?)" ["a.a","a.b","aa","aa.","ab","ab.","b.a","b.b","ba","ba.","bb","bb."] 1`] = ` +Array [ + "a.a", + "a.b", + "aa", + "aa.", + "ab", + "ab.", + "b.a", + "b.b", + "ba", + "ba.", + "bb", + "bb.", +] +` + exports[`test/optimization-level-0.ts TAP basic tests > "+(a)!(b)+(c)" ["ac","acc","adc"] 1`] = ` Array [ "ac", @@ -569,12 +624,55 @@ Array [ ] ` +exports[`test/optimization-level-0.ts TAP basic tests > "+(a|!(b))" ["a.a","a.b","aa","aa.","ab","ab.","b.a","b.b","ba","ba.","bb","bb."] 1`] = ` +Array [ + "a.a", + "a.b", + "aa", + "aa.", + "ab", + "ab.", + "b.a", + "b.b", + "ba", + "ba.", + "bb", + "bb.", +] +` + exports[`test/optimization-level-0.ts TAP basic tests > "+(a|*\\\\|c\\\\\\\\|d\\\\\\\\\\\\|e\\\\\\\\\\\\\\\\|f\\\\\\\\\\\\\\\\\\\\|g" ["+(a|b\\\\|c\\\\\\\\|d\\\\\\\\|e\\\\\\\\\\\\\\\\|f\\\\\\\\\\\\\\\\|g"] 1`] = ` Array [ "+(a|b\\\\|c\\\\\\\\|d\\\\\\\\|e\\\\\\\\\\\\\\\\|f\\\\\\\\\\\\\\\\|g", ] ` +exports[`test/optimization-level-0.ts TAP basic tests > "+(a|.)" [".aa","a.a","aa","aa."] 1`] = ` +Array [ + ".aa", + "a.a", + "aa", + "aa.", +] +` + +exports[`test/optimization-level-0.ts TAP basic tests > "+(a|?)" ["a.a","a.b","aa","aa.","ab","ab.","b.a","b.b","ba","ba.","bb","bb."] 1`] = ` +Array [ + "a.a", + "a.b", + "aa", + "aa.", + "ab", + "ab.", + "b.a", + "b.b", + "ba", + "ba.", + "bb", + "bb.", +] +` + exports[`test/optimization-level-0.ts TAP basic tests > "+(x|a[^)]y)" ["a.y","x"] 1`] = ` Array [ "a.y", @@ -1558,6 +1656,28 @@ Array [ ] ` +exports[`test/optimization-level-0.ts TAP basic tests > *(?) hasMagic known 1`] = ` +true +` + +exports[`test/optimization-level-0.ts TAP basic tests > *(?) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/optimization-level-0.ts TAP basic tests > *(?) parsed 1`] = ` +Array [ + Array [], + Array [ + "*", + Array [ + Array [], + "?", + ], + ], + Object {}, +] +` + exports[`test/optimization-level-0.ts TAP basic tests > *(a/b) hasMagic known 1`] = ` true ` @@ -2151,6 +2271,65 @@ Array [ ] ` +exports[`test/optimization-level-0.ts TAP basic tests > +(.|a|!(b)) hasMagic known 1`] = ` +true +` + +exports[`test/optimization-level-0.ts TAP basic tests > +(.|a|!(b)) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/optimization-level-0.ts TAP basic tests > +(.|a|!(b)) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + ".", + ], + Array [ + Array [], + "a", + ], + Array [ + Array [], + Array [ + "!", + Array [ + Array [], + "b", + Object {}, + ], + ], + ], + ], + Object {}, +] +` + +exports[`test/optimization-level-0.ts TAP basic tests > +(?) hasMagic known 1`] = ` +true +` + +exports[`test/optimization-level-0.ts TAP basic tests > +(?) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/optimization-level-0.ts TAP basic tests > +(?) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + "?", + ], + ], + Object {}, +] +` + exports[`test/optimization-level-0.ts TAP basic tests > +(a)!(b)+(c) hasMagic known 1`] = ` true ` @@ -2192,6 +2371,39 @@ Array [ ] ` +exports[`test/optimization-level-0.ts TAP basic tests > +(a|!(b)) hasMagic known 1`] = ` +true +` + +exports[`test/optimization-level-0.ts TAP basic tests > +(a|!(b)) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/optimization-level-0.ts TAP basic tests > +(a|!(b)) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + "a", + ], + Array [ + Array [], + Array [ + "!", + Array [ + Array [], + "b", + Object {}, + ], + ], + ], + ], + Object {}, +] +` + exports[`test/optimization-level-0.ts TAP basic tests > +(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g hasMagic known 1`] = ` true ` @@ -2211,6 +2423,58 @@ Array [ ] ` +exports[`test/optimization-level-0.ts TAP basic tests > +(a|.) hasMagic known 1`] = ` +true +` + +exports[`test/optimization-level-0.ts TAP basic tests > +(a|.) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/optimization-level-0.ts TAP basic tests > +(a|.) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + "a", + ], + Array [ + Array [], + ".", + ], + ], + Object {}, +] +` + +exports[`test/optimization-level-0.ts TAP basic tests > +(a|?) hasMagic known 1`] = ` +true +` + +exports[`test/optimization-level-0.ts TAP basic tests > +(a|?) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/optimization-level-0.ts TAP basic tests > +(a|?) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + "a", + ], + Array [ + Array [], + "?", + ], + ], + Object {}, +] +` + exports[`test/optimization-level-0.ts TAP basic tests > +(x|a[^)]y) hasMagic known 1`] = ` true ` @@ -4326,7 +4590,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe !()y 2`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe !(.a|js)@(.*) 1`] = ` -/^(?:(?!(?:\\.a(?:\\.[^/]*?)(?:$|\\/)|js(?:\\.[^/]*?)(?:$|\\/)))(?!\\.)[^/]*?)(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:(?!(?:\\.a(?:\\.[^/]*?)(?:$|\\/)|js(?:\\.[^/]*?)(?:$|\\/)))(?!\\.)[^/]*?)(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe !\\!a* 1`] = ` @@ -4350,7 +4614,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe #* 1`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe * 1`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe * 2`] = ` @@ -4358,7 +4622,11 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe * 2`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe * 3`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ +` + +exports[`test/optimization-level-0.ts TAP basic tests > makeRe *(?) 1`] = ` +/^(?:(?:(?!\\.)[^/])(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/])*?)?$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe *(a/b) 1`] = ` @@ -4426,7 +4694,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.* 1`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.* 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.[^/]*?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.[^/]*?$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.Y 1`] = ` @@ -4434,7 +4702,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.Y 1`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.Z 1`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.Z$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.Z$/i ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.\\* 1`] = ` @@ -4446,7 +4714,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.js 1`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.js 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.js$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.js$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.js 3`] = ` @@ -4454,7 +4722,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.js 3`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.js 4`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.js$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.js$/i ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.y 1`] = ` @@ -4462,7 +4730,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.y 1`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe *.z 1`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.z$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.z$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe */man*/bash.* 1`] = ` @@ -4493,24 +4761,44 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe +()*(x|a) 1`] = ` /^(?:)+(?:x|a)*$/ ` +exports[`test/optimization-level-0.ts TAP basic tests > makeRe +(.|a|!(b)) 1`] = ` +/^(?:(?:\\.|a|(?:(?!(?:b(?:$|\\/)))(?!\\.)[^/]*?))(?:\\.|a|(?:(?!(?:b(?:$|\\/)))[^/]*?))*?)$/ +` + +exports[`test/optimization-level-0.ts TAP basic tests > makeRe +(?) 1`] = ` +/^(?:(?:(?!\\.)[^/])(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/])*?)$/ +` + exports[`test/optimization-level-0.ts TAP basic tests > makeRe +(a)!(b)+(c) 1`] = ` /^(?:a)+(?:(?!(?:b(?:c)+(?:$|\\/)))[^/]*?)(?:c)+$/ ` +exports[`test/optimization-level-0.ts TAP basic tests > makeRe +(a|!(b)) 1`] = ` +/^(?:(?:a|(?:(?!(?:b(?:$|\\/)))(?!\\.)[^/]*?))(?:a|(?:(?!(?:b(?:$|\\/)))[^/]*?))*?)$/ +` + exports[`test/optimization-level-0.ts TAP basic tests > makeRe +(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g 1`] = ` /^\\+\\(a\\|[^/]*?|c\\\\\\|d\\\\|e\\\\\\\\\\|f\\\\\\\\|g$/ ` +exports[`test/optimization-level-0.ts TAP basic tests > makeRe +(a|.) 1`] = ` +/^(?:a|\\.)+$/ +` + +exports[`test/optimization-level-0.ts TAP basic tests > makeRe +(a|?) 1`] = ` +/^(?:(?:a|(?!\\.)[^/])(?:a|(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/])*?)$/ +` + exports[`test/optimization-level-0.ts TAP basic tests > makeRe +(x|a[^)]y) 1`] = ` /^(?:x|a[^)]y)+$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe .* 1`] = ` -/^(?!\\.\\.?(?:$|\\/))\\.[^/]*?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe .* 2`] = ` -/^(?!\\.\\.?(?:$|\\/))\\.[^/]*?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/**/* 1`] = ` @@ -4518,7 +4806,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/**/* 1`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/**/* 2`] = ` -/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/**/**/* 1`] = ` @@ -4526,7 +4814,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/**/**/* 1`] = ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/**/**/* 2`] = ` -/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/**/*/** 1`] = ` @@ -4534,7 +4822,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/**/*/** 1`] = ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/**/*/** 2`] = ` -/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/*/** 1`] = ` @@ -4542,7 +4830,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/*/** 1`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/*/** 2`] = ` -/^\\.x\\/(?!\\.\\.?(?:$|\\/))[^/]+?(?:\\/|(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)?$/ +/^\\.x\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?(?:\\/|(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)?$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/*/**/** 1`] = ` @@ -4550,7 +4838,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/*/**/** 1`] = ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe .x/*/**/** 2`] = ` -/^\\.x\\/(?!\\.\\.?(?:$|\\/))[^/]+?(?:\\/|(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)?$/ +/^\\.x\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?(?:\\/|(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)?$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe /^root:/{s/^[^:]*:[^:]*:([^:]*).*$// 1`] = ` @@ -4602,7 +4890,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?.js 1`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?.js 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]\\.js$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]\\.js$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?.js 3`] = ` @@ -4610,7 +4898,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?.js 3`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?.js 4`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]\\.js$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]\\.js$/i ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?? 1`] = ` @@ -4618,11 +4906,11 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?? 1`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?? 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/][^/]$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/][^/]$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?? 3`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/][^/]$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/][^/]$/i ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?? 4`] = ` @@ -4642,7 +4930,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe ??? 1`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe ??? 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/][^/][^/]$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/][^/][^/]$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?js 1`] = ` @@ -4650,35 +4938,35 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?js 1`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?js 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]js$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]js$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe ?js 3`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]js$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]js$/i ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe @(*|.*) 1`] = ` -/^(?:(?!\\.)[^/]+?|(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:(?!\\.)[^/]+?|(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe @(*|a) 1`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))[^/]+?|a)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?|a)$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe @(.*) 1`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe @(.*) 2`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe @(.*|*) 1`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?|(?!\\.)[^/]+?)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?|(?!\\.)[^/]+?)$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe @(.*|js) 1`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?|js)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?|js)$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe @(a|a[(])b 1`] = ` @@ -4690,7 +4978,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe @(a|a[)])b 1`] = ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe @(js|.*) 1`] = ` -/^(?:js|(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:js|(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe X* 1`] = ` @@ -4926,7 +5214,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe a*cd**?**??k 1`] ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe a/*/b 1`] = ` -/^a\\/(?!\\.\\.?(?:$|\\/))[^/]+?\\/b$/ +/^a\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?\\/b$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe a/*/b 2`] = ` @@ -4934,11 +5222,11 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe a/*/b 2`] = ` ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe a/.*/b 1`] = ` -/^a\\/(?!\\.\\.?(?:$|\\/))\\.[^/]*?\\/b$/ +/^a\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?\\/b$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe a/.*/b 2`] = ` -/^a\\/(?!\\.\\.?(?:$|\\/))\\.[^/]*?\\/b$/ +/^a\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?\\/b$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe a/[2015-03-10T00:23:08.647Z\\]/z 1`] = ` @@ -4998,7 +5286,7 @@ exports[`test/optimization-level-0.ts TAP basic tests > makeRe man/man1/bash.1 1 ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe s/\\..*// 1`] = ` -/^s\\/(?!\\.\\.?(?:$|\\/))\\.\\.[^/]*?\\/$/ +/^s\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.\\.[^/]*?\\/$/ ` exports[`test/optimization-level-0.ts TAP basic tests > makeRe x/*/../../a/b/c 1`] = ` diff --git a/tap-snapshots/test/optimization-level-2.ts.test.cjs b/tap-snapshots/test/optimization-level-2.ts.test.cjs index edb6475..47f04e4 100644 --- a/tap-snapshots/test/optimization-level-2.ts.test.cjs +++ b/tap-snapshots/test/optimization-level-2.ts.test.cjs @@ -259,6 +259,28 @@ Array [ ] ` +exports[`test/optimization-level-2.ts TAP basic tests > *(?) hasMagic known 1`] = ` +true +` + +exports[`test/optimization-level-2.ts TAP basic tests > *(?) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/optimization-level-2.ts TAP basic tests > *(?) parsed 1`] = ` +Array [ + Array [], + Array [ + "*", + Array [ + Array [], + "?", + ], + ], + Object {}, +] +` + exports[`test/optimization-level-2.ts TAP basic tests > *(a/b) hasMagic known 1`] = ` true ` @@ -852,6 +874,65 @@ Array [ ] ` +exports[`test/optimization-level-2.ts TAP basic tests > +(.|a|!(b)) hasMagic known 1`] = ` +true +` + +exports[`test/optimization-level-2.ts TAP basic tests > +(.|a|!(b)) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/optimization-level-2.ts TAP basic tests > +(.|a|!(b)) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + ".", + ], + Array [ + Array [], + "a", + ], + Array [ + Array [], + Array [ + "!", + Array [ + Array [], + "b", + Object {}, + ], + ], + ], + ], + Object {}, +] +` + +exports[`test/optimization-level-2.ts TAP basic tests > +(?) hasMagic known 1`] = ` +true +` + +exports[`test/optimization-level-2.ts TAP basic tests > +(?) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/optimization-level-2.ts TAP basic tests > +(?) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + "?", + ], + ], + Object {}, +] +` + exports[`test/optimization-level-2.ts TAP basic tests > +(a)!(b)+(c) hasMagic known 1`] = ` true ` @@ -893,6 +974,39 @@ Array [ ] ` +exports[`test/optimization-level-2.ts TAP basic tests > +(a|!(b)) hasMagic known 1`] = ` +true +` + +exports[`test/optimization-level-2.ts TAP basic tests > +(a|!(b)) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/optimization-level-2.ts TAP basic tests > +(a|!(b)) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + "a", + ], + Array [ + Array [], + Array [ + "!", + Array [ + Array [], + "b", + Object {}, + ], + ], + ], + ], + Object {}, +] +` + exports[`test/optimization-level-2.ts TAP basic tests > +(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g hasMagic known 1`] = ` true ` @@ -912,6 +1026,58 @@ Array [ ] ` +exports[`test/optimization-level-2.ts TAP basic tests > +(a|.) hasMagic known 1`] = ` +true +` + +exports[`test/optimization-level-2.ts TAP basic tests > +(a|.) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/optimization-level-2.ts TAP basic tests > +(a|.) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + "a", + ], + Array [ + Array [], + ".", + ], + ], + Object {}, +] +` + +exports[`test/optimization-level-2.ts TAP basic tests > +(a|?) hasMagic known 1`] = ` +true +` + +exports[`test/optimization-level-2.ts TAP basic tests > +(a|?) hasMagic pre-generate 1`] = ` +true +` + +exports[`test/optimization-level-2.ts TAP basic tests > +(a|?) parsed 1`] = ` +Array [ + Array [], + Array [ + "+", + Array [ + Array [], + "a", + ], + Array [ + Array [], + "?", + ], + ], + Object {}, +] +` + exports[`test/optimization-level-2.ts TAP basic tests > +(x|a[^)]y) hasMagic known 1`] = ` true ` @@ -3027,7 +3193,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe !()y 2`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe !(.a|js)@(.*) 1`] = ` -/^(?:(?!(?:\\.a(?:\\.[^/]*?)(?:$|\\/)|js(?:\\.[^/]*?)(?:$|\\/)))(?!\\.)[^/]*?)(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:(?!(?:\\.a(?:\\.[^/]*?)(?:$|\\/)|js(?:\\.[^/]*?)(?:$|\\/)))(?!\\.)[^/]*?)(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe !\\!a* 1`] = ` @@ -3051,7 +3217,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe #* 1`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe * 1`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe * 2`] = ` @@ -3059,7 +3225,11 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe * 2`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe * 3`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ +` + +exports[`test/optimization-level-2.ts TAP basic tests > makeRe *(?) 1`] = ` +/^(?:(?:(?!\\.)[^/])(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/])*?)?$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe *(a/b) 1`] = ` @@ -3127,7 +3297,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.* 1`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.* 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.[^/]*?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.[^/]*?$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.Y 1`] = ` @@ -3135,7 +3305,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.Y 1`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.Z 1`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.Z$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.Z$/i ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.\\* 1`] = ` @@ -3147,7 +3317,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.js 1`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.js 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.js$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.js$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.js 3`] = ` @@ -3155,7 +3325,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.js 3`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.js 4`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.js$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.js$/i ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.y 1`] = ` @@ -3163,7 +3333,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.y 1`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe *.z 1`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]*?\\.z$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]*?\\.z$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe */man*/bash.* 1`] = ` @@ -3194,24 +3364,44 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe +()*(x|a) 1`] = ` /^(?:)+(?:x|a)*$/ ` +exports[`test/optimization-level-2.ts TAP basic tests > makeRe +(.|a|!(b)) 1`] = ` +/^(?:(?:\\.|a|(?:(?!(?:b(?:$|\\/)))(?!\\.)[^/]*?))(?:\\.|a|(?:(?!(?:b(?:$|\\/)))[^/]*?))*?)$/ +` + +exports[`test/optimization-level-2.ts TAP basic tests > makeRe +(?) 1`] = ` +/^(?:(?:(?!\\.)[^/])(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/])*?)$/ +` + exports[`test/optimization-level-2.ts TAP basic tests > makeRe +(a)!(b)+(c) 1`] = ` /^(?:a)+(?:(?!(?:b(?:c)+(?:$|\\/)))[^/]*?)(?:c)+$/ ` +exports[`test/optimization-level-2.ts TAP basic tests > makeRe +(a|!(b)) 1`] = ` +/^(?:(?:a|(?:(?!(?:b(?:$|\\/)))(?!\\.)[^/]*?))(?:a|(?:(?!(?:b(?:$|\\/)))[^/]*?))*?)$/ +` + exports[`test/optimization-level-2.ts TAP basic tests > makeRe +(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g 1`] = ` /^\\+\\(a\\|[^/]*?|c\\\\\\|d\\\\|e\\\\\\\\\\|f\\\\\\\\|g$/ ` +exports[`test/optimization-level-2.ts TAP basic tests > makeRe +(a|.) 1`] = ` +/^(?:a|\\.)+$/ +` + +exports[`test/optimization-level-2.ts TAP basic tests > makeRe +(a|?) 1`] = ` +/^(?:(?:a|(?!\\.)[^/])(?:a|(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/])*?)$/ +` + exports[`test/optimization-level-2.ts TAP basic tests > makeRe +(x|a[^)]y) 1`] = ` /^(?:x|a[^)]y)+$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe .* 1`] = ` -/^(?!\\.\\.?(?:$|\\/))\\.[^/]*?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe .* 2`] = ` -/^(?!\\.\\.?(?:$|\\/))\\.[^/]*?$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/**/* 1`] = ` @@ -3219,7 +3409,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/**/* 1`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/**/* 2`] = ` -/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/**/**/* 1`] = ` @@ -3227,7 +3417,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/**/**/* 1`] = ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/**/**/* 2`] = ` -/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/**/*/** 1`] = ` @@ -3235,7 +3425,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/**/*/** 1`] = ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/**/*/** 2`] = ` -/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!\\.\\.?(?:$|\\/))[^/]+?$/ +/^\\.x(?:\\/|\\/(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?\\/)(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/*/** 1`] = ` @@ -3243,7 +3433,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/*/** 1`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/*/** 2`] = ` -/^\\.x\\/(?!\\.\\.?(?:$|\\/))[^/]+?(?:\\/|(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)?$/ +/^\\.x\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?(?:\\/|(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)?$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/*/**/** 1`] = ` @@ -3251,7 +3441,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/*/**/** 1`] = ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe .x/*/**/** 2`] = ` -/^\\.x\\/(?!\\.\\.?(?:$|\\/))[^/]+?(?:\\/|(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)?$/ +/^\\.x\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?(?:\\/|(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)?$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe /^root:/{s/^[^:]*:[^:]*:([^:]*).*$// 1`] = ` @@ -3303,7 +3493,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?.js 1`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?.js 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]\\.js$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]\\.js$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?.js 3`] = ` @@ -3311,7 +3501,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?.js 3`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?.js 4`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]\\.js$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]\\.js$/i ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?? 1`] = ` @@ -3319,11 +3509,11 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?? 1`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?? 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/][^/]$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/][^/]$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?? 3`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/][^/]$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/][^/]$/i ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?? 4`] = ` @@ -3343,7 +3533,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe ??? 1`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe ??? 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/][^/][^/]$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/][^/][^/]$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?js 1`] = ` @@ -3351,35 +3541,35 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?js 1`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?js 2`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]js$/ +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]js$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe ?js 3`] = ` -/^(?!\\.\\.?(?:$|\\/))[^/]js$/i +/^(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]js$/i ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe @(*|.*) 1`] = ` -/^(?:(?!\\.)[^/]+?|(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:(?!\\.)[^/]+?|(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe @(*|a) 1`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))[^/]+?|a)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?|a)$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe @(.*) 1`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe @(.*) 2`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe @(.*|*) 1`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?|(?!\\.)[^/]+?)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?|(?!\\.)[^/]+?)$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe @(.*|js) 1`] = ` -/^(?:(?!\\.\\.?(?:$|\\/))\\.[^/]*?|js)$/ +/^(?:(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?|js)$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe @(a|a[(])b 1`] = ` @@ -3391,7 +3581,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe @(a|a[)])b 1`] = ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe @(js|.*) 1`] = ` -/^(?:js|(?!\\.\\.?(?:$|\\/))\\.[^/]*?)$/ +/^(?:js|(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?)$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe X* 1`] = ` @@ -3627,7 +3817,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe a*cd**?**??k 1`] ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe a/*/b 1`] = ` -/^a\\/(?!\\.\\.?(?:$|\\/))[^/]+?\\/b$/ +/^a\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))[^/]+?\\/b$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe a/*/b 2`] = ` @@ -3635,11 +3825,11 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe a/*/b 2`] = ` ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe a/.*/b 1`] = ` -/^a\\/(?!\\.\\.?(?:$|\\/))\\.[^/]*?\\/b$/ +/^a\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?\\/b$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe a/.*/b 2`] = ` -/^a\\/(?!\\.\\.?(?:$|\\/))\\.[^/]*?\\/b$/ +/^a\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.[^/]*?\\/b$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe a/[2015-03-10T00:23:08.647Z\\]/z 1`] = ` @@ -3699,7 +3889,7 @@ exports[`test/optimization-level-2.ts TAP basic tests > makeRe man/man1/bash.1 1 ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe s/\\..*// 1`] = ` -/^s\\/(?!\\.\\.?(?:$|\\/))\\.\\.[^/]*?\\/$/ +/^s\\/(?!(?:^|\\/)\\.\\.?(?:$|\\/))\\.\\.[^/]*?\\/$/ ` exports[`test/optimization-level-2.ts TAP basic tests > makeRe x/*/../../a/b/c 1`] = ` diff --git a/test/patterns.js b/test/patterns.js index 85edeea..1be5c0d 100644 --- a/test/patterns.js +++ b/test/patterns.js @@ -461,6 +461,122 @@ module.exports = [ () => (files = ['x-a', 'x-ab', 'x-z', 'a-z', 'zb']), ['?(x-!(y)|z)', ['x-a', 'x-ab', 'x-z']], ['?(x-!(y)|z)b', ['x-ab', 'zb']], + + () => + (files = [ + '.aa', + '.ab', + '.ba', + '.bb', + 'a.a', + 'a.b', + 'b.a', + 'b.b', + 'aa', + 'ab', + 'ba', + 'bb', + 'aa.', + 'ab.', + 'ba.', + 'bb.', + ]), + + [ + '*(?)', + [ + 'a.a', + 'a.b', + 'b.a', + 'b.b', + 'aa', + 'ab', + 'ba', + 'bb', + 'aa.', + 'ab.', + 'ba.', + 'bb.', + ], + ], + + [ + '+(?)', + [ + 'a.a', + 'a.b', + 'b.a', + 'b.b', + 'aa', + 'ab', + 'ba', + 'bb', + 'aa.', + 'ab.', + 'ba.', + 'bb.', + ], + ], + + [ + '+(a|?)', + [ + 'a.a', + 'a.b', + 'b.a', + 'b.b', + 'aa', + 'ab', + 'ba', + 'bb', + 'aa.', + 'ab.', + 'ba.', + 'bb.', + ], + ], + + [ + '+(a|!(b))', + [ + 'a.a', + 'a.b', + 'aa', + 'aa.', + 'ab', + 'ab.', + 'b.a', + 'b.b', + 'ba', + 'ba.', + 'bb', + 'bb.', + ], + ], + + [ + '+(.|a|!(b))', + [ + '.aa', + '.ab', + '.ba', + '.bb', + 'a.a', + 'a.b', + 'aa', + 'aa.', + 'ab', + 'ab.', + 'b.a', + 'b.b', + 'ba', + 'ba.', + 'bb', + 'bb.', + ], + ], + + ['+(a|.)', ['a.a', 'aa', 'aa.', '.aa']], ] Object.defineProperty(module.exports, 'files', {