Skip to content

Commit 24e4cd9

Browse files
author
MQuy
committed
Rename isNewGroup and reuse scanner
1 parent 2c13fec commit 24e4cd9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/services/organizeImports.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ namespace ts.OrganizeImports {
8888
}
8989

9090
function groupImportsByNewlineContiguous(sourceFile: SourceFile,importDecls: ImportDeclaration[]): ImportDeclaration[][] {
91+
const scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ false, sourceFile.languageVariant);
9192
const groupImports: ImportDeclaration[][] = [];
9293
let groupIndex = 0;
9394
for (const topLevelImportDecl of importDecls) {
94-
if (isStartedNewGroup(sourceFile, topLevelImportDecl)) {
95+
if (isNewGroup(sourceFile, topLevelImportDecl, scanner)) {
9596
groupIndex++;
9697
}
9798

@@ -107,12 +108,11 @@ namespace ts.OrganizeImports {
107108

108109
// a new group is created if an import includes at least two new line
109110
// 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) {
111112
const startPos = topLevelImportDecl.getFullStart();
112113
const endPos = topLevelImportDecl.getStart();
113114

114-
const scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ false, sourceFile.languageVariant, sourceFile.text, /*onError:*/ undefined, startPos);
115-
115+
scanner.setText(sourceFile.text, startPos);
116116
let numberOfNewLines = 0;
117117
while (scanner.getTokenPos() < endPos) {
118118
const tokenKind = scanner.scan();

0 commit comments

Comments
 (0)