* Gets the self-recursive function specialized to retrieving the targeted import/export element for the given resolution configuration
(extensions, state, cache, redirectedReference, moduleName, scope, isImports)
| 44070 | * Gets the self-recursive function specialized to retrieving the targeted import/export element for the given resolution configuration |
| 44071 | */ |
| 44072 | function getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports) { |
| 44073 | return loadModuleFromTargetImportOrExport; |
| 44074 | function loadModuleFromTargetImportOrExport(target, subpath, pattern) { |
| 44075 | if (typeof target === "string") { |
| 44076 | if (!pattern && subpath.length > 0 && !ts.endsWith(target, "/")) { |
| 44077 | if (state.traceEnabled) { |
| 44078 | trace(state.host, ts.Diagnostics.package_json_scope_0_has_invalid_type_for_target_of_specifier_1, scope.packageDirectory, moduleName); |
| 44079 | } |
| 44080 | return toSearchResult(/*value*/ undefined); |
| 44081 | } |
| 44082 | if (!ts.startsWith(target, "./")) { |
| 44083 | if (isImports && !ts.startsWith(target, "../") && !ts.startsWith(target, "/") && !ts.isRootedDiskPath(target)) { |
| 44084 | var combinedLookup = pattern ? target.replace(/\*/g, subpath) : target + subpath; |
| 44085 | var result = nodeModuleNameResolverWorker(state.features, combinedLookup, scope.packageDirectory + "/", state.compilerOptions, state.host, cache, [extensions], redirectedReference); |
| 44086 | return toSearchResult(result.resolvedModule ? { path: result.resolvedModule.resolvedFileName, extension: result.resolvedModule.extension, packageId: result.resolvedModule.packageId, originalPath: result.resolvedModule.originalPath } : undefined); |
| 44087 | } |
| 44088 | if (state.traceEnabled) { |
| 44089 | trace(state.host, ts.Diagnostics.package_json_scope_0_has_invalid_type_for_target_of_specifier_1, scope.packageDirectory, moduleName); |
| 44090 | } |
| 44091 | return toSearchResult(/*value*/ undefined); |
| 44092 | } |
| 44093 | var parts = ts.pathIsRelative(target) ? ts.getPathComponents(target).slice(1) : ts.getPathComponents(target); |
| 44094 | var partsAfterFirst = parts.slice(1); |
| 44095 | if (partsAfterFirst.indexOf("..") >= 0 || partsAfterFirst.indexOf(".") >= 0 || partsAfterFirst.indexOf("node_modules") >= 0) { |
| 44096 | if (state.traceEnabled) { |
| 44097 | trace(state.host, ts.Diagnostics.package_json_scope_0_has_invalid_type_for_target_of_specifier_1, scope.packageDirectory, moduleName); |
| 44098 | } |
| 44099 | return toSearchResult(/*value*/ undefined); |
| 44100 | } |
| 44101 | var resolvedTarget = ts.combinePaths(scope.packageDirectory, target); |
| 44102 | // TODO: Assert that `resolvedTarget` is actually within the package directory? That's what the spec says.... but I'm not sure we need |
| 44103 | // to be in the business of validating everyone's import and export map correctness. |
| 44104 | var subpathParts = ts.getPathComponents(subpath); |
| 44105 | if (subpathParts.indexOf("..") >= 0 || subpathParts.indexOf(".") >= 0 || subpathParts.indexOf("node_modules") >= 0) { |
| 44106 | if (state.traceEnabled) { |
| 44107 | trace(state.host, ts.Diagnostics.package_json_scope_0_has_invalid_type_for_target_of_specifier_1, scope.packageDirectory, moduleName); |
| 44108 | } |
| 44109 | return toSearchResult(/*value*/ undefined); |
| 44110 | } |
| 44111 | var finalPath = toAbsolutePath(pattern ? resolvedTarget.replace(/\*/g, subpath) : resolvedTarget + subpath); |
| 44112 | var inputLink = tryLoadInputFileForPath(finalPath, subpath, ts.combinePaths(scope.packageDirectory, "package.json"), isImports); |
| 44113 | if (inputLink) |
| 44114 | return inputLink; |
| 44115 | return toSearchResult(withPackageId(scope, loadJSOrExactTSFileName(extensions, finalPath, /*onlyRecordFailures*/ false, state))); |
| 44116 | } |
| 44117 | else if (typeof target === "object" && target !== null) { // eslint-disable-line no-null/no-null |
| 44118 | if (!Array.isArray(target)) { |
| 44119 | for (var _i = 0, _a = ts.getOwnKeys(target); _i < _a.length; _i++) { |
| 44120 | var key = _a[_i]; |
| 44121 | if (key === "default" || state.conditions.indexOf(key) >= 0 || isApplicableVersionedTypesKey(state.conditions, key)) { |
| 44122 | var subTarget = target[key]; |
| 44123 | var result = loadModuleFromTargetImportOrExport(subTarget, subpath, pattern); |
| 44124 | if (result) { |
| 44125 | return result; |
| 44126 | } |
| 44127 | } |
| 44128 | } |
| 44129 | return undefined; |
no outgoing calls
no test coverage detected
searching dependent graphs…