Conversation
The option was documented as a boolean but stored as a string on the beginning-of-string token, and that string was only copied into the regex after the parser backtracked. Initialize parser output from it, skip fast paths that would drop it, and document the option as a string. When the tokenizer recursively parses a suffix after a negated extglob (for example `!(*.d).ts`), do not pass prepend back into parse() or the prefix is applied twice and files that should be excluded start matching. Closes micromatch#110
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
options.prependas astring(it was listed asbooleanwhile the description, micromatch, and the parser all treated it as a string).prependis set, because those paths never see the beginning-of-string token that holds it.!(*.d).ts), do not passprependback intoparse(), or the prefix is applied twice and excluded names start matching.Provenance: issue #110 reported the type/description mismatch. micromatch already documents this option as
string. This repo already stored it asopts.prepend || ''on the beginning-of-string token.Decision
stringand honor that string on parse/makeRe output, including fast-path globs, by sending those globs through the tokenizer.parse.fastpaths/wrapOutputso fast-path regexes stay byte-identical aside from the prefix.state.outputis what made the description false for most globs. Skipping fast paths keeps a single source of truth instead of assembling the prefix in three return sites. The cost is that prepended*.js/.*use full-parser semantics (the same asfastpaths: false), including no optional trailing slash on*.js.Test plan
npx mocha test/options.prepend.js, prepend appears on parse output,makeRe, fast-path globs like*.js, POSIX classes without doubling, and!(*.d).tswithout doublingparse('abc', { prepend: 'foo' }).output === 'fooabc'makeRe('abc', { prepend: 'foo' }).source === '^(?:fooabc)$'isMatch('foofile.d.ts', '!(*.d).ts', { prepend: 'foo' }) === falsenpx mocha)