@@ -431,7 +431,7 @@ namespace ts {
431
431
const moduleKind = getEmitModuleKind ( printerOptions ) ;
432
432
const bundledHelpers = createMap < boolean > ( ) ;
433
433
434
- let currentSourceFile ! : SourceFile ;
434
+ let currentSourceFile : SourceFile | undefined ;
435
435
let nodeIdToGeneratedName : string [ ] ; // Map of generated names for specific nodes.
436
436
let autoGeneratedIdToGeneratedName : string [ ] ; // Map of generated names for temp and loop variables.
437
437
let generatedNames : Map < true > ; // Set of names generated by the NameGenerator.
@@ -604,11 +604,13 @@ namespace ts {
604
604
pipelinePhase ( hint , node ) ;
605
605
}
606
606
607
- function setSourceFile ( sourceFile : SourceFile ) {
607
+ function setSourceFile ( sourceFile : SourceFile | undefined ) {
608
608
currentSourceFile = sourceFile ;
609
609
currentLineMap = undefined ;
610
610
detachedCommentsInfo = undefined ;
611
- setSourceMapSource ( sourceFile ) ;
611
+ if ( sourceFile ) {
612
+ setSourceMapSource ( sourceFile ) ;
613
+ }
612
614
}
613
615
614
616
function setWriter ( _writer : EmitTextWriter | undefined , _sourceMapGenerator : SourceMapGenerator | undefined ) {
@@ -635,7 +637,7 @@ namespace ts {
635
637
}
636
638
637
639
function getCurrentLineMap ( ) {
638
- return currentLineMap || ( currentLineMap = getLineStarts ( currentSourceFile ) ) ;
640
+ return currentLineMap || ( currentLineMap = getLineStarts ( currentSourceFile ! ) ) ;
639
641
}
640
642
641
643
function emit ( node : Node | undefined ) {
@@ -1130,7 +1132,7 @@ namespace ts {
1130
1132
const numNodes = bundle ? bundle . sourceFiles . length : 1 ;
1131
1133
for ( let i = 0 ; i < numNodes ; i ++ ) {
1132
1134
const currentNode = bundle ? bundle . sourceFiles [ i ] : node ;
1133
- const sourceFile = isSourceFile ( currentNode ) ? currentNode : currentSourceFile ;
1135
+ const sourceFile = isSourceFile ( currentNode ) ? currentNode : currentSourceFile ! ;
1134
1136
const shouldSkip = printerOptions . noEmitHelpers || getExternalHelpersModuleName ( sourceFile ) !== undefined ;
1135
1137
const shouldBundle = isSourceFile ( currentNode ) && ! isOwnFileEmit ;
1136
1138
const helpers = getEmitHelpers ( currentNode ) ;
@@ -1638,7 +1640,7 @@ namespace ts {
1638
1640
}
1639
1641
1640
1642
const preferNewLine = node . multiLine ? ListFormat . PreferNewLine : ListFormat . None ;
1641
- const allowTrailingComma = currentSourceFile . languageVersion >= ScriptTarget . ES5 && ! isJsonSourceFile ( currentSourceFile ) ? ListFormat . AllowTrailingComma : ListFormat . None ;
1643
+ const allowTrailingComma = currentSourceFile ! . languageVersion >= ScriptTarget . ES5 && ! isJsonSourceFile ( currentSourceFile ! ) ? ListFormat . AllowTrailingComma : ListFormat . None ;
1642
1644
emitList ( node , node . properties , ListFormat . ObjectLiteralExpressionProperties | allowTrailingComma | preferNewLine ) ;
1643
1645
1644
1646
if ( indentedFlag ) {
@@ -1651,7 +1653,7 @@ namespace ts {
1651
1653
let indentAfterDot = false ;
1652
1654
if ( ! ( getEmitFlags ( node ) & EmitFlags . NoIndentation ) ) {
1653
1655
const dotRangeStart = node . expression . end ;
1654
- const dotRangeEnd = skipTrivia ( currentSourceFile . text , node . expression . end ) + 1 ;
1656
+ const dotRangeEnd = skipTrivia ( currentSourceFile ! . text , node . expression . end ) + 1 ;
1655
1657
const dotToken = createToken ( SyntaxKind . DotToken ) ;
1656
1658
dotToken . pos = dotRangeStart ;
1657
1659
dotToken . end = dotRangeEnd ;
@@ -1937,7 +1939,7 @@ namespace ts {
1937
1939
emitExpression ( node . expression ) ;
1938
1940
// Emit semicolon in non json files
1939
1941
// or if json file that created synthesized expression(eg.define expression statement when --out and amd code generation)
1940
- if ( ! isJsonSourceFile ( currentSourceFile ) || nodeIsSynthesized ( node . expression ) ) {
1942
+ if ( ! isJsonSourceFile ( currentSourceFile ! ) || nodeIsSynthesized ( node . expression ) ) {
1941
1943
writeTrailingSemicolon ( ) ;
1942
1944
}
1943
1945
}
@@ -2057,10 +2059,10 @@ namespace ts {
2057
2059
const isSimilarNode = node && node . kind === contextNode . kind ;
2058
2060
const startPos = pos ;
2059
2061
if ( isSimilarNode ) {
2060
- pos = skipTrivia ( currentSourceFile . text , pos ) ;
2062
+ pos = skipTrivia ( currentSourceFile ! . text , pos ) ;
2061
2063
}
2062
2064
if ( emitLeadingCommentsOfPosition && isSimilarNode && contextNode . pos !== startPos ) {
2063
- const needsIndent = indentLeading && ! positionsAreOnSameLine ( startPos , pos , currentSourceFile ) ;
2065
+ const needsIndent = indentLeading && ! positionsAreOnSameLine ( startPos , pos , currentSourceFile ! ) ;
2064
2066
if ( needsIndent ) {
2065
2067
increaseIndent ( ) ;
2066
2068
}
@@ -2231,7 +2233,7 @@ namespace ts {
2231
2233
return false ;
2232
2234
}
2233
2235
2234
- if ( ! nodeIsSynthesized ( body ) && ! rangeIsOnSingleLine ( body , currentSourceFile ) ) {
2236
+ if ( ! nodeIsSynthesized ( body ) && ! rangeIsOnSingleLine ( body , currentSourceFile ! ) ) {
2235
2237
return false ;
2236
2238
}
2237
2239
@@ -2644,7 +2646,7 @@ namespace ts {
2644
2646
// treat synthesized nodes as located on the same line for emit purposes
2645
2647
nodeIsSynthesized ( parentNode ) ||
2646
2648
nodeIsSynthesized ( statements [ 0 ] ) ||
2647
- rangeStartPositionsAreOnSameLine ( parentNode , statements [ 0 ] , currentSourceFile )
2649
+ rangeStartPositionsAreOnSameLine ( parentNode , statements [ 0 ] , currentSourceFile ! )
2648
2650
) ;
2649
2651
2650
2652
let format = ListFormat . CaseOrDefaultClauseStatements ;
@@ -2998,6 +3000,7 @@ namespace ts {
2998
3000
setSourceFile ( sourceFile ) ;
2999
3001
emitPrologueDirectives ( sourceFile . statements , /*startWithNewLine*/ true , seenPrologueDirectives ) ;
3000
3002
}
3003
+ setSourceFile ( undefined ) ;
3001
3004
}
3002
3005
}
3003
3006
@@ -3488,13 +3491,13 @@ namespace ts {
3488
3491
3489
3492
const firstChild = children [ 0 ] ;
3490
3493
if ( firstChild === undefined ) {
3491
- return ! rangeIsOnSingleLine ( parentNode , currentSourceFile ) ;
3494
+ return ! rangeIsOnSingleLine ( parentNode , currentSourceFile ! ) ;
3492
3495
}
3493
3496
else if ( positionIsSynthesized ( parentNode . pos ) || nodeIsSynthesized ( firstChild ) ) {
3494
3497
return synthesizedNodeStartsOnNewLine ( firstChild , format ) ;
3495
3498
}
3496
3499
else {
3497
- return ! rangeStartPositionsAreOnSameLine ( parentNode , firstChild , currentSourceFile ) ;
3500
+ return ! rangeStartPositionsAreOnSameLine ( parentNode , firstChild , currentSourceFile ! ) ;
3498
3501
}
3499
3502
}
3500
3503
else {
@@ -3514,7 +3517,7 @@ namespace ts {
3514
3517
return synthesizedNodeStartsOnNewLine ( previousNode , format ) || synthesizedNodeStartsOnNewLine ( nextNode , format ) ;
3515
3518
}
3516
3519
else {
3517
- return ! rangeEndIsOnSameLineAsRangeStart ( previousNode , nextNode , currentSourceFile ) ;
3520
+ return ! rangeEndIsOnSameLineAsRangeStart ( previousNode , nextNode , currentSourceFile ! ) ;
3518
3521
}
3519
3522
}
3520
3523
else {
@@ -3533,13 +3536,13 @@ namespace ts {
3533
3536
3534
3537
const lastChild = lastOrUndefined ( children ) ;
3535
3538
if ( lastChild === undefined ) {
3536
- return ! rangeIsOnSingleLine ( parentNode , currentSourceFile ) ;
3539
+ return ! rangeIsOnSingleLine ( parentNode , currentSourceFile ! ) ;
3537
3540
}
3538
3541
else if ( positionIsSynthesized ( parentNode . pos ) || nodeIsSynthesized ( lastChild ) ) {
3539
3542
return synthesizedNodeStartsOnNewLine ( lastChild , format ) ;
3540
3543
}
3541
3544
else {
3542
- return ! rangeEndPositionsAreOnSameLine ( parentNode , lastChild , currentSourceFile ) ;
3545
+ return ! rangeEndPositionsAreOnSameLine ( parentNode , lastChild , currentSourceFile ! ) ;
3543
3546
}
3544
3547
}
3545
3548
else {
@@ -3573,12 +3576,12 @@ namespace ts {
3573
3576
return ! nodeIsSynthesized ( parent )
3574
3577
&& ! nodeIsSynthesized ( node1 )
3575
3578
&& ! nodeIsSynthesized ( node2 )
3576
- && ! rangeEndIsOnSameLineAsRangeStart ( node1 , node2 , currentSourceFile ) ;
3579
+ && ! rangeEndIsOnSameLineAsRangeStart ( node1 , node2 , currentSourceFile ! ) ;
3577
3580
}
3578
3581
3579
3582
function isEmptyBlock ( block : BlockLike ) {
3580
3583
return block . statements . length === 0
3581
- && rangeEndIsOnSameLineAsRangeStart ( block , block , currentSourceFile ) ;
3584
+ && rangeEndIsOnSameLineAsRangeStart ( block , block , currentSourceFile ! ) ;
3582
3585
}
3583
3586
3584
3587
function skipSynthesizedParentheses ( node : Node ) {
@@ -3603,7 +3606,7 @@ namespace ts {
3603
3606
return node . text ;
3604
3607
}
3605
3608
3606
- return getSourceTextOfNodeFromSourceFile ( currentSourceFile , node , includeTrivia ) ;
3609
+ return getSourceTextOfNodeFromSourceFile ( currentSourceFile ! , node , includeTrivia ) ;
3607
3610
}
3608
3611
3609
3612
function getLiteralTextOfNode ( node : LiteralLikeNode , neverAsciiEscape : boolean | undefined ) : string {
@@ -3619,7 +3622,7 @@ namespace ts {
3619
3622
}
3620
3623
}
3621
3624
3622
- return getLiteralText ( node , currentSourceFile , neverAsciiEscape ) ;
3625
+ return getLiteralText ( node , currentSourceFile ! , neverAsciiEscape ) ;
3623
3626
}
3624
3627
3625
3628
/**
@@ -4181,15 +4184,15 @@ namespace ts {
4181
4184
}
4182
4185
4183
4186
function emitLeadingComment ( commentPos : number , commentEnd : number , kind : SyntaxKind , hasTrailingNewLine : boolean , rangePos : number ) {
4184
- if ( ! shouldWriteComment ( currentSourceFile . text , commentPos ) ) return ;
4187
+ if ( ! shouldWriteComment ( currentSourceFile ! . text , commentPos ) ) return ;
4185
4188
if ( ! hasWrittenComment ) {
4186
4189
emitNewLineBeforeLeadingCommentOfPosition ( getCurrentLineMap ( ) , writer , rangePos , commentPos ) ;
4187
4190
hasWrittenComment = true ;
4188
4191
}
4189
4192
4190
4193
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
4191
4194
emitPos ( commentPos ) ;
4192
- writeCommentRange ( currentSourceFile . text , getCurrentLineMap ( ) , writer , commentPos , commentEnd , newLine ) ;
4195
+ writeCommentRange ( currentSourceFile ! . text , getCurrentLineMap ( ) , writer , commentPos , commentEnd , newLine ) ;
4193
4196
emitPos ( commentEnd ) ;
4194
4197
4195
4198
if ( hasTrailingNewLine ) {
@@ -4213,14 +4216,14 @@ namespace ts {
4213
4216
}
4214
4217
4215
4218
function emitTrailingComment ( commentPos : number , commentEnd : number , _kind : SyntaxKind , hasTrailingNewLine : boolean ) {
4216
- if ( ! shouldWriteComment ( currentSourceFile . text , commentPos ) ) return ;
4219
+ if ( ! shouldWriteComment ( currentSourceFile ! . text , commentPos ) ) return ;
4217
4220
// trailing comments are emitted at space/*trailing comment1 */space/*trailing comment2*/
4218
4221
if ( ! writer . isAtStartOfLine ( ) ) {
4219
4222
writer . writeSpace ( " " ) ;
4220
4223
}
4221
4224
4222
4225
emitPos ( commentPos ) ;
4223
- writeCommentRange ( currentSourceFile . text , getCurrentLineMap ( ) , writer , commentPos , commentEnd , newLine ) ;
4226
+ writeCommentRange ( currentSourceFile ! . text , getCurrentLineMap ( ) , writer , commentPos , commentEnd , newLine ) ;
4224
4227
emitPos ( commentEnd ) ;
4225
4228
4226
4229
if ( hasTrailingNewLine ) {
@@ -4241,7 +4244,7 @@ namespace ts {
4241
4244
// trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
4242
4245
4243
4246
emitPos ( commentPos ) ;
4244
- writeCommentRange ( currentSourceFile . text , getCurrentLineMap ( ) , writer , commentPos , commentEnd , newLine ) ;
4247
+ writeCommentRange ( currentSourceFile ! . text , getCurrentLineMap ( ) , writer , commentPos , commentEnd , newLine ) ;
4245
4248
emitPos ( commentEnd ) ;
4246
4249
4247
4250
if ( hasTrailingNewLine ) {
@@ -4285,11 +4288,11 @@ namespace ts {
4285
4288
detachedCommentsInfo = undefined ;
4286
4289
}
4287
4290
4288
- forEachLeadingCommentRange ( currentSourceFile . text , pos , cb , /*state*/ pos ) ;
4291
+ forEachLeadingCommentRange ( currentSourceFile ! . text , pos , cb , /*state*/ pos ) ;
4289
4292
}
4290
4293
4291
4294
function emitDetachedCommentsAndUpdateCommentsInfo ( range : TextRange ) {
4292
- const currentDetachedCommentInfo = emitDetachedComments ( currentSourceFile . text , getCurrentLineMap ( ) , writer , emitComment , range , newLine , commentsDisabled ) ;
4295
+ const currentDetachedCommentInfo = emitDetachedComments ( currentSourceFile ! . text , getCurrentLineMap ( ) , writer , emitComment , range , newLine , commentsDisabled ) ;
4293
4296
if ( currentDetachedCommentInfo ) {
4294
4297
if ( detachedCommentsInfo ) {
4295
4298
detachedCommentsInfo . push ( currentDetachedCommentInfo ) ;
@@ -4301,7 +4304,7 @@ namespace ts {
4301
4304
}
4302
4305
4303
4306
function emitComment ( text : string , lineMap : number [ ] , writer : EmitTextWriter , commentPos : number , commentEnd : number , newLine : string ) {
4304
- if ( ! shouldWriteComment ( currentSourceFile . text , commentPos ) ) return ;
4307
+ if ( ! shouldWriteComment ( currentSourceFile ! . text , commentPos ) ) return ;
4305
4308
emitPos ( commentPos ) ;
4306
4309
writeCommentRange ( text , lineMap , writer , commentPos , commentEnd , newLine ) ;
4307
4310
emitPos ( commentEnd ) ;
@@ -4313,7 +4316,7 @@ namespace ts {
4313
4316
* @return true if the comment is a triple-slash comment else false
4314
4317
*/
4315
4318
function isTripleSlashComment ( commentPos : number , commentEnd : number ) {
4316
- return isRecognizedTripleSlashComment ( currentSourceFile . text , commentPos , commentEnd ) ;
4319
+ return isRecognizedTripleSlashComment ( currentSourceFile ! . text , commentPos , commentEnd ) ;
4317
4320
}
4318
4321
4319
4322
// Source Maps
@@ -4377,7 +4380,7 @@ namespace ts {
4377
4380
return ;
4378
4381
}
4379
4382
4380
- const { line : sourceLine , character : sourceCharacter } = getLineAndCharacterOfPosition ( currentSourceFile , pos ) ;
4383
+ const { line : sourceLine , character : sourceCharacter } = getLineAndCharacterOfPosition ( currentSourceFile ! , pos ) ;
4381
4384
sourceMapGenerator ! . addMapping (
4382
4385
writer . getLine ( ) ,
4383
4386
writer . getColumn ( ) ,
0 commit comments