Skip to content

Commit 0cb9972

Browse files
committed
Merge branch 'master' into sigHelpCrash
2 parents 8346b48 + 39bcb10 commit 0cb9972

15 files changed

+248
-52
lines changed

Jakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ var servicesSources = [
5858
"shims.ts",
5959
"signatureHelp.ts",
6060
"utilities.ts",
61-
"navigationBar.ts"
61+
"navigationBar.ts",
62+
"outliningElementsCollector.ts"
6263
].map(function (f) {
6364
return path.join(servicesDirectory, f);
6465
}));

src/compiler/emitter.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,21 +3231,27 @@ module ts {
32313231
}
32323232

32333233
if (targetSourceFile === undefined) {
3234+
// No targetSourceFile is specified (e.g. calling emitter from batch compiler)
32343235
forEach(program.getSourceFiles(), sourceFile => {
32353236
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
32363237
var jsFilePath = getOwnEmitOutputFilePath(sourceFile, ".js");
32373238
emitFile(jsFilePath, sourceFile);
32383239
}
32393240
});
3240-
}
3241-
else {
3242-
// Emit only one file specified in targetFilename. This is mainly used in compilerOnSave feature
3243-
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js");
3244-
emitFile(jsFilePath, targetSourceFile);
3245-
}
32463241

3247-
if (compilerOptions.out) {
3248-
emitFile(compilerOptions.out);
3242+
if (compilerOptions.out) {
3243+
emitFile(compilerOptions.out);
3244+
}
3245+
} else {
3246+
// targetSourceFile is specified (e.g calling emitter from language service)
3247+
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
3248+
// If shouldEmitToOwnFile is true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file
3249+
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js");
3250+
emitFile(jsFilePath, targetSourceFile);
3251+
} else {
3252+
// If shouldEmitToOwnFile is false, then emit all, non-external-module file, into one single output file
3253+
emitFile(compilerOptions.out);
3254+
}
32493255
}
32503256

32513257
// Sort and make the unique list of diagnostics

