Skip to content

Commit 16d1cfd

Browse files
committed
Merge pull request #505 from Microsoft/newLineBetweenSourceFiles
Emit new lines between source files emit so that the file contents always start on new line
2 parents f835b7c + d2ae999 commit 16d1cfd

6 files changed

+232
-0
lines changed

src/compiler/emitter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,8 @@ module ts {
19251925

19261926
function emitSourceFile(node: SourceFile) {
19271927
currentSourceFile = node;
1928+
// Start new file on new line
1929+
writeLine();
19281930
emitDetachedComments(node);
19291931
// emit prologue directives prior to __extends
19301932
var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//// [tests/cases/compiler/sourceMapWithMultipleFilesWithCopyright.ts] ////
2+
3+
//// [a.ts]
4+
/*--------------------------------------------------------------------------
5+
Copyright
6+
---------------------------------------------------------------------------*/
7+
8+
var x = {
9+
a: 10,
10+
b: 20
11+
};
12+
13+
//// [b.ts]
14+
/*--------------------------------------------------------------------------
15+
Copyright
16+
---------------------------------------------------------------------------*/
17+
18+
///<reference path="a.ts"/>
19+
var y = x;
20+
21+
//// [a.js]
22+
/*--------------------------------------------------------------------------
23+
Copyright
24+
---------------------------------------------------------------------------*/
25+
var x = {
26+
a: 10,
27+
b: 20
28+
};
29+
/*--------------------------------------------------------------------------
30+
Copyright
31+
---------------------------------------------------------------------------*/
32+
///<reference path="a.ts"/>
33+
var y = x;
34+
//# sourceMappingURL=a.js.map
35+
36+
//// [a.d.ts]
37+
declare var x: {
38+
a: number;
39+
b: number;
40+
};
41+
declare var y: {
42+
a: number;
43+
b: number;
44+
};

tests/baselines/reference/sourceMapWithMultipleFilesWithCopyright.js.map

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
===================================================================
2+
JsFile: a.js
3+
mapUrl: a.js.map
4+
sourceRoot:
5+
sources: tests/cases/compiler/a.ts,tests/cases/compiler/b.ts
6+
===================================================================
7+
-------------------------------------------------------------------
8+
emittedFile:a.js
9+
sourceFile:tests/cases/compiler/a.ts
10+
-------------------------------------------------------------------
11+
>>>/*--------------------------------------------------------------------------
12+
1 >
13+
2 >^^^^^^^^^^->
14+
1 >
15+
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
16+
---
17+
>>>Copyright
18+
>>>---------------------------------------------------------------------------*/
19+
1->^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
1->/*--------------------------------------------------------------------------
21+
>Copyright
22+
>---------------------------------------------------------------------------*/
23+
1->Emitted(3, 78) Source(3, 78) + SourceIndex(0)
24+
---
25+
>>>var x = {
26+
1 >
27+
2 >^^^^
28+
3 > ^
29+
4 > ^^^
30+
5 > ^^^->
31+
1 >
32+
>
33+
>
34+
2 >var
35+
3 > x
36+
4 > =
37+
1 >Emitted(4, 1) Source(5, 1) + SourceIndex(0)
38+
2 >Emitted(4, 5) Source(5, 5) + SourceIndex(0)
39+
3 >Emitted(4, 6) Source(5, 6) + SourceIndex(0)
40+
4 >Emitted(4, 9) Source(5, 9) + SourceIndex(0)
41+
---
42+
>>> a: 10,
43+
1->^^^^
44+
2 > ^
45+
3 > ^^
46+
4 > ^^
47+
5 > ^->
48+
1->{
49+
>
50+
2 > a
51+
3 > :
52+
4 > 10
53+
1->Emitted(5, 5) Source(6, 5) + SourceIndex(0)
54+
2 >Emitted(5, 6) Source(6, 6) + SourceIndex(0)
55+
3 >Emitted(5, 8) Source(6, 8) + SourceIndex(0)
56+
4 >Emitted(5, 10) Source(6, 10) + SourceIndex(0)
57+
---
58+
>>> b: 20
59+
1->^^^^
60+
2 > ^
61+
3 > ^^
62+
4 > ^^
63+
1->,
64+
>
65+
2 > b
66+
3 > :
67+
4 > 20
68+
1->Emitted(6, 5) Source(7, 5) + SourceIndex(0)
69+
2 >Emitted(6, 6) Source(7, 6) + SourceIndex(0)
70+
3 >Emitted(6, 8) Source(7, 8) + SourceIndex(0)
71+
4 >Emitted(6, 10) Source(7, 10) + SourceIndex(0)
72+
---
73+
>>>};
74+
1 >^
75+
2 > ^
76+
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
77+
1 >
78+
>}
79+
2 > ;
80+
1 >Emitted(7, 2) Source(8, 2) + SourceIndex(0)
81+
2 >Emitted(7, 3) Source(8, 3) + SourceIndex(0)
82+
---
83+
-------------------------------------------------------------------
84+
emittedFile:a.js
85+
sourceFile:tests/cases/compiler/b.ts
86+
-------------------------------------------------------------------
87+
>>>/*--------------------------------------------------------------------------
88+
1->
89+
2 >^^^^^^^^^^->
90+
1->
91+
1->Emitted(8, 1) Source(1, 1) + SourceIndex(1)
92+
---
93+
>>>Copyright
94+
>>>---------------------------------------------------------------------------*/
95+
1->^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
96+
1->/*--------------------------------------------------------------------------
97+
>Copyright
98+
>---------------------------------------------------------------------------*/
99+
1->Emitted(10, 78) Source(3, 78) + SourceIndex(1)
100+
---
101+
>>>///<reference path="a.ts"/>
102+
1 >
103+
2 >
104+
3 >^^^^^^^^^^^^^^^^^^^^^^^^^^^
105+
1 >
106+
>
107+
>///<reference path="a.ts"/>
108+
>
109+
2 >
110+
3 >///<reference path="a.ts"/>
111+
1 >Emitted(11, 1) Source(6, 1) + SourceIndex(1)
112+
2 >Emitted(11, 1) Source(5, 1) + SourceIndex(1)
113+
3 >Emitted(11, 28) Source(5, 28) + SourceIndex(1)
114+
---
115+
>>>var y = x;
116+
1 >^^^^
117+
2 > ^
118+
3 > ^^^
119+
4 > ^
120+
5 > ^
121+
6 > ^^^^^^^^^^^^^^^^^^->
122+
1 >
123+
>var
124+
2 > y
125+
3 > =
126+
4 > x
127+
5 > ;
128+
1 >Emitted(12, 5) Source(6, 5) + SourceIndex(1)
129+
2 >Emitted(12, 6) Source(6, 6) + SourceIndex(1)
130+
3 >Emitted(12, 9) Source(6, 9) + SourceIndex(1)
131+
4 >Emitted(12, 10) Source(6, 10) + SourceIndex(1)
132+
5 >Emitted(12, 11) Source(6, 11) + SourceIndex(1)
133+
---
134+
>>>//# sourceMappingURL=a.js.map
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
=== tests/cases/compiler/b.ts ===
2+
/*--------------------------------------------------------------------------
3+
Copyright
4+
---------------------------------------------------------------------------*/
5+
6+
///<reference path="a.ts"/>
7+
var y = x;
8+
>y : { a: number; b: number; }
9+
>x : { a: number; b: number; }
10+
11+
=== tests/cases/compiler/a.ts ===
12+
/*--------------------------------------------------------------------------
13+
Copyright
14+
---------------------------------------------------------------------------*/
15+
16+
var x = {
17+
>x : { a: number; b: number; }
18+
>{
19+
a: 10,
20+
b: 20
21+
} : { a: number; b: number; }
22+
23+
a: 10,
24+
>a : number
25+
26+
b: 20
27+
>b : number
28+
29+
};
30+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @out: a.js
2+
// @sourcemap: true
3+
// @declaration: true
4+
// @Filename: a.ts
5+
/*--------------------------------------------------------------------------
6+
Copyright
7+
---------------------------------------------------------------------------*/
8+
9+
var x = {
10+
a: 10,
11+
b: 20
12+
};
13+
14+
// @Filename: b.ts
15+
/*--------------------------------------------------------------------------
16+
Copyright
17+
---------------------------------------------------------------------------*/
18+
19+
///<reference path="a.ts"/>
20+
var y = x;

0 commit comments

Comments
 (0)