@@ -100,27 +100,33 @@ export function parseScriptSetupRanges(
100100 let importSectionEndOffset = 0 ;
101101
102102 ts . forEachChild ( ast , node => {
103- const isTypeExport =
104- ( ts . isTypeAliasDeclaration ( node ) || ts . isInterfaceDeclaration ( node ) )
105- && node . modifiers ?. some ( mod => mod . kind === ts . SyntaxKind . ExportKeyword ) ;
106103 if (
107- ! foundNonImportExportNode
108- && ! ts . isImportDeclaration ( node )
109- && ! isTypeExport
110- && ! ts . isEmptyStatement ( node )
104+ foundNonImportExportNode
105+ || ts . isImportDeclaration ( node )
106+ || ts . isExportDeclaration ( node )
107+ || ts . isEmptyStatement ( node )
111108 // fix https://github.com/vuejs/language-tools/issues/1223
112- && ! ts . isImportEqualsDeclaration ( node )
109+ || ts . isImportEqualsDeclaration ( node )
113110 ) {
114- const commentRanges = ts . getLeadingCommentRanges ( text , node . pos ) ;
115- if ( commentRanges ?. length ) {
116- const commentRange = commentRanges . sort ( ( a , b ) => a . pos - b . pos ) [ 0 ] ;
117- importSectionEndOffset = commentRange . pos ;
118- }
119- else {
120- importSectionEndOffset = getStartEnd ( ts , node , ast ) . start ;
121- }
122- foundNonImportExportNode = true ;
111+ return ;
112+ }
113+
114+ if (
115+ ( ts . isTypeAliasDeclaration ( node ) || ts . isInterfaceDeclaration ( node ) )
116+ && node . modifiers ?. some ( mod => mod . kind === ts . SyntaxKind . ExportKeyword )
117+ ) {
118+ return ;
119+ }
120+
121+ const commentRanges = ts . getLeadingCommentRanges ( text , node . pos ) ;
122+ if ( commentRanges ?. length ) {
123+ const commentRange = commentRanges . sort ( ( a , b ) => a . pos - b . pos ) [ 0 ] ;
124+ importSectionEndOffset = commentRange . pos ;
125+ }
126+ else {
127+ importSectionEndOffset = getStartEnd ( ts , node , ast ) . start ;
123128 }
129+ foundNonImportExportNode = true ;
124130 } ) ;
125131 ts . forEachChild ( ast , node => visitNode ( node , [ ast ] ) ) ;
126132
0 commit comments