Fix explainFiles on files under nodenext with types references (#46367)

* Fix explainFiles on files under nodenext with types references

* Fix explainFiles crash on module nodenext
This commit is contained in:
Wesley Wigham 2021-10-14 17:00:55 -07:00 committed by GitHub
parent d16d7779a8
commit 2c7b13b830
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 1 deletions

View file

@ -685,7 +685,7 @@ namespace ts {
break;
case FileIncludeKind.TypeReferenceDirective:
({ pos, end } = file.typeReferenceDirectives[index]);
packageId = file.resolvedTypeReferenceDirectiveNames?.get(toFileNameLowerCase(file.typeReferenceDirectives[index].fileName), getModeForResolutionAtIndex(file, index))?.packageId;
packageId = file.resolvedTypeReferenceDirectiveNames?.get(toFileNameLowerCase(file.typeReferenceDirectives[index].fileName), file.impliedNodeFormat)?.packageId;
break;
case FileIncludeKind.LibReferenceDirective:
({ pos, end } = file.libReferenceDirectives[index]);

View file

@ -0,0 +1,37 @@
// === /node_modules/react-hook-form/dist/index.d.ts ===
// /// <reference types="[|react|]/*FIND ALL REFS*/" />
// export type Foo = React.Whatever;
// export function useForm(): any;
[
{
"definition": {
"containerKind": "",
"containerName": "",
"fileName": "/node_modules/react-hook-form/dist/index.d.ts",
"kind": "string",
"name": "react",
"textSpan": {
"start": 22,
"length": 5
},
"displayParts": [
{
"text": "\"react\"",
"kind": "stringLiteral"
}
]
},
"references": [
{
"textSpan": {
"start": 22,
"length": 5
},
"fileName": "/node_modules/react-hook-form/dist/index.d.ts",
"isWriteAccess": false,
"isDefinition": false
}
]
}
]

View file

@ -0,0 +1,45 @@
/// <reference path="fourslash.ts" />
// @Filename: /node_modules/react-hook-form/package.json
//// {
//// "name": "react-hook-form",
//// "main": "dist/index.cjs.js",
//// "module": "dist/index.esm.js",
//// "types": "dist/index.d.ts",
//// "exports": {
//// "./package.json": "./package.json",
//// ".": {
//// "import": "./dist/index.esm.js",
//// "require": "./dist/index.cjs.js",
//// "types": "./dist/index.d.ts"
//// }
//// }
//// }
// @Filename: /node_modules/react-hook-form/dist/index.cjs.js
//// module.exports = {};
// @Filename: /node_modules/react-hook-form/dist/index.esm.js
//// export function useForm() {}
// @Filename: /node_modules/react-hook-form/dist/index.d.ts
//// /// <reference types="react/**/" />
//// export type Foo = React.Whatever;
//// export function useForm(): any;
// @Filename: /node_modules/react/index.d.ts
//// declare namespace JSX {}
//// declare namespace React { export interface Whatever {} }
// @Filename: /tsconfig.json
//// {
//// "compilerOptions": {
//// "module": "nodenext",
//// "explainFiles": true
//// }
//// "files": ["./index.ts"]
//// }
// @Filename: /index.ts
//// import { useForm } from "react-hook-form";
verify.baselineFindAllReferences("");