src/services/navigationBar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ module ts.NavigationBar {
148148
var item = createItem(child);
149149
if (item !== undefined) {
150150
if (item.text.length > 0) {
151-
var key = item.text + "-" + item.kind;
151+
var key = item.text + "-" + item.kind + "-" + item.indent;
152152

153153
var itemWithSameName = keyToItem[key];
154154
if (itemWithSameName) {

src/services/outliningElementsCollector.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ module ts {
3333
export module OutliningElementsCollector {
3434
export function collectElements(sourceFile: SourceFile): OutliningSpan[] {
3535
var elements: OutliningSpan[] = [];
36+
var collapseText = "...";
3637

3738
function addOutliningSpan(hintSpanNode: Node, startElement: Node, endElement: Node, autoCollapse: boolean) {
3839
if (hintSpanNode && startElement && endElement) {
3940
var span: OutliningSpan = {
4041
textSpan: TypeScript.TextSpan.fromBounds(startElement.pos, endElement.end),
4142
hintSpan: TypeScript.TextSpan.fromBounds(hintSpanNode.getStart(), hintSpanNode.end),
42-
bannerText: "...",
43+
bannerText: collapseText,
4344
autoCollapse: autoCollapse
4445
};
4546
elements.push(span);
@@ -66,10 +67,39 @@ module ts {
6667
}
6768
switch (n.kind) {
6869
case SyntaxKind.Block:
70+
var parent = n.parent;
71+
var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
72+
var closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
73+
74+
// Check if the block is standalone, or 'attached' to some parent statement.
75+
// If the latter, we want to collaps the block, but consider its hint span
76+
// to be the entire span of the parent.
77+
if (parent.kind === SyntaxKind.DoStatement ||
78+
parent.kind === SyntaxKind.ForInStatement ||
79+
parent.kind === SyntaxKind.ForStatement ||
80+
parent.kind === SyntaxKind.IfStatement ||
81+
parent.kind === SyntaxKind.WhileStatement ||
82+
parent.kind === SyntaxKind.WithStatement) {
83+
84+
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n));
85+
}
86+
else {
87+
// Block was a standalone block. In this case we want to only collapse
88+
// the span of the block, independent of any parent span.
89+
var span = TypeScript.TextSpan.fromBounds(n.getStart(), n.end);
90+
elements.push({
91+
textSpan: span,
92+
hintSpan: span,
93+
bannerText: collapseText,
94+
autoCollapse: autoCollapse(n)
95+
});
96+
}
97+
break;
98+
99+
69100
case SyntaxKind.FunctionBlock:
70101
case SyntaxKind.ModuleBlock:
71102
case SyntaxKind.TryBlock:
72-
case SyntaxKind.TryBlock:
73103
case SyntaxKind.CatchBlock:
74104
case SyntaxKind.FinallyBlock:
75105
var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);

src/services/services.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -504,47 +504,65 @@ module ts {
504504
if (!this.namedDeclarations) {
505505
var sourceFile = this;
506506
var namedDeclarations: Declaration[] = [];
507-
var isExternalModule = ts.isExternalModule(sourceFile);
508507

509-
forEachChild(sourceFile, function visit(node: Node): boolean {
508+
forEachChild(sourceFile, function visit(node: Node): void {
510509
switch (node.kind) {
510+
case SyntaxKind.FunctionDeclaration:
511+
case SyntaxKind.Method:
512+
var functionDeclaration = <FunctionDeclaration>node;
513+
514+
if (functionDeclaration.name && functionDeclaration.name.kind !== SyntaxKind.Missing) {
515+
var lastDeclaration = namedDeclarations.length > 0 ?
516+
namedDeclarations[namedDeclarations.length - 1] :
517+
undefined;
518+
519+
// Check whether this declaration belongs to an "overload group".
520+
if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) {
521+
// Overwrite the last declaration if it was an overload
522+
// and this one is an implementation.
523+
if (functionDeclaration.body && !(<FunctionDeclaration>lastDeclaration).body) {
524+
namedDeclarations[namedDeclarations.length - 1] = functionDeclaration;
525+
}
526+
}
527+
else {
528+
namedDeclarations.push(node);
529+
}
530+
531+
forEachChild(node, visit);
532+
}
533+
break;
534+
511535
case SyntaxKind.ClassDeclaration:
512536
case SyntaxKind.InterfaceDeclaration:
513537
case SyntaxKind.EnumDeclaration:
514538
case SyntaxKind.ModuleDeclaration:
515539
case SyntaxKind.ImportDeclaration:
516-
case SyntaxKind.Method:
517-
case SyntaxKind.FunctionDeclaration:
518-
case SyntaxKind.Constructor:
519540
case SyntaxKind.GetAccessor:
520541
case SyntaxKind.SetAccessor:
521542
case SyntaxKind.TypeLiteral:
522543
if ((<Declaration>node).name) {
523544
namedDeclarations.push(<Declaration>node);
524545
}
525-
forEachChild(node, visit);
526-
break;
527-
546+
// fall through
547+
case SyntaxKind.Constructor:
528548
case SyntaxKind.VariableStatement:
529549
case SyntaxKind.ModuleBlock:
530550
case SyntaxKind.FunctionBlock:
531551
forEachChild(node, visit);
532552
break;
533553

534554
case SyntaxKind.Parameter:
555+
// Only consider properties defined as constructor parameters
535556
if (!(node.flags & NodeFlags.AccessibilityModifier)) {
536-
// Only consider properties defined as constructor parameters
537557
break;
538558
}
559+
// fall through
539560
case SyntaxKind.VariableDeclaration:
540561
case SyntaxKind.EnumMember:
541562
case SyntaxKind.Property:
542563
namedDeclarations.push(<Declaration>node);
543564
break;
544565
}
545-
546-
// do not go any deeper
547-
return undefined;
548566
});
549567

550568
this.namedDeclarations = namedDeclarations;
@@ -3882,7 +3900,8 @@ module ts {
38823900
filename = TypeScript.switchToForwardSlashes(filename);
38833901
var compilerOptions = program.getCompilerOptions();
38843902
var targetSourceFile = program.getSourceFile(filename); // Current selected file to be output
3885-
var emitToSingleFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions);
3903+
// If --out flag is not specified, shouldEmitToOwnFile is true. Otherwise shouldEmitToOwnFile is false.
3904+
var shouldEmitToOwnFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions);
38863905
var emitDeclaration = compilerOptions.declaration;
38873906
var emitOutput: EmitOutput = {
38883907
outputFiles: [],
@@ -3903,7 +3922,7 @@ module ts {
39033922
var syntacticDiagnostics: Diagnostic[] = [];
39043923
var containSyntacticErrors = false;
39053924

3906-
if (emitToSingleFile) {
3925+
if (shouldEmitToOwnFile) {
39073926
// Check only the file we want to emit
39083927
containSyntacticErrors = containErrors(program.getDiagnostics(targetSourceFile));
39093928
} else {
@@ -3930,7 +3949,7 @@ module ts {
39303949
// Perform semantic and force a type check before emit to ensure that all symbols are updated
39313950
// EmitFiles will report if there is an error from TypeChecker and Emitter
39323951
// Depend whether we will have to emit into a single file or not either emit only selected file in the project, emit all files into a single file
3933-
var emitFilesResult = emitToSingleFile ? getFullTypeCheckChecker().emitFiles(targetSourceFile) : getFullTypeCheckChecker().emitFiles();
3952+
var emitFilesResult = getFullTypeCheckChecker().emitFiles(targetSourceFile);
39343953
emitOutput.emitOutputStatus = emitFilesResult.emitResultStatus;
39353954

39363955
// Reset writer back to undefined to make sure that we produce an error message if CompilerHost.writeFile method is called when we are not in getEmitOutput

src/services/shims.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ module ts {
502502
start: diagnostic.start,
503503
length: diagnostic.length,
504504
/// TODO: no need for the tolowerCase call
505-
category: DiagnosticCategory[diagnostic.category].toLowerCase()
505+
category: DiagnosticCategory[diagnostic.category].toLowerCase(),
506+
code: diagnostic.code
506507
};
507508
}
508509

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
EmitOutputStatus : Succeeded
2+
Filename : declSingleFile.js
3+
var x = 5;
4+
var Bar = (function () {
5+
function Bar() {
6+
}
7+
return Bar;
8+
})();
9+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
EmitOutputStatus : JSGeneratedWithSemanticErrors
2+
Filename : declSingleFile.js
3+
var x = 5;
4+
var Bar = (function () {
5+
function Bar() {
6+
}
7+
return Bar;
8+
})();
9+
var x = "world";
10+
var Bar2 = (function () {
11+
function Bar2() {
12+
}
13+
return Bar2;
14+
})();
15+

tests/baselines/reference/getEmitOutputSingleFile2.baseline

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,4 @@ exports.bar = "hello world";
55
Filename : tests/cases/fourslash/inputFile3.d.ts
66
export declare var foo: number;
77
export declare var bar: string;
8-
Filename : declSingleFile.js
9-
var x = 5;
10-
var Bar = (function () {
11-
function Bar() {
12-
}
13-
return Bar;
14-
})();
15-
var x1 = "hello world";
16-
var Foo = (function () {
17-
function Foo() {
18-
}
19-
return Foo;
20-
})();
21-
Filename : declSingleFile.d.ts
22-
declare var x: number;
23-
declare class Bar {
24-
x: string;
25-
y: number;
26-
}
27-
declare var x1: string;
28-
declare class Foo {
29-
x: string;
30-
y: number;
31-
}
328

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @BaselineFile: getEmitOutputExternalModule.baseline
4+
// @out: declSingleFile.js
5+
6+
// @Filename: inputFile1.ts
7+
// @emitThisFile: true
8+
//// var x: number = 5;
9+
//// class Bar {
10+
//// x : string;
11+
//// y : number
12+
//// }
13+
14+
// @Filename: inputFile2.ts
15+
//// export module M {
16+
//// class C {c}
17+
//// }
18+
19+
verify.baselineGetEmitOutput();

0 commit comments

Comments
 (0)