Skip to content

Commit 526ed52

Browse files
authored
Ensure prepend texts are set when skipping internals (#33694)
1 parent a04f1eb commit 526ed52

File tree

4 files changed

+352
-2
lines changed

4 files changed

+352
-2
lines changed

src/compiler/factory.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2974,7 +2974,10 @@ namespace ts {
29742974
(texts || (texts = [])).push(prependNode);
29752975
break;
29762976
case BundleFileSectionKind.Internal:
2977-
if (stripInternal) break;
2977+
if (stripInternal) {
2978+
if (!texts) texts = [];
2979+
break;
2980+
}
29782981
// falls through
29792982

29802983
case BundleFileSectionKind.Text:

src/testRunner/unittests/tsbuild/helpers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ interface Symbol {
228228
if (section.kind !== BundleFileSectionKind.Prepend) {
229229
writeTextOfSection(section.pos, section.end);
230230
}
231-
else {
231+
else if (section.texts.length > 0) {
232232
Debug.assert(section.pos === first(section.texts).pos);
233233
Debug.assert(section.end === last(section.texts).end);
234234
for (const text of section.texts) {
@@ -237,6 +237,9 @@ interface Symbol {
237237
writeTextOfSection(text.pos, text.end);
238238
}
239239
}
240+
else {
241+
Debug.assert(section.pos === section.end);
242+
}
240243
}
241244
baselineRecorder.WriteLine("======================================================================");
242245

src/testRunner/unittests/tsbuild/outFile.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,40 @@ ${internal} enum internalEnum { a, b, c }`);
682682
ignoreDtsUnchanged: true,
683683
baselineOnly: true
684684
});
685+
686+
verifyOutFileScenario({
687+
subScenario: "stripInternal when prepend is completely internal",
688+
baselineOnly: true,
689+
ignoreDtsChanged: true,
690+
ignoreDtsUnchanged: true,
691+
modifyFs: fs => {
692+
fs.writeFileSync(sources[project.first][source.ts][part.one], "/* @internal */ const A = 1;");
693+
fs.writeFileSync(sources[project.third][source.ts][part.one], "const B = 2;");
694+
fs.writeFileSync(sources[project.first][source.config], JSON.stringify({
695+
compilerOptions: {
696+
composite: true,
697+
declaration: true,
698+
declarationMap: true,
699+
skipDefaultLibCheck: true,
700+
sourceMap: true,
701+
outFile: "./bin/first-output.js"
702+
},
703+
files: [sources[project.first][source.ts][part.one]]
704+
}));
705+
fs.writeFileSync(sources[project.third][source.config], JSON.stringify({
706+
compilerOptions: {
707+
composite: true,
708+
declaration: true,
709+
declarationMap: false,
710+
stripInternal: true,
711+
sourceMap: true,
712+
outFile: "./thirdjs/output/third-output.js"
713+
},
714+
references: [{ path: "../first", prepend: true }],
715+
files: [sources[project.third][source.ts][part.one]]
716+
}));
717+
}
718+
});
685719
});
686720

687721
describe("empty source files", () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
//// [/lib/initial-buildOutput.txt]
2+
/lib/tsc --b /src/third --verbose
3+
12:00:00 AM - Projects in this build:
4+
* src/first/tsconfig.json
5+
* src/third/tsconfig.json
6+
7+
12:00:00 AM - Project 'src/first/tsconfig.json' is out of date because output file 'src/first/bin/first-output.js' does not exist
8+
9+
12:00:00 AM - Building project '/src/first/tsconfig.json'...
10+
11+
12:00:00 AM - Project 'src/third/tsconfig.json' is out of date because output file 'src/third/thirdjs/output/third-output.js' does not exist
12+
13+
12:00:00 AM - Building project '/src/third/tsconfig.json'...
14+
15+
exitCode:: 0
16+
17+
18+
//// [/src/first/bin/first-output.d.ts]
19+
declare const A = 1;
20+
//# sourceMappingURL=first-output.d.ts.map
21+
22+
//// [/src/first/bin/first-output.d.ts.map]
23+
{"version":3,"file":"first-output.d.ts","sourceRoot":"","sources":["../first_PART1.ts"],"names":[],"mappings":"AAAgB,QAAA,MAAM,CAAC,IAAI,CAAC"}
24+
25+
//// [/src/first/bin/first-output.d.ts.map.baseline.txt]
26+
===================================================================
27+
JsFile: first-output.d.ts
28+
mapUrl: first-output.d.ts.map
29+
sourceRoot:
30+
sources: ../first_PART1.ts
31+
===================================================================
32+
-------------------------------------------------------------------
33+
emittedFile:/src/first/bin/first-output.d.ts
34+
sourceFile:../first_PART1.ts
35+
-------------------------------------------------------------------
36+
>>>declare const A = 1;
37+
1 >
38+
2 >^^^^^^^^
39+
3 > ^^^^^^
40+
4 > ^
41+
5 > ^^^^
42+
6 > ^
43+
7 > ^^^^^^^^^^^^^^^^^^^^^->
44+
1 >/* @internal */
45+
2 >
46+
3 > const
47+
4 > A
48+
5 > = 1
49+
6 > ;
50+
1 >Emitted(1, 1) Source(1, 17) + SourceIndex(0)
51+
2 >Emitted(1, 9) Source(1, 17) + SourceIndex(0)
52+
3 >Emitted(1, 15) Source(1, 23) + SourceIndex(0)
53+
4 >Emitted(1, 16) Source(1, 24) + SourceIndex(0)
54+
5 >Emitted(1, 20) Source(1, 28) + SourceIndex(0)
55+
6 >Emitted(1, 21) Source(1, 29) + SourceIndex(0)
56+
---
57+
>>>//# sourceMappingURL=first-output.d.ts.map
58+
59+
//// [/src/first/bin/first-output.js]
60+
/* @internal */ var A = 1;
61+
//# sourceMappingURL=first-output.js.map
62+
63+
//// [/src/first/bin/first-output.js.map]
64+
{"version":3,"file":"first-output.js","sourceRoot":"","sources":["../first_PART1.ts"],"names":[],"mappings":"AAAA,eAAe,CAAC,IAAM,CAAC,GAAG,CAAC,CAAC"}
65+
66+
//// [/src/first/bin/first-output.js.map.baseline.txt]
67+
===================================================================
68+
JsFile: first-output.js
69+
mapUrl: first-output.js.map
70+
sourceRoot:
71+
sources: ../first_PART1.ts
72+
===================================================================
73+
-------------------------------------------------------------------
74+
emittedFile:/src/first/bin/first-output.js
75+
sourceFile:../first_PART1.ts
76+
-------------------------------------------------------------------
77+
>>>/* @internal */ var A = 1;
78+
1 >
79+
2 >^^^^^^^^^^^^^^^
80+
3 > ^
81+
4 > ^^^^
82+
5 > ^
83+
6 > ^^^
84+
7 > ^
85+
8 > ^
86+
9 > ^^^^^^^^^^^^^->
87+
1 >
88+
2 >/* @internal */
89+
3 >
90+
4 > const
91+
5 > A
92+
6 > =
93+
7 > 1
94+
8 > ;
95+
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
96+
2 >Emitted(1, 16) Source(1, 16) + SourceIndex(0)
97+
3 >Emitted(1, 17) Source(1, 17) + SourceIndex(0)
98+
4 >Emitted(1, 21) Source(1, 23) + SourceIndex(0)
99+
5 >Emitted(1, 22) Source(1, 24) + SourceIndex(0)
100+
6 >Emitted(1, 25) Source(1, 27) + SourceIndex(0)
101+
7 >Emitted(1, 26) Source(1, 28) + SourceIndex(0)
102+
8 >Emitted(1, 27) Source(1, 29) + SourceIndex(0)
103+
---
104+
>>>//# sourceMappingURL=first-output.js.map
105+
106+
//// [/src/first/bin/first-output.tsbuildinfo]
107+
{
108+
"bundle": {
109+
"commonSourceDirectory": "..",
110+
"sourceFiles": [
111+
"../first_PART1.ts"
112+
],
113+
"js": {
114+
"sections": [
115+
{
116+
"pos": 0,
117+
"end": 28,
118+
"kind": "text"
119+
}
120+
]
121+
},
122+
"dts": {
123+
"sections": [
124+
{
125+
"pos": 0,
126+
"end": 20,
127+
"kind": "internal"
128+
}
129+
]
130+
}
131+
},
132+
"version": "FakeTSVersion"
133+
}
134+
135+
//// [/src/first/bin/first-output.tsbuildinfo.baseline.txt]
136+
======================================================================
137+
File:: /src/first/bin/first-output.js
138+
----------------------------------------------------------------------
139+
text: (0-28)
140+
/* @internal */ var A = 1;
141+
142+
======================================================================
143+
======================================================================
144+
File:: /src/first/bin/first-output.d.ts
145+
----------------------------------------------------------------------
146+
internal: (0-20)
147+
declare const A = 1;
148+
======================================================================
149+
150+
//// [/src/first/first_PART1.ts]
151+
/* @internal */ const A = 1;
152+
153+
//// [/src/first/tsconfig.json]
154+
{"compilerOptions":{"composite":true,"declaration":true,"declarationMap":true,"skipDefaultLibCheck":true,"sourceMap":true,"outFile":"./bin/first-output.js"},"files":["/src/first/first_PART1.ts"]}
155+
156+
//// [/src/third/thirdjs/output/third-output.d.ts]
157+
declare const B = 2;
158+
159+
160+
//// [/src/third/thirdjs/output/third-output.js]
161+
/* @internal */ var A = 1;
162+
var B = 2;
163+
//# sourceMappingURL=third-output.js.map
164+
165+
//// [/src/third/thirdjs/output/third-output.js.map]
166+
{"version":3,"file":"third-output.js","sourceRoot":"","sources":["../../../first/first_PART1.ts","../../third_part1.ts"],"names":[],"mappings":"AAAA,eAAe,CAAC,IAAM,CAAC,GAAG,CAAC,CAAC;ACA5B,IAAM,CAAC,GAAG,CAAC,CAAC"}
167+
168+
//// [/src/third/thirdjs/output/third-output.js.map.baseline.txt]
169+
===================================================================
170+
JsFile: third-output.js
171+
mapUrl: third-output.js.map
172+
sourceRoot:
173+
sources: ../../../first/first_PART1.ts,../../third_part1.ts
174+
===================================================================
175+
-------------------------------------------------------------------
176+
emittedFile:/src/third/thirdjs/output/third-output.js
177+
sourceFile:../../../first/first_PART1.ts
178+
-------------------------------------------------------------------
179+
>>>/* @internal */ var A = 1;
180+
1 >
181+
2 >^^^^^^^^^^^^^^^
182+
3 > ^
183+
4 > ^^^^
184+
5 > ^
185+
6 > ^^^
186+
7 > ^
187+
8 > ^
188+
1 >
189+
2 >/* @internal */
190+
3 >
191+
4 > const
192+
5 > A
193+
6 > =
194+
7 > 1
195+
8 > ;
196+
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
197+
2 >Emitted(1, 16) Source(1, 16) + SourceIndex(0)
198+
3 >Emitted(1, 17) Source(1, 17) + SourceIndex(0)
199+
4 >Emitted(1, 21) Source(1, 23) + SourceIndex(0)
200+
5 >Emitted(1, 22) Source(1, 24) + SourceIndex(0)
201+
6 >Emitted(1, 25) Source(1, 27) + SourceIndex(0)
202+
7 >Emitted(1, 26) Source(1, 28) + SourceIndex(0)
203+
8 >Emitted(1, 27) Source(1, 29) + SourceIndex(0)
204+
---
205+
-------------------------------------------------------------------
206+
emittedFile:/src/third/thirdjs/output/third-output.js
207+
sourceFile:../../third_part1.ts
208+
-------------------------------------------------------------------
209+
>>>var B = 2;
210+
1 >
211+
2 >^^^^
212+
3 > ^
213+
4 > ^^^
214+
5 > ^
215+
6 > ^
216+
7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
217+
1 >
218+
2 >const
219+
3 > B
220+
4 > =
221+
5 > 2
222+
6 > ;
223+
1 >Emitted(2, 1) Source(1, 1) + SourceIndex(1)
224+
2 >Emitted(2, 5) Source(1, 7) + SourceIndex(1)
225+
3 >Emitted(2, 6) Source(1, 8) + SourceIndex(1)
226+
4 >Emitted(2, 9) Source(1, 11) + SourceIndex(1)
227+
5 >Emitted(2, 10) Source(1, 12) + SourceIndex(1)
228+
6 >Emitted(2, 11) Source(1, 13) + SourceIndex(1)
229+
---
230+
>>>//# sourceMappingURL=third-output.js.map
231+
232+
//// [/src/third/thirdjs/output/third-output.tsbuildinfo]
233+
{
234+
"bundle": {
235+
"commonSourceDirectory": "../..",
236+
"sourceFiles": [
237+
"../../third_part1.ts"
238+
],
239+
"js": {
240+
"sections": [
241+
{
242+
"pos": 0,
243+
"end": 28,
244+
"kind": "prepend",
245+
"data": "../../../first/bin/first-output.js",
246+
"texts": [
247+
{
248+
"pos": 0,
249+
"end": 28,
250+
"kind": "text"
251+
}
252+
]
253+
},
254+
{
255+
"pos": 28,
256+
"end": 40,
257+
"kind": "text"
258+
}
259+
]
260+
},
261+
"dts": {
262+
"sections": [
263+
{
264+
"pos": 0,
265+
"end": 0,
266+
"kind": "prepend",
267+
"data": "../../../first/bin/first-output.d.ts",
268+
"texts": []
269+
},
270+
{
271+
"pos": 0,
272+
"end": 22,
273+
"kind": "text"
274+
}
275+
]
276+
}
277+
},
278+
"version": "FakeTSVersion"
279+
}
280+
281+
//// [/src/third/thirdjs/output/third-output.tsbuildinfo.baseline.txt]
282+
======================================================================
283+
File:: /src/third/thirdjs/output/third-output.js
284+
----------------------------------------------------------------------
285+
prepend: (0-28):: ../../../first/bin/first-output.js texts:: 1
286+
>>--------------------------------------------------------------------
287+
text: (0-28)
288+
/* @internal */ var A = 1;
289+
290+
----------------------------------------------------------------------
291+
text: (28-40)
292+
var B = 2;
293+
294+
======================================================================
295+
======================================================================
296+
File:: /src/third/thirdjs/output/third-output.d.ts
297+
----------------------------------------------------------------------
298+
prepend: (0-0):: ../../../first/bin/first-output.d.ts texts:: 0
299+
----------------------------------------------------------------------
300+
text: (0-22)
301+
declare const B = 2;
302+
303+
======================================================================
304+
305+
//// [/src/third/third_part1.ts]
306+
const B = 2;
307+
308+
//// [/src/third/tsconfig.json]
309+
{"compilerOptions":{"composite":true,"declaration":true,"declarationMap":false,"stripInternal":true,"sourceMap":true,"outFile":"./thirdjs/output/third-output.js"},"references":[{"path":"../first","prepend":true}],"files":["/src/third/third_part1.ts"]}
310+

0 commit comments

Comments
 (0)