Fixed crash when finding all references when JSDocImportTags are involved (#59207)

This commit is contained in:
Mateusz Burzyński 2024-07-09 22:59:54 +02:00 committed by GitHub
parent c9dd98ee7f
commit 8d84a68776
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 787 additions and 2 deletions

View File

@ -787,10 +787,9 @@ function getContainingModuleSymbol(importer: Importer, checker: TypeChecker): Sy
}
function getSourceFileLikeForImportDeclaration(node: ImporterOrCallExpression): SourceFileLike {
if (node.kind === SyntaxKind.CallExpression) {
if (node.kind === SyntaxKind.CallExpression || node.kind === SyntaxKind.JSDocImportTag) {
return node.getSourceFile();
}
const { parent } = node;
if (parent.kind === SyntaxKind.SourceFile) {
return parent as SourceFile;

View File

@ -0,0 +1,185 @@
// === findAllReferences ===
// === /player.js ===
// <|import [|{| defId: 0, isWriteAccess: true |}Component|] from './component.js';|>
//
// /**
// * @extends [|{| defId: 0 |}Component|]/*FIND ALL REFS*/
// */
// export class Player extends [|{| defId: 0 |}Component|] {}
// === /component.js ===
// <|export default class [|{| defId: 1, isWriteAccess: true |}Component|] {
// constructor() {
// this.id_ = Math.random();
// }
// id() {
// return this.id_;
// }
// }|>
// === /spatial-navigation.js ===
// /** <|@import [|{| defId: 2, isWriteAccess: true |}Component|] from './component.js'|> */
//
// export class SpatialNavigation {
// /**
// * @param {[|{| defId: 2 |}Component|]} component
// */
// add(component) {}
// }
// === Definitions ===
// === /player.js ===
// <|import [|{| defId: 0 |}Component|] from './component.js';|>
//
// /**
// * @extends Component/*FIND ALL REFS*/
// */
// export class Player extends Component {}
// === /component.js ===
// <|export default class [|{| defId: 1 |}Component|] {
// constructor() {
// this.id_ = Math.random();
// }
// id() {
// return this.id_;
// }
// }|>
// === /spatial-navigation.js ===
// /** <|@import [|{| defId: 2 |}Component|] from './component.js'|> */
//
// export class SpatialNavigation {
// /**
// --- (line: 5) skipped ---
// === Details ===
[
{
"defId": 0,
"containerKind": "",
"containerName": "",
"kind": "alias",
"name": "(alias) class Component\nimport Component",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "alias",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "class",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Component",
"kind": "aliasName"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": "import",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Component",
"kind": "aliasName"
}
]
},
{
"defId": 1,
"containerKind": "",
"containerName": "",
"kind": "class",
"name": "class Component",
"displayParts": [
{
"text": "class",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Component",
"kind": "className"
}
]
},
{
"defId": 2,
"containerKind": "",
"containerName": "",
"kind": "alias",
"name": "(alias) class Component\nimport Component",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "alias",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "class",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Component",
"kind": "aliasName"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": "import",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Component",
"kind": "aliasName"
}
]
}
]

View File

@ -0,0 +1,185 @@
// === findAllReferences ===
// === /player.js ===
// <|import { [|{| defId: 0, isWriteAccess: true |}Component|] } from './component.js';|>
//
// /**
// * @extends [|{| defId: 0 |}Component|]/*FIND ALL REFS*/
// */
// export class Player extends [|{| defId: 0 |}Component|] {}
// === /component.js ===
// <|export class [|{| defId: 1, isWriteAccess: true |}Component|] {
// constructor() {
// this.id_ = Math.random();
// }
// id() {
// return this.id_;
// }
// }|>
// === /spatial-navigation.js ===
// /** <|@import { [|{| defId: 2, isWriteAccess: true |}Component|] } from './component.js'|> */
//
// export class SpatialNavigation {
// /**
// * @param {[|{| defId: 2 |}Component|]} component
// */
// add(component) {}
// }
// === Definitions ===
// === /player.js ===
// <|import { [|{| defId: 0 |}Component|] } from './component.js';|>
//
// /**
// * @extends Component/*FIND ALL REFS*/
// */
// export class Player extends Component {}
// === /component.js ===
// <|export class [|{| defId: 1 |}Component|] {
// constructor() {
// this.id_ = Math.random();
// }
// id() {
// return this.id_;
// }
// }|>
// === /spatial-navigation.js ===
// /** <|@import { [|{| defId: 2 |}Component|] } from './component.js'|> */
//
// export class SpatialNavigation {
// /**
// --- (line: 5) skipped ---
// === Details ===
[
{
"defId": 0,
"containerKind": "",
"containerName": "",
"kind": "alias",
"name": "(alias) class Component\nimport Component",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "alias",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "class",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Component",
"kind": "aliasName"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": "import",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Component",
"kind": "aliasName"
}
]
},
{
"defId": 1,
"containerKind": "",
"containerName": "",
"kind": "class",
"name": "class Component",
"displayParts": [
{
"text": "class",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Component",
"kind": "className"
}
]
},
{
"defId": 2,
"containerKind": "",
"containerName": "",
"kind": "alias",
"name": "(alias) class Component\nimport Component",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "alias",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "class",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Component",
"kind": "aliasName"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": "import",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Component",
"kind": "aliasName"
}
]
}
]

