Skip to content

Add support for including dotted and .min.js files explicitly in include #9528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 22, 2016
10 changes: 7 additions & 3 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,17 +987,17 @@ namespace ts {
// The * and ? wildcards should not match directories or files that start with . if they
// appear first in a component. Dotted directories and files can be included explicitly
// like so: **/.*/.*
if (component.indexOf("*") === 0) {
if (component.charCodeAt(0) === CharacterCodes.asterisk) {
subpattern += "([^./]" + singleAsteriskRegexFragment + ")?";
component = component.substr(1);
}
else if (component.indexOf("?") === 0) {
else if (component.charCodeAt(0) === CharacterCodes.question) {
subpattern += "[^./]";
component = component.substr(1);
}
}

subpattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter);
subpattern += replaceWildcardCharacters(component, singleAsteriskRegexFragment);
hasWrittenComponent = true;
}
}
Expand All @@ -1020,6 +1020,10 @@ namespace ts {
}

return "^(" + pattern + (usage === "exclude" ? ")($|/)" : ")$");
}

function replaceWildcardCharacters(component: string, singleAsteriskRegexFragment: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still introduces a closure. Another approach would be:

// at :924
const singleAsteriskRegexFragmentForFiles = "([^./]*(\\.(?!min\\.js$))?)*";
const singleAsteriskRegexFragmentForOther = "[^/]*";

// at :938
const singleAsteriskRegexFragment = usage === "files" ? singleAsteriskRegexFragmentForFiles : singleAsteriskRegexFragmentForOther;
const replaceWildcardCharacter = usage === "files" ? replaceWildcardCharacterForFiles : replaceWildcardCharacterForOther;

// at :1000
subpattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter); // uses local from :939

// at :1025
function replaceWildcardCharacterForFiles(match: string) {
    return replaceWildcardCharacter(match, singleAsteriskRegexFragmentForFiles);
}

function replaceWildcardCharacterForOther(match: string) {
    return replaceWildcardCharacter(match, singleAsteriskRegexFragmentForOther);
}

function replaceWildcardCharacter(match: string, singleAsteriskRegexFragment: string) {
    return match === "*" ? singleAsteriskRegexFragment : match === "?" ? "[^/]" : "\\" + match; 
}

With this, no new closures are introduced.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return component.replace(reservedCharacterPattern, replaceWildcardCharacter);

function replaceWildcardCharacter(match: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer this stay outside of getRegularExpressionForWildcard and instead pass singleAsteriskRegexFragment as an argument to avoid the closure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote the whole replace step as a separate function to make it clearer

return match === "*" ? singleAsteriskRegexFragment : match === "?" ? "[^/]" : "\\" + match;
Expand Down