mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 20:37:46 -05:00
fix(48540): Extract to typedef from (invalid) type with comments in JS file causes assertion failure (#48545)
* fix(48540): Remove comments from jsdoc union type expression * fix(48540) - Remove comment for top level import and add extract typedef tests * fix(48540) - Remove comments from jsdoc's descendant * fix(48540) - Using no nested comments instead of traversing
This commit is contained in:
@@ -229,6 +229,8 @@ namespace ts.refactor {
|
||||
function doTypedefChange(changes: textChanges.ChangeTracker, file: SourceFile, name: string, info: ExtractInfo) {
|
||||
const { firstStatement, selection, typeParameters } = info;
|
||||
|
||||
setEmitFlags(selection, EmitFlags.NoComments | EmitFlags.NoNestedComments);
|
||||
|
||||
const node = factory.createJSDocTypedefTag(
|
||||
factory.createIdentifier("typedef"),
|
||||
factory.createJSDocTypeExpression(selection),
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
////type Foo = /*a*/[|{
|
||||
//// oops: string;
|
||||
//// /**
|
||||
//// *
|
||||
//// */
|
||||
////}|]/*b*/;
|
||||
|
||||
goTo.file('a.js')
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Extract type",
|
||||
actionName: "Extract to typedef",
|
||||
actionDescription: "Extract to typedef",
|
||||
newContent:
|
||||
`/**
|
||||
* @typedef {{
|
||||
oops: string;
|
||||
}} /*RENAME*/NewType
|
||||
*/
|
||||
|
||||
type Foo = NewType;`,
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
////type Foo = /*a*/[|{
|
||||
//// /**
|
||||
//// *
|
||||
//// */
|
||||
//// oops: string;
|
||||
////}|]/*b*/;
|
||||
|
||||
goTo.file('a.js')
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Extract type",
|
||||
actionName: "Extract to typedef",
|
||||
actionDescription: "Extract to typedef",
|
||||
newContent:
|
||||
`/**
|
||||
* @typedef {{
|
||||
oops: string;
|
||||
}} /*RENAME*/NewType
|
||||
*/
|
||||
|
||||
type Foo = NewType;`,
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
////type Bar = /*a*/[|string | boolean /* oops */ |]/*b*/;
|
||||
|
||||
goTo.file('a.js')
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Extract type",
|
||||
actionName: "Extract to typedef",
|
||||
actionDescription: "Extract to typedef",
|
||||
newContent:
|
||||
`/**
|
||||
* @typedef {string | boolean} /*RENAME*/NewType
|
||||
*/
|
||||
|
||||
type Bar = NewType /* oops */ ;`,
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
////type Bar = /*a*/[|string | /* oops */ boolean|]/*b*/;
|
||||
|
||||
goTo.file('a.js')
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Extract type",
|
||||
actionName: "Extract to typedef",
|
||||
actionDescription: "Extract to typedef",
|
||||
newContent:
|
||||
`/**
|
||||
* @typedef {string | boolean} /*RENAME*/NewType
|
||||
*/
|
||||
|
||||
type Bar = NewType;`,
|
||||
});
|
||||
Reference in New Issue
Block a user