Skip to content

Commit 33c91ff

Browse files
author
Yui T
committed
Merge remote-tracking branch 'origin/release-1.3' into reportErrorFromTargetFile
2 parents ac68f93 + 6bc3ed8 commit 33c91ff

File tree

64 files changed

+671
-507
lines changed

Some content is hidden

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

64 files changed

+671
-507
lines changed

src/compiler/checker.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@ module ts {
106106
writeTypeParameter: writeTypeParameter,
107107
writeTypeParametersOfSymbol: writeTypeParametersOfSymbol,
108108
isImplementationOfOverload: isImplementationOfOverload,
109-
getAliasedSymbol: resolveImport
109+
getAliasedSymbol: resolveImport,
110+
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
111+
isArgumentsSymbol: symbol => symbol === argumentsSymbol
110112
};
111113

112-
var undefinedSymbol = createSymbol(SymbolFlags.Undefined | SymbolFlags.Property | SymbolFlags.Transient, "undefined");
114+
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
113115
var argumentsSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "arguments");
114116
var unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown");
115117
var resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__");
@@ -737,7 +739,7 @@ module ts {
737739
return rightMeaning === SymbolFlags.Value ? SymbolFlags.Value : SymbolFlags.Namespace;
738740
}
739741

740-
function getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): Symbol[] {
742+
function getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, useOnlyExternalAliasing: boolean): Symbol[] {
741743
function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable): Symbol[] {
742744
function canQualifySymbol(symbolFromSymbolTable: Symbol, meaning: SymbolFlags) {
743745
// If the symbol is equivalent and doesn't need further qualification, this symbol is accessible
@@ -746,7 +748,7 @@ module ts {
746748
}
747749

748750
// If symbol needs qualification, make sure that parent is accessible, if it is then this symbol is accessible too
749-
var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning));
751+
var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing);
750752
return !!accessibleParent;
751753
}
752754

@@ -768,16 +770,21 @@ module ts {
768770
// Check if symbol is any of the alias
769771
return forEachValue(symbols, symbolFromSymbolTable => {
770772
if (symbolFromSymbolTable.flags & SymbolFlags.Import) {
771-
var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable);
772-
if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) {
773-
return [symbolFromSymbolTable];
774-
}
773+
if (!useOnlyExternalAliasing || // We can use any type of alias to get the name
774+
// Is this external alias, then use it to name
775+
ts.forEach(symbolFromSymbolTable.declarations, declaration =>
776+
declaration.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>declaration).externalModuleName)) {
777+
var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable);
778+
if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) {
779+
return [symbolFromSymbolTable];
780+
}
775781

