Skip to content

Commit ac55310

Browse files
committed
Fix prologue emitting in case of modules with --out scenario
1 parent b879b43 commit ac55310

17 files changed

+2412
-2787
lines changed

src/compiler/emitter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,7 +3377,7 @@ namespace ts {
33773377
* Emits any prologue directives at the start of a Statement list, returning the
33783378
* number of prologue directives written to the output.
33793379
*/
3380-
function emitPrologueDirectives(statements: ReadonlyArray<Node>, sourceFile?: SourceFile, seenPrologueDirectives?: Map<true>): number {
3380+
function emitPrologueDirectives(statements: ReadonlyArray<Node>, sourceFile?: SourceFile, seenPrologueDirectives?: Map<true>, recordBundleFileSection?: true): number {
33813381
let needsToSetSourceFile = !!sourceFile;
33823382
for (let i = 0; i < statements.length; i++) {
33833383
const statement = statements[i];
@@ -3391,7 +3391,7 @@ namespace ts {
33913391
writeLine();
33923392
const pos = writer.getTextPos();
33933393
emit(statement);
3394-
if (bundleFileInfo) bundleFileInfo.sections.push({ pos, end: writer.getTextPos(), kind: BundleFileSectionKind.Prologue, data: statement.expression.text });
3394+
if (recordBundleFileSection && bundleFileInfo) bundleFileInfo.sections.push({ pos, end: writer.getTextPos(), kind: BundleFileSectionKind.Prologue, data: statement.expression.text });
33953395
if (seenPrologueDirectives) {
33963396
seenPrologueDirectives.set(statement.expression.text, true);
33973397
}
@@ -3430,7 +3430,7 @@ namespace ts {
34303430
emitUnparsedPrologues((prepend as UnparsedSource).prologues, seenPrologueDirectives);
34313431
}
34323432
for (const sourceFile of sourceFileOrBundle.sourceFiles) {
3433-
emitPrologueDirectives(sourceFile.statements, sourceFile, seenPrologueDirectives);
3433+
emitPrologueDirectives(sourceFile.statements, sourceFile, seenPrologueDirectives, /*recordBundleFileSection*/ true);
34343434
}
34353435
setSourceFile(undefined);
34363436
}

src/testRunner/unittests/tsbuild/amdModulesWithOut.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ namespace ts {
109109
enableStrict(fs, sources[project.lib][source.config]);
110110
addTestPrologue(fs, sources[project.lib][source.ts][0], `"myPrologue"`);
111111
addTestPrologue(fs, sources[project.lib][source.ts][2], `"myPrologueFile"`);
112+
addTestPrologue(fs, sources[project.lib][source.ts][3], `"myPrologue3"`);
112113
enableStrict(fs, sources[project.app][source.config]);
113114
addTestPrologue(fs, sources[project.app][source.ts][0], `"myPrologue"`);
114115
addTestPrologue(fs, sources[project.app][source.ts][1], `"myPrologue2";`);
@@ -160,7 +161,7 @@ namespace ts {
160161
function stripInternalScenario(fs: vfs.FileSystem) {
161162
const internal = "/*@internal*/";
162163
replaceText(fs, sources[project.app][source.config], `"composite": true,`, `"composite": true,
163-
"stripInternal": true,`);;
164+
"stripInternal": true,`);
164165
replaceText(fs, sources[project.lib][source.ts][0], "const", `${internal} const`);
165166
appendText(fs, sources[project.lib][source.ts][1], `
166167
export class normalC {

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/modules-and-globals-mixed-in-amd.js

Lines changed: 53 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//// [/src/app/module.js]
2-
"use strict";
32
var myGlob = 20;
43
define("file1", ["require", "exports"], function (require, exports) {
54
"use strict";
@@ -22,7 +21,7 @@ var myVar = 30;
2221
//# sourceMappingURL=module.js.map
2322

2423
//// [/src/app/module.js.map]
25-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../lib/file0.ts","../lib/file1.ts","../lib/file2.ts","../lib/global.ts","file3.ts","file4.ts"],"names":[],"mappings":";AAAA,IAAM,MAAM,GAAG,EAAE,CAAC;;;;ICAL,QAAA,CAAC,GAAG,EAAE,CAAC;IAAA,OAAO,CAAC,GAAG,CAAC,SAAC,CAAC,CAAC;;;;;ICAtB,QAAA,CAAC,GAAG,EAAE,CAAC;;ACApB,IAAM,WAAW,GAAG,EAAE,CAAC;;;;ICAV,QAAA,CAAC,GAAG,EAAE,CAAC;;ACApB,IAAM,KAAK,GAAG,EAAE,CAAC"}
24+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../lib/file0.ts","../lib/file1.ts","../lib/file2.ts","../lib/global.ts","file3.ts","file4.ts"],"names":[],"mappings":"AAAA,IAAM,MAAM,GAAG,EAAE,CAAC;;;;ICAL,QAAA,CAAC,GAAG,EAAE,CAAC;IAAA,OAAO,CAAC,GAAG,CAAC,SAAC,CAAC,CAAC;;;;;ICAtB,QAAA,CAAC,GAAG,EAAE,CAAC;;ACApB,IAAM,WAAW,GAAG,EAAE,CAAC;;;;ICAV,QAAA,CAAC,GAAG,EAAE,CAAC;;ACApB,IAAM,KAAK,GAAG,EAAE,CAAC"}
2625

2726
//// [/src/app/module.js.map.baseline.txt]
2827
===================================================================
@@ -35,7 +34,6 @@ sources: ../lib/file0.ts,../lib/file1.ts,../lib/file2.ts,../lib/global.ts,file3.
3534
emittedFile:/src/app/module.js
3635
sourceFile:../lib/file0.ts
3736
-------------------------------------------------------------------
38-
>>> "use strict";
3937
>>>var myGlob = 20;
4038
1 >
4139
2 >^^^^
@@ -50,12 +48,12 @@ sourceFile:../lib/file0.ts
5048
4 > =
5149
5 > 20
5250
6 > ;
53-
1 >Emitted(2, 1) Source(1, 1) + SourceIndex(0)
54-
2 >Emitted(2, 5) Source(1, 7) + SourceIndex(0)
55-
3 >Emitted(2, 11) Source(1, 13) + SourceIndex(0)
56-
4 >Emitted(2, 14) Source(1, 16) + SourceIndex(0)
57-
5 >Emitted(2, 16) Source(1, 18) + SourceIndex(0)
58-
6 >Emitted(2, 17) Source(1, 19) + SourceIndex(0)
51+
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
52+
2 >Emitted(1, 5) Source(1, 7) + SourceIndex(0)
53+
3 >Emitted(1, 11) Source(1, 13) + SourceIndex(0)
54+
4 >Emitted(1, 14) Source(1, 16) + SourceIndex(0)
55+
5 >Emitted(1, 16) Source(1, 18) + SourceIndex(0)
56+
6 >Emitted(1, 17) Source(1, 19) + SourceIndex(0)
5957
---
6058
-------------------------------------------------------------------
6159
emittedFile:/src/app/module.js
@@ -78,12 +76,12 @@ sourceFile:../lib/file1.ts
7876
4 > =
7977
5 > 10
8078
6 > ;
81-
1->Emitted(6, 5) Source(1, 14) + SourceIndex(1)
82-
2 >Emitted(6, 13) Source(1, 14) + SourceIndex(1)
83-
3 >Emitted(6, 14) Source(1, 15) + SourceIndex(1)
84-
4 >Emitted(6, 17) Source(1, 18) + SourceIndex(1)
85-
5 >Emitted(6, 19) Source(1, 20) + SourceIndex(1)
86-
6 >Emitted(6, 20) Source(1, 21) + SourceIndex(1)
79+
1->Emitted(5, 5) Source(1, 14) + SourceIndex(1)
80+
2 >Emitted(5, 13) Source(1, 14) + SourceIndex(1)
81+
3 >Emitted(5, 14) Source(1, 15) + SourceIndex(1)
82+
4 >Emitted(5, 17) Source(1, 18) + SourceIndex(1)
83+
5 >Emitted(5, 19) Source(1, 20) + SourceIndex(1)
84+
6 >Emitted(5, 20) Source(1, 21) + SourceIndex(1)
8785
---
8886
>>> console.log(exports.x);
8987
1->^^^^
@@ -102,14 +100,14 @@ sourceFile:../lib/file1.ts
102100
6 > x
103101
7 > )
104102
8 > ;
105-
1->Emitted(7, 5) Source(1, 21) + SourceIndex(1)
106-
2 >Emitted(7, 12) Source(1, 28) + SourceIndex(1)
107-
3 >Emitted(7, 13) Source(1, 29) + SourceIndex(1)
108-
4 >Emitted(7, 16) Source(1, 32) + SourceIndex(1)
109-
5 >Emitted(7, 17) Source(1, 33) + SourceIndex(1)
110-
6 >Emitted(7, 26) Source(1, 34) + SourceIndex(1)
111-
7 >Emitted(7, 27) Source(1, 35) + SourceIndex(1)
112-
8 >Emitted(7, 28) Source(1, 36) + SourceIndex(1)
103+
1->Emitted(6, 5) Source(1, 21) + SourceIndex(1)
104+
2 >Emitted(6, 12) Source(1, 28) + SourceIndex(1)
105+
3 >Emitted(6, 13) Source(1, 29) + SourceIndex(1)
106+
4 >Emitted(6, 16) Source(1, 32) + SourceIndex(1)
107+
5 >Emitted(6, 17) Source(1, 33) + SourceIndex(1)
108+
6 >Emitted(6, 26) Source(1, 34) + SourceIndex(1)
109+
7 >Emitted(6, 27) Source(1, 35) + SourceIndex(1)
110+
8 >Emitted(6, 28) Source(1, 36) + SourceIndex(1)
113111
---
114112
-------------------------------------------------------------------
115113
emittedFile:/src/app/module.js
@@ -132,12 +130,12 @@ sourceFile:../lib/file2.ts
132130
4 > =
133131
5 > 20
134132
6 > ;
135-
1 >Emitted(12, 5) Source(1, 14) + SourceIndex(2)
136-
2 >Emitted(12, 13) Source(1, 14) + SourceIndex(2)
137-
3 >Emitted(12, 14) Source(1, 15) + SourceIndex(2)
138-
4 >Emitted(12, 17) Source(1, 18) + SourceIndex(2)
139-
5 >Emitted(12, 19) Source(1, 20) + SourceIndex(2)
140-
6 >Emitted(12, 20) Source(1, 21) + SourceIndex(2)
133+
1 >Emitted(11, 5) Source(1, 14) + SourceIndex(2)
134+
2 >Emitted(11, 13) Source(1, 14) + SourceIndex(2)
135+
3 >Emitted(11, 14) Source(1, 15) + SourceIndex(2)
136+
4 >Emitted(11, 17) Source(1, 18) + SourceIndex(2)
137+
5 >Emitted(11, 19) Source(1, 20) + SourceIndex(2)
138+
6 >Emitted(11, 20) Source(1, 21) + SourceIndex(2)
141139
---
142140
-------------------------------------------------------------------
143141
emittedFile:/src/app/module.js
@@ -158,12 +156,12 @@ sourceFile:../lib/global.ts
158156
4 > =
159157
5 > 10
160158
6 > ;
161-
1 >Emitted(14, 1) Source(1, 1) + SourceIndex(3)
162-
2 >Emitted(14, 5) Source(1, 7) + SourceIndex(3)
163-
3 >Emitted(14, 16) Source(1, 18) + SourceIndex(3)
164-
4 >Emitted(14, 19) Source(1, 21) + SourceIndex(3)
165-
5 >Emitted(14, 21) Source(1, 23) + SourceIndex(3)
166-
6 >Emitted(14, 22) Source(1, 24) + SourceIndex(3)
159+
1 >Emitted(13, 1) Source(1, 1) + SourceIndex(3)
160+
2 >Emitted(13, 5) Source(1, 7) + SourceIndex(3)
161+
3 >Emitted(13, 16) Source(1, 18) + SourceIndex(3)
162+
4 >Emitted(13, 19) Source(1, 21) + SourceIndex(3)
163+
5 >Emitted(13, 21) Source(1, 23) + SourceIndex(3)
164+
6 >Emitted(13, 22) Source(1, 24) + SourceIndex(3)
167165
---
168166
-------------------------------------------------------------------
169167
emittedFile:/src/app/module.js
@@ -185,12 +183,12 @@ sourceFile:file3.ts
185183
4 > =
186184
5 > 30
187185
6 > ;
188-
1->Emitted(18, 5) Source(1, 14) + SourceIndex(4)
189-
2 >Emitted(18, 13) Source(1, 14) + SourceIndex(4)
190-
3 >Emitted(18, 14) Source(1, 15) + SourceIndex(4)
191-
4 >Emitted(18, 17) Source(1, 18) + SourceIndex(4)
192-
5 >Emitted(18, 19) Source(1, 20) + SourceIndex(4)
193-
6 >Emitted(18, 20) Source(1, 21) + SourceIndex(4)
186+
1->Emitted(17, 5) Source(1, 14) + SourceIndex(4)
187+
2 >Emitted(17, 13) Source(1, 14) + SourceIndex(4)
188+
3 >Emitted(17, 14) Source(1, 15) + SourceIndex(4)
189+
4 >Emitted(17, 17) Source(1, 18) + SourceIndex(4)
190+
5 >Emitted(17, 19) Source(1, 20) + SourceIndex(4)
191+
6 >Emitted(17, 20) Source(1, 21) + SourceIndex(4)
194192
---
195193
-------------------------------------------------------------------
196194
emittedFile:/src/app/module.js
@@ -211,12 +209,12 @@ sourceFile:file4.ts
211209
4 > =
212210
5 > 30
213211
6 > ;
214-
1 >Emitted(20, 1) Source(1, 1) + SourceIndex(5)
215-
2 >Emitted(20, 5) Source(1, 7) + SourceIndex(5)
216-
3 >Emitted(20, 10) Source(1, 12) + SourceIndex(5)
217-
4 >Emitted(20, 13) Source(1, 15) + SourceIndex(5)
218-
5 >Emitted(20, 15) Source(1, 17) + SourceIndex(5)
219-
6 >Emitted(20, 16) Source(1, 18) + SourceIndex(5)
212+
1 >Emitted(19, 1) Source(1, 1) + SourceIndex(5)
213+
2 >Emitted(19, 5) Source(1, 7) + SourceIndex(5)
214+
3 >Emitted(19, 10) Source(1, 12) + SourceIndex(5)
215+
4 >Emitted(19, 13) Source(1, 15) + SourceIndex(5)
216+
5 >Emitted(19, 15) Source(1, 17) + SourceIndex(5)
217+
6 >Emitted(19, 16) Source(1, 18) + SourceIndex(5)
220218
---
221219
>>>//# sourceMappingURL=module.js.map
222220

@@ -232,26 +230,20 @@ sourceFile:file4.ts
232230
"sections": [
233231
{
234232
"pos": 0,
235-
"end": 17,
236-
"kind": "prologue",
237-
"data": "use strict"
238-
},
239-
{
240-
"pos": 19,
241-
"end": 457,
233+
"end": 438,
242234
"kind": "prepend",
243235
"data": "/src/lib/module.js",
244236
"texts": [
245237
{
246-
"pos": 19,
247-
"end": 457,
238+
"pos": 0,
239+
"end": 438,
248240
"kind": "text"
249241
}
250242
]
251243
},
252244
{
253-
"pos": 457,
254-
"end": 658,
245+
"pos": 438,
246+
"end": 639,
255247
"kind": "text"
256248
}
257249
]
@@ -285,12 +277,9 @@ sourceFile:file4.ts
285277
======================================================================
286278
File:: /src/app/module.js
287279
----------------------------------------------------------------------
288-
prologue: (0-17):: use strict
289-
"use strict";
290-
----------------------------------------------------------------------
291-
prepend: (19-457):: /src/lib/module.js texts:: 1
280+
prepend: (0-438):: /src/lib/module.js texts:: 1
292281
>>--------------------------------------------------------------------
293-
text: (19-457)
282+
text: (0-438)
294283
var myGlob = 20;
295284
define("file1", ["require", "exports"], function (require, exports) {
296285
"use strict";
@@ -306,7 +295,7 @@ define("file2", ["require", "exports"], function (require, exports) {
306295
var globalConst = 10;
307296

308297
----------------------------------------------------------------------
309-
text: (457-658)
298+
text: (438-639)
310299
define("file3", ["require", "exports"], function (require, exports) {
311300
"use strict";
312301
Object.defineProperty(exports, "__esModule", { value: true });
@@ -515,18 +504,6 @@ sourceFile:global.ts
515504
],
516505
"js": {
517506
"sections": [
518-
{
519-
"pos": 89,
520-
"end": 106,
521-
"kind": "prologue",
522-
"data": "use strict"
523-
},
524-
{
525-
"pos": 302,
526-
"end": 319,
527-
"kind": "prologue",
528-
"data": "use strict"
529-
},
530507
{
531508
"pos": 0,
532509
"end": 438,
@@ -550,12 +527,6 @@ sourceFile:global.ts
550527
======================================================================
551528
File:: /src/lib/module.js
552529
----------------------------------------------------------------------
553-
prologue: (89-106):: use strict
554-
"use strict";
555-
----------------------------------------------------------------------
556-
prologue: (302-319):: use strict
557-
"use strict";
558-
----------------------------------------------------------------------
559530
text: (0-438)
560531
var myGlob = 20;
561532
define("file1", ["require", "exports"], function (require, exports) {

0 commit comments

Comments
 (0)