diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 165e4c3cca7..3ed4c383ef2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4084,7 +4084,7 @@ namespace ts { enumType.symbol = symbol; if (enumHasLiteralMembers(symbol)) { const memberTypeList: Type[] = []; - const memberTypes = sparseArray(); + const memberTypes: SparseArray = []; for (const declaration of enumType.symbol.declarations) { if (declaration.kind === SyntaxKind.EnumDeclaration) { computeEnumMemberValues(declaration); diff --git a/src/compiler/core.ts b/src/compiler/core.ts index a7864a0646f..e9dbdb8786a 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -39,8 +39,6 @@ namespace ts { return map; } - export const sparseArray: () => SparseArray = createDictionaryObject; - /** Create a new map. If a template object is provided, the map will copy entries from it. */ export function createMap(template?: MapLike): Map { const map: Map = new MapCtr(); diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 661a0346f26..38e28fc2de0 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -3299,7 +3299,7 @@ namespace ts { export function collectExternalModuleInfo(sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo { const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = []; const exportSpecifiers = createMap(); - const exportedBindings = sparseArray(); + const exportedBindings: SparseArray = []; const uniqueExports = createMap(); let exportedNames: Identifier[]; let hasExportDefault = false; diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index a8b634c0234..1efe9078f5a 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -388,7 +388,7 @@ namespace ts { } } } - + function getCommonPrefix(directory: Path, resolution: string) { if (resolution === undefined) { return undefined; @@ -418,7 +418,7 @@ namespace ts { trace(host, Diagnostics.Resolving_module_0_from_1, moduleName, containingFile); } const containingDirectory = getDirectoryPath(containingFile); - let perFolderCache = cache && cache.getOrCreateCacheForDirectory(containingDirectory); + const perFolderCache = cache && cache.getOrCreateCacheForDirectory(containingDirectory); let result = perFolderCache && perFolderCache.get(moduleName); if (result) { @@ -991,7 +991,7 @@ namespace ts { * - { value: } - found - stop searching */ type SearchResult = { value: T | undefined } | undefined; - + /** * Wraps value to SearchResult. * @returns undefined if value is undefined or { value } otherwise diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index 7cf7602efa0..8c9da9c4847 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -2096,7 +2096,7 @@ namespace ts { if (!renamedCatchVariables) { renamedCatchVariables = createMap(); - renamedCatchVariableDeclarations = sparseArray(); + renamedCatchVariableDeclarations = []; context.enableSubstitution(SyntaxKind.Identifier); } diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index e5e27c8360d..192f1f81a8f 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -39,8 +39,8 @@ namespace ts { context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); // Substitutes shorthand property assignments for imported/exported symbols. context.enableEmitNotification(SyntaxKind.SourceFile); // Restore state when substituting nodes in a file. - const moduleInfoMap = sparseArray(); // The ExternalModuleInfo for each file. - const deferredExports = sparseArray(); // Exports to defer until an EndOfDeclarationMarker is found. + const moduleInfoMap: SparseArray = []; // The ExternalModuleInfo for each file. + const deferredExports: SparseArray = []; // Exports to defer until an EndOfDeclarationMarker is found. let currentSourceFile: SourceFile; // The current file. let currentModuleInfo: ExternalModuleInfo; // The ExternalModuleInfo for the current file. @@ -1105,7 +1105,7 @@ namespace ts { if (node.kind === SyntaxKind.SourceFile) { currentSourceFile = node; currentModuleInfo = moduleInfoMap[getOriginalNodeId(currentSourceFile)]; - noSubstitution = sparseArray(); + noSubstitution = []; previousOnEmitNode(emitContext, node, emitCallback); diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 5f23ccd0669..d332f3376b1 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -28,10 +28,10 @@ namespace ts { context.enableSubstitution(SyntaxKind.PostfixUnaryExpression); // Substitutes updates to exported symbols. context.enableEmitNotification(SyntaxKind.SourceFile); // Restore state when substituting nodes in a file. - const moduleInfoMap = sparseArray(); // The ExternalModuleInfo for each file. - const deferredExports = sparseArray(); // Exports to defer until an EndOfDeclarationMarker is found. - const exportFunctionsMap = sparseArray(); // The export function associated with a source file. - const noSubstitutionMap = sparseArray>(); // Set of nodes for which substitution rules should be ignored for each file. + const moduleInfoMap: SparseArray = []; // The ExternalModuleInfo for each file. + const deferredExports: SparseArray = []; // Exports to defer until an EndOfDeclarationMarker is found. + const exportFunctionsMap: SparseArray = []; // The export function associated with a source file. + const noSubstitutionMap: SparseArray> = []; // Set of nodes for which substitution rules should be ignored for each file. let currentSourceFile: SourceFile; // The current file. let moduleInfo: ExternalModuleInfo; // ExternalModuleInfo for the current file. @@ -1771,7 +1771,7 @@ namespace ts { * @param node The node which should not be substituted. */ function preventSubstitution(node: T): T { - if (noSubstitution === undefined) noSubstitution = sparseArray(); + if (noSubstitution === undefined) noSubstitution = []; noSubstitution[getNodeId(node)] = true; return node; } diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 0947c894db8..96b00434660 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -3125,7 +3125,7 @@ namespace ts { context.enableSubstitution(SyntaxKind.Identifier); // Keep track of class aliases. - classAliases = sparseArray(); + classAliases = []; } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 7fdda448ae8..44bb05dd4a8 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1,4 +1,4 @@ -/// +/// /* @internal */ namespace ts { @@ -3365,7 +3365,7 @@ namespace ts { return false; } - const syntaxKindCache = sparseArray(); + const syntaxKindCache: SparseArray = []; export function formatSyntaxKind(kind: SyntaxKind): string { const syntaxKindEnum = (ts).SyntaxKind; diff --git a/src/harness/unittests/session.ts b/src/harness/unittests/session.ts index 70cda27747b..82f6ede865f 100644 --- a/src/harness/unittests/session.ts +++ b/src/harness/unittests/session.ts @@ -416,7 +416,7 @@ namespace ts.server { class InProcClient { private server: InProcSession; private seq = 0; - private callbacks = sparseArray<(resp: protocol.Response) => void>(); + private callbacks: SparseArray<(resp: protocol.Response) => void> = []; private eventHandlers = createMap<(args: any) => void>(); handle(msg: protocol.Message): void { diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 98a34d2a3bb..4ae2dc7a389 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -292,7 +292,7 @@ namespace ts.projectSystem { } export class Callbacks { - private map = sparseArray(); + private map: SparseArray = []; private nextId = 1; register(cb: (...args: any[]) => void, args: any[]) { @@ -319,7 +319,7 @@ namespace ts.projectSystem { for (const key in this.map) { this.map[key](); } - this.map = sparseArray(); + this.map = []; } } diff --git a/src/services/codefixes/codeFixProvider.ts b/src/services/codefixes/codeFixProvider.ts index f4cb411b064..e1e3ef18865 100644 --- a/src/services/codefixes/codeFixProvider.ts +++ b/src/services/codefixes/codeFixProvider.ts @@ -16,7 +16,7 @@ namespace ts { } export namespace codefix { - const codeFixes = sparseArray(); + const codeFixes: SparseArray = []; export function registerCodeFix(action: CodeFix) { forEach(action.errorCodes, error => { diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 0df3c3134fe..81b299bf708 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -14,7 +14,7 @@ namespace ts.codefix { } class ImportCodeActionMap { - private symbolIdToActionMap = sparseArray(); + private symbolIdToActionMap: SparseArray = []; addAction(symbolId: number, newAction: ImportCodeAction) { if (!newAction) { @@ -125,7 +125,7 @@ namespace ts.codefix { const symbolIdActionMap = new ImportCodeActionMap(); // this is a module id -> module import declaration map - const cachedImportDeclarations = sparseArray<(ImportDeclaration | ImportEqualsDeclaration)[]>(); + const cachedImportDeclarations: SparseArray<(ImportDeclaration | ImportEqualsDeclaration)[]> = []; let cachedNewImportInsertPosition: number; const allPotentialModules = checker.getAmbientModules();