@@ -1329,13 +1329,17 @@ namespace ts {
13291329 return getTokenAtPosition ( sourceFile , declaration . members . pos - 1 , /*includeJsDocComment*/ false ) ;
13301330 }
13311331
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 ) ;
13381334 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 ;
13391343 // However we should still skip a pinned comment at the top
13401344 if ( ranges . length && ranges [ 0 ] . kind === SyntaxKind . MultiLineCommentTrivia && isPinnedComment ( text , ranges [ 0 ] ) ) {
13411345 position = ranges [ 0 ] . end ;
@@ -1344,7 +1348,7 @@ namespace ts {
13441348 }
13451349 // As well as any triple slash references
13461350 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 ) ) {
13481352 position = range . end ;
13491353 advancePastLineBreak ( ) ;
13501354 continue ;
@@ -1354,12 +1358,12 @@ namespace ts {
13541358 return position ;
13551359
13561360 function advancePastLineBreak ( ) {
1357- if ( position < textLength ) {
1361+ if ( position < text . length ) {
13581362 const charCode = text . charCodeAt ( position ) ;
13591363 if ( isLineBreak ( charCode ) ) {
13601364 position ++ ;
13611365
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 ) {
13631367 position ++ ;
13641368 }
13651369 }
0 commit comments