Skip to content

Commit 65ef51d

Browse files
author
Andy
authored
Merge pull request #12715 from Microsoft/map5
Use native maps when they're available
2 parents d80d8b7 + 30ccc7a commit 65ef51d

File tree

86 files changed

+1258
-1072
lines changed

Some content is hidden

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

86 files changed

+1258
-1072
lines changed

Gulpfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ const builtGeneratedDiagnosticMessagesJSON = path.join(builtLocalDirectory, "dia
328328
// processDiagnosticMessages script
329329
gulp.task(processDiagnosticMessagesJs, false, [], () => {
330330
const settings: tsc.Settings = getCompilerSettings({
331+
target: "es5",
331332
declaration: false,
332333
removeComments: true,
333334
noResolve: false,

scripts/processDiagnosticMessages.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function main(): void {
2727

2828
var inputFilePath = sys.args[0].replace(/\\/g, "/");
2929
var inputStr = sys.readFile(inputFilePath);
30-
30+
3131
var diagnosticMessages: InputDiagnosticMessageTable = JSON.parse(inputStr);
3232

3333
var names = Utilities.getObjectKeys(diagnosticMessages);
@@ -44,7 +44,7 @@ function main(): void {
4444
function checkForUniqueCodes(messages: string[], diagnosticTable: InputDiagnosticMessageTable) {
4545
const originalMessageForCode: string[] = [];
4646
let numConflicts = 0;
47-
47+
4848
for (const currentMessage of messages) {
4949
const code = diagnosticTable[currentMessage].code;
5050

@@ -74,7 +74,7 @@ function buildUniqueNameMap(names: string[]): ts.Map<string> {
7474
var uniqueNames = NameGenerator.ensureUniqueness(names, /* isCaseSensitive */ false, /* isFixed */ undefined);
7575

7676
for (var i = 0; i < names.length; i++) {
77-
nameMap[names[i]] = uniqueNames[i];
77+
nameMap.set(names[i], uniqueNames[i]);
7878
}
7979

8080
return nameMap;
@@ -91,7 +91,7 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
9191
for (var i = 0; i < names.length; i++) {
9292
var name = names[i];
9393
var diagnosticDetails = messageTable[name];
94-
var propName = convertPropertyName(nameMap[name]);
94+
var propName = convertPropertyName(nameMap.get(name));
9595

9696
result +=
9797
' ' + propName +
@@ -114,7 +114,7 @@ function buildDiagnosticMessageOutput(messageTable: InputDiagnosticMessageTable,
114114
for (var i = 0; i < names.length; i++) {
115115
var name = names[i];
116116
var diagnosticDetails = messageTable[name];
117-
var propName = convertPropertyName(nameMap[name]);
117+
var propName = convertPropertyName(nameMap.get(name));
118118

119119
result += '\r\n "' + createKey(propName, diagnosticDetails.code) + '"' + ' : "' + name.replace(/[\"]/g, '\\"') + '"';
120120
if (i !== names.length - 1) {

src/compiler/binder.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,20 @@ namespace ts {
349349
// Otherwise, we'll be merging into a compatible existing symbol (for example when
350350
// you have multiple 'vars' with the same name in the same container). In this case
351351
// just add this node into the declarations list of the symbol.
352-
symbol = symbolTable[name] || (symbolTable[name] = createSymbol(SymbolFlags.None, name));
352+
symbol = symbolTable.get(name);
353+
if (!symbol) {
354+
symbolTable.set(name, symbol = createSymbol(SymbolFlags.None, name));
355+
}
353356

354357
if (name && (includes & SymbolFlags.Classifiable)) {
355-
classifiableNames[name] = name;
358+
classifiableNames.set(name, name);
356359
}
357360

358361
if (symbol.flags & excludes) {
359362
if (symbol.isReplaceableByMethod) {
360363
// Javascript constructor-declared symbols can be discarded in favor of
361364
// prototype symbols like methods.
362-
symbol = symbolTable[name] = createSymbol(SymbolFlags.None, name);
365+
symbolTable.set(name, symbol = createSymbol(SymbolFlags.None, name));
363366
}
364367
else {
365368
if (node.name) {
@@ -1570,7 +1573,7 @@ namespace ts {
15701573
const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
15711574
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
15721575
typeLiteralSymbol.members = createMap<Symbol>();
1573-
typeLiteralSymbol.members[symbol.name] = symbol;
1576+
typeLiteralSymbol.members.set(symbol.name, symbol);
15741577
}
15751578

15761579
function bindObjectLiteralExpression(node: ObjectLiteralExpression) {
@@ -1601,9 +1604,9 @@ namespace ts {
16011604
? ElementKind.Property
16021605
: ElementKind.Accessor;
16031606

1604-
const existingKind = seen[identifier.text];
1607+
const existingKind = seen.get(identifier.text);
16051608
if (!existingKind) {
1606-
seen[identifier.text] = currentKind;
1609+
seen.set(identifier.text, currentKind);
16071610
continue;
16081611
}
16091612

@@ -2208,7 +2211,7 @@ namespace ts {
22082211
constructorFunction.parent = classPrototype;
22092212
classPrototype.parent = leftSideOfAssignment;
22102213

2211-
const funcSymbol = container.locals[constructorFunction.text];
2214+
const funcSymbol = container.locals.get(constructorFunction.text);
22122215
if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function || isDeclarationOfFunctionExpression(funcSymbol))) {
22132216
return;
22142217
}
@@ -2239,7 +2242,7 @@ namespace ts {
22392242
bindAnonymousDeclaration(node, SymbolFlags.Class, bindingName);
22402243
// Add name of class expression into the map for semantic classifier
22412244
if (node.name) {
2242-
classifiableNames[node.name.text] = node.name.text;
2245+
classifiableNames.set(node.name.text, node.name.text);
22432246
}
22442247
}
22452248

@@ -2255,14 +2258,14 @@ namespace ts {
22552258
// module might have an exported variable called 'prototype'. We can't allow that as
22562259
// that would clash with the built-in 'prototype' for the class.
22572260
const prototypeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Prototype, "prototype");
2258-
if (symbol.exports[prototypeSymbol.name]) {
2261+
const symbolExport = symbol.exports.get(prototypeSymbol.name);
2262+
if (symbolExport) {
22592263
if (node.name) {
22602264
node.name.parent = node;
22612265
}
2262-
file.bindDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0],
2263-
Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
2266+
file.bindDiagnostics.push(createDiagnosticForNode(symbolExport.declarations[0], Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
22642267
}
2265-
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
2268+
symbol.exports.set(prototypeSymbol.name, prototypeSymbol);
22662269
prototypeSymbol.parent = symbol;
22672270
}
22682271

0 commit comments

Comments
 (0)