Skip to content

Commit

Permalink
🤖 Pick PR #59160 (Fixed crash on authored import type...) into releas…
Browse files Browse the repository at this point in the history
…e-5.5 (#59226)

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
  • Loading branch information
TypeScript Bot and Andarist committed Jul 17, 2024
1 parent f35206d commit a44e2d9
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/services/codefixes/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,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))
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);`,
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,
});

0 comments on commit a44e2d9

Please sign in to comment.