From ea5a43a290d692337faebf044fabafe7eaebff93 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Thu, 17 Feb 2022 16:59:09 -0800 Subject: [PATCH] Cherry-pick PR #47830 into release-4.6 (#47928) Component commits: 8f0e9356c3 fix(47820): forbid extraction jsdoc Co-authored-by: Oleksandr T --- src/services/refactors/extractSymbol.ts | 4 ++-- tests/cases/fourslash/extract-jsdoc.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/extract-jsdoc.ts diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 0120f81cb02a9..9f0392f101478 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -283,7 +283,7 @@ namespace ts.refactor.extractSymbol { // Walk up starting from the the start position until we find a non-SourceFile node that subsumes the selected span. // This may fail (e.g. you select two statements in the root of a source file) - const start = cursorRequest ? getExtractableParent(startToken): getParentNodeInSpan(startToken, sourceFile, adjustedSpan); + const start = cursorRequest ? getExtractableParent(startToken) : getParentNodeInSpan(startToken, sourceFile, adjustedSpan); // Do the same for the ending position const end = cursorRequest ? start : getParentNodeInSpan(endToken, sourceFile, adjustedSpan); @@ -299,7 +299,7 @@ namespace ts.refactor.extractSymbol { return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] }; } - if (isJSDoc(start)) { + if (start.flags & NodeFlags.JSDoc) { return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractJSDoc)] }; } diff --git a/tests/cases/fourslash/extract-jsdoc.ts b/tests/cases/fourslash/extract-jsdoc.ts new file mode 100644 index 0000000000000..bc94fc8ae2792 --- /dev/null +++ b/tests/cases/fourslash/extract-jsdoc.ts @@ -0,0 +1,9 @@ +/// + +/////** +//// * /*a*//*b*/ +//// * {@link Foo} +//// */ + +goTo.select("a", "b"); +verify.not.refactorAvailableForTriggerReason("invoked", "Extract Symbol");