Skip to content

Commit f510897

Browse files
author
Andy Hanson
committed
Remove "sparseArray" constructor function and just use array literals
1 parent 9e33585 commit f510897

13 files changed

Lines changed: 23 additions & 25 deletions

File tree

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4084,7 +4084,7 @@ namespace ts {
40844084
enumType.symbol = symbol;
40854085
if (enumHasLiteralMembers(symbol)) {
40864086
const memberTypeList: Type[] = [];
4087-
const memberTypes = sparseArray<EnumLiteralType>();
4087+
const memberTypes: SparseArray<EnumLiteralType> = [];
40884088
for (const declaration of enumType.symbol.declarations) {
40894089
if (declaration.kind === SyntaxKind.EnumDeclaration) {
40904090
computeEnumMemberValues(<EnumDeclaration>declaration);

src/compiler/core.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ namespace ts {
3939
return map;
4040
}
4141

42-
export const sparseArray: <T>() => SparseArray<T> = createDictionaryObject;
43-
4442
/** Create a new map. If a template object is provided, the map will copy entries from it. */
4543
export function createMap<T>(template?: MapLike<T>): Map<T> {
4644
const map: Map<T> = new MapCtr<T>();

src/compiler/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3299,7 +3299,7 @@ namespace ts {
32993299
export function collectExternalModuleInfo(sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo {
33003300
const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = [];
33013301
const exportSpecifiers = createMap<ExportSpecifier[]>();
3302-
const exportedBindings = sparseArray<Identifier[]>();
3302+
const exportedBindings: SparseArray<Identifier[]> = [];
33033303
const uniqueExports = createMap<boolean>();
33043304
let exportedNames: Identifier[];
33053305
let hasExportDefault = false;

src/compiler/moduleNameResolver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ namespace ts {
388388
}
389389
}
390390
}
391-
391+
392392
function getCommonPrefix(directory: Path, resolution: string) {
393393
if (resolution === undefined) {
394394
return undefined;
@@ -418,7 +418,7 @@ namespace ts {
418418
trace(host, Diagnostics.Resolving_module_0_from_1, moduleName, containingFile);
419419
}
420420
const containingDirectory = getDirectoryPath(containingFile);
421-
let perFolderCache = cache && cache.getOrCreateCacheForDirectory(containingDirectory);
421+
const perFolderCache = cache && cache.getOrCreateCacheForDirectory(containingDirectory);
422422
let result = perFolderCache && perFolderCache.get(moduleName);
423423

424424
if (result) {
@@ -991,7 +991,7 @@ namespace ts {
991991
* - { value: <some-value> } - found - stop searching
992992
*/
993993
type SearchResult<T> = { value: T | undefined } | undefined;
994-
994+
995995
/**
996996
* Wraps value to SearchResult.
997997
* @returns undefined if value is undefined or { value } otherwise

src/compiler/transformers/generators.ts

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

20972097
if (!renamedCatchVariables) {
20982098
renamedCatchVariables = createMap<boolean>();
2099-
renamedCatchVariableDeclarations = sparseArray<Identifier>();
2099+
renamedCatchVariableDeclarations = [];
21002100
context.enableSubstitution(SyntaxKind.Identifier);
21012101
}
21022102

src/compiler/transformers/module/module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ namespace ts {
3939
context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); // Substitutes shorthand property assignments for imported/exported symbols.
4040
context.enableEmitNotification(SyntaxKind.SourceFile); // Restore state when substituting nodes in a file.
4141

42-
const moduleInfoMap = sparseArray<ExternalModuleInfo>(); // The ExternalModuleInfo for each file.
43-
const deferredExports = sparseArray<Statement[]>(); // Exports to defer until an EndOfDeclarationMarker is found.
42+
const moduleInfoMap: SparseArray<ExternalModuleInfo> = []; // The ExternalModuleInfo for each file.
43+
const deferredExports: SparseArray<Statement[]> = []; // Exports to defer until an EndOfDeclarationMarker is found.
4444

4545
let currentSourceFile: SourceFile; // The current file.
4646
let currentModuleInfo: ExternalModuleInfo; // The ExternalModuleInfo for the current file.
@@ -1105,7 +1105,7 @@ namespace ts {
11051105
if (node.kind === SyntaxKind.SourceFile) {
11061106
currentSourceFile = <SourceFile>node;
11071107
currentModuleInfo = moduleInfoMap[getOriginalNodeId(currentSourceFile)];
1108-
noSubstitution = sparseArray<boolean>();
1108+
noSubstitution = [];
11091109

11101110
previousOnEmitNode(emitContext, node, emitCallback);
11111111

src/compiler/transformers/module/system.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ namespace ts {
2828
context.enableSubstitution(SyntaxKind.PostfixUnaryExpression); // Substitutes updates to exported symbols.
2929
context.enableEmitNotification(SyntaxKind.SourceFile); // Restore state when substituting nodes in a file.
3030

31-
const moduleInfoMap = sparseArray<ExternalModuleInfo>(); // The ExternalModuleInfo for each file.
32-
const deferredExports = sparseArray<Statement[]>(); // Exports to defer until an EndOfDeclarationMarker is found.
33-
const exportFunctionsMap = sparseArray<Identifier>(); // The export function associated with a source file.
34-
const noSubstitutionMap = sparseArray<SparseArray<boolean>>(); // Set of nodes for which substitution rules should be ignored for each file.
31+
const moduleInfoMap: SparseArray<ExternalModuleInfo> = []; // The ExternalModuleInfo for each file.
32+
const deferredExports: SparseArray<Statement[]> = []; // Exports to defer until an EndOfDeclarationMarker is found.
33+
const exportFunctionsMap: SparseArray<Identifier> = []; // The export function associated with a source file.
34+
const noSubstitutionMap: SparseArray<SparseArray<boolean>> = []; // Set of nodes for which substitution rules should be ignored for each file.
3535

3636
let currentSourceFile: SourceFile; // The current file.
3737
let moduleInfo: ExternalModuleInfo; // ExternalModuleInfo for the current file.
@@ -1771,7 +1771,7 @@ namespace ts {
17711771
* @param node The node which should not be substituted.
17721772
*/
17731773
function preventSubstitution<T extends Node>(node: T): T {
1774-
if (noSubstitution === undefined) noSubstitution = sparseArray<boolean>();
1774+
if (noSubstitution === undefined) noSubstitution = [];
17751775
noSubstitution[getNodeId(node)] = true;
17761776
return node;
17771777
}

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3125,7 +3125,7 @@ namespace ts {
31253125
context.enableSubstitution(SyntaxKind.Identifier);
31263126

31273127
// Keep track of class aliases.
3128-
classAliases = sparseArray<Identifier>();
3128+
classAliases = [];
31293129
}
31303130
}
31313131

src/compiler/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="sys.ts" />
1+
/// <reference path="sys.ts" />
22

33
/* @internal */
44
namespace ts {
@@ -3365,7 +3365,7 @@ namespace ts {
33653365
return false;
33663366
}
33673367

3368-
const syntaxKindCache = sparseArray<string>();
3368+
const syntaxKindCache: SparseArray<string> = [];
33693369

33703370
export function formatSyntaxKind(kind: SyntaxKind): string {
33713371
const syntaxKindEnum = (<any>ts).SyntaxKind;

src/harness/unittests/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ namespace ts.server {
416416
class InProcClient {
417417
private server: InProcSession;
418418
private seq = 0;
419-
private callbacks = sparseArray<(resp: protocol.Response) => void>();
419+
private callbacks: SparseArray<(resp: protocol.Response) => void> = [];
420420
private eventHandlers = createMap<(args: any) => void>();
421421

422422
handle(msg: protocol.Message): void {

0 commit comments

Comments
 (0)