MCPcopy Create free account
hub / github.com/nodejs/node / getSubPatternFromSpec

Function getSubPatternFromSpec

test/fixtures/snapshot/typescript.js:20560–20625  ·  view source on GitHub ↗
(spec, basePath, usage, _a)

Source from the content-addressed store, hash-verified

20558 }
20559 ts.getPatternFromSpec = getPatternFromSpec;
20560 function getSubPatternFromSpec(spec, basePath, usage, _a) {
20561 var singleAsteriskRegexFragment = _a.singleAsteriskRegexFragment, doubleAsteriskRegexFragment = _a.doubleAsteriskRegexFragment, replaceWildcardCharacter = _a.replaceWildcardCharacter;
20562 var subpattern = "";
20563 var hasWrittenComponent = false;
20564 var components = ts.getNormalizedPathComponents(spec, basePath);
20565 var lastComponent = ts.last(components);
20566 if (usage !== "exclude" && lastComponent === "**") {
20567 return undefined;
20568 }
20569 // getNormalizedPathComponents includes the separator for the root component.
20570 // We need to remove to create our regex correctly.
20571 components[0] = ts.removeTrailingDirectorySeparator(components[0]);
20572 if (isImplicitGlob(lastComponent)) {
20573 components.push("**", "*");
20574 }
20575 var optionalCount = 0;
20576 for (var _i = 0, components_1 = components; _i < components_1.length; _i++) {
20577 var component = components_1[_i];
20578 if (component === "**") {
20579 subpattern += doubleAsteriskRegexFragment;
20580 }
20581 else {
20582 if (usage === "directories") {
20583 subpattern += "(";
20584 optionalCount++;
20585 }
20586 if (hasWrittenComponent) {
20587 subpattern += ts.directorySeparator;
20588 }
20589 if (usage !== "exclude") {
20590 var componentPattern = "";
20591 // The * and ? wildcards should not match directories or files that start with . if they
20592 // appear first in a component. Dotted directories and files can be included explicitly
20593 // like so: **/.*/.*
20594 if (component.charCodeAt(0) === 42 /* CharacterCodes.asterisk */) {
20595 componentPattern += "([^./]" + singleAsteriskRegexFragment + ")?";
20596 component = component.substr(1);
20597 }
20598 else if (component.charCodeAt(0) === 63 /* CharacterCodes.question */) {
20599 componentPattern += "[^./]";
20600 component = component.substr(1);
20601 }
20602 componentPattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter);
20603 // Patterns should not include subfolders like node_modules unless they are
20604 // explicitly included as part of the path.
20605 //
20606 // As an optimization, if the component pattern is the same as the component,
20607 // then there definitely were no wildcard characters and we do not need to
20608 // add the exclusion pattern.
20609 if (componentPattern !== component) {
20610 subpattern += implicitExcludePathRegexPattern;
20611 }
20612 subpattern += componentPattern;
20613 }
20614 else {
20615 subpattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter);
20616 }
20617 }

Callers 2

getPatternFromSpecFunction · 0.85

Calls 3

isImplicitGlobFunction · 0.85
lastMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected