mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
Remove "sparseArray" constructor function and just use array literals
This commit is contained in:
parent
9e33585a80
commit
f510897dbd
@ -4084,7 +4084,7 @@ namespace ts {
|
||||
enumType.symbol = symbol;
|
||||
if (enumHasLiteralMembers(symbol)) {
|
||||
const memberTypeList: Type[] = [];
|
||||
const memberTypes = sparseArray<EnumLiteralType>();
|
||||
const memberTypes: SparseArray<EnumLiteralType> = [];
|
||||
for (const declaration of enumType.symbol.declarations) {
|
||||
if (declaration.kind === SyntaxKind.EnumDeclaration) {
|
||||
computeEnumMemberValues(<EnumDeclaration>declaration);
|
||||
|
||||
@ -39,8 +39,6 @@ namespace ts {
|
||||
return map;
|
||||
}
|
||||
|
||||
export const sparseArray: <T>() => SparseArray<T> = createDictionaryObject;
|
||||
|
||||
/** Create a new map. If a template object is provided, the map will copy entries from it. */
|
||||
export function createMap<T>(template?: MapLike<T>): Map<T> {
|
||||
const map: Map<T> = new MapCtr<T>();
|
||||
|
||||
@ -3299,7 +3299,7 @@ namespace ts {
|
||||
export function collectExternalModuleInfo(sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo {
|
||||
const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = [];
|
||||
const exportSpecifiers = createMap<ExportSpecifier[]>();
|
||||
const exportedBindings = sparseArray<Identifier[]>();
|
||||
const exportedBindings: SparseArray<Identifier[]> = [];
|
||||
const uniqueExports = createMap<boolean>();
|
||||
let exportedNames: Identifier[];
|
||||
let hasExportDefault = false;
|
||||
|
||||
@ -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: <some-value> } - found - stop searching
|
||||
*/
|
||||
type SearchResult<T> = { value: T | undefined } | undefined;
|
||||
|
||||
|
||||
/**
|
||||
* Wraps value to SearchResult.
|
||||
* @returns undefined if value is undefined or { value } otherwise
|
||||
|
||||
@ -2096,7 +2096,7 @@ namespace ts {
|
||||
|
||||
if (!renamedCatchVariables) {
|
||||
renamedCatchVariables = createMap<boolean>();
|
||||
renamedCatchVariableDeclarations = sparseArray<Identifier>();
|
||||
renamedCatchVariableDeclarations = [];
|
||||
context.enableSubstitution(SyntaxKind.Identifier);
|
||||
}
|
||||
|
||||
|
||||
@ -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<ExternalModuleInfo>(); // The ExternalModuleInfo for each file.
|
||||
const deferredExports = sparseArray<Statement[]>(); // Exports to defer until an EndOfDeclarationMarker is found.
|
||||
const moduleInfoMap: SparseArray<ExternalModuleInfo> = []; // The ExternalModuleInfo for each file.
|
||||
const deferredExports: SparseArray<Statement[]> = []; // 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 = <SourceFile>node;
|
||||
currentModuleInfo = moduleInfoMap[getOriginalNodeId(currentSourceFile)];
|
||||
noSubstitution = sparseArray<boolean>();
|
||||
noSubstitution = [];
|
||||
|
||||
previousOnEmitNode(emitContext, node, emitCallback);
|
||||
|
||||
|
||||
@ -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<ExternalModuleInfo>(); // The ExternalModuleInfo for each file.
|
||||
const deferredExports = sparseArray<Statement[]>(); // Exports to defer until an EndOfDeclarationMarker is found.
|
||||
const exportFunctionsMap = sparseArray<Identifier>(); // The export function associated with a source file.
|
||||
const noSubstitutionMap = sparseArray<SparseArray<boolean>>(); // Set of nodes for which substitution rules should be ignored for each file.
|
||||
const moduleInfoMap: SparseArray<ExternalModuleInfo> = []; // The ExternalModuleInfo for each file.
|
||||
const deferredExports: SparseArray<Statement[]> = []; // Exports to defer until an EndOfDeclarationMarker is found.
|
||||
const exportFunctionsMap: SparseArray<Identifier> = []; // The export function associated with a source file.
|
||||
const noSubstitutionMap: SparseArray<SparseArray<boolean>> = []; // 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<T extends Node>(node: T): T {
|
||||
if (noSubstitution === undefined) noSubstitution = sparseArray<boolean>();
|
||||
if (noSubstitution === undefined) noSubstitution = [];
|
||||
noSubstitution[getNodeId(node)] = true;
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -3125,7 +3125,7 @@ namespace ts {
|
||||
context.enableSubstitution(SyntaxKind.Identifier);
|
||||
|
||||
// Keep track of class aliases.
|
||||
classAliases = sparseArray<Identifier>();
|
||||
classAliases = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/// <reference path="sys.ts" />
|
||||
/// <reference path="sys.ts" />
|
||||
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
@ -3365,7 +3365,7 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
const syntaxKindCache = sparseArray<string>();
|
||||
const syntaxKindCache: SparseArray<string> = [];
|
||||
|
||||
export function formatSyntaxKind(kind: SyntaxKind): string {
|
||||
const syntaxKindEnum = (<any>ts).SyntaxKind;
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -292,7 +292,7 @@ namespace ts.projectSystem {
|
||||
}
|
||||
|
||||
export class Callbacks {
|
||||
private map = sparseArray<TimeOutCallback>();
|
||||
private map: SparseArray<TimeOutCallback> = [];
|
||||
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<TimeOutCallback>();
|
||||
this.map = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export namespace codefix {
|
||||
const codeFixes = sparseArray<CodeFix[]>();
|
||||
const codeFixes: SparseArray<CodeFix[]> = [];
|
||||
|
||||
export function registerCodeFix(action: CodeFix) {
|
||||
forEach(action.errorCodes, error => {
|
||||
|
||||
@ -14,7 +14,7 @@ namespace ts.codefix {
|
||||
}
|
||||
|
||||
class ImportCodeActionMap {
|
||||
private symbolIdToActionMap = sparseArray<ImportCodeAction[]>();
|
||||
private symbolIdToActionMap: SparseArray<ImportCodeAction[]> = [];
|
||||
|
||||
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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user