Skip to content

Commit 74a7588

Browse files
author
Andy
authored
extractMethod: Don't try to extract an ExpressionStatement consisting of a single token (#18450) (#18473)
* extractMethod: Don't try to extract an ExpressionStatement consisting of a single token * Move to unit test
1 parent a2c56e0 commit 74a7588

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
@@ -378,6 +378,8 @@ namespace A {
378378
"Cannot extract range containing conditional return statement."
379379
]);
380380

381+
testExtractRangeFailed("extract-method-not-for-token-expression-statement", `[#|a|]`, ["Select more than a single token."]);
382+
381383
testExtractMethod("extractMethod1",
382384
`namespace A {
383385
let x = 1;

src/services/refactors/extractMethod.ts

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

229229
function checkRootNode(node: Node): Diagnostic[] | undefined {
230-
if (isToken(node)) {
230+
if (isToken(isExpressionStatement(node) ? node.expression : node)) {
231231
return [createDiagnosticForNode(node, Messages.InsufficientSelection)];
232232
}
233233
return undefined;

0 commit comments

Comments
 (0)