@@ -3333,12 +3333,14 @@ ${code}
3333
3333
const ranges : Range [ ] = [ ] ;
3334
3334
3335
3335
// Stuff related to the subfile we're parsing
3336
- let currentFileContent : string ;
3336
+ let currentFileContent : string | undefined ;
3337
3337
let currentFileName = fileName ;
3338
3338
let currentFileSymlinks : string [ ] | undefined ;
3339
3339
let currentFileOptions : { [ s : string ] : string } = { } ;
3340
3340
3341
3341
function nextFile ( ) {
3342
+ if ( currentFileContent === undefined ) return ;
3343
+
3342
3344
const file = parseFileContent ( currentFileContent , currentFileName , markerPositions , markers , ranges ) ;
3343
3345
file . fileOptions = currentFileOptions ;
3344
3346
file . symlinks = currentFileSymlinks ;
@@ -3353,25 +3355,13 @@ ${code}
3353
3355
}
3354
3356
3355
3357
for ( let line of lines ) {
3356
- const lineLength = line . length ;
3357
-
3358
- if ( lineLength > 0 && line . charAt ( lineLength - 1 ) === "\r" ) {
3359
- line = line . substr ( 0 , lineLength - 1 ) ;
3358
+ if ( line . length > 0 && line . charAt ( line . length - 1 ) === "\r" ) {
3359
+ line = line . substr ( 0 , line . length - 1 ) ;
3360
3360
}
3361
3361
3362
3362
if ( line . substr ( 0 , 4 ) === "////" ) {
3363
- // Subfile content line
3364
-
3365
- // Append to the current subfile content, inserting a newline needed
3366
- if ( currentFileContent === undefined ) {
3367
- currentFileContent = "" ;
3368
- }
3369
- else {
3370
- // End-of-line
3371
- currentFileContent = currentFileContent + "\n" ;
3372
- }
3373
-
3374
- currentFileContent = currentFileContent + line . substr ( 4 ) ;
3363
+ const text = line . substr ( 4 ) ;
3364
+ currentFileContent = currentFileContent === undefined ? text : currentFileContent + "\n" + text ;
3375
3365
}
3376
3366
else if ( line . substr ( 0 , 2 ) === "//" ) {
3377
3367
// Comment line, check for global/file @options and record them
@@ -3389,10 +3379,7 @@ ${code}
3389
3379
switch ( key ) {
3390
3380
case MetadataOptionNames . fileName :
3391
3381
// Found an @FileName directive, if this is not the first then create a new subfile
3392
- if ( currentFileContent ) {
3393
- nextFile ( ) ;
3394
- }
3395
-
3382
+ nextFile ( ) ;
3396
3383
currentFileName = ts . isRootedDiskPath ( value ) ? value : basePath + "/" + value ;
3397
3384
currentFileOptions [ key ] = value ;
3398
3385
break ;
@@ -3406,15 +3393,11 @@ ${code}
3406
3393
}
3407
3394
}
3408
3395
}
3409
- else if ( line === "" || lineLength === 0 ) {
3410
- // Previously blank lines between fourslash content caused it to be considered as 2 files,
3411
- // Remove this behavior since it just causes errors now
3412
- }
3413
- else {
3414
- // Empty line or code line, terminate current subfile if there is one
3415
- if ( currentFileContent ) {
3416
- nextFile ( ) ;
3417
- }
3396
+ // Previously blank lines between fourslash content caused it to be considered as 2 files,
3397
+ // Remove this behavior since it just causes errors now
3398
+ else if ( line !== "" ) {
3399
+ // Code line, terminate current subfile if there is one
3400
+ nextFile ( ) ;
3418
3401
}
3419
3402
}
3420
3403
0 commit comments