Skip to content

Commit ccb9d5e

Browse files
committed
Fixed crash on authored import type nodes when serializing for declarations
1 parent 3163fe7 commit ccb9d5e

5 files changed

+144
-2
lines changed

src/services/codefixes/helpers.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,14 @@ export function tryGetAutoImportableReferenceFromTypeNode(importTypeNode: TypeNo
899899
if (isLiteralImportTypeNode(node) && node.qualifier) {
900900
// Symbol for the left-most thing after the dot
901901
const firstIdentifier = getFirstIdentifier(node.qualifier);
902-
const name = getNameForExportedSymbol(firstIdentifier.symbol, scriptTarget);
903-
const qualifier = name !== firstIdentifier.text
902+
if (!firstIdentifier.symbol) {
903+
// if symbol is missing then this doesn't come from a synthesized import type node
904+
// it has to be an import type node authored by the user and thus it has to be valid
905+
// it can't refer to reserved internal symbol names and such
906+
return visitEachChild(node, visit, /*context*/ undefined);
907+
}
908+
const name = firstIdentifier.symbol && getNameForExportedSymbol(firstIdentifier.symbol, scriptTarget);
909+
const qualifier = name && name !== firstIdentifier.text
904910
? replaceFirstIdentifierOfEntityName(node.qualifier, factory.createIdentifier(name))
905911
: node.qualifier;
906912

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @module: nodenext
4+
5+
// @Filename: /generation.d.ts
6+
//// export type GenerationConfigType = { max_length?: number };
7+
8+
// @FileName: /index.d.ts
9+
//// export declare class PreTrainedModel {
10+
//// _get_generation_config(
11+
//// param: import("./generation.js").GenerationConfigType,
12+
//// ): import("./generation.js").GenerationConfigType;
13+
//// }
14+
////
15+
//// export declare class BlenderbotSmallPreTrainedModel extends PreTrainedModel {
16+
//// /*1*/
17+
//// }
18+
19+
verify.completions({
20+
marker: "1",
21+
includes: [
22+
{
23+
name: "_get_generation_config",
24+
insertText: `_get_generation_config(param: import("./generation.js").GenerationConfigType): import("./generation.js").GenerationConfigType;`,
25+
filterText: "_get_generation_config",
26+
hasAction: undefined,
27+
},
28+
],
29+
preferences: {
30+
includeCompletionsWithClassMemberSnippets: true,
31+
includeCompletionsWithInsertText: true,
32+
},
33+
isNewIdentifierLocation: true,
34+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @module: nodenext
4+
5+
// @FileName: /index.d.ts
6+
//// export declare class Cls {
7+
//// method(
8+
//// param: import("./doesntexist.js").Foo,
9+
//// ): import("./doesntexist.js").Foo;
10+
//// }
11+
////
12+
//// export declare class Derived extends Cls {
13+
//// /*1*/
14+
//// }
15+
16+
verify.completions({
17+
marker: "1",
18+
includes: [
19+
{
20+
name: "method",
21+
insertText: `method(param: import("./doesntexist.js").Foo);`,
22+
filterText: "method",
23+
hasAction: undefined,
24+
},
25+
],
26+
preferences: {
27+
includeCompletionsWithClassMemberSnippets: true,
28+
includeCompletionsWithInsertText: true,
29+
},
30+
isNewIdentifierLocation: true,
31+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @module: nodenext
4+
5+
// @FileName: /other/foo.d.ts
6+
//// export declare type Bar = { baz: string };
7+
8+
// @FileName: /other/cls.d.ts
9+
//// export declare class Cls {
10+
//// method(
11+
//// param: import("./foo.js").Bar,
12+
//// ): import("./foo.js").Bar;
13+
//// }
14+
15+
// @FileName: /index.d.ts
16+
//// import { Cls } from "./other/cls.js";
17+
////
18+
//// export declare class Derived extends Cls {
19+
//// /*1*/
20+
//// }
21+
22+
verify.completions({
23+
marker: "1",
24+
includes: [
25+
{
26+
name: "method",
27+
insertText: `method(param: import("./other/foo.js").Bar): import("./other/foo.js").Bar;`,
28+
filterText: "method",
29+
hasAction: undefined,
30+
},
31+
],
32+
preferences: {
33+
includeCompletionsWithClassMemberSnippets: true,
34+
includeCompletionsWithInsertText: true,
35+
},
36+
isNewIdentifierLocation: true,
37+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @module: nodenext
4+
5+
// @FileName: /other/cls.d.ts
6+
//// export declare class Cls {
7+
//// method(
8+
//// param: import("./doesntexist.js").Foo,
9+
//// ): import("./doesntexist.js").Foo;
10+
//// }
11+
12+
// @FileName: /index.d.ts
13+
//// import { Cls } from "./other/cls.js";
14+
////
15+
//// export declare class Derived extends Cls {
16+
//// /*1*/
17+
//// }
18+
19+
verify.completions({
20+
marker: "1",
21+
includes: [
22+
{
23+
name: "method",
24+
insertText: `method(param: import("./doesntexist.js").Foo);`,
25+
filterText: "method",
26+
hasAction: undefined,
27+
},
28+
],
29+
preferences: {
30+
includeCompletionsWithClassMemberSnippets: true,
31+
includeCompletionsWithInsertText: true,
32+
},
33+
isNewIdentifierLocation: true,
34+
});

0 commit comments

Comments
 (0)