Skip to content

Commit a98bf56

Browse files
author
Andy Hanson
committed
WIP
1 parent 0e7fa4f commit a98bf56

12 files changed

+83
-79
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace ts {
126126

127127
let symbolCount = 0;
128128
let Symbol: { new (flags: SymbolFlags, name: string): Symbol };
129-
let classifiableNames: Map<string>;
129+
let classifiableNames: Set;
130130

131131
const unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
132132
const reportedUnreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
@@ -140,7 +140,7 @@ namespace ts {
140140
options = opts;
141141
languageVersion = getEmitScriptTarget(options);
142142
inStrictMode = !!file.externalModuleIndicator;
143-
classifiableNames = createMap<string>();
143+
classifiableNames = createSet();
144144
symbolCount = 0;
145145
skipTransformFlagAggregation = isDeclarationFile(file);
146146

@@ -335,7 +335,7 @@ namespace ts {
335335
symbol = _getOrUpdate(symbolTable, name, name => createSymbol(SymbolFlags.None, name));
336336

337337
if (name && (includes & SymbolFlags.Classifiable)) {
338-
_s(classifiableNames, name, name);
338+
_add(classifiableNames, name);
339339
}
340340

341341
if (symbol.flags & excludes) {
@@ -2089,7 +2089,7 @@ namespace ts {
20892089
bindAnonymousDeclaration(node, SymbolFlags.Class, bindingName);
20902090
// Add name of class expression into the map for semantic classifier
20912091
if (node.name) {
2092-
_s(classifiableNames, node.name.text, node.name.text);
2092+
_add(classifiableNames, node.name.text);
20932093
}
20942094
}
20952095

src/compiler/checker.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7620,7 +7620,7 @@ namespace ts {
76207620
let targetStack: Type[];
76217621
let depth = 0;
76227622
let inferiority = 0;
7623-
const visited = createMap<boolean>();
7623+
const visited = createSet();
76247624
inferFromTypes(originalSource, originalTarget);
76257625

76267626
function isInProcess(source: Type, target: Type) {
@@ -7756,10 +7756,10 @@ namespace ts {
77567756
return;
77577757
}
77587758
const key = source.id + "," + target.id;
7759-
if (_g(visited, key)) {
7759+
if (_setHas(visited, key)) {
77607760
return;
77617761
}
7762-
_s(visited, key, true);
7762+
_add(visited, key);
77637763
if (depth === 0) {
77647764
sourceStack = [];
77657765
targetStack = [];
@@ -10377,7 +10377,7 @@ namespace ts {
1037710377
}
1037810378
}
1037910379

10380-
function checkJsxAttribute(node: JsxAttribute, elementAttributesType: Type, nameTable: Map<boolean>) {
10380+
function checkJsxAttribute(node: JsxAttribute, elementAttributesType: Type, nameTable: Set) {
1038110381
let correspondingPropType: Type = undefined;
1038210382

1038310383
// Look up the corresponding property for this attribute
@@ -10416,24 +10416,24 @@ namespace ts {
1041610416
checkTypeAssignableTo(exprType, correspondingPropType, node);
1041710417
}
1041810418

10419-
_s(nameTable, node.name.text, true);
10419+
_add(nameTable, node.name.text);
1042010420
return exprType;
1042110421
}
1042210422

10423-
function checkJsxSpreadAttribute(node: JsxSpreadAttribute, elementAttributesType: Type, nameTable: Map<boolean>) {
10423+
function checkJsxSpreadAttribute(node: JsxSpreadAttribute, elementAttributesType: Type, nameTable: Set) {
1042410424
const type = checkExpression(node.expression);
1042510425
const props = getPropertiesOfType(type);
1042610426
for (const prop of props) {
1042710427
// Is there a corresponding property in the element attributes type? Skip checking of properties
1042810428
// that have already been assigned to, as these are not actually pushed into the resulting type
10429-
if (!_g(nameTable, prop.name)) {
10429+
if (!_setHas(nameTable, prop.name)) {
1043010430
const targetPropSym = getPropertyOfType(elementAttributesType, prop.name);
1043110431
if (targetPropSym) {
1043210432
const msg = chainDiagnosticMessages(undefined, Diagnostics.Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property, prop.name);
1043310433
checkTypeAssignableTo(getTypeOfSymbol(prop), getTypeOfSymbol(targetPropSym), node, undefined, msg);
1043410434
}
1043510435

10436-
_s(nameTable, prop.name, true);
10436+
_add(nameTable, prop.name);
1043710437
}
1043810438
}
1043910439
return type;
@@ -10749,7 +10749,7 @@ namespace ts {
1074910749

1075010750
const targetAttributesType = getJsxElementAttributesType(node);
1075110751

10752-
const nameTable = createMap<boolean>();
10752+
const nameTable = createSet();
1075310753
// Process this array in right-to-left order so we know which
1075410754
// attributes (mostly from spreads) are being overwritten and
1075510755
// thus should have their types ignored
@@ -10773,7 +10773,7 @@ namespace ts {
1077310773
const targetProperties = getPropertiesOfType(targetAttributesType);
1077410774
for (let i = 0; i < targetProperties.length; i++) {
1077510775
if (!(targetProperties[i].flags & SymbolFlags.Optional) &&
10776-
!_g(nameTable, targetProperties[i].name)) {
10776+
!_setHas(nameTable, targetProperties[i].name)) {
1077710777

1077810778
error(node, Diagnostics.Property_0_is_missing_in_type_1, targetProperties[i].name, typeToString(targetAttributesType));
1077910779
}
@@ -14229,7 +14229,7 @@ namespace ts {
1422914229
}
1423014230

1423114231
function checkObjectTypeForDuplicateDeclarations(node: TypeLiteralNode | InterfaceDeclaration) {
14232-
const names = createMap<boolean>();
14232+
const names = createSet();
1423314233
for (const member of node.members) {
1423414234
if (member.kind == SyntaxKind.PropertySignature) {
1423514235
let memberName: string;
@@ -14243,12 +14243,12 @@ namespace ts {
1424314243
continue;
1424414244
}
1424514245

14246-
if (_g(names, memberName)) {
14246+
if (_setHas(names, memberName)) {
1424714247
error(member.symbol.valueDeclaration.name, Diagnostics.Duplicate_identifier_0, memberName);
1424814248
error(member.name, Diagnostics.Duplicate_identifier_0, memberName);
1424914249
}
1425014250
else {
14251-
_s(names, memberName, true);
14251+
_add(names, memberName);
1425214252
}
1425314253
}
1425414254
}

src/compiler/commandLineParser.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,6 @@ namespace ts {
975975
function convertOptionsFromJson(optionDeclarations: CommandLineOption[], jsonOptions: any, basePath: string,
976976
defaultOptions: CompilerOptions | TypingOptions, diagnosticMessage: DiagnosticMessage, errors: Diagnostic[]) {
977977

978-
//kill
979-
checkNotNativeMap(jsonOptions);
980-
981978
if (!jsonOptions) {
982979
return;
983980
}

src/compiler/dataStructures.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace ts {
5959
}
6060

6161
declare const Map: { new<T>(): NativeMap<T> } | undefined;
62-
const realMaps = typeof Map !== "undefined"; //false;
62+
const realMaps = typeof Map !== "undefined";
6363

6464
const createObject = Object.create;
6565
const hasOwnProperty = Object.prototype.hasOwnProperty;
@@ -92,8 +92,6 @@ namespace ts {
9292
return map;
9393
}
9494

95-
//PRIMITIVE OPERATIONS: Need a different strategy for real map vs {}
96-
9795
export const _g: <T>(map: Map<T>, key: string) => T = realMaps
9896
? <T>(map: NativeMap<T>, key: string) => map.get(key)
9997
: <T>(map: MapLike<T>, key: string) => map[key];
@@ -139,7 +137,6 @@ namespace ts {
139137

140138
export const _find: <T, U>(map: Map<T>, f: (key: string, value: T) => U | undefined) => U | undefined = realMaps
141139
? <T, U>(map: NativeMap<T>, f: (key: string, value: T) => U | undefined) => {
142-
//use forEach?
143140
const iter = map.entries();
144141
while (true) {
145142
const { value: pair, done } = iter.next();
@@ -321,11 +318,6 @@ namespace ts {
321318
}
322319
return undefined;
323320
};
324-
325-
//kill
326-
export function checkNotNativeMap(value: MapLike<any>) {
327-
Debug.assert(!(value instanceof Map));
328-
}
329321
}
330322

331323

@@ -366,12 +358,18 @@ namespace ts {
366358
* @param source A map from which properties should be copied.
367359
* @param target A map to which properties should be copied.
368360
*/
361+
//rename : "entries", not "properties"
369362
export function copyMapPropertiesFromTo<T>(source: Map<T>, target: Map<T>): void {
370363
_each(source, (key, value) => {
371364
_s(target, key, value);
372365
});
373366
}
374367

368+
//move
369+
export function copySetValuesFromTo<T>(source: Set, target: Set): void {
370+
_eachInSet(source, value => _add(target, value));
371+
}
372+
375373
//kill?
376374
/**
377375
* Reduce the properties of a map.
@@ -497,16 +495,39 @@ namespace ts {
497495
declare const Set: { new(): NativeSet } | undefined;
498496
const realSets = typeof Set !== "undefined";
499497

498+
/*interface StringSetModule {
499+
createSet(): Set
500+
add(set: Set, value: string): string;
501+
}
502+
const StringSet: StringSetModule = realSets ?
503+
{
504+
createSet: () => new Set(),
505+
add(set: NativeSet, value: string) {
506+
set.add(value);
507+
return value;
508+
}
509+
}
510+
:
511+
{
512+
createSet: () => createDictionaryModeObject(),
513+
add(set: SetLike, value: string) {
514+
set[value] = true;
515+
return value;
516+
}
517+
}*/
518+
500519
export const createSet: () => Set = realSets
501520
? () => new Set()
502521
: () => createDictionaryModeObject();
503522

504-
export const _add: (set: Set, value: string) => void = realSets
523+
export const _add: (set: Set, value: string) => string = realSets
505524
? (set: NativeSet, value: string) => {
506525
set.add(value);
526+
return value;
507527
}
508528
: (set: SetLike, value: string) => {
509529
set[value] = true;
530+
return value;
510531
}
511532

512533
export const _setHas: (set: Set, value: string) => boolean = realSets
@@ -537,15 +558,9 @@ namespace ts {
537558
for (const value in set)
538559
f(value);
539560
}
540-
541-
//todo: more iteration helpers
542561
}
543562

544-
545-
546-
547-
548-
//MAPLIKE CRAP
563+
//MAPLIKE
549564
/* @internal */
550565
namespace ts {
551566
const hasOwnProperty = Object.prototype.hasOwnProperty; //neater
@@ -570,7 +585,6 @@ namespace ts {
570585
* @param key A property key.
571586
*/
572587
export function hasProperty<T>(map: MapLike<T>, key: string): boolean {
573-
checkNotNativeMap(map);
574588
return hasOwnProperty.call(map, key);
575589
}
576590

@@ -584,7 +598,6 @@ namespace ts {
584598
* @param key A property key.
585599
*/
586600
export function getProperty<T>(map: MapLike<T>, key: string): T | undefined {
587-
checkNotNativeMap(map);
588601
return hasOwnProperty.call(map, key) ? map[key] : undefined;
589602
}
590603

@@ -597,7 +610,6 @@ namespace ts {
597610
* @param map A map-like.
598611
*/
599612
export function getOwnKeys<T>(map: MapLike<T>): string[] {
600-
checkNotNativeMap(map);
601613
const keys: string[] = [];
602614
for (const key in map) if (hasOwnProperty.call(map, key)) {
603615
keys.push(key);
@@ -609,9 +621,7 @@ namespace ts {
609621
export function assign<T1 extends MapLike<{}>, T2>(t: T1, arg1: T2): T1 & T2;
610622
export function assign<T1 extends MapLike<{}>>(t: T1, ...args: any[]): any;
611623
export function assign<T1 extends MapLike<{}>>(t: T1, ...args: any[]) {
612-
checkNotNativeMap(t);
613624
for (const arg of args) {
614-
checkNotNativeMap(arg);
615625
for (const p of getOwnKeys(arg)) {
616626
t[p] = arg[p];
617627
}
@@ -630,7 +640,6 @@ namespace ts {
630640
* @param initial The initial value for the reduction.
631641
*/
632642
export function reduceOwnProperties<T, U>(map: MapLike<T>, callback: (aggregate: U, value: T, key: string) => U, initial: U): U {
633-
checkNotNativeMap(map);
634643
let result = initial;
635644
for (const key in map) if (hasOwnProperty.call(map, key)) {
636645
result = callback(result, map[key], String(key));
@@ -645,8 +654,6 @@ namespace ts {
645654
* @param right A map-like whose properties should be compared.
646655
*/
647656
export function equalOwnProperties<T>(left: MapLike<T>, right: MapLike<T>, equalityComparer?: (left: T, right: T) => boolean) {
648-
checkNotNativeMap(left);
649-
checkNotNativeMap(right);
650657
if (left === right) return true;
651658
if (!left || !right) return false;
652659
for (const key in left) if (hasOwnProperty.call(left, key)) {
@@ -660,8 +667,6 @@ namespace ts {
660667
}
661668

662669
export function extend<T1, T2>(first: T1 , second: T2): T1 & T2 {
663-
checkNotNativeMap(first);
664-
checkNotNativeMap(second);
665670
const result: T1 & T2 = <any>{};
666671
for (const id in second) if (hasOwnProperty.call(second, id)) {
667672
(result as any)[id] = (second as any)[id];

src/compiler/declarationEmitter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace ts {
7575
// and we could be collecting these paths from multiple files into single one with --out option
7676
let referencesOutput = "";
7777

78-
let usedTypeDirectiveReferences: Map<string>;
78+
let usedTypeDirectiveReferences: Set;
7979

8080
// Emit references corresponding to each file
8181
const emittedReferencedFiles: SourceFile[] = [];
@@ -156,7 +156,7 @@ namespace ts {
156156
});
157157

158158
if (usedTypeDirectiveReferences) {
159-
_eachKey(usedTypeDirectiveReferences, directive => {
159+
_eachInSet(usedTypeDirectiveReferences, directive => {
160160
referencesOutput += `/// <reference types="${directive}" />${newLine}`;
161161
});
162162
}
@@ -267,11 +267,11 @@ namespace ts {
267267
}
268268

269269
if (!usedTypeDirectiveReferences) {
270-
usedTypeDirectiveReferences = createMap<string>();
270+
usedTypeDirectiveReferences = createSet();
271271
}
272272
for (const directive of typeReferenceDirectives) {
273-
if (!_has(usedTypeDirectiveReferences, directive)) {
274-
_s(usedTypeDirectiveReferences, directive, directive);
273+
if (!_setHas(usedTypeDirectiveReferences, directive)) {
274+
_add(usedTypeDirectiveReferences, directive);
275275
}
276276
}
277277
}

src/compiler/emitter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ const _super = (function (geti, seti) {
218218

219219
let nodeIdToGeneratedName: string[];
220220
let autoGeneratedIdToGeneratedName: string[];
221-
let generatedNameSet: Map<string>;
221+
let generatedNameSet: Set;
222222
let tempFlags: TempFlags;
223223
let currentSourceFile: SourceFile;
224224
let currentText: string;
@@ -296,7 +296,7 @@ const _super = (function (geti, seti) {
296296
sourceMap.initialize(jsFilePath, sourceMapFilePath, sourceFiles, isBundledEmit);
297297
nodeIdToGeneratedName = [];
298298
autoGeneratedIdToGeneratedName = [];
299-
generatedNameSet = createMap<string>();
299+
generatedNameSet = createSet();
300300
isOwnFileEmit = !isBundledEmit;
301301

302302
// Emit helpers from all the files
@@ -2704,7 +2704,7 @@ const _super = (function (geti, seti) {
27042704
function isUniqueName(name: string): boolean {
27052705
return !resolver.hasGlobalName(name) &&
27062706
!_has(currentFileIdentifiers, name) &&
2707-
!_has(generatedNameSet, name);
2707+
!_setHas(generatedNameSet, name);
27082708
}
27092709

27102710
function isUniqueLocalName(name: string, container: Node): boolean {
@@ -2760,7 +2760,7 @@ const _super = (function (geti, seti) {
27602760
while (true) {
27612761
const generatedName = baseName + i;
27622762
if (isUniqueName(generatedName)) {
2763-
return _s(generatedNameSet, generatedName, generatedName);
2763+
return _add(generatedNameSet, generatedName);
27642764
}
27652765
i++;
27662766
}

0 commit comments

Comments
 (0)