776-
// Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain
777-
// but only if the symbolFromSymbolTable can be qualified
778-
var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined;
779-
if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) {
780-
return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports);
782+
// Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain
783+
// but only if the symbolFromSymbolTable can be qualified
784+
var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined;
785+
if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) {
786+
return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports);
787+
}
781788
}
782789
}
783790
});
@@ -823,7 +830,7 @@ module ts {
823830
var meaningToLook = meaning;
824831
while (symbol) {
825832
// Symbol is accessible if it by itself is accessible
826-
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook);
833+
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, /*useOnlyExternalAliasing*/ false);
827834
if (accessibleSymbolChain) {
828835
var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
829836
if (!hasAccessibleDeclarations) {
@@ -1006,7 +1013,7 @@ module ts {
10061013
writer.trackSymbol(symbol, enclosingDeclaration, meaning);
10071014
function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void {
10081015
if (symbol) {
1009-
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning);
1016+
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing));
10101017

10111018
if (!accessibleSymbolChain ||
10121019
needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
@@ -4085,7 +4092,7 @@ module ts {
40854092
}
40864093

40874094
function isNumericName(name: string) {
4088-
return !isNaN(<number><any>name);
4095+
return (name !== "") && !isNaN(<number><any>name);
40894096
}
40904097

40914098
function checkObjectLiteral(node: ObjectLiteral, contextualMapper?: TypeMapper): Type {
@@ -6644,6 +6651,9 @@ module ts {
66446651
var ambient = isInAmbientContext(node);
66456652

66466653
forEach(node.members, member => {
6654+
if(isNumericName(member.name.text)) {
6655+
error(member.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name);
6656+
}
66476657
var initializer = member.initializer;
66486658
if (initializer) {
66496659
autoValue = getConstantValueForExpression(initializer);

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ module ts {
114114
Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile external modules unless the '--module' flag is provided." },
115115
Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" },
116116
new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead." },
117+
An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." },
117118
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
118119
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
119120
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

src/compiler/diagnosticMessages.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"category": "Error",
1212
"code": 1005
1313
},
14-
"A file cannot have a reference to itself.": {
14+
"A file cannot have a reference to itself.": {
1515
"category": "Error",
1616
"code": 1006
1717
},
@@ -187,7 +187,7 @@
187187
"category": "Error",
188188
"code": 1066
189189
},
190-
"Unexpected token. A constructor, method, accessor, or property was expected." : {
190+
"Unexpected token. A constructor, method, accessor, or property was expected.": {
191191
"category": "Error",
192192
"code": 1068
193193
},
@@ -444,9 +444,13 @@
444444
"code": 1149
445445
},
446446
"'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.": {
447-
"category": "Error",
448-
"code": 1150
449-
},
447+
"category": "Error",
448+
"code": 1150
449+
},
450+
"An enum member cannot have a numeric name.": {
451+
"category": "Error",
452+
"code": 1151
453+
},
450454

451455
"Duplicate identifier '{0}'.": {
452456
"category": "Error",
@@ -556,7 +560,7 @@
556560
"category": "Error",
557561
"code": 2326
558562
},
559-
"Property '{0}' is optional in type '{1}' but required in type '{2}'.": {
563+
"Property '{0}' is optional in type '{1}' but required in type '{2}'.": {
560564
"category": "Error",
561565
"code": 2327
562566
},

src/compiler/types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ module ts {
657657
writeTypeParameter(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
658658
writeTypeParametersOfSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags): void;
659659
isImplementationOfOverload(node: FunctionDeclaration): boolean;
660+
isUndefinedSymbol(symbol: Symbol): boolean;
661+
isArgumentsSymbol(symbol: Symbol): boolean;
660662

661663
// Returns the constant value of this enum member, or 'undefined' if the enum member has a
662664
// computed value.
@@ -696,6 +698,9 @@ module ts {
696698
// eg. class C<T> { p: T } <-- Show p as C<T>.p here
697699
// var a: C<number>;
698700
// var p = a.p; <--- Here p is property of C<number> so show it as C<number>.p instead of just C.p
701+
UseOnlyExternalAliasing = 0x00000002, // Use only external alias information to get the symbol name in the given context
702+
// eg. module m { export class c { } } import x = m.c;
703+
// When this flag is specified m.c will be used to refer to the class instead of alias symbol x
699704
}
700705

701706
export enum SymbolAccessibility {
@@ -765,8 +770,6 @@ module ts {
765770
Transient = 0x02000000, // Transient symbol (created during type check)
766771
Prototype = 0x04000000, // Symbol for the prototype property (without source code representation)
767772

768-
Undefined = 0x08000000, // Symbol for the undefined
769-
770773
Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor,
771774
Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter,
772775
Namespace = ValueModule | NamespaceModule,

src/services/formatting/smartIndenter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ module ts.formatting {
108108
function getActualIndentationForListItemBeforeComma(commaToken: Node, sourceFile: SourceFile, options: TypeScript.FormattingOptions): number {
109109
// previous token is comma that separates items in list - find the previous item and try to derive indentation from it
110110
var commaItemInfo = findListItemInfo(commaToken);
111-
Debug.assert(commaItemInfo.listItemIndex > 0);
111+
Debug.assert(commaItemInfo && commaItemInfo.listItemIndex > 0);
112112
// The item we're interested in is right before the comma
113113
return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options);
114114
}

0 commit comments

Comments
 (0)