Skip to content

Commit bcc0807

Browse files
author
Andy Hanson
committed
Respond to PR comments
1 parent 8670937 commit bcc0807

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+203
-190
lines changed

scripts/processDiagnosticMessages.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function checkForUniqueCodes(messages: string[], diagnosticTable: InputDiagnosti
6969
}
7070

7171
function buildUniqueNameMap(names: string[]): ts.Map<string, string> {
72-
var nameMap = new ts.StringMap<string>();
72+
var nameMap = ts.createMap<string, string>();
7373

7474
var uniqueNames = NameGenerator.ensureUniqueness(names, /* isCaseSensitive */ false, /* isFixed */ undefined);
7575

src/compiler/binder.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ namespace ts {
147147
options = opts;
148148
languageVersion = getEmitScriptTarget(options);
149149
inStrictMode = bindInStrictMode(file, opts);
150-
classifiableNames = new StringSet();
150+
classifiableNames = createSet();
151151
symbolCount = 0;
152152
skipTransformFlagAggregation = isDeclarationFile(file);
153153

@@ -207,11 +207,11 @@ namespace ts {
207207
symbol.declarations.push(node);
208208

209209
if (symbolFlags & SymbolFlags.HasExports && !symbol.exports) {
210-
symbol.exports = new StringMap<Symbol>();
210+
symbol.exports = createMap<string, Symbol>();
211211
}
212212

213213
if (symbolFlags & SymbolFlags.HasMembers && !symbol.members) {
214-
symbol.members = new StringMap<Symbol>();
214+
symbol.members = createMap<string, Symbol>();
215215
}
216216

217217
if (symbolFlags & SymbolFlags.Value) {
@@ -484,7 +484,7 @@ namespace ts {
484484
if (containerFlags & ContainerFlags.IsContainer) {
485485
container = blockScopeContainer = node;
486486
if (containerFlags & ContainerFlags.HasLocals) {
487-
container.locals = new StringMap<Symbol>();
487+
container.locals = createMap<string, Symbol>();
488488
}
489489
addToContainerChain(container);
490490
}
@@ -1525,7 +1525,7 @@ namespace ts {
15251525

15261526
const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
15271527
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
1528-
typeLiteralSymbol.members = new StringMap([[symbol.name, symbol]]);
1528+
typeLiteralSymbol.members = createMap([[symbol.name, symbol]]);
15291529
}
15301530

15311531
function bindObjectLiteralExpression(node: ObjectLiteralExpression) {
@@ -1535,7 +1535,7 @@ namespace ts {
15351535
}
15361536

15371537
if (inStrictMode) {
1538-
const seen = new StringMap<ElementKind>();
1538+
const seen = createMap<string, ElementKind>();
15391539

15401540
for (const prop of node.properties) {
15411541
if (prop.name.kind !== SyntaxKind.Identifier) {
@@ -1591,7 +1591,7 @@ namespace ts {
15911591
// fall through.
15921592
default:
15931593
if (!blockScopeContainer.locals) {
1594-
blockScopeContainer.locals = new StringMap<Symbol>();
1594+
blockScopeContainer.locals = createMap<string, Symbol>();
15951595
addToContainerChain(blockScopeContainer);
15961596
}
15971597
declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes);
@@ -2071,7 +2071,7 @@ namespace ts {
20712071
}
20722072
}
20732073

2074-
file.symbol.globalExports = file.symbol.globalExports || new StringMap<Symbol>();
2074+
file.symbol.globalExports = file.symbol.globalExports || createMap<string, Symbol>();
20752075
declareSymbol(file.symbol.globalExports, file.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
20762076
}
20772077

@@ -2118,7 +2118,7 @@ namespace ts {
21182118
Debug.assert(isInJavaScriptFile(node));
21192119
// Declare a 'member' if the container is an ES5 class or ES6 constructor
21202120
if (container.kind === SyntaxKind.FunctionDeclaration || container.kind === SyntaxKind.FunctionExpression) {
2121-
container.symbol.members = container.symbol.members || new StringMap<Symbol>();
2121+
container.symbol.members = container.symbol.members || createMap<string, Symbol>();
21222122
// It's acceptable for multiple 'this' assignments of the same identifier to occur
21232123
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
21242124
}
@@ -2157,7 +2157,7 @@ namespace ts {
21572157

21582158
// Set up the members collection if it doesn't exist already
21592159
if (!funcSymbol.members) {
2160-
funcSymbol.members = new StringMap<Symbol>();
2160+
funcSymbol.members = createMap<string, Symbol>();
21612161
}
21622162

21632163
// Declare the method/property

src/compiler/checker.ts

+36-36
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace ts {
4747
let symbolCount = 0;
4848

4949
const emptyArray: any[] = [];
50-
const emptySymbols = new StringMap<Symbol>();
50+
const emptySymbols = createMap<string, Symbol>();
5151

5252
const compilerOptions = host.getCompilerOptions();
5353
const languageVersion = compilerOptions.target || ScriptTarget.ES3;
@@ -111,10 +111,10 @@ namespace ts {
111111
};
112112

113113
const tupleTypes: GenericType[] = [];
114-
const unionTypes = new StringMap<UnionType>();
115-
const intersectionTypes = new StringMap<IntersectionType>();
116-
const stringLiteralTypes = new StringMap<LiteralType>();
117-
const numericLiteralTypes = new StringMap<LiteralType>();
114+
const unionTypes = createMap<string, UnionType>();
115+
const intersectionTypes = createMap<string, IntersectionType>();
116+
const stringLiteralTypes = createMap<string, LiteralType>();
117+
const numericLiteralTypes = createMap<string, LiteralType>();
118118
const evolvingArrayTypes: EvolvingArrayType[] = [];
119119

120120
const unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown");
@@ -139,7 +139,7 @@ namespace ts {
139139

140140
const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
141141
const emptyGenericType = <GenericType><ObjectType>createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
142-
emptyGenericType.instantiations = new StringMap<TypeReference>();
142+
emptyGenericType.instantiations = createMap<string, TypeReference>();
143143

144144
const anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
145145
// The anyFunctionType contains the anyFunctionType by definition. The flag is further propagated
@@ -155,7 +155,7 @@ namespace ts {
155155

156156
const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true);
157157

158-
const globals = new StringMap<Symbol>();
158+
const globals = createMap<string, Symbol>();
159159
/**
160160
* List of every ambient module with a "*" wildcard.
161161
* Unlike other ambient modules, these can't be stored in `globals` because symbol tables only deal with exact matches.
@@ -325,7 +325,7 @@ namespace ts {
325325

326326
let jsxElementType: Type;
327327
/** Things we lazy load from the JSX namespace */
328-
const jsxTypes = new StringMap<Type>();
328+
const jsxTypes = createMap<string, Type>();
329329
const JsxNames = {
330330
JSX: "JSX",
331331
IntrinsicElements: "IntrinsicElements",
@@ -336,11 +336,11 @@ namespace ts {
336336
IntrinsicClassAttributes: "IntrinsicClassAttributes"
337337
};
338338

339-
const subtypeRelation = new StringMap<RelationComparisonResult>();
340-
const assignableRelation = new StringMap<RelationComparisonResult>();
341-
const comparableRelation = new StringMap<RelationComparisonResult>();
342-
const identityRelation = new StringMap<RelationComparisonResult>();
343-
const enumRelation = new StringMap<boolean>();
339+
const subtypeRelation = createMap<string, RelationComparisonResult>();
340+
const assignableRelation = createMap<string, RelationComparisonResult>();
341+
const comparableRelation = createMap<string, RelationComparisonResult>();
342+
const identityRelation = createMap<string, RelationComparisonResult>();
343+
const enumRelation = createMap<string, boolean>();
344344

345345
// This is for caching the result of getSymbolDisplayBuilder. Do not access directly.
346346
let _displayBuilder: SymbolDisplayBuilder;
@@ -354,7 +354,7 @@ namespace ts {
354354
ResolvedReturnType
355355
}
356356

357-
const builtinGlobals = new StringMap([[undefinedSymbol.name, undefinedSymbol]]);
357+
const builtinGlobals = createMap([[undefinedSymbol.name, undefinedSymbol]]);
358358

359359
initializeTypeChecker();
360360

@@ -437,11 +437,11 @@ namespace ts {
437437
target.declarations.push(node);
438438
});
439439
if (source.members) {
440-
if (!target.members) target.members = new StringMap<Symbol>();
440+
if (!target.members) target.members = createMap<string, Symbol>();
441441
mergeSymbolTable(target.members, source.members);
442442
}
443443
if (source.exports) {
444-
if (!target.exports) target.exports = new StringMap<Symbol>();
444+
if (!target.exports) target.exports = createMap<string, Symbol>();
445445
mergeSymbolTable(target.exports, source.exports);
446446
}
447447
recordMergedSymbol(target, source);
@@ -1418,7 +1418,7 @@ namespace ts {
14181418
// This provides a name to the module. See the test tests/cases/fourslash/untypedModuleImport.ts
14191419
const newSymbol = createSymbol(SymbolFlags.ValueModule, quotedName);
14201420
// Module symbols are expected to have 'exports', although since this is an untyped module it can be empty.
1421-
newSymbol.exports = new StringMap<Symbol>();
1421+
newSymbol.exports = createMap<string, Symbol>();
14221422
// Cache it so subsequent accesses will return the same module.
14231423
globals.set(quotedName, newSymbol);
14241424
return newSymbol;
@@ -1531,8 +1531,8 @@ namespace ts {
15311531
// All export * declarations are collected in an __export symbol by the binder
15321532
const exportStars = symbol.exports.get("__export");
15331533
if (exportStars) {
1534-
const nestedSymbols = new StringMap<Symbol>();
1535-
const lookupTable = new StringMap<ExportCollisionTracker>();
1534+
const nestedSymbols = createMap<string, Symbol>();
1535+
const lookupTable = createMap<string, ExportCollisionTracker>();
15361536
for (const node of exportStars.declarations) {
15371537
const resolvedModule = resolveExternalModuleName(node, (node as ExportDeclaration).moduleSpecifier);
15381538
const exportedSymbols = visit(resolvedModule);
@@ -3237,7 +3237,7 @@ namespace ts {
32373237

32383238
// Return the type implied by an object binding pattern
32393239
function getTypeFromObjectBindingPattern(pattern: ObjectBindingPattern, includePatternInType: boolean, reportErrors: boolean): Type {
3240-
const members = new StringMap<Symbol>();
3240+
const members = createMap<string, Symbol>();
32413241
let hasComputedProperties = false;
32423242
forEach(pattern.elements, e => {
32433243
const name = e.propertyName || <Identifier>e.name;
@@ -3842,7 +3842,7 @@ namespace ts {
38423842
type.typeParameters = concatenate(outerTypeParameters, localTypeParameters);
38433843
type.outerTypeParameters = outerTypeParameters;
38443844
type.localTypeParameters = localTypeParameters;
3845-
(<GenericType>type).instantiations = new StringMap([[getTypeListId(type.typeParameters), <GenericType>type]]);
3845+
(<GenericType>type).instantiations = createMap([[getTypeListId(type.typeParameters), <GenericType>type]]);
38463846
(<GenericType>type).target = <GenericType>type;
38473847
(<GenericType>type).typeArguments = type.typeParameters;
38483848
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
@@ -3884,7 +3884,7 @@ namespace ts {
38843884
if (typeParameters) {
38853885
// Initialize the instantiation cache for generic type aliases. The declared type corresponds to
38863886
// an instantiation of the type alias with the type parameters supplied as type arguments.
3887-
links.instantiations = new StringMap([[getTypeListId(links.typeParameters), type]]);
3887+
links.instantiations = createMap([[getTypeListId(links.typeParameters), type]]);
38883888
}
38893889
}
38903890
else {
@@ -4572,7 +4572,7 @@ namespace ts {
45724572
// these partial properties when identifying discriminant properties, but otherwise they are filtered out
45734573
// and do not appear to be present in the union type.
45744574
function getUnionOrIntersectionProperty(type: UnionOrIntersectionType, name: string): Symbol {
4575-
const properties = type.resolvedProperties || (type.resolvedProperties = new StringMap<Symbol>());
4575+
const properties = type.resolvedProperties || (type.resolvedProperties = createMap<string, Symbol>());
45764576
let property = properties.get(name);
45774577
if (!property) {
45784578
property = createUnionOrIntersectionProperty(type, name);
@@ -5393,7 +5393,7 @@ namespace ts {
53935393
type.typeParameters = typeParameters;
53945394
type.outerTypeParameters = undefined;
53955395
type.localTypeParameters = typeParameters;
5396-
type.instantiations = new StringMap([[getTypeListId(type.typeParameters), <GenericType>type]]);
5396+
type.instantiations = createMap([[getTypeListId(type.typeParameters), <GenericType>type]]);
53975397
type.target = <GenericType>type;
53985398
type.typeArguments = type.typeParameters;
53995399
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
@@ -6906,7 +6906,7 @@ namespace ts {
69066906
}
69076907
sourceStack[depth] = source;
69086908
targetStack[depth] = target;
6909-
maybeStack[depth] = new StringMap([[id, RelationComparisonResult.Succeeded]]);
6909+
maybeStack[depth] = createMap([[id, RelationComparisonResult.Succeeded]]);
69106910
depth++;
69116911
const saveExpandingFlags = expandingFlags;
69126912
if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack, depth)) expandingFlags |= 1;
@@ -7591,7 +7591,7 @@ namespace ts {
75917591
}
75927592

75937593
function transformTypeOfMembers(type: Type, f: (propertyType: Type) => Type) {
7594-
const members = new StringMap<Symbol>();
7594+
const members = createMap<string, Symbol>();
75957595
for (const property of getPropertiesOfObjectType(type)) {
75967596
const original = getTypeOfSymbol(property);
75977597
const updated = f(original);
@@ -7814,7 +7814,7 @@ namespace ts {
78147814
let targetStack: Type[];
78157815
let depth = 0;
78167816
let inferiority = 0;
7817-
const visited = new StringSet();
7817+
const visited = createSet();
78187818
inferFromTypes(originalSource, originalTarget);
78197819

78207820
function isInProcess(source: Type, target: Type) {
@@ -8894,7 +8894,7 @@ namespace ts {
88948894
// If we have previously computed the control flow type for the reference at
88958895
// this flow loop junction, return the cached type.
88968896
const id = getFlowNodeId(flow);
8897-
const cache = flowLoopCaches[id] || (flowLoopCaches[id] = new StringMap<Type>());
8897+
const cache = flowLoopCaches[id] || (flowLoopCaches[id] = createMap<string, Type>());
88988898
if (!key) {
88998899
key = getFlowCacheKey(reference);
89008900
}
@@ -10594,7 +10594,7 @@ namespace ts {
1059410594
// Grammar checking
1059510595
checkGrammarObjectLiteralExpression(node, inDestructuringPattern);
1059610596

10597-
const propertiesTable = new StringMap<Symbol>();
10597+
const propertiesTable = createMap<string, Symbol>();
1059810598
const propertiesArray: Symbol[] = [];
1059910599
const contextualType = getApparentTypeOfContextualType(node);
1060010600
const contextualTypeHasPattern = contextualType && contextualType.pattern &&
@@ -11145,7 +11145,7 @@ namespace ts {
1114511145

1114611146
const targetAttributesType = getJsxElementAttributesType(node);
1114711147

11148-
const nameTable = new StringSet();
11148+
const nameTable = createSet();
1114911149
// Process this array in right-to-left order so we know which
1115011150
// attributes (mostly from spreads) are being overwritten and
1115111151
// thus should have their types ignored
@@ -14622,8 +14622,8 @@ namespace ts {
1462214622
Property = Getter | Setter
1462314623
}
1462414624

14625-
const instanceNames = new StringMap<Accessor>();
14626-
const staticNames = new StringMap<Accessor>();
14625+
const instanceNames = createMap<string, Accessor>();
14626+
const staticNames = createMap<string, Accessor>();
1462714627
for (const member of node.members) {
1462814628
if (member.kind === SyntaxKind.Constructor) {
1462914629
for (const param of (member as ConstructorDeclaration).parameters) {
@@ -14672,7 +14672,7 @@ namespace ts {
1467214672
}
1467314673

1467414674
function checkObjectTypeForDuplicateDeclarations(node: TypeLiteralNode | InterfaceDeclaration) {
14675-
const names = new StringSet();
14675+
const names = createSet();
1467614676
for (const member of node.members) {
1467714677
if (member.kind == SyntaxKind.PropertySignature) {
1467814678
let memberName: string;
@@ -18490,7 +18490,7 @@ namespace ts {
1849018490
}
1849118491

1849218492
function getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[] {
18493-
const symbols = new StringMap<Symbol>();
18493+
const symbols = createMap<string, Symbol>();
1849418494
let memberFlags: ModifierFlags = ModifierFlags.None;
1849518495

1849618496
if (isInsideWithStatementBody(location)) {
@@ -20315,7 +20315,7 @@ namespace ts {
2031520315
}
2031620316

2031720317
function checkGrammarObjectLiteralExpression(node: ObjectLiteralExpression, inDestructuring: boolean) {
20318-
const seen = new StringMap<SymbolFlags>();
20318+
const seen = createMap<string, SymbolFlags>();
2031920319
const Property = 1;
2032020320
const GetAccessor = 2;
2032120321
const SetAccessor = 4;
@@ -20402,7 +20402,7 @@ namespace ts {
2040220402
}
2040320403

2040420404
function checkGrammarJsxElement(node: JsxOpeningLikeElement) {
20405-
const seen = new StringSet();
20405+
const seen = createSet();
2040620406
for (const attr of node.attributes) {
2040720407
if (attr.kind === SyntaxKind.JsxSpreadAttribute) {
2040820408
continue;

0 commit comments

Comments
 (0)