Fixed crash on authored import type nodes when serializing for declarations (#59160)

This commit is contained in:
Mateusz Burzyński 2024-07-18 01:41:47 +02:00 коммит произвёл GitHub
Родитель 95a968ce6b
Коммит 45062406e4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 142 добавлений и 0 удалений

Просмотреть файл

@ -899,6 +899,12 @@ export function tryGetAutoImportableReferenceFromTypeNode(importTypeNode: TypeNo
if (isLiteralImportTypeNode(node) && node.qualifier) {
// Symbol for the left-most thing after the dot
const firstIdentifier = getFirstIdentifier(node.qualifier);
if (!firstIdentifier.symbol) {
// if symbol is missing then this doesn't come from a synthesized import type node
// it has to be an import type node authored by the user and thus it has to be valid
// it can't refer to reserved internal symbol names and such
return visitEachChild(node, visit, /*context*/ undefined);
}
const name = getNameForExportedSymbol(firstIdentifier.symbol, scriptTarget);
const qualifier = name !== firstIdentifier.text
? replaceFirstIdentifierOfEntityName(node.qualifier, factory.createIdentifier(name))

Просмотреть файл

@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />
// @module: nodenext
// @Filename: /generation.d.ts
//// export type GenerationConfigType = { max_length?: number };
// @FileName: /index.d.ts
//// export declare class PreTrainedModel {
//// _get_generation_config(
//// param: import("./generation.js").GenerationConfigType,
//// ): import("./generation.js").GenerationConfigType;
//// }
////
//// export declare class BlenderbotSmallPreTrainedModel extends PreTrainedModel {
//// /*1*/
//// }
verify.completions({
marker: "1",
includes: [
{
name: "_get_generation_config",
insertText: `_get_generation_config(param: import("./generation.js").GenerationConfigType): import("./generation.js").GenerationConfigType;`,
filterText: "_get_generation_config",
hasAction: undefined,
},
],
preferences: {
includeCompletionsWithClassMemberSnippets: true,
includeCompletionsWithInsertText: true,
},
isNewIdentifierLocation: true,
});

Просмотреть файл

@ -0,0 +1,31 @@
/// <reference path="fourslash.ts" />
// @module: nodenext
// @FileName: /index.d.ts
//// export declare class Cls {
//// method(
//// param: import("./doesntexist.js").Foo,
//// ): import("./doesntexist.js").Foo;
//// }
////
//// export declare class Derived extends Cls {
//// /*1*/
//// }
verify.completions({
marker: "1",
includes: [
{
name: "method",
insertText: `method(param: import("./doesntexist.js").Foo);`,
filterText: "method",
hasAction: undefined,
},
],
preferences: {
includeCompletionsWithClassMemberSnippets: true,
includeCompletionsWithInsertText: true,
},
isNewIdentifierLocation: true,
});

Просмотреть файл

@ -0,0 +1,37 @@
/// <reference path="fourslash.ts" />
// @module: nodenext
// @FileName: /other/foo.d.ts
//// export declare type Bar = { baz: string };
// @FileName: /other/cls.d.ts
//// export declare class Cls {
//// method(
//// param: import("./foo.js").Bar,
//// ): import("./foo.js").Bar;
//// }
// @FileName: /index.d.ts
//// import { Cls } from "./other/cls.js";
////
//// export declare class Derived extends Cls {
//// /*1*/
//// }
verify.completions({
marker: "1",
includes: [
{
name: "method",
insertText: `method(param: import("./other/foo.js").Bar): import("./other/foo.js").Bar;`,
filterText: "method",
hasAction: undefined,
},
],
preferences: {
includeCompletionsWithClassMemberSnippets: true,
includeCompletionsWithInsertText: true,
},
isNewIdentifierLocation: true,
});

Просмотреть файл

@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />
// @module: nodenext
// @FileName: /other/cls.d.ts
//// export declare class Cls {
//// method(
//// param: import("./doesntexist.js").Foo,
//// ): import("./doesntexist.js").Foo;
//// }
// @FileName: /index.d.ts
//// import { Cls } from "./other/cls.js";
////
//// export declare class Derived extends Cls {
//// /*1*/
//// }
verify.completions({
marker: "1",
includes: [
{
name: "method",
insertText: `method(param: import("./doesntexist.js").Foo);`,
filterText: "method",
hasAction: undefined,
},
],
preferences: {
includeCompletionsWithClassMemberSnippets: true,
includeCompletionsWithInsertText: true,
},
isNewIdentifierLocation: true,
});