Skip to content

Commit 6e512a4

Browse files
author
Andy
authored
extractMethod: Don't try to extract an ExpressionStatement consisting of a single token (#18450)
* extractMethod: Don't try to extract an ExpressionStatement consisting of a single token * Move to unit test
1 parent 76eab54 commit 6e512a4

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/harness/unittests/extractMethods.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ function test(x: number) {
410410
"Statement or expression expected."
411411
]);
412412

413+
testExtractRangeFailed("extract-method-not-for-token-expression-statement", `[#|a|]`, ["Select more than a single token."]);
414+
413415
testExtractMethod("extractMethod1",
414416
`namespace A {
415417
let x = 1;

src/services/refactors/extractMethod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ namespace ts.refactor.extractMethod {
231231
}
232232

233233
function checkRootNode(node: Node): Diagnostic[] | undefined {
234-
if (isToken(node)) {
234+
if (isToken(isExpressionStatement(node) ? node.expression : node)) {
235235
return [createDiagnosticForNode(node, Messages.InsufficientSelection)];
236236
}
237237
return undefined;

0 commit comments

Comments
 (0)