Skip to content

Commit 08030c7

Browse files
author
Andy
authored
Convert most of core.ts to accept ReadonlyArray (microsoft#17092)
* Convert most of core.ts to accept ReadonlyArray * Fix lint * Fix isArray
1 parent 25f4e46 commit 08030c7

21 files changed

+117
-106
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ namespace ts {
20102010
}
20112011

20122012
function getAccessibleSymbolChainFromSymbolTableWorker(symbols: SymbolTable, visitedSymbolTables: SymbolTable[]): Symbol[] {
2013-
if (contains(visitedSymbolTables, symbols)) {
2013+
if (contains<SymbolTable>(visitedSymbolTables, symbols)) {
20142014
return undefined;
20152015
}
20162016
visitedSymbolTables.push(symbols);
@@ -20918,7 +20918,7 @@ namespace ts {
2091820918
}
2091920919
}
2092020920

20921-
function areTypeParametersIdentical(declarations: (ClassDeclaration | InterfaceDeclaration)[], typeParameters: TypeParameter[]) {
20921+
function areTypeParametersIdentical(declarations: ReadonlyArray<ClassDeclaration | InterfaceDeclaration>, typeParameters: TypeParameter[]) {
2092220922
const maxTypeArgumentCount = length(typeParameters);
2092320923
const minTypeArgumentCount = getMinTypeArgumentCount(typeParameters);
2092420924

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ namespace ts {
21362136
* @param extensionPriority The priority of the extension.
21372137
* @param context The expansion context.
21382138
*/
2139-
function hasFileWithHigherPriorityExtension(file: string, literalFiles: Map<string>, wildcardFiles: Map<string>, extensions: string[], keyMapper: (value: string) => string) {
2139+
function hasFileWithHigherPriorityExtension(file: string, literalFiles: Map<string>, wildcardFiles: Map<string>, extensions: ReadonlyArray<string>, keyMapper: (value: string) => string) {
21402140
const extensionPriority = getExtensionPriority(file, extensions);
21412141
const adjustedExtensionPriority = adjustExtensionPriority(extensionPriority, extensions);
21422142
for (let i = ExtensionPriority.Highest; i < adjustedExtensionPriority; i++) {
@@ -2158,7 +2158,7 @@ namespace ts {
21582158
* @param extensionPriority The priority of the extension.
21592159
* @param context The expansion context.
21602160
*/
2161-
function removeWildcardFilesWithLowerPriorityExtension(file: string, wildcardFiles: Map<string>, extensions: string[], keyMapper: (value: string) => string) {
2161+
function removeWildcardFilesWithLowerPriorityExtension(file: string, wildcardFiles: Map<string>, extensions: ReadonlyArray<string>, keyMapper: (value: string) => string) {
21622162
const extensionPriority = getExtensionPriority(file, extensions);
21632163
const nextExtensionPriority = getNextLowestExtensionPriority(extensionPriority, extensions);
21642164
for (let i = nextExtensionPriority; i < extensions.length; i++) {

src/compiler/core.ts

Lines changed: 80 additions & 67 deletions
Large diffs are not rendered by default.

src/compiler/sys.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace ts {
3939
getExecutingFilePath(): string;
4040
getCurrentDirectory(): string;
4141
getDirectories(path: string): string[];
42-
readDirectory(path: string, extensions?: string[], exclude?: string[], include?: string[], depth?: number): string[];
42+
readDirectory(path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[];
4343
getModifiedTime?(path: string): Date;
4444
/**
4545
* This should be cryptographically secure.
@@ -100,7 +100,7 @@ namespace ts {
100100
readFile(path: string): string;
101101
writeFile(path: string, contents: string): void;
102102
getDirectories(path: string): string[];
103-
readDirectory(path: string, extensions?: string[], basePaths?: string[], excludeEx?: string, includeFileEx?: string, includeDirEx?: string): string[];
103+
readDirectory(path: string, extensions?: ReadonlyArray<string>, basePaths?: ReadonlyArray<string>, excludeEx?: string, includeFileEx?: string, includeDirEx?: string): string[];
104104
watchFile?(path: string, callback: FileWatcherCallback): FileWatcher;
105105
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher;
106106
realpath(path: string): string;
@@ -287,7 +287,7 @@ namespace ts {
287287
}
288288
}
289289

290-
function readDirectory(path: string, extensions?: string[], excludes?: string[], includes?: string[], depth?: number): string[] {
290+
function readDirectory(path: string, extensions?: ReadonlyArray<string>, excludes?: ReadonlyArray<string>, includes?: ReadonlyArray<string>, depth?: number): string[] {
291291
return matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, process.cwd(), depth, getAccessibleFileSystemEntries);
292292
}
293293

src/compiler/transformers/es2015.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3579,7 +3579,7 @@ namespace ts {
35793579
// Map spans of spread expressions into their expressions and spans of other
35803580
// expressions into an array literal.
35813581
const numElements = elements.length;
3582-
const segments = flatten(
3582+
const segments = flatten<Expression>(
35833583
spanMap(elements, partitionSpread, (partition, visitPartition, _start, end) =>
35843584
visitPartition(partition, multiLine, hasTrailingComma && end === numElements)
35853585
)

src/compiler/transformers/jsx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace ts {
8888
else {
8989
// Map spans of JsxAttribute nodes into object literals and spans
9090
// of JsxSpreadAttribute nodes into expressions.
91-
const segments = flatten(
91+
const segments = flatten<Expression | ObjectLiteralExpression>(
9292
spanMap(attrs, isJsxSpreadAttribute, (attrs, isSpread) => isSpread
9393
? map(attrs, transformJsxSpreadAttributeToExpression)
9494
: createObjectLiteral(map(attrs, transformJsxAttributeToObjectLiteralElement))

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ namespace ts {
13771377

13781378
const decoratorExpressions: Expression[] = [];
13791379
addRange(decoratorExpressions, map(allDecorators.decorators, transformDecorator));
1380-
addRange(decoratorExpressions, flatMap(allDecorators.parameters, transformDecoratorsOfParameter));
1380+
addRange(decoratorExpressions, flatMap<Decorator[], Expression>(allDecorators.parameters, transformDecoratorsOfParameter));
13811381
addTypeMetadata(node, container, decoratorExpressions);
13821382
return decoratorExpressions;
13831383
}

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2406,7 +2406,7 @@ namespace ts {
24062406
export interface ParseConfigHost {
24072407
useCaseSensitiveFileNames: boolean;
24082408

2409-
readDirectory(rootDir: string, extensions: string[], excludes: string[], includes: string[], depth: number): string[];
2409+
readDirectory(rootDir: string, extensions: ReadonlyArray<string>, excludes: ReadonlyArray<string>, includes: ReadonlyArray<string>, depth: number): string[];
24102410

24112411
/**
24122412
* Gets a value indicating whether the specified path exists and is a file.

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3334,7 +3334,7 @@ namespace ts {
33343334
}
33353335
}
33363336

3337-
return stableSort(result, (x, y) => compareValues(x[0], y[0]));
3337+
return stableSort<[number, string]>(result, (x, y) => compareValues(x[0], y[0]));
33383338
}
33393339

33403340
export function formatSyntaxKind(kind: SyntaxKind): string {

src/harness/fourslash.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ namespace FourSlash {
219219

220220
// Add input file which has matched file name with the given reference-file path.
221221
// This is necessary when resolveReference flag is specified
222-
private addMatchedInputFile(referenceFilePath: string, extensions: string[]) {
222+
private addMatchedInputFile(referenceFilePath: string, extensions: ReadonlyArray<string>) {
223223
const inputFiles = this.inputFiles;
224224
const languageServiceAdapterHost = this.languageServiceAdapterHost;
225225
if (!extensions) {
@@ -605,7 +605,7 @@ namespace FourSlash {
605605
this.verifyGoToXPlain(arg0, endMarkerNames, getDefs);
606606
}
607607
else if (ts.isArray(arg0)) {
608-
const pairs: [string | string[], string | string[]][] = arg0;
608+
const pairs: ReadonlyArray<[string | string[], string | string[]]> = arg0;
609609
for (const [start, end] of pairs) {
610610
this.verifyGoToXPlain(start, end, getDefs);
611611
}

0 commit comments

Comments
 (0)