Use custom conditions in path completions (#54332)

This commit is contained in:
Emma Hamilton 2023-06-02 09:16:50 +10:00 committed by GitHub
parent b03926ea78
commit d49a28534a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 1 deletions

View File

@ -44,6 +44,7 @@ import {
flatten,
forEachAncestorDirectory,
getBaseFileName,
getConditions,
getContextualTypeFromParent,
getDirectoryPath,
getEffectiveTypeRoots,
@ -924,7 +925,7 @@ function getCompletionEntriesForNonRelativeModules(
}
const keys = getOwnKeys(exports);
const fragmentSubpath = components.join("/") + (components.length && hasTrailingDirectorySeparator(fragment) ? "/" : "");
const conditions = mode === ModuleKind.ESNext ? ["node", "import", "types"] : ["node", "require", "types"];
const conditions = getConditions(compilerOptions, mode === ModuleKind.ESNext);
addCompletionEntriesFromPathsOrExports(
result,
fragmentSubpath,

View File

@ -0,0 +1,31 @@
/// <reference path="fourslash.ts" />
// @moduleResolution: bundler
// @Filename: /node_modules/foo/package.json
//// {
//// "name": "foo",
//// "exports": {
//// "./only-for-node": {
//// "node": "./something.js"
//// },
//// "./for-everywhere": "./other.js",
//// }
//// }
// @Filename: /node_modules/foo/something.d.ts
//// export const index = 0;
// @Filename: /node_modules/foo/other.d.ts
//// export const index = 0;
// @Filename: /index.ts
//// import { } from "foo//**/";
verify.completions({
marker: "",
isNewIdentifierLocation: true,
exact: [
{ name: "for-everywhere", kind: "script", kindModifiers: "" },
]
});

View File

@ -0,0 +1,28 @@
/// <reference path="fourslash.ts" />
// @module: nodenext
// @customConditions: custom-condition
// @Filename: /node_modules/foo/package.json
//// {
//// "name": "foo",
//// "exports": {
//// "./only-with-custom-conditions": {
//// "custom-condition": "./something.js"
//// },
//// }
//// }
// @Filename: /node_modules/foo/something.d.ts
//// export const index = 0;
// @Filename: /index.ts
//// import { } from "foo//**/";
verify.completions({
marker: "",
isNewIdentifierLocation: true,
exact: [
{ name: "only-with-custom-conditions", kind: "script", kindModifiers: "" },
]
});