@@ -28,7 +28,7 @@ namespace ts {
28
28
if ( outFile ( options ) ) {
29
29
const prepends = host . getPrependNodes ( ) ;
30
30
if ( sourceFiles . length || prepends . length ) {
31
- const bundle = createBundle ( sourceFiles , prepends ) ;
31
+ const bundle = factory . createBundle ( sourceFiles , prepends ) ;
32
32
const result = action ( getOutputPathsFor ( bundle , host , forceDtsEmit ) , bundle ) ;
33
33
if ( result ) {
34
34
return result ;
@@ -356,7 +356,7 @@ namespace ts {
356
356
return ;
357
357
}
358
358
// Transform the source files
359
- const transform = transformNodes ( resolver , host , compilerOptions , [ sourceFileOrBundle ] , scriptTransformers , /*allowDtsFiles*/ false ) ;
359
+ const transform = transformNodes ( resolver , host , factory , compilerOptions , [ sourceFileOrBundle ] , scriptTransformers , /*allowDtsFiles*/ false ) ;
360
360
361
361
const printerOptions : PrinterOptions = {
362
362
removeComments : compilerOptions . removeComments ,
@@ -404,13 +404,13 @@ namespace ts {
404
404
const sourceFiles = isSourceFile ( sourceFileOrBundle ) ? [ sourceFileOrBundle ] : sourceFileOrBundle . sourceFiles ;
405
405
const filesForEmit = forceDtsEmit ? sourceFiles : filter ( sourceFiles , isSourceFileNotJson ) ;
406
406
// Setup and perform the transformation to retrieve declarations from the input files
407
- const inputListOrBundle = outFile ( compilerOptions ) ? [ createBundle ( filesForEmit , ! isSourceFile ( sourceFileOrBundle ) ? sourceFileOrBundle . prepends : undefined ) ] : filesForEmit ;
407
+ const inputListOrBundle = outFile ( compilerOptions ) ? [ factory . createBundle ( filesForEmit , ! isSourceFile ( sourceFileOrBundle ) ? sourceFileOrBundle . prepends : undefined ) ] : filesForEmit ;
408
408
if ( emitOnlyDtsFiles && ! getEmitDeclarations ( compilerOptions ) ) {
409
409
// Checker wont collect the linked aliases since thats only done when declaration is enabled.
410
410
// Do that here when emitting only dts files
411
411
filesForEmit . forEach ( collectLinkedAliases ) ;
412
412
}
413
- const declarationTransform = transformNodes ( resolver , host , compilerOptions , inputListOrBundle , declarationTransformers , /*allowDtsFiles*/ false ) ;
413
+ const declarationTransform = transformNodes ( resolver , host , factory , compilerOptions , inputListOrBundle , declarationTransformers , /*allowDtsFiles*/ false ) ;
414
414
if ( length ( declarationTransform . diagnostics ) ) {
415
415
for ( const diagnostic of declarationTransform . diagnostics ! ) {
416
416
emitterDiagnostics . add ( diagnostic ) ;
@@ -680,30 +680,30 @@ namespace ts {
680
680
}
681
681
682
682
function createSourceFilesFromBundleBuildInfo ( bundle : BundleBuildInfo , buildInfoDirectory : string , host : EmitUsingBuildInfoHost ) : readonly SourceFile [ ] {
683
- const sourceFiles = bundle . sourceFiles . map ( fileName => {
684
- const sourceFile = createNode ( SyntaxKind . SourceFile , 0 , 0 ) as SourceFile ;
683
+ const jsBundle = Debug . checkDefined ( bundle . js ) ;
684
+ const prologueMap = jsBundle . sources ?. prologues && arrayToMap ( jsBundle . sources . prologues , prologueInfo => "" + prologueInfo . file ) ;
685
+ return bundle . sourceFiles . map ( ( fileName , index ) => {
686
+ const prologueInfo = prologueMap ?. get ( "" + index ) ;
687
+ const statements = prologueInfo ?. directives . map ( directive => {
688
+ const literal = setTextRange ( factory . createStringLiteral ( directive . expression . text ) , directive . expression ) ;
689
+ const statement = setTextRange ( factory . createExpressionStatement ( literal ) , directive ) ;
690
+ setParent ( literal , statement ) ;
691
+ return statement ;
692
+ } ) ;
693
+ const eofToken = factory . createToken ( SyntaxKind . EndOfFileToken ) ;
694
+ const sourceFile = factory . createSourceFile ( statements ?? [ ] , eofToken , NodeFlags . None ) ;
685
695
sourceFile . fileName = getRelativePathFromDirectory (
686
696
host . getCurrentDirectory ( ) ,
687
697
getNormalizedAbsolutePath ( fileName , buildInfoDirectory ) ,
688
698
! host . useCaseSensitiveFileNames ( )
689
699
) ;
690
- sourceFile . text = "" ;
691
- sourceFile . statements = createNodeArray ( ) ;
700
+ sourceFile . text = prologueInfo ?. text ?? "" ;
701
+ setTextRangePosWidth ( sourceFile , 0 , prologueInfo ?. text . length ?? 0 ) ;
702
+ setEachParent ( sourceFile . statements , sourceFile ) ;
703
+ setTextRangePosWidth ( eofToken , sourceFile . end , 0 ) ;
704
+ setParent ( eofToken , sourceFile ) ;
692
705
return sourceFile ;
693
706
} ) ;
694
- const jsBundle = Debug . checkDefined ( bundle . js ) ;
695
- forEach ( jsBundle . sources && jsBundle . sources . prologues , prologueInfo => {
696
- const sourceFile = sourceFiles [ prologueInfo . file ] ;
697
- sourceFile . text = prologueInfo . text ;
698
- sourceFile . end = prologueInfo . text . length ;
699
- sourceFile . statements = createNodeArray ( prologueInfo . directives . map ( directive => {
700
- const statement = createNode ( SyntaxKind . ExpressionStatement , directive . pos , directive . end ) as PrologueDirective ;
701
- statement . expression = createNode ( SyntaxKind . StringLiteral , directive . expression . pos , directive . expression . end ) as StringLiteral ;
702
- statement . expression . text = directive . expression . text ;
703
- return statement ;
704
- } ) ) ;
705
- } ) ;
706
- return sourceFiles ;
707
707
}
708
708
709
709
/*@internal */
@@ -2292,7 +2292,7 @@ namespace ts {
2292
2292
2293
2293
function emitPropertyAccessExpression ( node : PropertyAccessExpression ) {
2294
2294
const expression = cast ( emitExpression ( node . expression ) , isExpression ) ;
2295
- const token = node . questionDotToken || createNode ( SyntaxKind . DotToken , node . expression . end , node . name . pos ) as DotToken ;
2295
+ const token = node . questionDotToken || setTextRangePosEnd ( factory . createToken ( SyntaxKind . DotToken ) as DotToken , node . expression . end , node . name . pos ) ;
2296
2296
const linesBeforeDot = getLinesBetweenNodes ( node , node . expression , token ) ;
2297
2297
const linesAfterDot = getLinesBetweenNodes ( node , token , node . name ) ;
2298
2298
@@ -3559,15 +3559,15 @@ namespace ts {
3559
3559
}
3560
3560
3561
3561
function emitJSDocTypeLiteral ( lit : JSDocTypeLiteral ) {
3562
- emitList ( lit , createNodeArray ( lit . jsDocPropertyTags ) , ListFormat . JSDocComment ) ;
3562
+ emitList ( lit , factory . createNodeArray ( lit . jsDocPropertyTags ) , ListFormat . JSDocComment ) ;
3563
3563
}
3564
3564
3565
3565
function emitJSDocSignature ( sig : JSDocSignature ) {
3566
3566
if ( sig . typeParameters ) {
3567
- emitList ( sig , createNodeArray ( sig . typeParameters ) , ListFormat . JSDocComment ) ;
3567
+ emitList ( sig , factory . createNodeArray ( sig . typeParameters ) , ListFormat . JSDocComment ) ;
3568
3568
}
3569
3569
if ( sig . parameters ) {
3570
- emitList ( sig , createNodeArray ( sig . parameters ) , ListFormat . JSDocComment ) ;
3570
+ emitList ( sig , factory . createNodeArray ( sig . parameters ) , ListFormat . JSDocComment ) ;
3571
3571
}
3572
3572
if ( sig . type ) {
3573
3573
writeLine ( ) ;
0 commit comments