@@ -1329,13 +1329,17 @@ namespace ts {
1329
1329
return getTokenAtPosition ( sourceFile , declaration . members . pos - 1 , /*includeJsDocComment*/ false ) ;
1330
1330
}
1331
1331
1332
- export function getSourceFileImportLocation ( node : SourceFile ) {
1333
- // For a source file, it is possible there are detached comments we should not skip
1334
- const text = node . text ;
1335
- const textLength = text . length ;
1336
- let ranges = getLeadingCommentRanges ( text , 0 ) ;
1337
- if ( ! ranges ) return 0 ;
1332
+ export function getSourceFileImportLocation ( { text } : SourceFile ) {
1333
+ const shebang = getShebang ( text ) ;
1338
1334
let position = 0 ;
1335
+ if ( shebang !== undefined ) {
1336
+ position = shebang . length ;
1337
+ advancePastLineBreak ( ) ;
1338
+ }
1339
+
1340
+ // For a source file, it is possible there are detached comments we should not skip
1341
+ let ranges = getLeadingCommentRanges ( text , position ) ;
1342
+ if ( ! ranges ) return position ;
1339
1343
// However we should still skip a pinned comment at the top
1340
1344
if ( ranges . length && ranges [ 0 ] . kind === SyntaxKind . MultiLineCommentTrivia && isPinnedComment ( text , ranges [ 0 ] ) ) {
1341
1345
position = ranges [ 0 ] . end ;
@@ -1344,7 +1348,7 @@ namespace ts {
1344
1348
}
1345
1349
// As well as any triple slash references
1346
1350
for ( const range of ranges ) {
1347
- if ( range . kind === SyntaxKind . SingleLineCommentTrivia && isRecognizedTripleSlashComment ( node . text , range . pos , range . end ) ) {
1351
+ if ( range . kind === SyntaxKind . SingleLineCommentTrivia && isRecognizedTripleSlashComment ( text , range . pos , range . end ) ) {
1348
1352
position = range . end ;
1349
1353
advancePastLineBreak ( ) ;
1350
1354
continue ;
@@ -1354,12 +1358,12 @@ namespace ts {
1354
1358
return position ;
1355
1359
1356
1360
function advancePastLineBreak ( ) {
1357
- if ( position < textLength ) {
1361
+ if ( position < text . length ) {
1358
1362
const charCode = text . charCodeAt ( position ) ;
1359
1363
if ( isLineBreak ( charCode ) ) {
1360
1364
position ++ ;
1361
1365
1362
- if ( position < textLength && charCode === CharacterCodes . carriageReturn && text . charCodeAt ( position ) === CharacterCodes . lineFeed ) {
1366
+ if ( position < text . length && charCode === CharacterCodes . carriageReturn && text . charCodeAt ( position ) === CharacterCodes . lineFeed ) {
1363
1367
position ++ ;
1364
1368
}
1365
1369
}
0 commit comments