Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/services/codefixes/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Value-space identifiers get their .symbol in the binder but type-level identifiers in import type nodes don't.

Alternatively, this could be fixed in visitExistingNodeTreeSymbolsWorker but it's more tricky there.

// 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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
});
Original file line number Diff line number Diff line change
@@ -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);`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird but not anything new. Return types nodes with errors are omitted based on NodeBuilderFlags.SuppressAnyReturnType. No mechanism like this for parameters is used.

filterText: "method",
hasAction: undefined,
},
],
preferences: {
includeCompletionsWithClassMemberSnippets: true,
includeCompletionsWithInsertText: true,
},
isNewIdentifierLocation: true,
});
Original file line number Diff line number Diff line change
@@ -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,
});
Original file line number Diff line number Diff line change
@@ -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,
});