Skip to content

Commit dc0560a

Browse files
committed
Merge branch 'master' into getReferences
Conflicts: tests/baselines/reference/aliasUsageInGenericFunction.types tests/baselines/reference/aliasUsageInObjectLiteral.types tests/baselines/reference/aliasUsageInOrExpression.types tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types
2 parents 41d8d6c + 4fbc003 commit dc0560a

File tree

553 files changed

+15067
-27523
lines changed

Some content is hidden

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

553 files changed

+15067
-27523
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: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ module ts {
908908
// Get qualified name
909909
if (enclosingDeclaration &&
910910
// Properties/methods/Signatures/Constructors/TypeParameters do not need qualification
911-
!(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))) {
912912
var symbolName: string;
913913
while (symbol) {
914914
var isFirstName = !symbolName;
@@ -2238,13 +2238,12 @@ module ts {
22382238
return emptyObjectType;
22392239
}
22402240
var type = getDeclaredTypeOfSymbol(symbol);
2241-
var name = symbol.name;
22422241
if (!(type.flags & TypeFlags.ObjectType)) {
2243-
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_be_a_class_or_interface_type, name);
2242+
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name);
22442243
return emptyObjectType;
22452244
}
22462245
if (((<InterfaceType>type).typeParameters ? (<InterfaceType>type).typeParameters.length : 0) !== arity) {
2247-
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, name, arity);
2246+
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity);
22482247
return emptyObjectType;
22492248
}
22502249
return <ObjectType>type;
@@ -3548,7 +3547,8 @@ module ts {
35483547
return false;
35493548
}
35503549