View File

@ -0,0 +1,41 @@
// === findAllReferences ===
// === /player.js ===
// <|import * as [|{| isWriteAccess: true |}C|] from './component.js';|>
//
// /**
// * @extends [|C|]/*FIND ALL REFS*/.Component
// */
// export class Player extends Component {}
// === Definitions ===
// === /player.js ===
// <|import * as [|C|] from './component.js';|>
//
// /**
// * @extends C/*FIND ALL REFS*/.Component
// */
// export class Player extends Component {}
// === Details ===
[
{
"containerKind": "",
"containerName": "",
"kind": "alias",
"name": "import C",
"displayParts": [
{
"text": "import",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "C",
"kind": "aliasName"
}
]
}
]

View File

@ -0,0 +1,265 @@
// === findAllReferences ===
// === /a.js ===
// <|export default function /*FIND ALL REFS*/[|{| defId: 0, isWriteAccess: true, isDefinition: true |}a|]() {}|>
// === /b.js ===
// /** <|@import [|{| defId: 1, isWriteAccess: true |}a|], * as ns from "./a"|> */
// === Definitions ===
// === /a.js ===
// <|export default function /*FIND ALL REFS*/[|{| defId: 0 |}a|]() {}|>
// === /b.js ===
// /** <|@import [|{| defId: 1 |}a|], * as ns from "./a"|> */
// === Details ===
[
{
"defId": 0,
"containerKind": "",
"containerName": "",
"kind": "function",
"name": "function a(): void",
"displayParts": [
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "a",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
]
},
{
"defId": 1,
"containerKind": "",
"containerName": "",
"kind": "alias",
"name": "(alias) function a(): void\nimport a",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "alias",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "a",
"kind": "aliasName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": "import",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "a",
"kind": "aliasName"
}
]
}
]
// === findAllReferences ===
// === /b.js ===
// /** <|@import /*FIND ALL REFS*/[|{| defId: 0, isWriteAccess: true, isDefinition: true |}a|], * as ns from "./a"|> */
// === /a.js ===
// <|export default function [|{| defId: 1, isWriteAccess: true |}a|]() {}|>
// === Definitions ===
// === /b.js ===
// /** <|@import /*FIND ALL REFS*/[|{| defId: 0 |}a|], * as ns from "./a"|> */
// === /a.js ===
// <|export default function [|{| defId: 1 |}a|]() {}|>
// === Details ===
[
{
"defId": 0,
"containerKind": "",
"containerName": "",
"kind": "alias",
"name": "(alias) function a(): void\nimport a",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "alias",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "a",
"kind": "aliasName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
},
{
"text": "\n",
"kind": "lineBreak"
},
{
"text": "import",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "a",
"kind": "aliasName"
}
]
},
{
"defId": 1,
"containerKind": "",
"containerName": "",
"kind": "function",
"name": "function a(): void",
"displayParts": [
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "a",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
]
}
]

View File

@ -0,0 +1,33 @@
/// <reference path="fourslash.ts" />
// @checkJs: true
// @Filename: /component.js
//// export default class Component {
//// constructor() {
//// this.id_ = Math.random();
//// }
//// id() {
//// return this.id_;
//// }
//// }
// @Filename: /spatial-navigation.js
//// /** @import Component from './component.js' */
////
//// export class SpatialNavigation {
//// /**
//// * @param {Component} component
//// */
//// add(component) {}
//// }
// @Filename: /player.js
//// import Component from './component.js';
////
//// /**
//// * @extends Component/*1*/
//// */
//// export class Player extends Component {}
verify.baselineFindAllReferences("1");

View File

@ -0,0 +1,33 @@
/// <reference path="fourslash.ts" />
// @checkJs: true
// @Filename: /component.js
//// export class Component {
//// constructor() {
//// this.id_ = Math.random();
//// }
//// id() {
//// return this.id_;
//// }
//// }
// @Filename: /spatial-navigation.js
//// /** @import { Component } from './component.js' */
////
//// export class SpatialNavigation {
//// /**
//// * @param {Component} component
//// */
//// add(component) {}
//// }
// @Filename: /player.js
//// import { Component } from './component.js';
////
//// /**
//// * @extends Component/*1*/
//// */
//// export class Player extends Component {}
verify.baselineFindAllReferences("1");

View File

@ -0,0 +1,33 @@
/// <reference path="fourslash.ts" />
// @checkJs: true
// @Filename: /component.js
//// export class Component {
//// constructor() {
//// this.id_ = Math.random();
//// }
//// id() {
//// return this.id_;
//// }
//// }
// @Filename: /spatial-navigation.js
//// /** @import * as C from './component.js' */
////
//// export class SpatialNavigation {
//// /**
//// * @param {C.Component} component
//// */
//// add(component) {}
//// }
// @Filename: /player.js
//// import * as C from './component.js';
////
//// /**
//// * @extends C/*1*/.Component
//// */
//// export class Player extends Component {}
verify.baselineFindAllReferences("1");

View File

@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />
// @checkJs: true
// @Filename: /a.js
//// export default function /*0*/a() {}
// @Filename: /b.js
//// /** @import /*1*/a, * as ns from "./a" */
verify.baselineFindAllReferences("0", "1");