Skip to content

Commit 2105404

Browse files
committed
Merge branch 'master' into deferredTypeLiterals
2 parents deaf8e4 + 655039c commit 2105404

File tree

643 files changed

+17213
-28062
lines changed

Some content is hidden

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

643 files changed

+17213
-28062
lines changed

Jakefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ var compilerSources = [
4343

4444
var servicesSources = [
4545
"core.ts",
46-
"sys.ts",
4746
"types.ts",
4847
"scanner.ts",
4948
"parser.ts",

bin/services.js

Lines changed: 0 additions & 13134 deletions
This file was deleted.

bin/tsc.js

Lines changed: 117 additions & 52 deletions
Large diffs are not rendered by default.

bin/typescriptServices.js

Lines changed: 779 additions & 760 deletions
Large diffs are not rendered by default.

src/compiler/checker.ts

Lines changed: 72 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ module ts {
1111
var nextNodeId = 1;
1212
var nextMergeId = 1;
1313

14+
export function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration {
15+
var declarations = symbol.declarations;
16+
for (var i = 0; i < declarations.length; i++) {
17+
var declaration = declarations[i];
18+
if (declaration.kind === kind) {
19+
return declaration;
20+
}
21+
}
22+
23+
return undefined;
24+
}
25+
1426
/// fullTypeCheck denotes if this instance of the typechecker will be used to get semantic diagnostics.
1527
/// If fullTypeCheck === true - then typechecker should do every possible check to produce all errors
1628
/// If fullTypeCheck === false - typechecker can shortcut and skip checks that only produce errors.
@@ -49,7 +61,9 @@ module ts {
4961
getApparentType: getApparentType,
5062
typeToString: typeToString,
5163
symbolToString: symbolToString,
52-
getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType
64+
getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType,
65+
getRootSymbol: getRootSymbol,
66+
getContextualType: getContextualType
5367
};
5468

5569
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
@@ -568,18 +582,6 @@ module ts {
568582
return false;
569583
}
570584

571-
function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration {
572-
var declarations = symbol.declarations;
573-
for (var i = 0; i < declarations.length; i++) {
574-
var declaration = declarations[i];
575-
if (declaration.kind === kind) {
576-
return declaration;
577-
}
578-
}
579-
580-
return undefined;
581-
}
582-
583585
function findConstructorDeclaration(node: ClassDeclaration): ConstructorDeclaration {
584586
var members = node.members;
585587
for (var i = 0; i < members.length; i++) {
@@ -906,7 +908,7 @@ module ts {
906908
// Get qualified name
907909
if (enclosingDeclaration &&
908910
// Properties/methods/Signatures/Constructors/TypeParameters do not need qualification
909-
!(symbol.flags & SymbolFlags.PropertyOrAccessor & SymbolFlags.Signature & SymbolFlags.Constructor & SymbolFlags.Method & SymbolFlags.TypeParameter)) {
911+
!(symbol.flags & (SymbolFlags.PropertyOrAccessor | SymbolFlags.Signature | SymbolFlags.Constructor | SymbolFlags.Method | SymbolFlags.TypeParameter))) {
910912
var symbolName: string;
911913
while (symbol) {
912914
var isFirstName = !symbolName;
@@ -2248,13 +2250,12 @@ module ts {
22482250
return emptyObjectType;
22492251
}
22502252
var type = getDeclaredTypeOfSymbol(symbol);
2251-
var name = symbol.name;
22522253
if (!(type.flags & TypeFlags.ObjectType)) {
2253-
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_be_a_class_or_interface_type, name);
2254+
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name);
22542255
return emptyObjectType;
22552256
}
22562257
if (((<InterfaceType>type).typeParameters ? (<InterfaceType>type).typeParameters.length : 0) !== arity) {
2257-
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, name, arity);
2258+
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity);
22582259
return emptyObjectType;
22592260
}
22602261
return <ObjectType>type;
@@ -3156,6 +3157,7 @@ module ts {
31563157
symbol.declarations = p.declarations;
31573158
symbol.parent = p.parent;
31583159
symbol.type = widenedTypes[index++];
3160+
symbol.target = p;
31593161
if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration;
31603162
members[symbol.name] = symbol;
31613163
});
@@ -3552,7 +3554,8 @@ module ts {
35523554
return false;
35533555
}
35543556

3555-
function checkSuperExpression(node: Node, isCallExpression: boolean): Type {
3557+
function checkSuperExpression(node: Node): Type {
3558+
var isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (<CallExpression>node.parent).func === node;
35563559
var enclosingClass = <ClassDeclaration>getAncestor(node, SyntaxKind.ClassDeclaration);
35573560
var baseClass: Type;
35583561
if (enclosingClass && enclosingClass.baseType) {
@@ -3828,6 +3831,7 @@ module ts {
38283831
prop.parent = member.parent;
38293832
if (member.valueDeclaration) prop.valueDeclaration = member.valueDeclaration;
38303833
prop.type = type;
3834+
prop.target = member;
38313835
member = prop;
38323836
}
38333837
else {
@@ -4186,7 +4190,7 @@ module ts {
41864190

41874191
function resolveCallExpression(node: CallExpression): Signature {
41884192
if (node.func.kind === SyntaxKind.SuperKeyword) {
4189-
var superType = checkSuperExpression(node.func, true);
4193+
var superType = checkSuperExpression(node.func);
41904194
if (superType !== unknownType) {
41914195
return resolveCall(node, getSignaturesOfType(superType, SignatureKind.Construct));
41924196
}
@@ -4834,7 +4838,7 @@ module ts {
48344838
case SyntaxKind.ThisKeyword:
48354839
return checkThisExpression(node);
48364840
case SyntaxKind.SuperKeyword:
4837-
return checkSuperExpression(node, false);
4841+
return checkSuperExpression(node);
48384842
case SyntaxKind.NullKeyword:
48394843
return nullType;
48404844
case SyntaxKind.TrueKeyword:
@@ -6591,24 +6595,6 @@ module ts {
65916595
(<Declaration>name.parent).name === name;
65926596
}
65936597

6594-
// True if the given identifier, string literal, or number literal is the name of a declaration node
6595-
function isDeclarationOrFunctionExpressionOrCatchVariableName(name: Node): boolean {
6596-
if (name.kind !== SyntaxKind.Identifier && name.kind !== SyntaxKind.StringLiteral && name.kind !== SyntaxKind.NumericLiteral) {
6597-
return false;
6598-
}
6599-
6600-
var parent = name.parent;
6601-
if (isDeclaration(parent) || parent.kind === SyntaxKind.FunctionExpression) {
6602-
return (<Declaration>parent).name === name;
6603-
}
6604-
6605-
if (parent.kind === SyntaxKind.CatchBlock) {
6606-
return (<CatchBlock>parent).variable === name;
6607-
}
6608-
6609-
return false;
6610-
}
6611-
66126598
function isTypeDeclaration(node: Node): boolean {
66136599
switch (node.kind) {
66146600
case SyntaxKind.TypeParameter:
@@ -6619,28 +6605,6 @@ module ts {
66196605
}
66206606
}
66216607

6622-
function isDeclaration(node: Node): boolean {
6623-
switch (node.kind) {
6624-
case SyntaxKind.TypeParameter:
6625-
case SyntaxKind.Parameter:
6626-
case SyntaxKind.VariableDeclaration:
6627-
case SyntaxKind.Property:
6628-
case SyntaxKind.PropertyAssignment:
6629-
case SyntaxKind.EnumMember:
6630-
case SyntaxKind.Method:
6631-
case SyntaxKind.FunctionDeclaration:
6632-
case SyntaxKind.GetAccessor:
6633-
case SyntaxKind.SetAccessor:
6634-
case SyntaxKind.ClassDeclaration:
6635-
case SyntaxKind.InterfaceDeclaration:
6636-
case SyntaxKind.EnumDeclaration:
6637-
case SyntaxKind.ModuleDeclaration:
6638-
case SyntaxKind.ImportDeclaration:
6639-
return true;
6640-
}
6641-
return false;
6642-
}
6643-
66446608
// True if the given identifier is part of a type reference
66456609
function isTypeReferenceIdentifier(entityName: EntityName): boolean {
66466610
var node: Node = entityName;
@@ -6688,6 +6652,7 @@ module ts {
66886652
case SyntaxKind.Parameter:
66896653
case SyntaxKind.Property:
66906654
case SyntaxKind.EnumMember:
6655+
case SyntaxKind.PropertyAssignment:
66916656
return (<VariableDeclaration>parent).initializer === node;
66926657
case SyntaxKind.ExpressionStatement:
66936658
case SyntaxKind.IfStatement:
@@ -6817,6 +6782,11 @@ module ts {
68176782
/*all meanings*/ SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Import);
68186783
}
68196784

6785+
if (isInRightSideOfImportOrExportAssignment(entityName)) {
6786+
// Since we already checked for ExportAssignment, this really could only be an Import
6787+
return getSymbolOfPartOfRightHandSideOfImport(entityName);
6788+
}
6789+
68206790
if (isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
68216791
entityName = entityName.parent;
68226792
}
@@ -6853,6 +6823,17 @@ module ts {
68536823
}
68546824

68556825
function getSymbolInfo(node: Node) {
6826+
if (isDeclarationOrFunctionExpressionOrCatchVariableName(node)) {
6827+
// This is a declaration, call getSymbolOfNode
6828+
return getSymbolOfNode(node.parent);
6829+
}
6830+
6831+
if (node.kind === SyntaxKind.Identifier && isInRightSideOfImportOrExportAssignment(node)) {
6832+
return node.parent.kind === SyntaxKind.ExportAssignment
6833+
? getSymbolOfEntityName(<Identifier>node)
6834+
: getSymbolOfPartOfRightHandSideOfImport(node);
6835+
}
6836+
68566837
switch (node.kind) {
68576838
case SyntaxKind.Identifier:
68586839
case SyntaxKind.PropertyAccess:
@@ -6863,7 +6844,7 @@ module ts {
68636844
case SyntaxKind.SuperKeyword:
68646845
var type = checkExpression(node);
68656846
return type.symbol;
6866-
6847+
68676848
case SyntaxKind.ConstructorKeyword:
68686849
// constructor keyword for an overload, should take us to the definition if it exist
68696850
var constructorDeclaration = node.parent;
@@ -6873,23 +6854,22 @@ module ts {
68736854
return undefined;
68746855

68756856
case SyntaxKind.StringLiteral:
6876-
// Property access
6877-
if (node.parent.kind === SyntaxKind.IndexedAccess && (<IndexedAccess>node.parent).index === node) {
6878-
var objectType = checkExpression((<IndexedAccess>node.parent).object);
6879-
if (objectType === unknownType) return undefined;
6880-
var apparentType = getApparentType(objectType);
6881-
if (<Type>apparentType === unknownType) return undefined;
6882-
return getPropertyOfApparentType(apparentType, (<LiteralExpression>node).text);
6883-
}
68846857
// External module name in an import declaration
6885-
else if (node.parent.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node.parent).externalModuleName === node) {
6858+
if (node.parent.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node.parent).externalModuleName === node) {
68866859
var importSymbol = getSymbolOfNode(node.parent);
68876860
var moduleType = getTypeOfSymbol(importSymbol);
68886861
return moduleType ? moduleType.symbol : undefined;
68896862
}
6890-
// External module name in an ambient declaration
6891-
else if (node.parent.kind === SyntaxKind.ModuleDeclaration) {
6892-
return getSymbolOfNode(node.parent);
6863+
6864+
// Intentinal fallthrough
6865+
case SyntaxKind.NumericLiteral:
6866+
// index access
6867+
if (node.parent.kind == SyntaxKind.IndexedAccess && (<IndexedAccess>node.parent).index === node) {
6868+
var objectType = checkExpression((<IndexedAccess>node.parent).object);
6869+
if (objectType === unknownType) return undefined;
6870+
var apparentType = getApparentType(objectType);
6871+
if (<Type>apparentType === unknownType) return undefined;
6872+
return getPropertyOfApparentType(apparentType, (<LiteralExpression>node).text);
68936873
}
68946874
break;
68956875
}
@@ -6927,11 +6907,7 @@ module ts {
69276907
}
69286908

69296909
if (isInRightSideOfImportOrExportAssignment(node)) {
6930-
var symbol: Symbol;
6931-
symbol = node.parent.kind === SyntaxKind.ExportAssignment
6932-
? getSymbolInfo(node)
6933-
: getSymbolOfPartOfRightHandSideOfImport(node);
6934-
6910+
var symbol = getSymbolInfo(node);
69356911
var declaredType = getDeclaredTypeOfSymbol(symbol);
69366912
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
69376913
}
@@ -6983,6 +6959,10 @@ module ts {
69836959
}
69846960
}
69856961

6962+
function getRootSymbol(symbol: Symbol) {
6963+
return (symbol.flags & SymbolFlags.Transient) ? getSymbolLinks(symbol).target : symbol;
6964+
}
6965+
69866966
// Emitter support
69876967

69886968
function isExternalModuleSymbol(symbol: Symbol): boolean {
@@ -7101,7 +7081,20 @@ module ts {
71017081
function isImplementationOfOverload(node: FunctionDeclaration) {
71027082
if (node.body) {
71037083
var symbol = getSymbolOfNode(node);
7104-
return getSignaturesOfSymbol(symbol).length > 1;
7084+
var signaturesOfSymbol = getSignaturesOfSymbol(symbol);
7085+
// If this function body corresponds to function with multiple signature, it is implementation of overload
7086+
// eg: function foo(a: string): string;
7087+
// function foo(a: number): number;
7088+
// function foo(a: any) { // This is implementation of the overloads
7089+
// return a;
7090+
// }
7091+
return signaturesOfSymbol.length > 1 ||
7092+
// If there is single signature for the symbol, it is overload if that signature isnt coming from the node
7093+
// eg: function foo(a: string): string;
7094+
// function foo(a: any) { // This is implementation of the overloads
7095+
// return a;
7096+
// }
7097+
(signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node);
71057098
}
71067099
return false;
71077100
}

src/compiler/core.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,6 @@ module ts {
509509
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
510510
}
511511

512-
export function getCanonicalFileName(fileName: string): string {
513-
// if underlying system can distinguish between two files whose names differs only in cases then file name already in canonical form.
514-
// otherwise use toLowerCase as a canonical form.
515-
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
516-
}
517-
518512
export interface ObjectAllocator {
519513
getNodeConstructor(kind: SyntaxKind): new () => Node;
520514
getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol;

0 commit comments

Comments
 (0)