3551-
function checkSuperExpression(node: Node, isCallExpression: boolean): Type {
3550+
function checkSuperExpression(node: Node): Type {
3551+
var isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (<CallExpression>node.parent).func === node;
35523552
var enclosingClass = <ClassDeclaration>getAncestor(node, SyntaxKind.ClassDeclaration);
35533553
var baseClass: Type;
35543554
if (enclosingClass && enclosingClass.baseType) {
@@ -4183,7 +4183,7 @@ module ts {
41834183

41844184
function resolveCallExpression(node: CallExpression): Signature {
41854185
if (node.func.kind === SyntaxKind.SuperKeyword) {
4186-
var superType = checkSuperExpression(node.func, true);
4186+
var superType = checkSuperExpression(node.func);
41874187
if (superType !== unknownType) {
41884188
return resolveCall(node, getSignaturesOfType(superType, SignatureKind.Construct));
41894189
}
@@ -4831,7 +4831,7 @@ module ts {
48314831
case SyntaxKind.ThisKeyword:
48324832
return checkThisExpression(node);
48334833
case SyntaxKind.SuperKeyword:
4834-
return checkSuperExpression(node, false);
4834+
return checkSuperExpression(node);
48354835
case SyntaxKind.NullKeyword:
48364836
return nullType;
48374837
case SyntaxKind.TrueKeyword:
@@ -6775,6 +6775,11 @@ module ts {
67756775
/*all meanings*/ SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Import);
67766776
}
67776777

6778+
if (isInRightSideOfImportOrExportAssignment(entityName)) {
6779+
// Since we already checked for ExportAssignment, this really could only be an Import
6780+
return getSymbolOfPartOfRightHandSideOfImport(entityName);
6781+
}
6782+
67786783
if (isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
67796784
entityName = entityName.parent;
67806785
}
@@ -6895,11 +6900,7 @@ module ts {
68956900
}
68966901

68976902
if (isInRightSideOfImportOrExportAssignment(node)) {
6898-
var symbol: Symbol;
6899-
symbol = node.parent.kind === SyntaxKind.ExportAssignment
6900-
? getSymbolInfo(node)
6901-
: getSymbolOfPartOfRightHandSideOfImport(node);
6902-
6903+
var symbol = getSymbolInfo(node);
69036904
var declaredType = getDeclaredTypeOfSymbol(symbol);
69046905
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
69056906
}
@@ -7073,7 +7074,20 @@ module ts {
70737074
function isImplementationOfOverload(node: FunctionDeclaration) {
70747075
if (node.body) {
70757076
var symbol = getSymbolOfNode(node);
7076-
return getSignaturesOfSymbol(symbol).length > 1;
7077+
var signaturesOfSymbol = getSignaturesOfSymbol(symbol);
7078+
// If this function body corresponds to function with multiple signature, it is implementation of overload
7079+
// eg: function foo(a: string): string;
7080+
// function foo(a: number): number;
7081+
// function foo(a: any) { // This is implementation of the overloads
7082+
// return a;
7083+
// }
7084+
return signaturesOfSymbol.length > 1 ||
7085+
// If there is single signature for the symbol, it is overload if that signature isnt coming from the node
7086+
// eg: function foo(a: string): string;
7087+
// function foo(a: any) { // This is implementation of the overloads
7088+
// return a;
7089+
// }
7090+
(signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node);
70777091
}
70787092
return false;
70797093
}

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;

src/compiler/emitter.ts

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ module ts {
290290
}
291291
else {
292292
// Empty string - make sure we write empty line
293-
writer.writeLiteral(sys.newLine);
293+
writer.writeLiteral(newLine);
294294
}
295295
}
296296

@@ -336,6 +336,9 @@ module ts {
336336
/** Emit detached comments of the node */
337337
var emitDetachedComments = compilerOptions.removeComments ? (node: TextRange) => { } : emitDetachedCommentsAtPosition;
338338

339+
/** Emits /// or pinned which is comment starting with /*! comments */
340+
var emitPinnedOrTripleSlashComments = compilerOptions.removeComments ? (node: Node) => { } : emitPinnedOrTripleSlashCommentsOfNode;
341+
339342
var writeComment = writeCommentRange;
340343

341344
/** Emit a node */
@@ -1318,7 +1321,10 @@ module ts {
13181321
}
13191322

13201323
function emitFunctionDeclaration(node: FunctionDeclaration) {
1321-
if (!node.body) return;
1324+
if (!node.body) {
1325+
return emitPinnedOrTripleSlashComments(node);
1326+
}
1327+
13221328
if (node.kind !== SyntaxKind.Method) {
13231329
// Methods will emit the comments as part of emitting method declaration
13241330
emitLeadingComments(node);
@@ -1488,7 +1494,10 @@ module ts {
14881494
function emitMemberFunctions(node: ClassDeclaration) {
14891495
forEach(node.members, member => {
14901496
if (member.kind === SyntaxKind.Method) {
1491-
if (!(<MethodDeclaration>member).body) return;
1497+
if (!(<MethodDeclaration>member).body) {
1498+
return emitPinnedOrTripleSlashComments(member);
1499+
}
1500+
14921501
writeLine();
14931502
emitLeadingComments(member);
14941503
emitStart(member);
@@ -1611,6 +1620,13 @@ module ts {
16111620
emitTrailingComments(node);
16121621

16131622
function emitConstructorOfClass() {
1623+
// Emit the constructor overload pinned comments
1624+
forEach(node.members, member => {
1625+
if (member.kind === SyntaxKind.Constructor && !(<ConstructorDeclaration>member).body) {
1626+
emitPinnedOrTripleSlashComments(member);
1627+
}
1628+
});
1629+
16141630
var ctor = getFirstConstructorWithBody(node);
16151631
if (ctor) {
16161632
emitLeadingComments(ctor);
@@ -1666,6 +1682,10 @@ module ts {
16661682
}
16671683
}
16681684

1685+
function emitInterfaceDeclaration(node: InterfaceDeclaration) {
1686+
emitPinnedOrTripleSlashComments(node);
1687+
}
1688+
16691689
function emitEnumDeclaration(node: EnumDeclaration) {
16701690
emitLeadingComments(node);
16711691
if (!(node.flags & NodeFlags.Export)) {
@@ -1741,7 +1761,10 @@ module ts {
17411761
}
17421762

17431763
function emitModuleDeclaration(node: ModuleDeclaration) {
1744-
if (!isInstantiated(node)) return;
1764+
if (!isInstantiated(node)) {
1765+
return emitPinnedOrTripleSlashComments(node);
1766+
}
1767+
17451768
emitLeadingComments(node);
17461769
if (!(node.flags & NodeFlags.Export)) {
17471770
emitStart(node);
@@ -1969,7 +1992,14 @@ module ts {
19691992
}
19701993

19711994
function emitNode(node: Node) {
1972-
if (!node || node.flags & NodeFlags.Ambient) return;
1995+
if (!node) {
1996+
return;
1997+
}
1998+
1999+
if (node.flags & NodeFlags.Ambient) {
2000+
return emitPinnedOrTripleSlashComments(node);
2001+
}
2002+
19732003
switch (node.kind) {
19742004
case SyntaxKind.Identifier:
19752005
return emitIdentifier(<Identifier>node);
@@ -2073,6 +2103,8 @@ module ts {
20732103
return emitVariableDeclaration(<VariableDeclaration>node);
20742104
case SyntaxKind.ClassDeclaration:
20752105
return emitClassDeclaration(<ClassDeclaration>node);
2106+
case SyntaxKind.InterfaceDeclaration:
2107+
return emitInterfaceDeclaration(<InterfaceDeclaration>node);
20762108
case SyntaxKind.EnumDeclaration:
20772109
return emitEnumDeclaration(<EnumDeclaration>node);
20782110
case SyntaxKind.ModuleDeclaration:
@@ -2101,7 +2133,7 @@ module ts {
21012133
return leadingComments;
21022134
}
21032135

2104-
function emitLeadingDeclarationComments(node: Node) {
2136+
function getLeadingCommentsToEmit(node: Node) {
21052137
// Emit the leading comments only if the parent's pos doesnt match because parent should take care of emitting these comments
21062138
if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) {
21072139
var leadingComments: Comment[];
@@ -2113,12 +2145,17 @@ module ts {
21132145
// get the leading comments from the node
21142146
leadingComments = getLeadingCommentsOfNode(node, currentSourceFile);
21152147
}
2116-
emitNewLineBeforeLeadingComments(node, leadingComments, writer);
2117-
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
2118-
emitComments(leadingComments, /*trailingSeparator*/ true, writer, writeComment);
2148+
return leadingComments;
21192149
}
21202150
}
21212151

2152+
function emitLeadingDeclarationComments(node: Node) {
2153+
var leadingComments = getLeadingCommentsToEmit(node);
2154+
emitNewLineBeforeLeadingComments(node, leadingComments, writer);
2155+
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
2156+
emitComments(leadingComments, /*trailingSeparator*/ true, writer, writeComment);
2157+
}
2158+
21222159
function emitTrailingDeclarationComments(node: Node) {
21232160
// Emit the trailing comments only if the parent's end doesnt match
21242161
if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) {
@@ -2166,7 +2203,7 @@ module ts {
21662203
lastComment = comment;
21672204
});
21682205

2169-
if (detachedComments && detachedComments.length) {
2206+
if (detachedComments.length) {
21702207
// All comments look like they could have been part of the copyright header. Make
21712208
// sure there is at least one blank line between it and the node. If not, it's not
21722209
// a copyright header.
@@ -2188,6 +2225,28 @@ module ts {
21882225
}
21892226
}
21902227

2228+
function emitPinnedOrTripleSlashCommentsOfNode(node: Node) {
2229+
var pinnedComments = ts.filter(getLeadingCommentsToEmit(node), isPinnedOrTripleSlashComment);
2230+
2231+
function isPinnedOrTripleSlashComment(comment: Comment) {
2232+
if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) {
2233+
return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation;
2234+
}
2235+
// Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text
2236+
// so that we dont end up computing comment string and doing match for all // comments
2237+
else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash &&
2238+
comment.pos + 2 < comment.end &&
2239+
currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash &&
2240+
currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx)) {
2241+
return true;
2242+
}
2243+
}
2244+
2245+
emitNewLineBeforeLeadingComments(node, pinnedComments, writer);
2246+
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
2247+
emitComments(pinnedComments, /*trailingSeparator*/ true, writer, writeComment);
2248+
}
2249+
21912250
if (compilerOptions.sourceMap) {
21922251
initializeEmitterWithSourceMaps();
21932252
}

src/compiler/parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/// <reference path="sys.ts"/>
21
/// <reference path="types.ts"/>
32
/// <reference path="core.ts"/>
43
/// <reference path="scanner.ts"/>
@@ -165,6 +164,8 @@ module ts {
165164
}
166165
}
167166

167+
export var fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/
168+
168169
// Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes
169170
// stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise,
170171
// embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns
@@ -3555,8 +3556,7 @@ module ts {
35553556
file.hasNoDefaultLib = true;
35563557
}
35573558
else {
3558-
var fullReferenceRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
3559-
var matchResult = fullReferenceRegEx.exec(comment);
3559+
var matchResult = fullTripleSlashReferencePathRegEx.exec(comment);
35603560
if (!matchResult) {
35613561
var start = range.pos;
35623562
var length = range.end - start;

src/compiler/tsc.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ module ts {
137137
var currentDirectory: string;
138138
var existingDirectories: Map<boolean> = {};
139139

140+
function getCanonicalFileName(fileName: string): string {
141+
// if underlying system can distinguish between two files whose names differs only in cases then file name already in canonical form.
142+
// otherwise use toLowerCase as a canonical form.
143+
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
144+
}
145+
140146
function getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile {
141147
try {
142148
var text = sys.readFile(filename, options.charset);
@@ -323,6 +329,7 @@ module ts {
323329
function compile(commandLine: ParsedCommandLine, compilerHost: CompilerHost) {
324330
var parseStart = new Date().getTime();
325331
var program = createProgram(commandLine.filenames, commandLine.options, compilerHost);
332+
326333
var bindStart = new Date().getTime();
327334
var errors = program.getDiagnostics();
328335
if (errors.length) {

0 commit comments

Comments
 (0)