1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | const utils = require("../../utils");
|
---|
4 | class Matcher {
|
---|
5 | constructor(_patterns, _settings, _micromatchOptions) {
|
---|
6 | this._patterns = _patterns;
|
---|
7 | this._settings = _settings;
|
---|
8 | this._micromatchOptions = _micromatchOptions;
|
---|
9 | this._storage = [];
|
---|
10 | this._fillStorage();
|
---|
11 | }
|
---|
12 | _fillStorage() {
|
---|
13 | /**
|
---|
14 | * The original pattern may include `{,*,**,a/*}`, which will lead to problems with matching (unresolved level).
|
---|
15 | * So, before expand patterns with brace expansion into separated patterns.
|
---|
16 | */
|
---|
17 | const patterns = utils.pattern.expandPatternsWithBraceExpansion(this._patterns);
|
---|
18 | for (const pattern of patterns) {
|
---|
19 | const segments = this._getPatternSegments(pattern);
|
---|
20 | const sections = this._splitSegmentsIntoSections(segments);
|
---|
21 | this._storage.push({
|
---|
22 | complete: sections.length <= 1,
|
---|
23 | pattern,
|
---|
24 | segments,
|
---|
25 | sections
|
---|
26 | });
|
---|
27 | }
|
---|
28 | }
|
---|
29 | _getPatternSegments(pattern) {
|
---|
30 | const parts = utils.pattern.getPatternParts(pattern, this._micromatchOptions);
|
---|
31 | return parts.map((part) => {
|
---|
32 | const dynamic = utils.pattern.isDynamicPattern(part, this._settings);
|
---|
33 | if (!dynamic) {
|
---|
34 | return {
|
---|
35 | dynamic: false,
|
---|
36 | pattern: part
|
---|
37 | };
|
---|
38 | }
|
---|
39 | return {
|
---|
40 | dynamic: true,
|
---|
41 | pattern: part,
|
---|
42 | patternRe: utils.pattern.makeRe(part, this._micromatchOptions)
|
---|
43 | };
|
---|
44 | });
|
---|
45 | }
|
---|
46 | _splitSegmentsIntoSections(segments) {
|
---|
47 | return utils.array.splitWhen(segments, (segment) => segment.dynamic && utils.pattern.hasGlobStar(segment.pattern));
|
---|
48 | }
|
---|
49 | }
|
---|
50 | exports.default = Matcher;
|
---|