fix(33325): allow extract refactoring on selected statement without trailing semicolon (#45765)

This commit is contained in:
Oleksandr T
2021-11-05 19:00:31 +02:00
committed by GitHub
parent 4fca1e1fcd
commit 2d4b243195
3 changed files with 24 additions and 4 deletions

View File

@@ -364,10 +364,11 @@ namespace ts.refactor.extractSymbol {
return node.expression;
}
}
else if (isVariableStatement(node)) {
else if (isVariableStatement(node) || isVariableDeclarationList(node)) {
const declarations = isVariableStatement(node) ? node.declarationList.declarations : node.declarations;
let numInitializers = 0;
let lastInitializer: Expression | undefined;
for (const declaration of node.declarationList.declarations) {
for (const declaration of declarations) {
if (declaration.initializer) {
numInitializers++;
lastInitializer = declaration.initializer;
@@ -383,7 +384,6 @@ namespace ts.refactor.extractSymbol {
return node.initializer;
}
}
return node;
}

View File

@@ -191,7 +191,7 @@ namespace ts {
testExtractRange("extractRange28", `[#|return [$|1|];|]`);
// For statements
testExtractRange("extractRange29", `for ([#|var i = 1|]; i < 2; i++) {}`);
testExtractRange("extractRange29", `for ([#|var i = [$|1|]|]; i < 2; i++) {}`);
testExtractRange("extractRange30", `for (var i = [#|[$|1|]|]; i < 2; i++) {}`);
});