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
This commit is contained in:
Andy 2017-09-14 11:35:38 -07:00 committed by GitHub
parent a2c56e0f9d
commit 74a7588f4d
2 changed files with 3 additions and 1 deletions

View File

@ -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;

View File

@ -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;