matcher.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. for (const pattern of this._patterns) {
  14. const segments = this._getPatternSegments(pattern);
  15. const sections = this._splitSegmentsIntoSections(segments);
  16. this._storage.push({
  17. complete: sections.length <= 1,
  18. pattern,
  19. segments,
  20. sections
  21. });
  22. }
  23. }
  24. _getPatternSegments(pattern) {
  25. const parts = utils.pattern.getPatternParts(pattern, this._micromatchOptions);
  26. return parts.map((part) => {
  27. const dynamic = utils.pattern.isDynamicPattern(part, this._settings);
  28. if (!dynamic) {
  29. return {
  30. dynamic: false,
  31. pattern: part
  32. };
  33. }
  34. return {
  35. dynamic: true,
  36. pattern: part,
  37. patternRe: utils.pattern.makeRe(part, this._micromatchOptions)
  38. };
  39. });
  40. }
  41. _splitSegmentsIntoSections(segments) {
  42. return utils.array.splitWhen(segments, (segment) => segment.dynamic && utils.pattern.hasGlobStar(segment.pattern));
  43. }
  44. }
  45. exports.default = Matcher;