@@ -88,10 +88,11 @@ namespace ts.OrganizeImports {
88
88
}
89
89
90
90
function groupImportsByNewlineContiguous ( sourceFile : SourceFile , importDecls : ImportDeclaration [ ] ) : ImportDeclaration [ ] [ ] {
91
+ const scanner = createScanner ( sourceFile . languageVersion , /*skipTrivia*/ false , sourceFile . languageVariant ) ;
91
92
const groupImports : ImportDeclaration [ ] [ ] = [ ] ;
92
93
let groupIndex = 0 ;
93
94
for ( const topLevelImportDecl of importDecls ) {
94
- if ( isStartedNewGroup ( sourceFile , topLevelImportDecl ) ) {
95
+ if ( isNewGroup ( sourceFile , topLevelImportDecl , scanner ) ) {
95
96
groupIndex ++ ;
96
97
}
97
98
@@ -107,12 +108,11 @@ namespace ts.OrganizeImports {
107
108
108
109
// a new group is created if an import includes at least two new line
109
110
// new line from multi-line comment doesn't count
110
- function isStartedNewGroup ( sourceFile : SourceFile , topLevelImportDecl : ImportDeclaration ) {
111
+ function isNewGroup ( sourceFile : SourceFile , topLevelImportDecl : ImportDeclaration , scanner : Scanner ) {
111
112
const startPos = topLevelImportDecl . getFullStart ( ) ;
112
113
const endPos = topLevelImportDecl . getStart ( ) ;
113
114
114
- const scanner = createScanner ( sourceFile . languageVersion , /*skipTrivia*/ false , sourceFile . languageVariant , sourceFile . text , /*onError:*/ undefined , startPos ) ;
115
-
115
+ scanner . setText ( sourceFile . text , startPos ) ;
116
116
let numberOfNewLines = 0 ;
117
117
while ( scanner . getTokenPos ( ) < endPos ) {
118
118
const tokenKind = scanner . scan ( ) ;
0 commit comments