-
Notifications
You must be signed in to change notification settings - Fork 13k
Adds glob-style pattern matching for files in tsconfig.json #5980
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
Changes from 6 commits
f9ae3e4
30575db
5de2fcc
def3ba1
c3c3bca
bf9af46
d857250
247657f
94a5327
6f85fe9
d23df34
c224917
cde12ef
c1205eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,9 @@ namespace ts { | |
contains, | ||
remove, | ||
forEachValue: forEachValueInMap, | ||
clear | ||
reduceProperties: reducePropertiesInMap, | ||
clear, | ||
mergeFrom | ||
}; | ||
|
||
function forEachValueInMap(f: (key: Path, value: T) => void) { | ||
|
@@ -34,6 +36,10 @@ namespace ts { | |
} | ||
} | ||
|
||
function reducePropertiesInMap<U>(callback: (memo: U, value: T, key: Path) => U, initial: U) { | ||
return reduceProperties(files, callback, initial); | ||
} | ||
|
||
// path should already be well-formed so it does not need to be normalized | ||
function get(path: Path): T { | ||
return files[toKey(path)]; | ||
|
@@ -56,6 +62,16 @@ namespace ts { | |
files = {}; | ||
} | ||
|
||
function mergeFrom(other: FileMap<T>) { | ||
other.forEachValue(mergeFromOther); | ||
} | ||
|
||
function mergeFromOther(key: Path, value: T) { | ||
if (!contains(key)) { | ||
set(key, value); | ||
} | ||
} | ||
|
||
function toKey(path: Path): string { | ||
return keyMapper ? keyMapper(path) : path; | ||
} | ||
|
@@ -490,6 +506,24 @@ namespace ts { | |
return a < b ? Comparison.LessThan : Comparison.GreaterThan; | ||
} | ||
|
||
export function compareStrings(a: string, b: string, ignoreCase?: boolean): Comparison { | ||
if (a === b) return Comparison.EqualTo; | ||
if (a === undefined) return Comparison.LessThan; | ||
if (b === undefined) return Comparison.GreaterThan; | ||
if (ignoreCase) { | ||
if (String.prototype.localeCompare) { | ||
const result = a.localeCompare(b, /*locales*/ undefined, { usage: "sort", sensitivity: "accent" }); | ||
return result < 0 ? Comparison.LessThan : result > 0 ? Comparison.GreaterThan : Comparison.EqualTo; | ||
} | ||
|
||
a = a.toUpperCase(); | ||
b = b.toUpperCase(); | ||
if (a === b) return Comparison.EqualTo; | ||
} | ||
|
||
return a < b ? Comparison.LessThan : Comparison.GreaterThan; | ||
} | ||
|
||
function getDiagnosticFileName(diagnostic: Diagnostic): string { | ||
return diagnostic.file ? diagnostic.file.fileName : undefined; | ||
} | ||
|
@@ -756,6 +790,71 @@ namespace ts { | |
return path1 + directorySeparator + path2; | ||
} | ||
|
||
/** | ||
* Removes a trailing directory separator from a path. | ||
* @param path The path. | ||
*/ | ||
export function removeTrailingDirectorySeparator(path: string) { | ||
if (path.charAt(path.length - 1) === directorySeparator) { | ||
return path.substr(0, path.length - 1); | ||
} | ||
|
||
return path; | ||
} | ||
|
||
/** | ||
* Adds a trailing directory separator to a path, if it does not already have one. | ||
* @param path The path. | ||
*/ | ||
export function ensureTrailingDirectorySeparator(path: string) { | ||
if (path.charAt(path.length - 1) !== directorySeparator) { | ||
return path + directorySeparator; | ||
} | ||
|
||
return path; | ||
} | ||
|
||
export function comparePaths(a: string, b: string, currentDirectory: string, ignoreCase?: boolean) { | ||
if (a === b) return Comparison.EqualTo; | ||
if (a === undefined) return Comparison.LessThan; | ||
if (b === undefined) return Comparison.GreaterThan; | ||
a = removeTrailingDirectorySeparator(a); | ||
b = removeTrailingDirectorySeparator(b); | ||
const aComponents = getNormalizedPathComponents(a, currentDirectory); | ||
const bComponents = getNormalizedPathComponents(b, currentDirectory); | ||
const sharedLength = Math.min(aComponents.length, bComponents.length); | ||
for (let i = 0; i < sharedLength; ++i) { | ||
const result = compareStrings(aComponents[i], bComponents[i], ignoreCase); | ||
if (result !== Comparison.EqualTo) { | ||
return result; | ||
} | ||
} | ||
|
||
return compareValues(aComponents.length, bComponents.length); | ||
} | ||
|
||
export function containsPath(parent: string, child: string, currentDirectory: string, ignoreCase?: boolean) { | ||
if (parent === undefined || child === undefined) return false; | ||
if (parent === child) return true; | ||
parent = removeTrailingDirectorySeparator(parent); | ||
child = removeTrailingDirectorySeparator(child); | ||
if (parent === child) return true; | ||
const parentComponents = getNormalizedPathComponents(parent, currentDirectory); | ||
const childComponents = getNormalizedPathComponents(child, currentDirectory); | ||
if (childComponents.length < parentComponents.length) { | ||
return false; | ||
} | ||
|
||
for (let i = 0; i < parentComponents.length; ++i) { | ||
const result = compareStrings(parentComponents[i], childComponents[i], ignoreCase); | ||
if (result !== Comparison.EqualTo) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
export function fileExtensionIs(path: string, extension: string): boolean { | ||
const pathLen = path.length; | ||
const extLen = extension.length; | ||
|
@@ -784,6 +883,59 @@ namespace ts { | |
return false; | ||
} | ||
|
||
/** | ||
* Extension boundaries by priority. Lower numbers indicate higher priorities, and are | ||
* aligned to the offset of the highest priority extension in the | ||
* allSupportedExtensions array. | ||
*/ | ||
export const enum ExtensionPriority { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any specific reason for these values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a formal way to specify the offsets to each extension in |
||
TypeScriptFiles = 0, | ||
DeclarationAndJavaScriptFiles = 2, | ||
Limit = 5, | ||
|
||
Highest = TypeScriptFiles, | ||
Lowest = DeclarationAndJavaScriptFiles, | ||
} | ||
|
||
export function getExtensionPriority(path: string, supportedExtensions: string[]): ExtensionPriority { | ||
for (let i = supportedExtensions.length - 1; i >= 0; i--) { | ||
if (fileExtensionIs(path, supportedExtensions[i])) { | ||
return adjustExtensionPriority(<ExtensionPriority>i); | ||
} | ||
} | ||
|
||
// If its not in the list of supported extensions, this is likely a | ||
// TypeScript file with a non-ts extension | ||
return ExtensionPriority.Highest; | ||
} | ||
|
||
/** | ||
* Adjusts an extension priority to be the highest priority within the same range. | ||
*/ | ||
export function adjustExtensionPriority(extensionPriority: ExtensionPriority): ExtensionPriority { | ||
if (extensionPriority < ExtensionPriority.DeclarationAndJavaScriptFiles) { | ||
return ExtensionPriority.TypeScriptFiles; | ||
} | ||
else if (extensionPriority < ExtensionPriority.Limit) { | ||
return ExtensionPriority.DeclarationAndJavaScriptFiles; | ||
} | ||
else { | ||
return ExtensionPriority.Limit; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the next lowest extension priority for a given priority. | ||
*/ | ||
export function getNextLowestExtensionPriority(extensionPriority: ExtensionPriority): ExtensionPriority { | ||
if (extensionPriority < ExtensionPriority.DeclarationAndJavaScriptFiles) { | ||
return ExtensionPriority.DeclarationAndJavaScriptFiles; | ||
} | ||
else { | ||
return ExtensionPriority.Limit; | ||
} | ||
} | ||
|
||
const extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"]; | ||
export function removeFileExtension(path: string): string { | ||
for (const ext of extensionsToRemove) { | ||
|
@@ -794,6 +946,10 @@ namespace ts { | |
return path; | ||
} | ||
|
||
export function changeExtension<T extends string | Path>(path: T, newExtension: string): T { | ||
return <T>(removeFileExtension(path) + newExtension); | ||
} | ||
|
||
const backslashOrDoubleQuote = /[\"\\]/g; | ||
const escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g; | ||
const escapedCharsMap: Map<string> = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this file to the tsconfig.json files in
src\**\
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no tsconfig.json in either src/harness or tests/cases/unittests