Skip to content

Commit 67eff65

Browse files
author
Yui T
committed
Add more test cases
1 parent 40f6b67 commit 67eff65

7 files changed

+75
-10
lines changed

src/compiler/emitter.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ module ts {
2525
return indentStrings[1].length;
2626
}
2727

28+
function isDeclarationFile(sourceFile: SourceFile): boolean {
29+
if (sourceFile.flags & NodeFlags.DeclarationFile) {
30+
return true;
31+
}
32+
return false;
33+
}
34+
2835
export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean {
29-
if (!(sourceFile.flags & NodeFlags.DeclarationFile)) {
36+
if (!isDeclarationFile(sourceFile)) {
3037
if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.filename, ".js")) {
3138
return true;
3239
}
@@ -3242,14 +3249,15 @@ module ts {
32423249
if (compilerOptions.out) {
32433250
emitFile(compilerOptions.out);
32443251
}
3245-
} else {
3252+
}
3253+
else {
32463254
// targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
32473255
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
32483256
// If shouldEmitToOwnFile return true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file
32493257
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js");
32503258
emitFile(jsFilePath, targetSourceFile);
32513259
}
3252-
else if (compilerOptions.out) {
3260+
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
32533261
// Otherwise, if --out is specified and targetSourceFile shouldn't be emitted to own file, then emit all, non-external-module file, into one single output file
32543262
emitFile(compilerOptions.out);
32553263
}

tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
EmitOutputStatus : JSGeneratedWithSemanticErrors
1+
EmitOutputStatus : Succeeded
22

3-
EmitOutputStatus : JSGeneratedWithSemanticErrors
3+
EmitOutputStatus : Succeeded
44
Filename : tests/cases/fourslash/inputFile2.js
55
var x1 = "hello world";
66
var Foo = (function () {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
EmitOutputStatus : Succeeded
2+
3+
EmitOutputStatus : Succeeded
4+
Filename : tests/cases/fourslash/inputFile2.js
5+
var Foo = (function () {
6+
function Foo() {
7+
}
8+
return Foo;
9+
})();
10+
exports.Foo = Foo;
11+
12+
EmitOutputStatus : Succeeded
13+
Filename : tests/cases/fourslash/inputFile3.js
14+
var x = "hello";
15+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
EmitOutputStatus : Succeeded
2+
3+
EmitOutputStatus : Succeeded
4+
Filename : declSingle.js
5+
var x = "hello";
6+
var x1 = 1000;
7+

tests/cases/fourslash/getEmitOutputWithDeclarationFile.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
// @Filename: decl.d.ts
66
// @emitThisFile: true
7-
//// declare x: string;
8-
//// declare class Bar {
9-
//// x : string;
10-
//// y : number
11-
//// }
7+
//// interface I { a: string; }
128

139
// @Filename: inputFile2.ts
1410
// @emitThisFile: true
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @BaselineFile: getEmitOutputWithDeclarationFile2.baseline
4+
5+
// @Filename: decl.d.ts
6+
// @emitThisFile: true
7+
//// interface I { a: string; }
8+
9+
// @Filename: inputFile2.ts
10+
// @emitThisFile: true
11+
//// export class Foo { }
12+
13+
// @Filename: inputFile3.ts
14+
// @emitThisFile: true
15+
//// var x:string = "hello";
16+
17+
debugger;
18+
verify.baselineGetEmitOutput();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @BaselineFile: getEmitOutputWithDeclarationFile3.baseline
4+
// @out: declSingle.js
5+
6+
// @Filename: decl.d.ts
7+
// @emitThisFile: true
8+
//// interface I { a: string; }
9+
10+
// @Filename: inputFile2.ts
11+
//// export class Foo { }
12+
13+
// @Filename: inputFile3.ts
14+
// @emitThisFile: true
15+
//// var x:string = "hello";
16+
17+
// @Filename: inputFile4.ts
18+
//// var x1:number = 1000;
19+
20+
debugger;
21+
verify.baselineGetEmitOutput();

0 commit comments

Comments
 (0)