From 74a7588f4da5db2ccb39b451eba158e06cd88a6b Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 14 Sep 2017 11:35:38 -0700 Subject: [PATCH] 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 --- src/harness/unittests/extractMethods.ts | 2 ++ src/services/refactors/extractMethod.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/harness/unittests/extractMethods.ts b/src/harness/unittests/extractMethods.ts index c9f3fe358bb..28f45c6997b 100644 --- a/src/harness/unittests/extractMethods.ts +++ b/src/harness/unittests/extractMethods.ts @@ -378,6 +378,8 @@ namespace A { "Cannot extract range containing conditional return statement." ]); + testExtractRangeFailed("extract-method-not-for-token-expression-statement", `[#|a|]`, ["Select more than a single token."]); + testExtractMethod("extractMethod1", `namespace A { let x = 1; diff --git a/src/services/refactors/extractMethod.ts b/src/services/refactors/extractMethod.ts index 287d6a8d7de..505f514b04c 100644 --- a/src/services/refactors/extractMethod.ts +++ b/src/services/refactors/extractMethod.ts @@ -227,7 +227,7 @@ namespace ts.refactor.extractMethod { } function checkRootNode(node: Node): Diagnostic[] | undefined { - if (isToken(node)) { + if (isToken(isExpressionStatement(node) ? node.expression : node)) { return [createDiagnosticForNode(node, Messages.InsufficientSelection)]; } return undefined;