Skip to content

Commit f125ee2

Browse files
committed
Merge branch 'master' into bom
Conflicts: src/compiler/commandLineParser.ts src/compiler/emitter.ts
2 parents a4a773a + 891d379 commit f125ee2

File tree

41 files changed

+5748
-395
lines changed

Some content is hidden

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

41 files changed

+5748
-395
lines changed

Jakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ var processDiagnosticMessagesTs = path.join(scriptsDirectory, "processDiagnostic
197197
var diagnosticMessagesJson = path.join(compilerDirectory, "diagnosticMessages.json");
198198
var diagnosticInfoMapTs = path.join(compilerDirectory, "diagnosticInformationMap.generated.ts");
199199

200+
file(processDiagnosticMessagesTs)
201+
200202
// processDiagnosticMessages script
201203
compileFile(processDiagnosticMessagesJs,
202204
[processDiagnosticMessagesTs],
File renamed without changes.

scripts/processDiagnosticMessages.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function main(): void {
3939
function buildUniqueNameMap(names: string[]): IIndexable<string> {
4040
var nameMap: IIndexable<string> = {};
4141

42-
var uniqueNames = NameGenerator.ensureUniqueness(names, /*isFixed */ undefined, /* isCaseSensitive */ false);
42+
var uniqueNames = NameGenerator.ensureUniqueness(names, /* isCaseSensitive */ false, /* isFixed */ undefined);
4343

4444
for (var i = 0; i < names.length; i++) {
4545
nameMap[names[i]] = uniqueNames[i];
@@ -94,17 +94,17 @@ function convertPropertyName(origName: string): string {
9494
}
9595

9696
module NameGenerator {
97-
export function ensureUniqueness(
98-
names: string[],
99-
isFixed: boolean[]= names.map(() => false),
100-
isCaseSensitive: boolean = true): string[] {
97+
export function ensureUniqueness(names: string[], isCaseSensitive: boolean, isFixed?: boolean[]): string[]{
98+
if (!isFixed) {
99+
isFixed = names.map(() => false)
100+
}
101101

102-
var names = names.map(x => x);
103-
ensureUniquenessInPlace(names, isFixed, isCaseSensitive);
102+
var names = names.slice();
103+
ensureUniquenessInPlace(names, isCaseSensitive, isFixed);
104104
return names;
105105
}
106106

107-
function ensureUniquenessInPlace(names: string[], isFixed: boolean[], isCaseSensitive: boolean): void {
107+
function ensureUniquenessInPlace(names: string[], isCaseSensitive: boolean, isFixed: boolean[]): void {
108108
for (var i = 0; i < names.length; i++) {
109109
var name = names[i];
110110
var collisionIndices = Utilities.collectMatchingIndices(name, names, isCaseSensitive);
@@ -131,9 +131,12 @@ module NameGenerator {
131131
}
132132

133133
while (true) {
134-
var newName = name + suffix++;
134+
var newName = name + suffix;
135+
suffix++;
135136

136-
if (proposedNames.some((name) => Utilities.stringEquals(name, newName, isCaseSensitive))) {
137+
// Check if we've synthesized a unique name, and if so
138+
// replace the conflicting name with the new one.
139+
if (!proposedNames.some(name => Utilities.stringEquals(name, newName, isCaseSensitive))) {
137140
proposedNames[collisionIndex] = newName;
138141
break;
139142
}
@@ -144,7 +147,7 @@ module NameGenerator {
144147

145148
module Utilities {
146149
/// Return a list of all indices where a string occurs.
147-
export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean = true): number[] {
150+
export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean): number[] {
148151
var matchingIndices: number[] = [];
149152

150153
for (var i = 0; i < proposedNames.length; i++) {
@@ -156,8 +159,8 @@ module Utilities {
156159
return matchingIndices;
157160
}
158161

159-
export function stringEquals(s1: string, s2: string, caseSensitive: boolean = true): boolean {
160-
if (!caseSensitive) {
162+
export function stringEquals(s1: string, s2: string, caseSensitive: boolean): boolean {
163+
if (caseSensitive) {
161164
s1 = s1.toLowerCase();
162165
s2 = s2.toLowerCase();
163166
}

src/compiler/checker.ts

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ module ts {
677677
}
678678

679679
// If symbol is directly available by its name in the symbol table
680-
if (isAccessible(symbols[symbol.name])) {
680+
if (isAccessible(lookUp(symbols, symbol.name))) {
681681
return symbol;
682682
}
683683

@@ -700,7 +700,7 @@ module ts {
700700
var qualify = false;
701701
forEachSymbolTableInScope(enclosingDeclaration, symbolTable => {
702702
// If symbol of this name is not available in the symbol table we are ok
703-
if (!symbolTable[symbol.name]) {
703+
if (!hasProperty(symbolTable, symbol.name)) {
704704
// Continue to the next symbol table
705705
return false;
706706
}
@@ -725,6 +725,52 @@ module ts {
725725
return qualify;
726726
}
727727

728+
function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult {
729+
if (symbol && enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)) {
730+
var initialSymbol = symbol;
731+
var meaningToLook = meaning;
732+
while (symbol) {
733+
// Symbol is accessible if it by itself is accessible
734+
var accessibleSymbol = getAccessibleSymbol(symbol, enclosingDeclaration, meaningToLook);
735+
if (accessibleSymbol) {
736+
if (forEach(accessibleSymbol.declarations, declaration => !isDeclarationVisible(declaration))) {
737+
return {
738+
accessibility: SymbolAccessibility.NotAccessible,
739+
errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
740+
errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, SymbolFlags.Namespace) : undefined
741+
};
742+
}
743+
return { accessibility: SymbolAccessibility.Accessible };
744+
}
745+
746+
// TODO(shkamat): Handle static method of class
747+
748+
// If we havent got the accessible symbol doesnt mean the symbol is actually inaccessible.
749+
// It could be qualified symbol and hence verify the path
750+
// eg:
751+
// module m {
752+
// export class c {
753+
// }
754+
// }
755+
// var x: typeof m.c
756+
// In the above example when we start with checking if typeof m.c symbol is accessible,
757+
// we are going to see if c can be accessed in scope directly.
758+
// But it cant, hence the accessible is going to be undefined, but that doesnt mean m.c is accessible
759+
// It is accessible if the parent m is accessible because then m.c can be accessed through qualification
760+
meaningToLook = SymbolFlags.Namespace;
761+
symbol = symbol.parent;
762+
}
763+
764+
// This is a local symbol that cannot be named
765+
return {
766+
accessibility: SymbolAccessibility.CannotBeNamed,
767+
errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
768+
};
769+
}
770+
771+
return { accessibility: SymbolAccessibility.Accessible };
772+
}
773+
728774
// Enclosing declaration is optional when we dont want to get qualified name in the enclosing declaration scope
729775
// Meaning needs to be specified if the enclosing declaration is given
730776
function symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) {
@@ -760,10 +806,15 @@ module ts {
760806
return getSymbolName(symbol);
761807
}
762808

809+
function writeSymbolToTextWriter(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, writer: TextWriter) {
810+
writer.write(symbolToString(symbol, enclosingDeclaration, meaning));
811+
}
812+
763813
function createSingleLineTextWriter() {
764814
var result = "";
765815
return {
766816
write(s: string) { result += s; },
817+
writeSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, this); },
767818
writeLine() { result += " "; },
768819
increaseIndent() { },
769820
decreaseIndent() { },
@@ -790,7 +841,7 @@ module ts {
790841
writeTypeReference(<TypeReference>type);
791842
}
792843
else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) {
793-
writer.write(symbolToString(type.symbol, enclosingDeclaration, SymbolFlags.Type));
844+
writer.writeSymbol(type.symbol, enclosingDeclaration, SymbolFlags.Type);
794845
}
795846
else if (type.flags & TypeFlags.Anonymous) {
796847
writeAnonymousType(<ObjectType>type, allowFunctionOrConstructorTypeLiteral);
@@ -812,7 +863,7 @@ module ts {
812863
writer.write("[]");
813864
}
814865
else {
815-
writer.write(symbolToString(type.target.symbol, enclosingDeclaration, SymbolFlags.Type));
866+
writer.writeSymbol(type.target.symbol, enclosingDeclaration, SymbolFlags.Type);
816867
writer.write("<");
817868
for (var i = 0; i < type.typeArguments.length; i++) {
818869
if (i > 0) {
@@ -846,7 +897,7 @@ module ts {
846897

847898
function writeTypeofSymbol(type: ObjectType) {
848899
writer.write("typeof ");
849-
writer.write(symbolToString(type.symbol, enclosingDeclaration, SymbolFlags.Value));
900+
writer.writeSymbol(type.symbol, enclosingDeclaration, SymbolFlags.Value);
850901
}
851902

852903
function writeLiteralType(type: ObjectType, allowFunctionOrConstructorTypeLiteral: boolean) {
@@ -902,7 +953,7 @@ module ts {
902953
if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfType(t).length) {
903954
var signatures = getSignaturesOfType(t, SignatureKind.Call);
904955
for (var j = 0; j < signatures.length; j++) {
905-
writer.write(symbolToString(p));
956+
writer.writeSymbol(p);
906957
if (isOptionalProperty(p)) {
907958
writer.write("?");
908959
}
@@ -912,7 +963,7 @@ module ts {
912963
}
913964
}
914965
else {
915-
writer.write(symbolToString(p));
966+
writer.writeSymbol(p);
916967
if (isOptionalProperty(p)) {
917968
writer.write("?");
918969
}
@@ -934,7 +985,7 @@ module ts {
934985
writer.write(", ");
935986
}
936987
var tp = signature.typeParameters[i];
937-
writer.write(symbolToString(tp.symbol));
988+
writer.writeSymbol(tp.symbol);
938989
var constraint = getConstraintOfTypeParameter(tp);
939990
if (constraint) {
940991
writer.write(" extends ");
@@ -952,7 +1003,7 @@ module ts {
9521003
if (getDeclarationFlagsFromSymbol(p) & NodeFlags.Rest) {
9531004
writer.write("...");
9541005
}
955-
writer.write(symbolToString(p));
1006+
writer.writeSymbol(p);
9561007
if (p.valueDeclaration.flags & NodeFlags.QuestionMark || (<VariableDeclaration>p.valueDeclaration).initializer) {
9571008
writer.write("?");
9581009
}
@@ -6695,7 +6746,9 @@ module ts {
66956746
isDeclarationVisible: isDeclarationVisible,
66966747
isImplementationOfOverload: isImplementationOfOverload,
66976748
writeTypeAtLocation: writeTypeAtLocation,
6698-
writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration
6749+
writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration,
6750+
writeSymbol: writeSymbolToTextWriter,
6751+
isSymbolAccessible: isSymbolAccessible
66996752
};
67006753
checkProgram();
67016754
return emitFiles(resolver);

0 commit comments

Comments
 (0)