Skip to content

Commit

Permalink
Merge pull request #12715 from Microsoft/map5
Browse files Browse the repository at this point in the history
Use native maps when they're available
  • Loading branch information
Andy committed Jan 17, 2017
2 parents d80d8b7 + 30ccc7a commit 65ef51d
Show file tree
Hide file tree
Showing 86 changed files with 1,258 additions and 1,072 deletions.
1 change: 1 addition & 0 deletions Gulpfile.ts
Expand Up @@ -328,6 +328,7 @@ const builtGeneratedDiagnosticMessagesJSON = path.join(builtLocalDirectory, "dia
// processDiagnosticMessages script
gulp.task(processDiagnosticMessagesJs, false, [], () => {
const settings: tsc.Settings = getCompilerSettings({
target: "es5",
declaration: false,
removeComments: true,
noResolve: false,
Expand Down
10 changes: 5 additions & 5 deletions scripts/processDiagnosticMessages.ts
Expand Up @@ -27,7 +27,7 @@ function main(): void {

var inputFilePath = sys.args[0].replace(/\\/g, "/");
var inputStr = sys.readFile(inputFilePath);

var diagnosticMessages: InputDiagnosticMessageTable = JSON.parse(inputStr);

var names = Utilities.getObjectKeys(diagnosticMessages);
Expand All @@ -44,7 +44,7 @@ function main(): void {
function checkForUniqueCodes(messages: string[], diagnosticTable: InputDiagnosticMessageTable) {
const originalMessageForCode: string[] = [];
let numConflicts = 0;

for (const currentMessage of messages) {
const code = diagnosticTable[currentMessage].code;

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

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

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

result +=
' ' + propName +
Expand All @@ -114,7 +114,7 @@ function buildDiagnosticMessageOutput(messageTable: InputDiagnosticMessageTable,
for (var i = 0; i < names.length; i++) {
var name = names[i];
var diagnosticDetails = messageTable[name];
var propName = convertPropertyName(nameMap[name]);
var propName = convertPropertyName(nameMap.get(name));

result += '\r\n "' + createKey(propName, diagnosticDetails.code) + '"' + ' : "' + name.replace(/[\"]/g, '\\"') + '"';
if (i !== names.length - 1) {
Expand Down
27 changes: 15 additions & 12 deletions src/compiler/binder.ts
Expand Up @@ -349,17 +349,20 @@ namespace ts {
// Otherwise, we'll be merging into a compatible existing symbol (for example when
// you have multiple 'vars' with the same name in the same container). In this case
// just add this node into the declarations list of the symbol.
symbol = symbolTable[name] || (symbolTable[name] = createSymbol(SymbolFlags.None, name));
symbol = symbolTable.get(name);
if (!symbol) {
symbolTable.set(name, symbol = createSymbol(SymbolFlags.None, name));
}

if (name && (includes & SymbolFlags.Classifiable)) {
classifiableNames[name] = name;
classifiableNames.set(name, name);
}

if (symbol.flags & excludes) {
if (symbol.isReplaceableByMethod) {
// Javascript constructor-declared symbols can be discarded in favor of
// prototype symbols like methods.
symbol = symbolTable[name] = createSymbol(SymbolFlags.None, name);
symbolTable.set(name, symbol = createSymbol(SymbolFlags.None, name));
}
else {
if (node.name) {
Expand Down Expand Up @@ -1570,7 +1573,7 @@ namespace ts {
const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
typeLiteralSymbol.members = createMap<Symbol>();
typeLiteralSymbol.members[symbol.name] = symbol;
typeLiteralSymbol.members.set(symbol.name, symbol);
}

function bindObjectLiteralExpression(node: ObjectLiteralExpression) {
Expand Down Expand Up @@ -1601,9 +1604,9 @@ namespace ts {
? ElementKind.Property
: ElementKind.Accessor;

const existingKind = seen[identifier.text];
const existingKind = seen.get(identifier.text);
if (!existingKind) {
seen[identifier.text] = currentKind;
seen.set(identifier.text, currentKind);
continue;
}

Expand Down Expand Up @@ -2208,7 +2211,7 @@ namespace ts {
constructorFunction.parent = classPrototype;
classPrototype.parent = leftSideOfAssignment;

const funcSymbol = container.locals[constructorFunction.text];
const funcSymbol = container.locals.get(constructorFunction.text);
if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function || isDeclarationOfFunctionExpression(funcSymbol))) {
return;
}
Expand Down Expand Up @@ -2239,7 +2242,7 @@ namespace ts {
bindAnonymousDeclaration(node, SymbolFlags.Class, bindingName);
// Add name of class expression into the map for semantic classifier
if (node.name) {
classifiableNames[node.name.text] = node.name.text;
classifiableNames.set(node.name.text, node.name.text);
}
}

Expand All @@ -2255,14 +2258,14 @@ namespace ts {
// module might have an exported variable called 'prototype'. We can't allow that as
// that would clash with the built-in 'prototype' for the class.
const prototypeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Prototype, "prototype");
if (symbol.exports[prototypeSymbol.name]) {
const symbolExport = symbol.exports.get(prototypeSymbol.name);
if (symbolExport) {
if (node.name) {
node.name.parent = node;
}
file.bindDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0],
Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
file.bindDiagnostics.push(createDiagnosticForNode(symbolExport.declarations[0], Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
}
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
symbol.exports.set(prototypeSymbol.name, prototypeSymbol);
prototypeSymbol.parent = symbol;
}

Expand Down

0 comments on commit 65ef51d

Please sign in to comment.