Find-all-references: Don't crash on 'typeof import' (#23448)
* Find-all-references: Don't crash on 'typeof import' * Move `| ImportTypeNode` out of `AnyImportOrReExport`
This commit is contained in:
parent
391c0565d7
commit
f5101e21c3
6 changed files with 24 additions and 3 deletions
|
@ -3193,7 +3193,8 @@ namespace ts {
|
|||
export type AnyValidImportOrReExport =
|
||||
| (ImportDeclaration | ExportDeclaration) & { moduleSpecifier: StringLiteral }
|
||||
| ImportEqualsDeclaration & { moduleReference: ExternalModuleReference & { expression: StringLiteral } }
|
||||
| RequireOrImportCall;
|
||||
| RequireOrImportCall
|
||||
| ImportTypeNode & { argument: LiteralType };
|
||||
|
||||
/* @internal */
|
||||
export type RequireOrImportCall = CallExpression & { arguments: [StringLiteralLike] };
|
||||
|
|
|
@ -1710,8 +1710,10 @@ namespace ts {
|
|||
return (node.parent as ExternalModuleReference).parent as AnyValidImportOrReExport;
|
||||
case SyntaxKind.CallExpression:
|
||||
return node.parent as AnyValidImportOrReExport;
|
||||
case SyntaxKind.LiteralType:
|
||||
return cast(node.parent.parent, isImportTypeNode) as ImportTypeNode & { argument: LiteralType };
|
||||
default:
|
||||
return Debug.fail(Debug.showSyntaxKind(node));
|
||||
return Debug.fail(Debug.showSyntaxKind(node.parent));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4926,6 +4928,10 @@ namespace ts {
|
|||
return node.kind === SyntaxKind.LiteralType;
|
||||
}
|
||||
|
||||
export function isImportTypeNode(node: Node): node is ImportTypeNode {
|
||||
return node.kind === SyntaxKind.ImportType;
|
||||
}
|
||||
|
||||
// Binding patterns
|
||||
|
||||
export function isObjectBindingPattern(node: Node): node is ObjectBindingPattern {
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace ts.FindAllReferences {
|
|||
interface AmbientModuleDeclaration extends ModuleDeclaration { body?: ModuleBlock; }
|
||||
type SourceFileLike = SourceFile | AmbientModuleDeclaration;
|
||||
// Identifier for the case of `const x = require("y")`.
|
||||
type Importer = AnyImportOrReExport | Identifier;
|
||||
type Importer = AnyImportOrReExport | ImportTypeNode | Identifier;
|
||||
type ImporterOrCallExpression = Importer | CallExpression;
|
||||
|
||||
/** Returns import statements that directly reference the exporting module, and a list of files that may access the module through a namespace. */
|
||||
|
@ -215,6 +215,10 @@ namespace ts.FindAllReferences {
|
|||
return;
|
||||
}
|
||||
|
||||
if (decl.kind === SyntaxKind.ImportType) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore if there's a grammar error
|
||||
if (decl.moduleSpecifier.kind !== SyntaxKind.StringLiteral) {
|
||||
return;
|
||||
|
|
|
@ -3169,6 +3169,7 @@ declare namespace ts {
|
|||
function isIndexedAccessTypeNode(node: Node): node is IndexedAccessTypeNode;
|
||||
function isMappedTypeNode(node: Node): node is MappedTypeNode;
|
||||
function isLiteralTypeNode(node: Node): node is LiteralTypeNode;
|
||||
function isImportTypeNode(node: Node): node is ImportTypeNode;
|
||||
function isObjectBindingPattern(node: Node): node is ObjectBindingPattern;
|
||||
function isArrayBindingPattern(node: Node): node is ArrayBindingPattern;
|
||||
function isBindingElement(node: Node): node is BindingElement;
|
||||
|
|
|
@ -3169,6 +3169,7 @@ declare namespace ts {
|
|||
function isIndexedAccessTypeNode(node: Node): node is IndexedAccessTypeNode;
|
||||
function isMappedTypeNode(node: Node): node is MappedTypeNode;
|
||||
function isLiteralTypeNode(node: Node): node is LiteralTypeNode;
|
||||
function isImportTypeNode(node: Node): node is ImportTypeNode;
|
||||
function isObjectBindingPattern(node: Node): node is ObjectBindingPattern;
|
||||
function isArrayBindingPattern(node: Node): node is ArrayBindingPattern;
|
||||
function isBindingElement(node: Node): node is BindingElement;
|
||||
|
|
8
tests/cases/fourslash/findAllRefsTypeofImport.ts
Normal file
8
tests/cases/fourslash/findAllRefsTypeofImport.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////export const [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0;
|
||||
////declare const a: typeof import("./a");
|
||||
////a.[|x|];
|
||||
|
||||
verify.singleReferenceGroup("const x: 0");
|
Loading…
Reference in a new issue