diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1b5726bdc7b..4b2bde6089c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -556,12 +556,14 @@ namespace ts { emitHelpers(bundle); emitSyntheticTripleSlashReferencesIfNeeded(bundle); - const pos = getTextPosWithWriteLine(); for (const prepend of bundle.prepends) { writeLine(); + const pos = getTextPosWithWriteLine(); print(EmitHint.Unspecified, prepend, /*sourceFile*/ undefined); + if (bundleFileInfo) bundleFileInfo.push({ pos, end: writer.getTextPos(), kind: BundleFileSectionKind.Prepend, fileName: (prepend as UnparsedSource).fileName }); } + const pos = getTextPosWithWriteLine(); for (const sourceFile of bundle.sourceFiles) { print(EmitHint.SourceFile, sourceFile, sourceFile); } diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index cc8a50087c8..0d07434c0e4 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2675,6 +2675,7 @@ namespace ts { const sections = textOrInputFiles.buildInfo ? mapPathOrType === "js" ? textOrInputFiles.buildInfo.js : textOrInputFiles.buildInfo.dts : undefined; if (sections) { + let setPos = false; for (const section of sections) { switch (section.kind) { case BundleFileSectionKind.Prologue: @@ -2698,9 +2699,13 @@ namespace ts { case BundleFileSectionKind.Lib: (libReferenceDirectives || (libReferenceDirectives = [])).push({ pos: -1, end: -1, fileName: section.fileName }); break; + case BundleFileSectionKind.Prepend: case BundleFileSectionKind.Text: - // For now just set node.pos to this - node.pos = section.pos; + if (!setPos) { + // For now just set node.pos to this + node.pos = section.pos; + setPos = true; + } break; default: Debug.assertNever(section); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f117d881bd8..ad1d48fd252 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5440,6 +5440,7 @@ namespace ts { Reference = "reference", Type = "type", Lib = "lib", + Prepend = "prepend", Text = "text", // internal comments? } @@ -5472,6 +5473,12 @@ namespace ts { fileName: string; } + /*@internal*/ + export interface BundleFilePrepend extends BundleFileSectionBase { + kind: BundleFileSectionKind.Prepend; + fileName: string; + } + /*@internal*/ export interface BundleFileText extends BundleFileSectionBase { kind: BundleFileSectionKind.Text; @@ -5479,7 +5486,7 @@ namespace ts { /*@internal*/ export type BundleFileSection = BundleFilePrologue | BundleFileEmitHelpers | - BundleFileHasNoDefaultLib | BundleFileReference | BundleFileText; + BundleFileHasNoDefaultLib | BundleFileReference | BundleFilePrepend | BundleFileText; /*@internal*/ export type BundleFileInfo = BundleFileSection[]; diff --git a/tests/baselines/reference/outFile-baseline-sectioned-sourcemaps.js b/tests/baselines/reference/outFile-baseline-sectioned-sourcemaps.js index bbfad6ac703..643796c0699 100644 --- a/tests/baselines/reference/outFile-baseline-sectioned-sourcemaps.js +++ b/tests/baselines/reference/outFile-baseline-sectioned-sourcemaps.js @@ -724,6 +724,18 @@ sourceFile:../first_part3.ts "js": [ { "pos": 0, + "end": 150, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 152, + "end": 478, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 480, "end": 516, "kind": "text" } @@ -731,6 +743,18 @@ sourceFile:../first_part3.ts "dts": [ { "pos": 0, + "end": 199, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 201, + "end": 344, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 346, "end": 365, "kind": "text" } diff --git a/tests/baselines/reference/outFile-emitHelpers-in-all-projects.js b/tests/baselines/reference/outFile-emitHelpers-in-all-projects.js index fb7aee7d13a..fe20d4ab36e 100644 --- a/tests/baselines/reference/outFile-emitHelpers-in-all-projects.js +++ b/tests/baselines/reference/outFile-emitHelpers-in-all-projects.js @@ -1151,6 +1151,18 @@ class second2 extends second1 { } }, { "pos": 599, + "end": 1043, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 1045, + "end": 1673, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 1675, "end": 2005, "kind": "text" } @@ -1158,6 +1170,18 @@ class second2 extends second1 { } "dts": [ { "pos": 0, + "end": 268, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 270, + "end": 485, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 487, "end": 575, "kind": "text" } diff --git a/tests/baselines/reference/outFile-emitHelpers-in-only-one-dependency-project.js b/tests/baselines/reference/outFile-emitHelpers-in-only-one-dependency-project.js index 1175dbca11a..aac0dab4949 100644 --- a/tests/baselines/reference/outFile-emitHelpers-in-only-one-dependency-project.js +++ b/tests/baselines/reference/outFile-emitHelpers-in-only-one-dependency-project.js @@ -943,6 +943,18 @@ class second2 extends second1 { } }, { "pos": 599, + "end": 749, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 751, + "end": 1379, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 1381, "end": 1417, "kind": "text" } @@ -950,6 +962,18 @@ class second2 extends second1 { } "dts": [ { "pos": 0, + "end": 199, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 201, + "end": 416, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 418, "end": 437, "kind": "text" } diff --git a/tests/baselines/reference/outFile-multiple-emitHelpers-in-all-projects.js b/tests/baselines/reference/outFile-multiple-emitHelpers-in-all-projects.js index f8f1ce796df..40ac51c1550 100644 --- a/tests/baselines/reference/outFile-multiple-emitHelpers-in-all-projects.js +++ b/tests/baselines/reference/outFile-multiple-emitHelpers-in-all-projects.js @@ -1594,6 +1594,18 @@ secondsecond_part2Spread(...[10, 20, 30]); }, { "pos": 1277, + "end": 1933, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 1935, + "end": 2779, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 2781, "end": 3323, "kind": "text" } @@ -1601,6 +1613,18 @@ secondsecond_part2Spread(...[10, 20, 30]); "dts": [ { "pos": 0, + "end": 332, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 334, + "end": 615, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 617, "end": 769, "kind": "text" } diff --git a/tests/baselines/reference/outFile-multiple-emitHelpers-in-different-projects.js b/tests/baselines/reference/outFile-multiple-emitHelpers-in-different-projects.js index 4898a6cffa4..aba4e4427b0 100644 --- a/tests/baselines/reference/outFile-multiple-emitHelpers-in-different-projects.js +++ b/tests/baselines/reference/outFile-multiple-emitHelpers-in-different-projects.js @@ -1170,6 +1170,18 @@ class second2 extends second1 { } }, { "pos": 1277, + "end": 1639, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 1641, + "end": 2269, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 2271, "end": 2519, "kind": "text" } @@ -1177,6 +1189,18 @@ class second2 extends second1 { } "dts": [ { "pos": 0, + "end": 263, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 265, + "end": 480, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 482, "end": 565, "kind": "text" } diff --git a/tests/baselines/reference/outFile-multiple-prologues-in-all-projects.js b/tests/baselines/reference/outFile-multiple-prologues-in-all-projects.js index 80ce35e472d..c16fdc80276 100644 --- a/tests/baselines/reference/outFile-multiple-prologues-in-all-projects.js +++ b/tests/baselines/reference/outFile-multiple-prologues-in-all-projects.js @@ -913,6 +913,18 @@ class C { }, { "pos": 62, + "end": 212, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 214, + "end": 540, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 542, "end": 578, "kind": "text" } @@ -920,6 +932,18 @@ class C { "dts": [ { "pos": 0, + "end": 199, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 201, + "end": 344, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 346, "end": 365, "kind": "text" } diff --git a/tests/baselines/reference/outFile-multiple-prologues-in-different-projects.js b/tests/baselines/reference/outFile-multiple-prologues-in-different-projects.js index faa2092aaec..4e0e4516b0d 100644 --- a/tests/baselines/reference/outFile-multiple-prologues-in-different-projects.js +++ b/tests/baselines/reference/outFile-multiple-prologues-in-different-projects.js @@ -845,6 +845,18 @@ class C { }, { "pos": 46, + "end": 196, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 198, + "end": 524, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 526, "end": 562, "kind": "text" } @@ -852,6 +864,18 @@ class C { "dts": [ { "pos": 0, + "end": 199, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 201, + "end": 344, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 346, "end": 365, "kind": "text" } diff --git a/tests/baselines/reference/outFile-shebang-in-all-projects.js b/tests/baselines/reference/outFile-shebang-in-all-projects.js index 093a4c1563c..4ea347f8fca 100644 --- a/tests/baselines/reference/outFile-shebang-in-all-projects.js +++ b/tests/baselines/reference/outFile-shebang-in-all-projects.js @@ -772,6 +772,18 @@ namespace N { "js": [ { "pos": 33, + "end": 183, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 185, + "end": 511, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 513, "end": 549, "kind": "text" } @@ -779,6 +791,18 @@ namespace N { "dts": [ { "pos": 33, + "end": 232, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 234, + "end": 377, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 379, "end": 398, "kind": "text" } diff --git a/tests/baselines/reference/outFile-shebang-in-only-one-dependency-project.js b/tests/baselines/reference/outFile-shebang-in-only-one-dependency-project.js index 00b8eece4f0..62256b137b0 100644 --- a/tests/baselines/reference/outFile-shebang-in-only-one-dependency-project.js +++ b/tests/baselines/reference/outFile-shebang-in-only-one-dependency-project.js @@ -745,6 +745,18 @@ namespace N { "js": [ { "pos": 35, + "end": 185, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 187, + "end": 513, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 515, "end": 551, "kind": "text" } @@ -752,6 +764,18 @@ namespace N { "dts": [ { "pos": 35, + "end": 234, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 236, + "end": 379, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 381, "end": 400, "kind": "text" } diff --git a/tests/baselines/reference/outFile-strict-in-all-projects.js b/tests/baselines/reference/outFile-strict-in-all-projects.js index ea188b9f883..2a54bb6e1fb 100644 --- a/tests/baselines/reference/outFile-strict-in-all-projects.js +++ b/tests/baselines/reference/outFile-strict-in-all-projects.js @@ -786,6 +786,18 @@ sourceFile:../first_part3.ts }, { "pos": 15, + "end": 165, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 167, + "end": 493, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 495, "end": 531, "kind": "text" } @@ -793,6 +805,18 @@ sourceFile:../first_part3.ts "dts": [ { "pos": 0, + "end": 199, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 201, + "end": 344, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 346, "end": 365, "kind": "text" } diff --git a/tests/baselines/reference/outFile-strict-in-one-dependency.js b/tests/baselines/reference/outFile-strict-in-one-dependency.js index fbd04d5f03c..327a3da4d57 100644 --- a/tests/baselines/reference/outFile-strict-in-one-dependency.js +++ b/tests/baselines/reference/outFile-strict-in-one-dependency.js @@ -756,6 +756,18 @@ sourceFile:../first_part3.ts }, { "pos": 15, + "end": 165, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 167, + "end": 493, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 495, "end": 531, "kind": "text" } @@ -763,6 +775,18 @@ sourceFile:../first_part3.ts "dts": [ { "pos": 0, + "end": 199, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 201, + "end": 344, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 346, "end": 365, "kind": "text" } diff --git a/tests/baselines/reference/outFile-triple-slash-refs-in-all-projects.js b/tests/baselines/reference/outFile-triple-slash-refs-in-all-projects.js index 56f37f9c3c8..0c6bdf10d85 100644 --- a/tests/baselines/reference/outFile-triple-slash-refs-in-all-projects.js +++ b/tests/baselines/reference/outFile-triple-slash-refs-in-all-projects.js @@ -875,6 +875,18 @@ declare class secondsecond_part1 { } "js": [ { "pos": 0, + "end": 198, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 200, + "end": 577, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 579, "end": 663, "kind": "text" } @@ -900,6 +912,18 @@ declare class secondsecond_part1 { } }, { "pos": 160, + "end": 410, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 412, + "end": 609, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 611, "end": 681, "kind": "text" } diff --git a/tests/baselines/reference/outFile-triple-slash-refs-in-one-project.js b/tests/baselines/reference/outFile-triple-slash-refs-in-one-project.js index 8fb60cacdfb..aaa174dcd86 100644 --- a/tests/baselines/reference/outFile-triple-slash-refs-in-one-project.js +++ b/tests/baselines/reference/outFile-triple-slash-refs-in-one-project.js @@ -803,6 +803,18 @@ declare class secondsecond_part1 { } "js": [ { "pos": 0, + "end": 150, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 152, + "end": 529, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 531, "end": 567, "kind": "text" } @@ -816,6 +828,18 @@ declare class secondsecond_part1 { } }, { "pos": 57, + "end": 256, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 258, + "end": 455, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 457, "end": 476, "kind": "text" } diff --git a/tests/baselines/reference/outFile-when-final-project-is-not-composite-but-uses-project-references.js b/tests/baselines/reference/outFile-when-final-project-is-not-composite-but-uses-project-references.js index d6005021eb4..a5e155089db 100644 --- a/tests/baselines/reference/outFile-when-final-project-is-not-composite-but-uses-project-references.js +++ b/tests/baselines/reference/outFile-when-final-project-is-not-composite-but-uses-project-references.js @@ -724,6 +724,18 @@ sourceFile:../first_part3.ts "js": [ { "pos": 0, + "end": 150, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.js" + }, + { + "pos": 152, + "end": 478, + "kind": "prepend", + "fileName": "/src/2/second-output.js" + }, + { + "pos": 480, "end": 516, "kind": "text" } @@ -731,6 +743,18 @@ sourceFile:../first_part3.ts "dts": [ { "pos": 0, + "end": 199, + "kind": "prepend", + "fileName": "/src/first/bin/first-output.d.ts" + }, + { + "pos": 201, + "end": 344, + "kind": "prepend", + "fileName": "/src/2/second-output.d.ts" + }, + { + "pos": 346, "end": 365, "kind": "text" }