Skip to content

Commit

Permalink
Cherry-pick PR #47830 into release-4.6 (#47928)
Browse files Browse the repository at this point in the history
Component commits:
8f0e935 fix(47820): forbid extraction jsdoc

Co-authored-by: Oleksandr T <oleksandr.tarasiuk@outlook.com>
  • Loading branch information
TypeScript Bot and a-tarasyuk authored Feb 18, 2022
1 parent b6ec37a commit ea5a43a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/refactors/extractSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)] };
}

Expand Down
9 changes: 9 additions & 0 deletions tests/cases/fourslash/extract-jsdoc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />

/////**
//// * /*a*//*b*/
//// * {@link Foo}
//// */

goTo.select("a", "b");
verify.not.refactorAvailableForTriggerReason("invoked", "Extract Symbol");

0 comments on commit ea5a43a

Please # to comment.