mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 11:35:42 -06:00
Merge pull request #11704 from Microsoft/refactor_module_resolution
Return both ts and js results from module resolution
This commit is contained in:
commit
b5ba3152ff
@ -1374,7 +1374,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
const resolvedModule = getResolvedModule(getSourceFileOfNode(location), moduleReference);
|
||||
const sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName);
|
||||
const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule);
|
||||
const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName);
|
||||
if (sourceFile) {
|
||||
if (sourceFile.symbol) {
|
||||
// merged symbol is module declaration symbol combined with all augmentations
|
||||
@ -1396,13 +1397,18 @@ namespace ts {
|
||||
|
||||
if (moduleNotFoundError) {
|
||||
// report errors only if it was requested
|
||||
const tsExtension = tryExtractTypeScriptExtension(moduleName);
|
||||
if (tsExtension) {
|
||||
const diag = Diagnostics.An_import_path_cannot_end_with_a_0_extension_Consider_importing_1_instead;
|
||||
error(errorNode, diag, tsExtension, removeExtension(moduleName, tsExtension));
|
||||
if (resolutionDiagnostic) {
|
||||
error(errorNode, resolutionDiagnostic, moduleName, resolvedModule.resolvedFileName);
|
||||
}
|
||||
else {
|
||||
error(errorNode, moduleNotFoundError, moduleName);
|
||||
const tsExtension = tryExtractTypeScriptExtension(moduleName);
|
||||
if (tsExtension) {
|
||||
const diag = Diagnostics.An_import_path_cannot_end_with_a_0_extension_Consider_importing_1_instead;
|
||||
error(errorNode, diag, tsExtension, removeExtension(moduleName, tsExtension));
|
||||
}
|
||||
else {
|
||||
error(errorNode, moduleNotFoundError, moduleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
|
||||
@ -1938,10 +1938,6 @@ namespace ts {
|
||||
return path.substring(0, path.length - extension.length);
|
||||
}
|
||||
|
||||
export function isJsxOrTsxExtension(ext: string): boolean {
|
||||
return ext === ".jsx" || ext === ".tsx";
|
||||
}
|
||||
|
||||
export function changeExtension<T extends string | Path>(path: T, newExtension: string): T {
|
||||
return <T>(removeFileExtension(path) + newExtension);
|
||||
}
|
||||
@ -2134,4 +2130,33 @@ namespace ts {
|
||||
// pos === undefined || pos === null || isNaN(pos) || pos < 0;
|
||||
return !(pos >= 0);
|
||||
}
|
||||
|
||||
/** True if an extension is one of the supported TypeScript extensions. */
|
||||
export function extensionIsTypeScript(ext: Extension): boolean {
|
||||
return ext <= Extension.LastTypeScriptExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extension from a path.
|
||||
* Path must have a valid extension.
|
||||
*/
|
||||
export function extensionFromPath(path: string): Extension {
|
||||
if (fileExtensionIs(path, ".d.ts")) {
|
||||
return Extension.Dts;
|
||||
}
|
||||
if (fileExtensionIs(path, ".ts")) {
|
||||
return Extension.Ts;
|
||||
}
|
||||
if (fileExtensionIs(path, ".tsx")) {
|
||||
return Extension.Tsx;
|
||||
}
|
||||
if (fileExtensionIs(path, ".js")) {
|
||||
return Extension.Js;
|
||||
}
|
||||
if (fileExtensionIs(path, ".jsx")) {
|
||||
return Extension.Jsx;
|
||||
}
|
||||
Debug.fail(`File ${path} has unknown extension.`);
|
||||
return Extension.Js;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2693,7 +2693,7 @@
|
||||
"category": "Message",
|
||||
"code": 6099
|
||||
},
|
||||
"'package.json' does not have 'types' field.": {
|
||||
"'package.json' does not have a 'types' or 'main' field.": {
|
||||
"category": "Message",
|
||||
"code": 6100
|
||||
},
|
||||
@ -2841,7 +2841,7 @@
|
||||
"category": "Message",
|
||||
"code": 6136
|
||||
},
|
||||
"No types specified in 'package.json' but 'allowJs' is set, so returning 'main' value of '{0}'": {
|
||||
"No types specified in 'package.json', so returning 'main' value of '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 6137
|
||||
},
|
||||
@ -2861,6 +2861,14 @@
|
||||
"category": "Message",
|
||||
"code": 6141
|
||||
},
|
||||
"Module '{0}' was resolved to '{1}', but '--jsx' is not set.": {
|
||||
"category": "Error",
|
||||
"code": 6142
|
||||
},
|
||||
"Module '{0}' was resolved to '{1}', but '--allowJs' is not set.": {
|
||||
"category": "Error",
|
||||
"code": 6143
|
||||
},
|
||||
"Variable '{0}' implicitly has an '{1}' type.": {
|
||||
"category": "Error",
|
||||
"code": 7005
|
||||
|
||||
@ -2,39 +2,86 @@
|
||||
/// <reference path="diagnosticInformationMap.generated.ts" />
|
||||
|
||||
namespace ts {
|
||||
|
||||
/* @internal */
|
||||
export function trace(host: ModuleResolutionHost, message: DiagnosticMessage, ...args: any[]): void;
|
||||
export function trace(host: ModuleResolutionHost): void {
|
||||
function trace(host: ModuleResolutionHost, message: DiagnosticMessage, ...args: any[]): void;
|
||||
function trace(host: ModuleResolutionHost): void {
|
||||
host.trace(formatMessage.apply(undefined, arguments));
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function isTraceEnabled(compilerOptions: CompilerOptions, host: ModuleResolutionHost): boolean {
|
||||
function isTraceEnabled(compilerOptions: CompilerOptions, host: ModuleResolutionHost): boolean {
|
||||
return compilerOptions.traceResolution && host.trace !== undefined;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function createResolvedModule(resolvedFileName: string, isExternalLibraryImport: boolean, failedLookupLocations: string[]): ResolvedModuleWithFailedLookupLocations {
|
||||
return { resolvedModule: resolvedFileName ? { resolvedFileName, isExternalLibraryImport } : undefined, failedLookupLocations };
|
||||
/**
|
||||
* Result of trying to resolve a module.
|
||||
* At least one of `ts` and `js` should be defined, or the whole thing should be `undefined`.
|
||||
*/
|
||||
interface Resolved {
|
||||
path: string;
|
||||
extension: Extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kinds of file that we are currently looking for.
|
||||
* Typically there is one pass with Extensions.TypeScript, then a second pass with Extensions.JavaScript.
|
||||
*/
|
||||
const enum Extensions {
|
||||
TypeScript, /** '.ts', '.tsx', or '.d.ts' */
|
||||
JavaScript, /** '.js' or '.jsx' */
|
||||
DtsOnly /** Only '.d.ts' */
|
||||
}
|
||||
|
||||
/** Used with `Extensions.DtsOnly` to extract the path from TypeScript results. */
|
||||
function resolvedTypeScriptOnly(resolved: Resolved | undefined): string | undefined {
|
||||
if (!resolved) {
|
||||
return undefined;
|
||||
}
|
||||
Debug.assert(extensionIsTypeScript(resolved.extension));
|
||||
return resolved.path;
|
||||
}
|
||||
|
||||
/** Create Resolved from a file with unknown extension. */
|
||||
function resolvedFromAnyFile(path: string): Resolved | undefined {
|
||||
return { path, extension: extensionFromPath(path) };
|
||||
}
|
||||
|
||||
/** Adds `isExernalLibraryImport` to a Resolved to get a ResolvedModule. */
|
||||
function resolvedModuleFromResolved({ path, extension }: Resolved, isExternalLibraryImport: boolean): ResolvedModule {
|
||||
return { resolvedFileName: path, extension, isExternalLibraryImport };
|
||||
}
|
||||
|
||||
function createResolvedModuleWithFailedLookupLocations(resolved: Resolved | undefined, isExternalLibraryImport: boolean, failedLookupLocations: string[]): ResolvedModuleWithFailedLookupLocations {
|
||||
return { resolvedModule: resolved && resolvedModuleFromResolved(resolved, isExternalLibraryImport), failedLookupLocations };
|
||||
}
|
||||
|
||||
function moduleHasNonRelativeName(moduleName: string): boolean {
|
||||
return !(isRootedDiskPath(moduleName) || isExternalModuleNameRelative(moduleName));
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export interface ModuleResolutionState {
|
||||
interface ModuleResolutionState {
|
||||
host: ModuleResolutionHost;
|
||||
compilerOptions: CompilerOptions;
|
||||
// We only use this subset of the compiler options.
|
||||
compilerOptions: { rootDirs?: string[], baseUrl?: string, paths?: MapLike<string[]> };
|
||||
traceEnabled: boolean;
|
||||
// skip .tsx files if jsx is not enabled
|
||||
skipTsx: boolean;
|
||||
}
|
||||
|
||||
function tryReadTypesSection(packageJsonPath: string, baseDirectory: string, state: ModuleResolutionState): string {
|
||||
function tryReadTypesSection(extensions: Extensions, packageJsonPath: string, baseDirectory: string, state: ModuleResolutionState): string {
|
||||
const jsonContent = readJson(packageJsonPath, state.host);
|
||||
|
||||
switch (extensions) {
|
||||
case Extensions.DtsOnly:
|
||||
case Extensions.TypeScript:
|
||||
return tryReadFromField("typings") || tryReadFromField("types");
|
||||
|
||||
case Extensions.JavaScript:
|
||||
if (typeof jsonContent.main === "string") {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.No_types_specified_in_package_json_so_returning_main_value_of_0, jsonContent.main);
|
||||
}
|
||||
return normalizePath(combinePaths(baseDirectory, jsonContent.main));
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function tryReadFromField(fieldName: string) {
|
||||
if (hasProperty(jsonContent, fieldName)) {
|
||||
const typesFile = (<any>jsonContent)[fieldName];
|
||||
@ -52,21 +99,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const typesFilePath = tryReadFromField("typings") || tryReadFromField("types");
|
||||
if (typesFilePath) {
|
||||
return typesFilePath;
|
||||
}
|
||||
|
||||
// Use the main module for inferring types if no types package specified and the allowJs is set
|
||||
if (state.compilerOptions.allowJs && jsonContent.main && typeof jsonContent.main === "string") {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.No_types_specified_in_package_json_but_allowJs_is_set_so_returning_main_value_of_0, jsonContent.main);
|
||||
}
|
||||
const mainFilePath = normalizePath(combinePaths(baseDirectory, jsonContent.main));
|
||||
return mainFilePath;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function readJson(path: string, host: ModuleResolutionHost): { typings?: string, types?: string, main?: string } {
|
||||
@ -80,8 +112,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
const typeReferenceExtensions = [".d.ts"];
|
||||
|
||||
export function getEffectiveTypeRoots(options: CompilerOptions, host: { directoryExists?: (directoryName: string) => boolean, getCurrentDirectory?: () => string }): string[] | undefined {
|
||||
if (options.typeRoots) {
|
||||
return options.typeRoots;
|
||||
@ -132,12 +162,11 @@ namespace ts {
|
||||
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
|
||||
* is assumed to be the same as root directory of the project.
|
||||
*/
|
||||
export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost): ResolvedTypeReferenceDirectiveWithFailedLookupLocations {
|
||||
export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost): ResolvedTypeReferenceDirectiveWithFailedLookupLocations {
|
||||
const traceEnabled = isTraceEnabled(options, host);
|
||||
const moduleResolutionState: ModuleResolutionState = {
|
||||
compilerOptions: options,
|
||||
host: host,
|
||||
skipTsx: true,
|
||||
traceEnabled
|
||||
};
|
||||
|
||||
@ -168,19 +197,20 @@ namespace ts {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", "));
|
||||
}
|
||||
const primarySearchPaths = typeRoots;
|
||||
for (const typeRoot of primarySearchPaths) {
|
||||
for (const typeRoot of typeRoots) {
|
||||
const candidate = combinePaths(typeRoot, typeReferenceDirectiveName);
|
||||
const candidateDirectory = getDirectoryPath(candidate);
|
||||
const resolvedFile = loadNodeModuleFromDirectory(typeReferenceExtensions, candidate, failedLookupLocations,
|
||||
!directoryProbablyExists(candidateDirectory, host), moduleResolutionState);
|
||||
|
||||
if (resolvedFile) {
|
||||
const resolved = resolvedTypeScriptOnly(
|
||||
loadNodeModuleFromDirectory(Extensions.DtsOnly, candidate, failedLookupLocations,
|
||||
!directoryProbablyExists(candidateDirectory, host), moduleResolutionState));
|
||||
|
||||
if (resolved) {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFile, true);
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolved, true);
|
||||
}
|
||||
return {
|
||||
resolvedTypeReferenceDirective: { primary: true, resolvedFileName: resolvedFile },
|
||||
resolvedTypeReferenceDirective: { primary: true, resolvedFileName: resolved },
|
||||
failedLookupLocations
|
||||
};
|
||||
}
|
||||
@ -193,17 +223,14 @@ namespace ts {
|
||||
}
|
||||
|
||||
let resolvedFile: string;
|
||||
let initialLocationForSecondaryLookup: string;
|
||||
if (containingFile) {
|
||||
initialLocationForSecondaryLookup = getDirectoryPath(containingFile);
|
||||
}
|
||||
const initialLocationForSecondaryLookup = containingFile && getDirectoryPath(containingFile);
|
||||
|
||||
if (initialLocationForSecondaryLookup !== undefined) {
|
||||
// check secondary locations
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Looking_up_in_node_modules_folder_initial_location_0, initialLocationForSecondaryLookup);
|
||||
}
|
||||
resolvedFile = loadModuleFromNodeModules(typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState, /*checkOneLevel*/ false);
|
||||
resolvedFile = resolvedTypeScriptOnly(loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState, /*checkOneLevel*/ false));
|
||||
if (traceEnabled) {
|
||||
if (resolvedFile) {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFile, false);
|
||||
@ -219,9 +246,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
return {
|
||||
resolvedTypeReferenceDirective: resolvedFile
|
||||
? { primary: false, resolvedFileName: resolvedFile }
|
||||
: undefined,
|
||||
resolvedTypeReferenceDirective: resolvedFile ? { primary: false, resolvedFileName: resolvedFile } : undefined,
|
||||
failedLookupLocations
|
||||
};
|
||||
}
|
||||
@ -313,7 +338,7 @@ namespace ts {
|
||||
* 'typings' entry or file 'index' with some supported extension
|
||||
* - Classic loader will only try to interpret '/a/b/c' as file.
|
||||
*/
|
||||
type ResolutionKindSpecificLoader = (candidate: string, extensions: string[], failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState) => string;
|
||||
type ResolutionKindSpecificLoader = (extensions: Extensions, candidate: string, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState) => Resolved | undefined;
|
||||
|
||||
/**
|
||||
* Any module resolution kind can be augmented with optional settings: 'baseUrl', 'paths' and 'rootDirs' - they are used to
|
||||
@ -375,19 +400,19 @@ namespace ts {
|
||||
* be converted to a path relative to found rootDir entry './content/protocols/file2' (*). As a last step compiler will check all remaining
|
||||
* entries in 'rootDirs', use them to build absolute path out of (*) and try to resolve module from this location.
|
||||
*/
|
||||
function tryLoadModuleUsingOptionalResolutionSettings(moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader,
|
||||
failedLookupLocations: string[], supportedExtensions: string[], state: ModuleResolutionState): string {
|
||||
function tryLoadModuleUsingOptionalResolutionSettings(extensions: Extensions, moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader,
|
||||
failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
|
||||
if (moduleHasNonRelativeName(moduleName)) {
|
||||
return tryLoadModuleUsingBaseUrl(moduleName, loader, failedLookupLocations, supportedExtensions, state);
|
||||
return tryLoadModuleUsingBaseUrl(extensions, moduleName, loader, failedLookupLocations, state);
|
||||
}
|
||||
else {
|
||||
return tryLoadModuleUsingRootDirs(moduleName, containingDirectory, loader, failedLookupLocations, supportedExtensions, state);
|
||||
return tryLoadModuleUsingRootDirs(extensions, moduleName, containingDirectory, loader, failedLookupLocations, state);
|
||||
}
|
||||
}
|
||||
|
||||
function tryLoadModuleUsingRootDirs(moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader,
|
||||
failedLookupLocations: string[], supportedExtensions: string[], state: ModuleResolutionState): string {
|
||||
function tryLoadModuleUsingRootDirs(extensions: Extensions, moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader,
|
||||
failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
|
||||
if (!state.compilerOptions.rootDirs) {
|
||||
return undefined;
|
||||
@ -432,7 +457,7 @@ namespace ts {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Loading_0_from_the_root_dir_1_candidate_location_2, suffix, matchedNormalizedPrefix, candidate);
|
||||
}
|
||||
const resolvedFileName = loader(candidate, supportedExtensions, failedLookupLocations, !directoryProbablyExists(containingDirectory, state.host), state);
|
||||
const resolvedFileName = loader(extensions, candidate, failedLookupLocations, !directoryProbablyExists(containingDirectory, state.host), state);
|
||||
if (resolvedFileName) {
|
||||
return resolvedFileName;
|
||||
}
|
||||
@ -451,7 +476,7 @@ namespace ts {
|
||||
trace(state.host, Diagnostics.Loading_0_from_the_root_dir_1_candidate_location_2, suffix, rootDir, candidate);
|
||||
}
|
||||
const baseDirectory = getDirectoryPath(candidate);
|
||||
const resolvedFileName = loader(candidate, supportedExtensions, failedLookupLocations, !directoryProbablyExists(baseDirectory, state.host), state);
|
||||
const resolvedFileName = loader(extensions, candidate, failedLookupLocations, !directoryProbablyExists(baseDirectory, state.host), state);
|
||||
if (resolvedFileName) {
|
||||
return resolvedFileName;
|
||||
}
|
||||
@ -463,9 +488,7 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function tryLoadModuleUsingBaseUrl(moduleName: string, loader: ResolutionKindSpecificLoader, failedLookupLocations: string[],
|
||||
supportedExtensions: string[], state: ModuleResolutionState): string {
|
||||
|
||||
function tryLoadModuleUsingBaseUrl(extensions: Extensions, moduleName: string, loader: ResolutionKindSpecificLoader, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
if (!state.compilerOptions.baseUrl) {
|
||||
return undefined;
|
||||
}
|
||||
@ -494,9 +517,9 @@ namespace ts {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Trying_substitution_0_candidate_module_location_Colon_1, subst, path);
|
||||
}
|
||||
const resolvedFileName = loader(candidate, supportedExtensions, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), state.host), state);
|
||||
if (resolvedFileName) {
|
||||
return resolvedFileName;
|
||||
const resolved = loader(extensions, candidate, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), state.host), state);
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
@ -508,56 +531,64 @@ namespace ts {
|
||||
trace(state.host, Diagnostics.Resolving_module_name_0_relative_to_base_url_1_2, moduleName, state.compilerOptions.baseUrl, candidate);
|
||||
}
|
||||
|
||||
return loader(candidate, supportedExtensions, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), state.host), state);
|
||||
return loader(extensions, candidate, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), state.host), state);
|
||||
}
|
||||
}
|
||||
|
||||
export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
|
||||
const containingDirectory = getDirectoryPath(containingFile);
|
||||
const supportedExtensions = getSupportedExtensions(compilerOptions);
|
||||
const traceEnabled = isTraceEnabled(compilerOptions, host);
|
||||
|
||||
const failedLookupLocations: string[] = [];
|
||||
const state = { compilerOptions, host, traceEnabled, skipTsx: false };
|
||||
let resolvedFileName = tryLoadModuleUsingOptionalResolutionSettings(moduleName, containingDirectory, nodeLoadModuleByRelativeName,
|
||||
failedLookupLocations, supportedExtensions, state);
|
||||
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
|
||||
|
||||
const result = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript);
|
||||
if (result) {
|
||||
const { resolved, isExternalLibraryImport } = result;
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved && resolvedWithRealpath(resolved, host, traceEnabled), isExternalLibraryImport, failedLookupLocations);
|
||||
}
|
||||
return { resolvedModule: undefined, failedLookupLocations };
|
||||
|
||||
function tryResolve(extensions: Extensions): { resolved: Resolved, isExternalLibraryImport: boolean } | undefined {
|
||||
const resolved = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, nodeLoadModuleByRelativeName, failedLookupLocations, state);
|
||||
if (resolved) {
|
||||
return { resolved, isExternalLibraryImport: false };
|
||||
}
|
||||
|
||||
let isExternalLibraryImport = false;
|
||||
if (!resolvedFileName) {
|
||||
if (moduleHasNonRelativeName(moduleName)) {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Loading_module_0_from_node_modules_folder, moduleName);
|
||||
}
|
||||
resolvedFileName = loadModuleFromNodeModules(moduleName, containingDirectory, failedLookupLocations, state, /*checkOneLevel*/ false);
|
||||
isExternalLibraryImport = resolvedFileName !== undefined;
|
||||
const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state, /*checkOneLevel*/ false);
|
||||
return resolved && { resolved, isExternalLibraryImport: true };
|
||||
}
|
||||
else {
|
||||
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
resolvedFileName = nodeLoadModuleByRelativeName(candidate, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
const resolved = nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
return resolved && { resolved, isExternalLibraryImport: false };
|
||||
}
|
||||
}
|
||||
|
||||
if (resolvedFileName && host.realpath) {
|
||||
const originalFileName = resolvedFileName;
|
||||
resolvedFileName = normalizePath(host.realpath(resolvedFileName));
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Resolving_real_path_for_0_result_1, originalFileName, resolvedFileName);
|
||||
}
|
||||
}
|
||||
|
||||
return createResolvedModule(resolvedFileName, isExternalLibraryImport, failedLookupLocations);
|
||||
}
|
||||
|
||||
function nodeLoadModuleByRelativeName(candidate: string, supportedExtensions: string[], failedLookupLocations: string[],
|
||||
onlyRecordFailures: boolean, state: ModuleResolutionState): string {
|
||||
function resolvedWithRealpath(resolved: Resolved, host: ModuleResolutionHost, traceEnabled: boolean): Resolved {
|
||||
if (!host.realpath) {
|
||||
return resolved;
|
||||
}
|
||||
|
||||
const real = normalizePath(host.realpath(resolved.path));
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Resolving_real_path_for_0_result_1, resolved.path, real);
|
||||
}
|
||||
return { path: real, extension: resolved.extension };
|
||||
}
|
||||
|
||||
function nodeLoadModuleByRelativeName(extensions: Extensions, candidate: string, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Loading_module_as_file_Slash_folder_candidate_module_location_0, candidate);
|
||||
}
|
||||
|
||||
const resolvedFileName = !pathEndsWithDirectorySeparator(candidate) && loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, onlyRecordFailures, state);
|
||||
|
||||
return resolvedFileName || loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, onlyRecordFailures, state);
|
||||
const resolvedFromFile = !pathEndsWithDirectorySeparator(candidate) && loadModuleFromFile(extensions, candidate, failedLookupLocations, onlyRecordFailures, state);
|
||||
return resolvedFromFile || loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, onlyRecordFailures, state);
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
@ -570,9 +601,9 @@ namespace ts {
|
||||
* @param {boolean} onlyRecordFailures - if true then function won't try to actually load files but instead record all attempts as failures. This flag is necessary
|
||||
* in cases when we know upfront that all load attempts will fail (because containing folder does not exists) however we still need to record all failed lookup locations.
|
||||
*/
|
||||
function loadModuleFromFile(candidate: string, extensions: string[], failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined {
|
||||
function loadModuleFromFile(extensions: Extensions, candidate: string, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
// First, try adding an extension. An import of "foo" could be matched by a file "foo.ts", or "foo.js" by "foo.js.ts"
|
||||
const resolvedByAddingExtension = tryAddingExtensions(candidate, extensions, failedLookupLocation, onlyRecordFailures, state);
|
||||
const resolvedByAddingExtension = tryAddingExtensions(candidate, extensions, failedLookupLocations, onlyRecordFailures, state);
|
||||
if (resolvedByAddingExtension) {
|
||||
return resolvedByAddingExtension;
|
||||
}
|
||||
@ -585,12 +616,12 @@ namespace ts {
|
||||
const extension = candidate.substring(extensionless.length);
|
||||
trace(state.host, Diagnostics.File_name_0_has_a_1_extension_stripping_it, candidate, extension);
|
||||
}
|
||||
return tryAddingExtensions(extensionless, extensions, failedLookupLocation, onlyRecordFailures, state);
|
||||
return tryAddingExtensions(extensionless, extensions, failedLookupLocations, onlyRecordFailures, state);
|
||||
}
|
||||
}
|
||||
|
||||
/** Try to return an existing file that adds one of the `extensions` to `candidate`. */
|
||||
function tryAddingExtensions(candidate: string, extensions: string[], failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined {
|
||||
function tryAddingExtensions(candidate: string, extensions: Extensions, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
if (!onlyRecordFailures) {
|
||||
// check if containing folder exists - if it doesn't then just record failures for all supported extensions without disk probing
|
||||
const directory = getDirectoryPath(candidate);
|
||||
@ -598,8 +629,20 @@ namespace ts {
|
||||
onlyRecordFailures = !directoryProbablyExists(directory, state.host);
|
||||
}
|
||||
}
|
||||
return forEach(extensions, ext =>
|
||||
!(state.skipTsx && isJsxOrTsxExtension(ext)) && tryFile(candidate + ext, failedLookupLocation, onlyRecordFailures, state));
|
||||
|
||||
switch (extensions) {
|
||||
case Extensions.DtsOnly:
|
||||
return tryExtension(".d.ts", Extension.Dts);
|
||||
case Extensions.TypeScript:
|
||||
return tryExtension(".ts", Extension.Ts) || tryExtension(".tsx", Extension.Tsx) || tryExtension(".d.ts", Extension.Dts);
|
||||
case Extensions.JavaScript:
|
||||
return tryExtension(".js", Extension.Js) || tryExtension(".jsx", Extension.Jsx);
|
||||
}
|
||||
|
||||
function tryExtension(ext: string, extension: Extension): Resolved | undefined {
|
||||
const path = tryFile(candidate + ext, failedLookupLocations, onlyRecordFailures, state);
|
||||
return path && { path, extension };
|
||||
}
|
||||
}
|
||||
|
||||
/** Return the file if it exists. */
|
||||
@ -619,26 +662,31 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function loadNodeModuleFromDirectory(extensions: string[], candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string {
|
||||
function loadNodeModuleFromDirectory(extensions: Extensions, candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
const packageJsonPath = pathToPackageJson(candidate);
|
||||
const directoryExists = !onlyRecordFailures && directoryProbablyExists(candidate, state.host);
|
||||
|
||||
if (directoryExists && state.host.fileExists(packageJsonPath)) {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Found_package_json_at_0, packageJsonPath);
|
||||
}
|
||||
const typesFile = tryReadTypesSection(packageJsonPath, candidate, state);
|
||||
const typesFile = tryReadTypesSection(extensions, packageJsonPath, candidate, state);
|
||||
if (typesFile) {
|
||||
const onlyRecordFailures = !directoryProbablyExists(getDirectoryPath(typesFile), state.host);
|
||||
// A package.json "typings" may specify an exact filename, or may choose to omit an extension.
|
||||
const result = tryFile(typesFile, failedLookupLocation, onlyRecordFailures, state) ||
|
||||
tryAddingExtensions(typesFile, extensions, failedLookupLocation, onlyRecordFailures, state);
|
||||
if (result) {
|
||||
return result;
|
||||
const fromFile = tryFile(typesFile, failedLookupLocation, onlyRecordFailures, state);
|
||||
if (fromFile) {
|
||||
// Note: this would allow a package.json to specify a ".js" file as typings. Maybe that should be forbidden.
|
||||
return resolvedFromAnyFile(fromFile);
|
||||
}
|
||||
const x = tryAddingExtensions(typesFile, Extensions.TypeScript, failedLookupLocation, onlyRecordFailures, state);
|
||||
if (x) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.package_json_does_not_have_types_field);
|
||||
trace(state.host, Diagnostics.package_json_does_not_have_a_types_or_main_field);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -650,104 +698,90 @@ namespace ts {
|
||||
failedLookupLocation.push(packageJsonPath);
|
||||
}
|
||||
|
||||
return loadModuleFromFile(combinePaths(candidate, "index"), extensions, failedLookupLocation, !directoryExists, state);
|
||||
return loadModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocation, !directoryExists, state);
|
||||
}
|
||||
|
||||
function pathToPackageJson(directory: string): string {
|
||||
return combinePaths(directory, "package.json");
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModulesFolder(moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): string {
|
||||
function loadModuleFromNodeModulesFolder(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
const nodeModulesFolder = combinePaths(directory, "node_modules");
|
||||
const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host);
|
||||
const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName));
|
||||
const supportedExtensions = getSupportedExtensions(state.compilerOptions);
|
||||
|
||||
let result = loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, !nodeModulesFolderExists, state);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
return loadModuleFromFile(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state) ||
|
||||
loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state);
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function loadModuleFromNodeModules(moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState, checkOneLevel: boolean): string {
|
||||
return loadModuleFromNodeModulesWorker(moduleName, directory, failedLookupLocations, state, checkOneLevel, /*typesOnly*/ false);
|
||||
function loadModuleFromNodeModules(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState, checkOneLevel: boolean): Resolved | undefined {
|
||||
return loadModuleFromNodeModulesWorker(extensions, moduleName, directory, failedLookupLocations, state, checkOneLevel, /*typesOnly*/ false);
|
||||
}
|
||||
function loadModuleFromNodeModulesAtTypes(moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
return loadModuleFromNodeModulesWorker(Extensions.TypeScript, moduleName, directory, failedLookupLocations, state, /*checkOneLevel*/ false, /*typesOnly*/ true);
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModulesAtTypes(moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): string {
|
||||
return loadModuleFromNodeModulesWorker(moduleName, directory, failedLookupLocations, state, /*checkOneLevel*/ false, /*typesOnly*/ true);
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModulesWorker(moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState, checkOneLevel: boolean, typesOnly: boolean): string {
|
||||
function loadModuleFromNodeModulesWorker(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState, checkOneLevel: boolean, typesOnly: boolean): Resolved | undefined {
|
||||
directory = normalizeSlashes(directory);
|
||||
while (true) {
|
||||
const baseName = getBaseFileName(directory);
|
||||
if (baseName !== "node_modules") {
|
||||
let packageResult: string | undefined;
|
||||
if (!typesOnly) {
|
||||
// Try to load source from the package
|
||||
packageResult = loadModuleFromNodeModulesFolder(moduleName, directory, failedLookupLocations, state);
|
||||
if (packageResult && hasTypeScriptFileExtension(packageResult)) {
|
||||
// Always prefer a TypeScript (.ts, .tsx, .d.ts) file shipped with the package
|
||||
return packageResult;
|
||||
}
|
||||
}
|
||||
|
||||
// Else prefer a types package over non-TypeScript results (e.g. JavaScript files)
|
||||
const typesResult = loadModuleFromNodeModulesFolder(combinePaths("@types", moduleName), directory, failedLookupLocations, state);
|
||||
if (typesResult || packageResult) {
|
||||
return typesResult || packageResult;
|
||||
if (getBaseFileName(directory) !== "node_modules") {
|
||||
const resolved = tryInDirectory();
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
|
||||
const parentPath = getDirectoryPath(directory);
|
||||
if (parentPath === directory || checkOneLevel) {
|
||||
break;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
directory = parentPath;
|
||||
}
|
||||
return undefined;
|
||||
|
||||
function tryInDirectory(): Resolved | undefined {
|
||||
const packageResult = typesOnly ? undefined : loadModuleFromNodeModulesFolder(extensions, moduleName, directory, failedLookupLocations, state);
|
||||
return packageResult || loadModuleFromNodeModulesFolder(extensions, combinePaths("@types", moduleName), directory, failedLookupLocations, state);
|
||||
}
|
||||
}
|
||||
|
||||
export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
|
||||
const traceEnabled = isTraceEnabled(compilerOptions, host);
|
||||
const state = { compilerOptions, host, traceEnabled, skipTsx: !compilerOptions.jsx };
|
||||
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
|
||||
const failedLookupLocations: string[] = [];
|
||||
const supportedExtensions = getSupportedExtensions(compilerOptions);
|
||||
const containingDirectory = getDirectoryPath(containingFile);
|
||||
|
||||
const resolvedFileName = tryLoadModuleUsingOptionalResolutionSettings(moduleName, containingDirectory, loadModuleFromFile, failedLookupLocations, supportedExtensions, state);
|
||||
if (resolvedFileName) {
|
||||
return createResolvedModule(resolvedFileName, /*isExternalLibraryImport*/false, failedLookupLocations);
|
||||
}
|
||||
const resolved = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript);
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ false, failedLookupLocations);
|
||||
|
||||
let referencedSourceFile: string;
|
||||
if (moduleHasNonRelativeName(moduleName)) {
|
||||
referencedSourceFile = referencedSourceFile = loadModuleFromAncestorDirectories(moduleName, containingDirectory, supportedExtensions, failedLookupLocations, state) ||
|
||||
// If we didn't find the file normally, look it up in @types.
|
||||
loadModuleFromNodeModulesAtTypes(moduleName, containingDirectory, failedLookupLocations, state);
|
||||
}
|
||||
else {
|
||||
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
referencedSourceFile = loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
}
|
||||
function tryResolve(extensions: Extensions): Resolved | undefined {
|
||||
const resolvedUsingSettings = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loadModuleFromFile, failedLookupLocations, state);
|
||||
if (resolvedUsingSettings) {
|
||||
return resolvedUsingSettings;
|
||||
}
|
||||
|
||||
|
||||
return referencedSourceFile
|
||||
? { resolvedModule: { resolvedFileName: referencedSourceFile }, failedLookupLocations }
|
||||
: { resolvedModule: undefined, failedLookupLocations };
|
||||
if (moduleHasNonRelativeName(moduleName)) {
|
||||
const resolved = loadModuleFromAncestorDirectories(extensions, moduleName, containingDirectory, failedLookupLocations, state);
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
}
|
||||
if (extensions === Extensions.TypeScript) {
|
||||
// If we didn't find the file normally, look it up in @types.
|
||||
return loadModuleFromNodeModulesAtTypes(moduleName, containingDirectory, failedLookupLocations, state);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
return loadModuleFromFile(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Climb up parent directories looking for a module. */
|
||||
function loadModuleFromAncestorDirectories(moduleName: string, containingDirectory: string, supportedExtensions: string[], failedLookupLocations: string[], state: ModuleResolutionState): string | undefined {
|
||||
function loadModuleFromAncestorDirectories(extensions: Extensions, moduleName: string, containingDirectory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined {
|
||||
while (true) {
|
||||
const searchName = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
const referencedSourceFile = loadModuleFromFile(searchName, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
const referencedSourceFile = loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
if (referencedSourceFile) {
|
||||
return referencedSourceFile;
|
||||
}
|
||||
@ -758,4 +792,21 @@ namespace ts {
|
||||
containingDirectory = parentPath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* LSHost may load a module from a global cache of typings.
|
||||
* This is the minumum code needed to expose that functionality; the rest is in LSHost.
|
||||
*/
|
||||
/* @internal */
|
||||
export function loadModuleFromGlobalCache(moduleName: string, projectName: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, globalCache: string): ResolvedModuleWithFailedLookupLocations {
|
||||
const traceEnabled = isTraceEnabled(compilerOptions, host);
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Auto_discovery_for_typings_is_enabled_in_project_0_Running_extra_resolution_pass_for_module_1_using_cache_location_2, projectName, moduleName, globalCache);
|
||||
}
|
||||
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
|
||||
const failedLookupLocations: string[] = [];
|
||||
const resolved = loadModuleFromNodeModules(Extensions.TypeScript, moduleName, globalCache, failedLookupLocations, state, /*checkOneLevel*/ true) ||
|
||||
loadModuleFromNodeModules(Extensions.JavaScript, moduleName, globalCache, failedLookupLocations, state, /*checkOneLevel*/ true);
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ true, failedLookupLocations);
|
||||
}
|
||||
}
|
||||
@ -307,7 +307,7 @@ namespace ts {
|
||||
// - This calls resolveModuleNames, and then calls findSourceFile for each resolved module.
|
||||
// As all these operations happen - and are nested - within the createProgram call, they close over the below variables.
|
||||
// The current resolution depth is tracked by incrementing/decrementing as the depth first search progresses.
|
||||
const maxNodeModulesJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 0;
|
||||
const maxNodeModuleJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 0;
|
||||
let currentNodeModulesDepth = 0;
|
||||
|
||||
// If a module has some of its imports skipped due to being at the depth limit under node_modules, then track
|
||||
@ -331,7 +331,15 @@ namespace ts {
|
||||
|
||||
let resolveModuleNamesWorker: (moduleNames: string[], containingFile: string) => ResolvedModule[];
|
||||
if (host.resolveModuleNames) {
|
||||
resolveModuleNamesWorker = (moduleNames, containingFile) => host.resolveModuleNames(moduleNames, containingFile);
|
||||
resolveModuleNamesWorker = (moduleNames, containingFile) => host.resolveModuleNames(moduleNames, containingFile).map(resolved => {
|
||||
// An older host may have omitted extension, in which case we should infer it from the file extension of resolvedFileName.
|
||||
if (!resolved || resolved.extension) {
|
||||
return resolved;
|
||||
}
|
||||
resolved = clone(resolved);
|
||||
resolved.extension = extensionFromPath(resolved.resolvedFileName);
|
||||
return resolved;
|
||||
});
|
||||
}
|
||||
else {
|
||||
const loader = (moduleName: string, containingFile: string) => resolveModuleName(moduleName, containingFile, options, host).resolvedModule;
|
||||
@ -1149,7 +1157,7 @@ namespace ts {
|
||||
}
|
||||
// See if we need to reprocess the imports due to prior skipped imports
|
||||
else if (file && modulesWithElidedImports[file.path]) {
|
||||
if (currentNodeModulesDepth < maxNodeModulesJsDepth) {
|
||||
if (currentNodeModulesDepth < maxNodeModuleJsDepth) {
|
||||
modulesWithElidedImports[file.path] = false;
|
||||
processImportedModules(file);
|
||||
}
|
||||
@ -1292,35 +1300,39 @@ namespace ts {
|
||||
file.resolvedModules = createMap<ResolvedModule>();
|
||||
const moduleNames = map(concatenate(file.imports, file.moduleAugmentations), getTextOfLiteral);
|
||||
const resolutions = resolveModuleNamesWorker(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory));
|
||||
Debug.assert(resolutions.length === moduleNames.length);
|
||||
for (let i = 0; i < moduleNames.length; i++) {
|
||||
const resolution = resolutions[i];
|
||||
setResolvedModule(file, moduleNames[i], resolution);
|
||||
|
||||
if (!resolution) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const isFromNodeModulesSearch = resolution.isExternalLibraryImport;
|
||||
const isJsFileFromNodeModules = isFromNodeModulesSearch && !extensionIsTypeScript(resolution.extension);
|
||||
const resolvedFileName = resolution.resolvedFileName;
|
||||
|
||||
if (isFromNodeModulesSearch) {
|
||||
currentNodeModulesDepth++;
|
||||
}
|
||||
|
||||
// add file to program only if:
|
||||
// - resolution was successful
|
||||
// - noResolve is falsy
|
||||
// - module name comes from the list of imports
|
||||
// - it's not a top level JavaScript module that exceeded the search max
|
||||
const isFromNodeModulesSearch = resolution && resolution.isExternalLibraryImport;
|
||||
const isJsFileFromNodeModules = isFromNodeModulesSearch && hasJavaScriptFileExtension(resolution.resolvedFileName);
|
||||
|
||||
if (isFromNodeModulesSearch) {
|
||||
currentNodeModulesDepth++;
|
||||
}
|
||||
|
||||
const elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModulesJsDepth;
|
||||
const shouldAddFile = resolution && !options.noResolve && i < file.imports.length && !elideImport;
|
||||
const elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModuleJsDepth;
|
||||
// Don't add the file if it has a bad extension (e.g. 'tsx' if we don't have '--allowJs')
|
||||
const shouldAddFile = resolvedFileName && !getResolutionDiagnostic(options, resolution) && !options.noResolve && i < file.imports.length && !elideImport;
|
||||
|
||||
if (elideImport) {
|
||||
modulesWithElidedImports[file.path] = true;
|
||||
}
|
||||
else if (shouldAddFile) {
|
||||
findSourceFile(resolution.resolvedFileName,
|
||||
toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName),
|
||||
/*isDefaultLib*/ false,
|
||||
file,
|
||||
skipTrivia(file.text, file.imports[i].pos),
|
||||
file.imports[i].end);
|
||||
const path = toPath(resolvedFileName, currentDirectory, getCanonicalFileName);
|
||||
const pos = skipTrivia(file.text, file.imports[i].pos);
|
||||
findSourceFile(resolvedFileName, path, /*isDefaultLib*/ false, file, pos, file.imports[i].end);
|
||||
}
|
||||
|
||||
if (isFromNodeModulesSearch) {
|
||||
@ -1332,7 +1344,6 @@ namespace ts {
|
||||
// no imports - drop cached module resolutions
|
||||
file.resolvedModules = undefined;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function computeCommonSourceDirectory(sourceFiles: SourceFile[]): string {
|
||||
@ -1557,4 +1568,25 @@ namespace ts {
|
||||
programDiagnostics.add(createCompilerDiagnostic(message, emitFileName));
|
||||
}
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
/**
|
||||
* Returns a DiagnosticMessage if we can't use a resolved module due to its extension.
|
||||
* The DiagnosticMessage's parameters are the imported module name, and the filename it resolved to.
|
||||
*/
|
||||
export function getResolutionDiagnostic(options: CompilerOptions, { extension }: ResolvedModule): DiagnosticMessage | undefined {
|
||||
switch (extension) {
|
||||
case Extension.Ts:
|
||||
case Extension.Dts:
|
||||
// These are always allowed.
|
||||
return undefined;
|
||||
|
||||
case Extension.Tsx:
|
||||
case Extension.Jsx:
|
||||
return options.jsx ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set;
|
||||
|
||||
case Extension.Js:
|
||||
return options.allowJs ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_allowJs_is_not_set;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3347,10 +3347,21 @@ namespace ts {
|
||||
getDirectories?(path: string): string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the result of module resolution.
|
||||
* Module resolution will pick up tsx/jsx/js files even if '--jsx' and '--allowJs' are turned off.
|
||||
* The Program will then filter results based on these flags.
|
||||
*
|
||||
* At least one of `resolvedTsFileName` or `resolvedJsFileName` must be defined,
|
||||
* else resolution should just return `undefined` instead of a ResolvedModule.
|
||||
*/
|
||||
export interface ResolvedModule {
|
||||
/** Path of the file the module was resolved to. */
|
||||
resolvedFileName: string;
|
||||
/*
|
||||
* Denotes if 'resolvedFileName' is isExternalLibraryImport and thus should be proper external module:
|
||||
/** Extension of resolvedFileName. This must match what's at the end of resolvedFileName. */
|
||||
extension: Extension;
|
||||
/**
|
||||
* Denotes if 'resolvedFileName' is isExternalLibraryImport and thus should be a proper external module:
|
||||
* - be a .d.ts file
|
||||
* - use top level imports\exports
|
||||
* - don't use tripleslash references
|
||||
@ -3358,8 +3369,17 @@ namespace ts {
|
||||
isExternalLibraryImport?: boolean;
|
||||
}
|
||||
|
||||
export enum Extension {
|
||||
Ts,
|
||||
Tsx,
|
||||
Dts,
|
||||
Js,
|
||||
Jsx,
|
||||
LastTypeScriptExtension = Dts
|
||||
}
|
||||
|
||||
export interface ResolvedModuleWithFailedLookupLocations {
|
||||
resolvedModule: ResolvedModule;
|
||||
resolvedModule: ResolvedModule | undefined;
|
||||
failedLookupLocations: string[];
|
||||
}
|
||||
|
||||
|
||||
@ -108,8 +108,14 @@ namespace ts {
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
/**
|
||||
* Considers two ResolvedModules equal if they have the same `resolvedFileName`.
|
||||
* Thus `{ ts: foo, js: bar }` is equal to `{ ts: foo, js: baz }` because `ts` is preferred.
|
||||
*/
|
||||
export function moduleResolutionIsEqualTo(oldResolution: ResolvedModule, newResolution: ResolvedModule): boolean {
|
||||
return oldResolution.resolvedFileName === newResolution.resolvedFileName && oldResolution.isExternalLibraryImport === newResolution.isExternalLibraryImport;
|
||||
return oldResolution.isExternalLibraryImport === newResolution.isExternalLibraryImport &&
|
||||
oldResolution.extension === newResolution.extension &&
|
||||
oldResolution.resolvedFileName === newResolution.resolvedFileName;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
||||
@ -1,6 +1,28 @@
|
||||
/// <reference path="..\harness.ts" />
|
||||
|
||||
namespace ts {
|
||||
export function checkResolvedModule(expected: ResolvedModule, actual: ResolvedModule): boolean {
|
||||
if (!expected === !actual) {
|
||||
if (expected) {
|
||||
assert.isTrue(expected.resolvedFileName === actual.resolvedFileName, `'resolvedFileName': expected '${expected.resolvedFileName}' to be equal to '${actual.resolvedFileName}'`);
|
||||
assert.isTrue(expected.extension === actual.extension, `'ext': expected '${Extension[expected.extension]}' to be equal to '${Extension[actual.extension]}'`);
|
||||
assert.isTrue(expected.isExternalLibraryImport === actual.isExternalLibraryImport, `'isExternalLibraryImport': expected '${expected.isExternalLibraryImport}' to be equal to '${actual.isExternalLibraryImport}'`);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function checkResolvedModuleWithFailedLookupLocations(actual: ResolvedModuleWithFailedLookupLocations, expectedResolvedModule: ResolvedModule, expectedFailedLookupLocations: string[]): void {
|
||||
assert.isTrue(actual.resolvedModule !== undefined, "module should be resolved");
|
||||
checkResolvedModule(actual.resolvedModule, expectedResolvedModule);
|
||||
assert.deepEqual(actual.failedLookupLocations, expectedFailedLookupLocations);
|
||||
}
|
||||
|
||||
export function createResolvedModule(resolvedFileName: string, isExternalLibraryImport = false): ResolvedModule {
|
||||
return { resolvedFileName, extension: extensionFromPath(resolvedFileName), isExternalLibraryImport };
|
||||
}
|
||||
|
||||
interface File {
|
||||
name: string;
|
||||
content?: string;
|
||||
@ -53,8 +75,7 @@ namespace ts {
|
||||
const containingFile = { name: containingFileName };
|
||||
const moduleFile = { name: moduleFileNameNoExt + ext };
|
||||
const resolution = nodeModuleNameResolver(moduleName, containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, moduleFile));
|
||||
assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name);
|
||||
assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false);
|
||||
checkResolvedModule(resolution.resolvedModule, createResolvedModule(moduleFile.name));
|
||||
|
||||
const failedLookupLocations: string[] = [];
|
||||
const dir = getDirectoryPath(containingFileName);
|
||||
@ -97,8 +118,7 @@ namespace ts {
|
||||
const packageJson = { name: packageJsonFileName, content: JSON.stringify({ "typings": fieldRef }) };
|
||||
const moduleFile = { name: moduleFileName };
|
||||
const resolution = nodeModuleNameResolver(moduleName, containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, packageJson, moduleFile));
|
||||
assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name);
|
||||
assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false);
|
||||
checkResolvedModule(resolution.resolvedModule, createResolvedModule(moduleFile.name));
|
||||
// expect three failed lookup location - attempt to load module as file with all supported extensions
|
||||
assert.equal(resolution.failedLookupLocations.length, supportedTypeScriptExtensions.length);
|
||||
}
|
||||
@ -125,7 +145,7 @@ namespace ts {
|
||||
|
||||
const resolution = nodeModuleNameResolver("b", containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, packageJson, moduleFile, indexFile));
|
||||
|
||||
assert.equal(resolution.resolvedModule.resolvedFileName, indexPath);
|
||||
checkResolvedModule(resolution.resolvedModule, createResolvedModule(indexPath, /*isExternalLibraryImport*/true));
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,7 +158,6 @@ namespace ts {
|
||||
/* tslint:enable no-null-keyword */
|
||||
testTypingsIgnored(undefined);
|
||||
});
|
||||
|
||||
it("module name as directory - load index.d.ts", () => {
|
||||
test(/*hasDirectoryExists*/ false);
|
||||
test(/*hasDirectoryExists*/ true);
|
||||
@ -148,9 +167,7 @@ namespace ts {
|
||||
const packageJson = { name: "/a/b/foo/package.json", content: JSON.stringify({ main: "/c/d" }) };
|
||||
const indexFile = { name: "/a/b/foo/index.d.ts" };
|
||||
const resolution = nodeModuleNameResolver("./foo", containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, packageJson, indexFile));
|
||||
assert.equal(resolution.resolvedModule.resolvedFileName, indexFile.name);
|
||||
assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false);
|
||||
assert.deepEqual(resolution.failedLookupLocations, [
|
||||
checkResolvedModuleWithFailedLookupLocations(resolution, createResolvedModule(indexFile.name), [
|
||||
"/a/b/foo.ts",
|
||||
"/a/b/foo.tsx",
|
||||
"/a/b/foo.d.ts",
|
||||
@ -170,33 +187,39 @@ namespace ts {
|
||||
const containingFile = { name: "/a/b/c/d/e.ts" };
|
||||
const moduleFile = { name: "/a/b/node_modules/foo.ts" };
|
||||
const resolution = nodeModuleNameResolver("foo", containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, moduleFile));
|
||||
assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name);
|
||||
assert.deepEqual(resolution.failedLookupLocations, [
|
||||
checkResolvedModuleWithFailedLookupLocations(resolution, createResolvedModule(moduleFile.name, /*isExternalLibraryImport*/ true), [
|
||||
"/a/b/c/d/node_modules/foo.ts",
|
||||
"/a/b/c/d/node_modules/foo.tsx",
|
||||
"/a/b/c/d/node_modules/foo.d.ts",
|
||||
"/a/b/c/d/node_modules/foo/package.json",
|
||||
|
||||
"/a/b/c/d/node_modules/foo/index.ts",
|
||||
"/a/b/c/d/node_modules/foo/index.tsx",
|
||||
"/a/b/c/d/node_modules/foo/index.d.ts",
|
||||
|
||||
"/a/b/c/d/node_modules/@types/foo.ts",
|
||||
"/a/b/c/d/node_modules/@types/foo.tsx",
|
||||
"/a/b/c/d/node_modules/@types/foo.d.ts",
|
||||
"/a/b/c/d/node_modules/@types/foo/package.json",
|
||||
|
||||
"/a/b/c/d/node_modules/@types/foo/index.ts",
|
||||
"/a/b/c/d/node_modules/@types/foo/index.tsx",
|
||||
"/a/b/c/d/node_modules/@types/foo/index.d.ts",
|
||||
|
||||
"/a/b/c/node_modules/foo.ts",
|
||||
"/a/b/c/node_modules/foo.tsx",
|
||||
"/a/b/c/node_modules/foo.d.ts",
|
||||
"/a/b/c/node_modules/foo/package.json",
|
||||
|
||||
"/a/b/c/node_modules/foo/index.ts",
|
||||
"/a/b/c/node_modules/foo/index.tsx",
|
||||
"/a/b/c/node_modules/foo/index.d.ts",
|
||||
|
||||
"/a/b/c/node_modules/@types/foo.ts",
|
||||
"/a/b/c/node_modules/@types/foo.tsx",
|
||||
"/a/b/c/node_modules/@types/foo.d.ts",
|
||||
"/a/b/c/node_modules/@types/foo/package.json",
|
||||
|
||||
"/a/b/c/node_modules/@types/foo/index.ts",
|
||||
"/a/b/c/node_modules/@types/foo/index.tsx",
|
||||
"/a/b/c/node_modules/@types/foo/index.d.ts",
|
||||
@ -212,8 +235,7 @@ namespace ts {
|
||||
const containingFile = { name: "/a/b/c/d/e.ts" };
|
||||
const moduleFile = { name: "/a/b/node_modules/foo.d.ts" };
|
||||
const resolution = nodeModuleNameResolver("foo", containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, moduleFile));
|
||||
assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name);
|
||||
assert.equal(resolution.resolvedModule.isExternalLibraryImport, true);
|
||||
checkResolvedModule(resolution.resolvedModule, createResolvedModule(moduleFile.name, /*isExternalLibraryImport*/ true));
|
||||
}
|
||||
});
|
||||
|
||||
@ -225,55 +247,66 @@ namespace ts {
|
||||
const containingFile = { name: "/a/node_modules/b/c/node_modules/d/e.ts" };
|
||||
const moduleFile = { name: "/a/node_modules/foo/index.d.ts" };
|
||||
const resolution = nodeModuleNameResolver("foo", containingFile.name, {}, createModuleResolutionHost(hasDirectoryExists, containingFile, moduleFile));
|
||||
assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name);
|
||||
assert.equal(resolution.resolvedModule.isExternalLibraryImport, true);
|
||||
assert.deepEqual(resolution.failedLookupLocations, [
|
||||
checkResolvedModuleWithFailedLookupLocations(resolution, createResolvedModule(moduleFile.name, /*isExternalLibraryImport*/ true), [
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/foo.ts",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/foo.tsx",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/foo.d.ts",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/foo/package.json",
|
||||
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/foo/index.ts",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/foo/index.tsx",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/foo/index.d.ts",
|
||||
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo.ts",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo.tsx",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo.d.ts",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo/package.json",
|
||||
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo/index.ts",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo/index.tsx",
|
||||
"/a/node_modules/b/c/node_modules/d/node_modules/@types/foo/index.d.ts",
|
||||
|
||||
"/a/node_modules/b/c/node_modules/foo.ts",
|
||||
"/a/node_modules/b/c/node_modules/foo.tsx",
|
||||
"/a/node_modules/b/c/node_modules/foo.d.ts",
|
||||
"/a/node_modules/b/c/node_modules/foo/package.json",
|
||||
|
||||
"/a/node_modules/b/c/node_modules/foo/index.ts",
|
||||
"/a/node_modules/b/c/node_modules/foo/index.tsx",
|
||||
"/a/node_modules/b/c/node_modules/foo/index.d.ts",
|
||||
|
||||
"/a/node_modules/b/c/node_modules/@types/foo.ts",
|
||||
"/a/node_modules/b/c/node_modules/@types/foo.tsx",
|
||||
"/a/node_modules/b/c/node_modules/@types/foo.d.ts",
|
||||
"/a/node_modules/b/c/node_modules/@types/foo/package.json",
|
||||
|
||||
"/a/node_modules/b/c/node_modules/@types/foo/index.ts",
|
||||
"/a/node_modules/b/c/node_modules/@types/foo/index.tsx",
|
||||
"/a/node_modules/b/c/node_modules/@types/foo/index.d.ts",
|
||||
|
||||
"/a/node_modules/b/node_modules/foo.ts",
|
||||
"/a/node_modules/b/node_modules/foo.tsx",
|
||||
"/a/node_modules/b/node_modules/foo.d.ts",
|
||||
"/a/node_modules/b/node_modules/foo/package.json",
|
||||
|
||||
"/a/node_modules/b/node_modules/foo/index.ts",
|
||||
"/a/node_modules/b/node_modules/foo/index.tsx",
|
||||
"/a/node_modules/b/node_modules/foo/index.d.ts",
|
||||
|
||||
"/a/node_modules/b/node_modules/@types/foo.ts",
|
||||
"/a/node_modules/b/node_modules/@types/foo.tsx",
|
||||
"/a/node_modules/b/node_modules/@types/foo.d.ts",
|
||||
"/a/node_modules/b/node_modules/@types/foo/package.json",
|
||||
|
||||
"/a/node_modules/b/node_modules/@types/foo/index.ts",
|
||||
"/a/node_modules/b/node_modules/@types/foo/index.tsx",
|
||||
"/a/node_modules/b/node_modules/@types/foo/index.d.ts",
|
||||
|
||||
"/a/node_modules/foo.ts",
|
||||
"/a/node_modules/foo.tsx",
|
||||
"/a/node_modules/foo.d.ts",
|
||||
"/a/node_modules/foo/package.json",
|
||||
|
||||
"/a/node_modules/foo/index.ts",
|
||||
"/a/node_modules/foo/index.tsx"
|
||||
]);
|
||||
@ -481,21 +514,15 @@ import b = require("./moduleB");
|
||||
const options: CompilerOptions = { moduleResolution, baseUrl: "/root" };
|
||||
{
|
||||
const result = resolveModuleName("folder2/file2", file1.name, options, host);
|
||||
assert.isTrue(result.resolvedModule !== undefined, "module should be resolved");
|
||||
assert.equal(result.resolvedModule.resolvedFileName, file2.name);
|
||||
assert.deepEqual(result.failedLookupLocations, []);
|
||||
checkResolvedModuleWithFailedLookupLocations(result, createResolvedModule(file2.name), []);
|
||||
}
|
||||
{
|
||||
const result = resolveModuleName("./file3", file2.name, options, host);
|
||||
assert.isTrue(result.resolvedModule !== undefined, "module should be resolved");
|
||||
assert.equal(result.resolvedModule.resolvedFileName, file3.name);
|
||||
assert.deepEqual(result.failedLookupLocations, []);
|
||||
checkResolvedModuleWithFailedLookupLocations(result, createResolvedModule(file3.name), []);
|
||||
}
|
||||
{
|
||||
const result = resolveModuleName("/root/folder1/file1", file2.name, options, host);
|
||||
assert.isTrue(result.resolvedModule !== undefined, "module should be resolved");
|
||||
assert.equal(result.resolvedModule.resolvedFileName, file1.name);
|
||||
assert.deepEqual(result.failedLookupLocations, []);
|
||||
checkResolvedModuleWithFailedLookupLocations(result, createResolvedModule(file1.name), []);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -520,12 +547,11 @@ import b = require("./moduleB");
|
||||
check("m1", main, m1);
|
||||
check("m2", main, m2);
|
||||
check("m3", main, m3Typings);
|
||||
check("m4", main, m4);
|
||||
check("m4", main, m4, /*isExternalLibraryImport*/true);
|
||||
|
||||
function check(name: string, caller: File, expected: File) {
|
||||
function check(name: string, caller: File, expected: File, isExternalLibraryImport = false) {
|
||||
const result = resolveModuleName(name, caller.name, options, host);
|
||||
assert.isTrue(result.resolvedModule !== undefined);
|
||||
assert.equal(result.resolvedModule.resolvedFileName, expected.name);
|
||||
checkResolvedModule(result.resolvedModule, createResolvedModule(expected.name, isExternalLibraryImport));
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -547,8 +573,7 @@ import b = require("./moduleB");
|
||||
|
||||
function check(name: string, caller: File, expected: File) {
|
||||
const result = resolveModuleName(name, caller.name, options, host);
|
||||
assert.isTrue(result.resolvedModule !== undefined);
|
||||
assert.equal(result.resolvedModule.resolvedFileName, expected.name);
|
||||
checkResolvedModule(result.resolvedModule, createResolvedModule(expected.name));
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -590,9 +615,10 @@ import b = require("./moduleB");
|
||||
"/root/folder1/file2.tsx",
|
||||
"/root/folder1/file2.d.ts",
|
||||
"/root/folder1/file2/package.json",
|
||||
|
||||
"/root/folder1/file2/index.ts",
|
||||
"/root/folder1/file2/index.tsx",
|
||||
"/root/folder1/file2/index.d.ts"
|
||||
"/root/folder1/file2/index.d.ts",
|
||||
// then first attempt on 'generated/*' was successful
|
||||
]);
|
||||
check("folder2/file3", file3, [
|
||||
@ -601,14 +627,17 @@ import b = require("./moduleB");
|
||||
"/root/folder2/file3.tsx",
|
||||
"/root/folder2/file3.d.ts",
|
||||
"/root/folder2/file3/package.json",
|
||||
|
||||
"/root/folder2/file3/index.ts",
|
||||
"/root/folder2/file3/index.tsx",
|
||||
"/root/folder2/file3/index.d.ts",
|
||||
|
||||
// then use remapped location
|
||||
"/root/generated/folder2/file3.ts",
|
||||
"/root/generated/folder2/file3.tsx",
|
||||
"/root/generated/folder2/file3.d.ts",
|
||||
"/root/generated/folder2/file3/package.json",
|
||||
|
||||
"/root/generated/folder2/file3/index.ts",
|
||||
"/root/generated/folder2/file3/index.tsx",
|
||||
// success on index.d.ts
|
||||
@ -619,13 +648,15 @@ import b = require("./moduleB");
|
||||
"/root/folder2/file4.tsx",
|
||||
"/root/folder2/file4.d.ts",
|
||||
"/root/folder2/file4/package.json",
|
||||
|
||||
"/root/folder2/file4/index.ts",
|
||||
"/root/folder2/file4/index.tsx",
|
||||
"/root/folder2/file4/index.d.ts",
|
||||
|
||||
// try to load from file from remapped location
|
||||
"/root/generated/folder2/file4.ts",
|
||||
"/root/generated/folder2/file4.tsx",
|
||||
"/root/generated/folder2/file4.d.ts"
|
||||
"/root/generated/folder2/file4.d.ts",
|
||||
// success on loading as from folder
|
||||
]);
|
||||
check("somefolder/file5", file5, [
|
||||
@ -634,6 +665,7 @@ import b = require("./moduleB");
|
||||
"/root/someanotherfolder/file5.ts",
|
||||
"/root/someanotherfolder/file5.tsx",
|
||||
"/root/someanotherfolder/file5.d.ts",
|
||||
|
||||
// load from folder
|
||||
"/root/someanotherfolder/file5/package.json",
|
||||
"/root/someanotherfolder/file5/index.ts",
|
||||
@ -646,46 +678,51 @@ import b = require("./moduleB");
|
||||
"/root/file6.ts",
|
||||
"/root/file6.tsx",
|
||||
"/root/file6.d.ts",
|
||||
|
||||
// load from folder
|
||||
"/root/file6/package.json",
|
||||
"/root/file6/index.ts",
|
||||
"/root/file6/index.tsx",
|
||||
"/root/file6/index.d.ts",
|
||||
|
||||
// then try 'generated/*'
|
||||
// load from file
|
||||
"/root/generated/file6.ts",
|
||||
"/root/generated/file6.tsx",
|
||||
"/root/generated/file6.d.ts",
|
||||
|
||||
// load from folder
|
||||
"/root/generated/file6/package.json",
|
||||
"/root/generated/file6/index.ts",
|
||||
"/root/generated/file6/index.tsx",
|
||||
"/root/generated/file6/index.d.ts",
|
||||
|
||||
// fallback to standard node behavior
|
||||
// load from file
|
||||
"/root/folder1/node_modules/file6.ts",
|
||||
"/root/folder1/node_modules/file6.tsx",
|
||||
"/root/folder1/node_modules/file6.d.ts",
|
||||
|
||||
// load from folder
|
||||
"/root/folder1/node_modules/file6/package.json",
|
||||
"/root/folder1/node_modules/file6/index.ts",
|
||||
"/root/folder1/node_modules/file6/index.tsx",
|
||||
"/root/folder1/node_modules/file6/index.d.ts",
|
||||
|
||||
"/root/folder1/node_modules/@types/file6.ts",
|
||||
"/root/folder1/node_modules/@types/file6.tsx",
|
||||
"/root/folder1/node_modules/@types/file6.d.ts",
|
||||
|
||||
"/root/folder1/node_modules/@types/file6/package.json",
|
||||
"/root/folder1/node_modules/@types/file6/index.ts",
|
||||
"/root/folder1/node_modules/@types/file6/index.tsx",
|
||||
"/root/folder1/node_modules/@types/file6/index.d.ts"
|
||||
"/root/folder1/node_modules/@types/file6/index.d.ts",
|
||||
// success on /root/node_modules/file6.ts
|
||||
]);
|
||||
], /*isExternalLibraryImport*/ true);
|
||||
|
||||
function check(name: string, expected: File, expectedFailedLookups: string[]) {
|
||||
function check(name: string, expected: File, expectedFailedLookups: string[], isExternalLibraryImport = false) {
|
||||
const result = resolveModuleName(name, main.name, options, host);
|
||||
assert.isTrue(result.resolvedModule !== undefined, "module should be resolved");
|
||||
assert.equal(result.resolvedModule.resolvedFileName, expected.name);
|
||||
assert.deepEqual(result.failedLookupLocations, expectedFailedLookups);
|
||||
checkResolvedModuleWithFailedLookupLocations(result, createResolvedModule(expected.name, isExternalLibraryImport), expectedFailedLookups);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -744,9 +781,7 @@ import b = require("./moduleB");
|
||||
|
||||
function check(name: string, expected: File, expectedFailedLookups: string[]) {
|
||||
const result = resolveModuleName(name, main.name, options, host);
|
||||
assert.isTrue(result.resolvedModule !== undefined, "module should be resolved");
|
||||
assert.equal(result.resolvedModule.resolvedFileName, expected.name);
|
||||
assert.deepEqual(result.failedLookupLocations, expectedFailedLookups);
|
||||
checkResolvedModuleWithFailedLookupLocations(result, createResolvedModule(expected.name), expectedFailedLookups);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -819,9 +854,7 @@ import b = require("./moduleB");
|
||||
|
||||
function check(name: string, container: File, expected: File, expectedFailedLookups: string[]) {
|
||||
const result = resolveModuleName(name, container.name, options, host);
|
||||
assert.isTrue(result.resolvedModule !== undefined, "module should be resolved");
|
||||
assert.equal(result.resolvedModule.resolvedFileName, expected.name);
|
||||
assert.deepEqual(result.failedLookupLocations, expectedFailedLookups);
|
||||
checkResolvedModuleWithFailedLookupLocations(result, createResolvedModule(expected.name), expectedFailedLookups);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -875,9 +908,7 @@ import b = require("./moduleB");
|
||||
|
||||
function check(name: string, container: File, expected: File, expectedFailedLookups: string[]) {
|
||||
const result = resolveModuleName(name, container.name, options, host);
|
||||
assert.isTrue(result.resolvedModule !== undefined, "module should be resolved");
|
||||
assert.equal(result.resolvedModule.resolvedFileName, expected.name);
|
||||
assert.deepEqual(result.failedLookupLocations, expectedFailedLookups);
|
||||
checkResolvedModuleWithFailedLookupLocations(result, createResolvedModule(expected.name), expectedFailedLookups);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -899,9 +930,7 @@ import b = require("./moduleB");
|
||||
}
|
||||
};
|
||||
const result = resolveModuleName("libs/guid", app.name, options, host);
|
||||
assert.isTrue(result.resolvedModule !== undefined, "module should be resolved");
|
||||
assert.equal(result.resolvedModule.resolvedFileName, libsTypings.name);
|
||||
assert.deepEqual(result.failedLookupLocations, [
|
||||
checkResolvedModuleWithFailedLookupLocations(result, createResolvedModule(libsTypings.name), [
|
||||
// first try to load module as file
|
||||
"/root/src/libs/guid.ts",
|
||||
"/root/src/libs/guid.tsx",
|
||||
|
||||
@ -150,17 +150,6 @@ namespace ts {
|
||||
return program;
|
||||
}
|
||||
|
||||
function checkResolvedModule(expected: ResolvedModule, actual: ResolvedModule): boolean {
|
||||
if (!expected === !actual) {
|
||||
if (expected) {
|
||||
assert.isTrue(expected.resolvedFileName === actual.resolvedFileName, `'resolvedFileName': expected '${expected.resolvedFileName}' to be equal to '${actual.resolvedFileName}'`);
|
||||
assert.isTrue(expected.isExternalLibraryImport === actual.isExternalLibraryImport, `'isExternalLibraryImport': expected '${expected.isExternalLibraryImport}' to be equal to '${actual.isExternalLibraryImport}'`);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkResolvedTypeDirective(expected: ResolvedTypeReferenceDirective, actual: ResolvedTypeReferenceDirective): boolean {
|
||||
if (!expected === !actual) {
|
||||
if (expected) {
|
||||
@ -300,7 +289,7 @@ namespace ts {
|
||||
const options: CompilerOptions = { target };
|
||||
|
||||
const program_1 = newProgram(files, ["a.ts"], options);
|
||||
checkResolvedModulesCache(program_1, "a.ts", createMap({ "b": { resolvedFileName: "b.ts" } }));
|
||||
checkResolvedModulesCache(program_1, "a.ts", createMap({ "b": createResolvedModule("b.ts") }));
|
||||
checkResolvedModulesCache(program_1, "b.ts", undefined);
|
||||
|
||||
const program_2 = updateProgram(program_1, ["a.ts"], options, files => {
|
||||
@ -309,7 +298,7 @@ namespace ts {
|
||||
assert.isTrue(program_1.structureIsReused);
|
||||
|
||||
// content of resolution cache should not change
|
||||
checkResolvedModulesCache(program_1, "a.ts", createMap({ "b": { resolvedFileName: "b.ts" } }));
|
||||
checkResolvedModulesCache(program_1, "a.ts", createMap({ "b": createResolvedModule("b.ts") }));
|
||||
checkResolvedModulesCache(program_1, "b.ts", undefined);
|
||||
|
||||
// imports has changed - program is not reused
|
||||
@ -326,7 +315,7 @@ namespace ts {
|
||||
files[0].text = files[0].text.updateImportsAndExports(newImports);
|
||||
});
|
||||
assert.isTrue(!program_3.structureIsReused);
|
||||
checkResolvedModulesCache(program_4, "a.ts", createMap({ "b": { resolvedFileName: "b.ts" }, "c": undefined }));
|
||||
checkResolvedModulesCache(program_4, "a.ts", createMap({ "b": createResolvedModule("b.ts"), "c": undefined }));
|
||||
});
|
||||
|
||||
it("resolved type directives cache follows type directives", () => {
|
||||
|
||||
@ -1659,67 +1659,74 @@ namespace ts.projectSystem {
|
||||
"File '/a/b/node_modules/lib.ts' does not exist.",
|
||||
"File '/a/b/node_modules/lib.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/lib.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/lib.js' does not exist.",
|
||||
"File '/a/b/node_modules/lib.jsx' does not exist.",
|
||||
"File '/a/b/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.ts' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.js' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.jsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.js' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.jsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.js' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.jsx' does not exist.",
|
||||
"File '/a/node_modules/lib.ts' does not exist.",
|
||||
"File '/a/node_modules/lib.tsx' does not exist.",
|
||||
"File '/a/node_modules/lib.d.ts' does not exist.",
|
||||
"File '/a/node_modules/lib.js' does not exist.",
|
||||
"File '/a/node_modules/lib.jsx' does not exist.",
|
||||
"File '/a/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/node_modules/lib/index.ts' does not exist.",
|
||||
"File '/a/node_modules/lib/index.tsx' does not exist.",
|
||||
"File '/a/node_modules/lib/index.d.ts' does not exist.",
|
||||
"File '/a/node_modules/lib/index.js' does not exist.",
|
||||
"File '/a/node_modules/lib/index.jsx' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.tsx' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.d.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.js' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.jsx' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.tsx' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.d.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.js' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.jsx' does not exist.",
|
||||
"File '/node_modules/lib.ts' does not exist.",
|
||||
"File '/node_modules/lib.tsx' does not exist.",
|
||||
"File '/node_modules/lib.d.ts' does not exist.",
|
||||
"File '/node_modules/lib.js' does not exist.",
|
||||
"File '/node_modules/lib.jsx' does not exist.",
|
||||
"File '/node_modules/lib/package.json' does not exist.",
|
||||
"File '/node_modules/lib/index.ts' does not exist.",
|
||||
"File '/node_modules/lib/index.tsx' does not exist.",
|
||||
"File '/node_modules/lib/index.d.ts' does not exist.",
|
||||
"File '/node_modules/lib/index.js' does not exist.",
|
||||
"File '/node_modules/lib/index.jsx' does not exist.",
|
||||
"File '/node_modules/@types/lib.ts' does not exist.",
|
||||
"File '/node_modules/@types/lib.tsx' does not exist.",
|
||||
"File '/node_modules/@types/lib.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/lib.js' does not exist.",
|
||||
"File '/node_modules/@types/lib.jsx' does not exist.",
|
||||
"File '/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/node_modules/@types/lib/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/lib/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/lib/index.d.ts' does not exist.",
|
||||
"Loading module 'lib' from 'node_modules' folder.",
|
||||
"File '/a/b/node_modules/lib.js' does not exist.",
|
||||
"File '/a/b/node_modules/lib.jsx' does not exist.",
|
||||
"File '/a/b/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.js' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.jsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.js' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.jsx' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.js' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.jsx' does not exist.",
|
||||
"File '/a/node_modules/lib.js' does not exist.",
|
||||
"File '/a/node_modules/lib.jsx' does not exist.",
|
||||
"File '/a/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/node_modules/lib/index.js' does not exist.",
|
||||
"File '/a/node_modules/lib/index.jsx' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.js' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.jsx' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.js' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.jsx' does not exist.",
|
||||
"File '/node_modules/lib.js' does not exist.",
|
||||
"File '/node_modules/lib.jsx' does not exist.",
|
||||
"File '/node_modules/lib/package.json' does not exist.",
|
||||
"File '/node_modules/lib/index.js' does not exist.",
|
||||
"File '/node_modules/lib/index.jsx' does not exist.",
|
||||
"File '/node_modules/@types/lib.js' does not exist.",
|
||||
"File '/node_modules/@types/lib.jsx' does not exist.",
|
||||
"File '/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/node_modules/@types/lib/index.js' does not exist.",
|
||||
"File '/node_modules/@types/lib/index.jsx' does not exist.",
|
||||
"======== Module name 'lib' was not resolved. ========",
|
||||
@ -1727,19 +1734,13 @@ namespace ts.projectSystem {
|
||||
"File '/a/cache/node_modules/lib.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/lib.tsx' does not exist.",
|
||||
"File '/a/cache/node_modules/lib.d.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/lib.js' does not exist.",
|
||||
"File '/a/cache/node_modules/lib.jsx' does not exist.",
|
||||
"File '/a/cache/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/cache/node_modules/lib/index.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/lib/index.tsx' does not exist.",
|
||||
"File '/a/cache/node_modules/lib/index.d.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/lib/index.js' does not exist.",
|
||||
"File '/a/cache/node_modules/lib/index.jsx' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib.tsx' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib.d.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib.js' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib.jsx' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib/index.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib/index.tsx' does not exist.",
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
namespace ts.server {
|
||||
export class LSHost implements ts.LanguageServiceHost, ModuleResolutionHost, ServerLanguageServiceHost {
|
||||
private compilationSettings: ts.CompilerOptions;
|
||||
private readonly resolvedModuleNames: ts.FileMap<Map<ResolvedModuleWithFailedLookupLocations>>;
|
||||
private readonly resolvedTypeReferenceDirectives: ts.FileMap<Map<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>>;
|
||||
private readonly resolvedModuleNames= createFileMap<Map<ResolvedModuleWithFailedLookupLocations>>();
|
||||
private readonly resolvedTypeReferenceDirectives = createFileMap<Map<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>>();
|
||||
private readonly getCanonicalFileName: (fileName: string) => string;
|
||||
|
||||
private filesWithChangedSetOfUnresolvedImports: Path[];
|
||||
@ -16,40 +16,27 @@ namespace ts.server {
|
||||
|
||||
constructor(private readonly host: ServerHost, private readonly project: Project, private readonly cancellationToken: HostCancellationToken) {
|
||||
this.getCanonicalFileName = ts.createGetCanonicalFileName(this.host.useCaseSensitiveFileNames);
|
||||
this.resolvedModuleNames = createFileMap<Map<ResolvedModuleWithFailedLookupLocations>>();
|
||||
this.resolvedTypeReferenceDirectives = createFileMap<Map<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>>();
|
||||
|
||||
if (host.trace) {
|
||||
this.trace = s => host.trace(s);
|
||||
}
|
||||
|
||||
this.resolveModuleName = (moduleName, containingFile, compilerOptions, host) => {
|
||||
const globalCache = this.project.getTypingOptions().enableAutoDiscovery
|
||||
? this.project.projectService.typingsInstaller.globalTypingsCacheLocation
|
||||
: undefined;
|
||||
const primaryResult = resolveModuleName(moduleName, containingFile, compilerOptions, host);
|
||||
if (primaryResult.resolvedModule) {
|
||||
// return result immediately only if it is .ts, .tsx or .d.ts
|
||||
// return result immediately only if it is .ts, .tsx or .d.ts
|
||||
if (!(primaryResult.resolvedModule && extensionIsTypeScript(primaryResult.resolvedModule.extension)) && globalCache !== undefined) {
|
||||
// otherwise try to load typings from @types
|
||||
if (fileExtensionIsAny(primaryResult.resolvedModule.resolvedFileName, supportedTypeScriptExtensions)) {
|
||||
return primaryResult;
|
||||
|
||||
// create different collection of failed lookup locations for second pass
|
||||
// if it will fail and we've already found something during the first pass - we don't want to pollute its results
|
||||
const { resolvedModule, failedLookupLocations } = loadModuleFromGlobalCache(moduleName, this.project.getProjectName(), compilerOptions, host, globalCache);
|
||||
if (resolvedModule) {
|
||||
return { resolvedModule, failedLookupLocations: primaryResult.failedLookupLocations.concat(failedLookupLocations) };
|
||||
}
|
||||
}
|
||||
// create different collection of failed lookup locations for second pass
|
||||
// if it will fail and we've already found something during the first pass - we don't want to pollute its results
|
||||
const secondaryLookupFailedLookupLocations: string[] = [];
|
||||
const globalCache = this.project.projectService.typingsInstaller.globalTypingsCacheLocation;
|
||||
if (this.project.getTypingOptions().enableAutoDiscovery && globalCache) {
|
||||
const traceEnabled = isTraceEnabled(compilerOptions, host);
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Auto_discovery_for_typings_is_enabled_in_project_0_Running_extra_resolution_pass_for_module_1_using_cache_location_2, this.project.getProjectName(), moduleName, globalCache);
|
||||
}
|
||||
const state: ModuleResolutionState = { compilerOptions, host, skipTsx: false, traceEnabled };
|
||||
const resolvedName = loadModuleFromNodeModules(moduleName, globalCache, secondaryLookupFailedLookupLocations, state, /*checkOneLevel*/ true);
|
||||
if (resolvedName) {
|
||||
return createResolvedModule(resolvedName, /*isExternalLibraryImport*/ true, primaryResult.failedLookupLocations.concat(secondaryLookupFailedLookupLocations));
|
||||
}
|
||||
}
|
||||
if (!primaryResult.resolvedModule && secondaryLookupFailedLookupLocations.length) {
|
||||
primaryResult.failedLookupLocations = primaryResult.failedLookupLocations.concat(secondaryLookupFailedLookupLocations);
|
||||
}
|
||||
return primaryResult;
|
||||
};
|
||||
}
|
||||
@ -64,12 +51,13 @@ namespace ts.server {
|
||||
return collected;
|
||||
}
|
||||
|
||||
private resolveNamesWithLocalCache<T extends { failedLookupLocations: string[] }, R extends { resolvedFileName?: string }>(
|
||||
private resolveNamesWithLocalCache<T extends { failedLookupLocations: string[] }, R>(
|
||||
names: string[],
|
||||
containingFile: string,
|
||||
cache: ts.FileMap<Map<T>>,
|
||||
loader: (name: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost) => T,
|
||||
getResult: (s: T) => R,
|
||||
getResultFileName: (result: R) => string | undefined,
|
||||
logChanges: boolean): R[] {
|
||||
|
||||
const path = toPath(containingFile, this.host.getCurrentDirectory(), this.getCanonicalFileName);
|
||||
@ -123,7 +111,7 @@ namespace ts.server {
|
||||
if (!oldResult || !newResult) {
|
||||
return false;
|
||||
}
|
||||
return oldResult.resolvedFileName === newResult.resolvedFileName;
|
||||
return getResultFileName(oldResult) === getResultFileName(newResult);
|
||||
}
|
||||
|
||||
function moduleResolutionIsValid(resolution: T): boolean {
|
||||
@ -133,10 +121,7 @@ namespace ts.server {
|
||||
|
||||
const result = getResult(resolution);
|
||||
if (result) {
|
||||
if (result.resolvedFileName && result.resolvedFileName === lastDeletedFileName) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return getResultFileName(result) !== lastDeletedFileName;
|
||||
}
|
||||
|
||||
// consider situation if we have no candidate locations as valid resolution.
|
||||
@ -162,11 +147,13 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
resolveTypeReferenceDirectives(typeDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[] {
|
||||
return this.resolveNamesWithLocalCache(typeDirectiveNames, containingFile, this.resolvedTypeReferenceDirectives, resolveTypeReferenceDirective, m => m.resolvedTypeReferenceDirective, /*logChanges*/ false);
|
||||
return this.resolveNamesWithLocalCache(typeDirectiveNames, containingFile, this.resolvedTypeReferenceDirectives, resolveTypeReferenceDirective,
|
||||
m => m.resolvedTypeReferenceDirective, r => r.resolvedFileName, /*logChanges*/ false);
|
||||
}
|
||||
|
||||
resolveModuleNames(moduleNames: string[], containingFile: string): ResolvedModule[] {
|
||||
return this.resolveNamesWithLocalCache(moduleNames, containingFile, this.resolvedModuleNames, this.resolveModuleName, m => m.resolvedModule, /*logChanges*/ true);
|
||||
return this.resolveNamesWithLocalCache(moduleNames, containingFile, this.resolvedModuleNames, this.resolveModuleName,
|
||||
m => m.resolvedModule, r => r.resolvedFileName, /*logChanges*/ true);
|
||||
}
|
||||
|
||||
getDefaultLibFileName() {
|
||||
|
||||
@ -328,7 +328,7 @@ namespace ts {
|
||||
const resolutionsInFile = <MapLike<string>>JSON.parse(this.shimHost.getModuleResolutionsForFile(containingFile));
|
||||
return map(moduleNames, name => {
|
||||
const result = getProperty(resolutionsInFile, name);
|
||||
return result ? { resolvedFileName: result } : undefined;
|
||||
return result ? { resolvedFileName: result, extension: extensionFromPath(result), isExternalLibraryImport: false } : undefined;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@ -6,5 +6,9 @@
|
||||
"File '/foo/index.ts' does not exist.",
|
||||
"File '/foo/index.tsx' does not exist.",
|
||||
"File '/foo/index.d.ts' does not exist.",
|
||||
"Loading module as file / folder, candidate module location '/foo/'.",
|
||||
"File '/foo/package.json' does not exist.",
|
||||
"File '/foo/index.js' does not exist.",
|
||||
"File '/foo/index.jsx' does not exist.",
|
||||
"======== Module name './foo/' was not resolved. ========"
|
||||
]
|
||||
@ -2,17 +2,12 @@
|
||||
"======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory not set. ========",
|
||||
"Root directory cannot be determined, skipping primary search paths.",
|
||||
"Looking up in 'node_modules' folder, initial location '/a/b'",
|
||||
"File '/a/b/node_modules/jquery.ts' does not exist.",
|
||||
"File '/a/b/node_modules/jquery.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/jquery/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/jquery/index.ts' does not exist.",
|
||||
"File '/a/b/node_modules/jquery/index.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/jquery.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/jquery.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/jquery/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/@types/jquery/index.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/jquery/index.d.ts' does not exist.",
|
||||
"File '/a/node_modules/jquery.ts' does not exist.",
|
||||
"File '/a/node_modules/jquery.d.ts' does not exist.",
|
||||
"Found 'package.json' at '/a/node_modules/jquery/package.json'.",
|
||||
"'package.json' has 'typings' field 'jquery.d.ts' that references '/a/node_modules/jquery/jquery.d.ts'.",
|
||||
|
||||
@ -2,17 +2,12 @@
|
||||
"======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory not set. ========",
|
||||
"Root directory cannot be determined, skipping primary search paths.",
|
||||
"Looking up in 'node_modules' folder, initial location '/a/b'",
|
||||
"File '/a/b/node_modules/jquery.ts' does not exist.",
|
||||
"File '/a/b/node_modules/jquery.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/jquery/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/jquery/index.ts' does not exist.",
|
||||
"File '/a/b/node_modules/jquery/index.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/jquery.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/jquery.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/jquery/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/@types/jquery/index.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/jquery/index.d.ts' does not exist.",
|
||||
"File '/a/node_modules/jquery.ts' does not exist.",
|
||||
"File '/a/node_modules/jquery.d.ts' does not exist.",
|
||||
"Found 'package.json' at '/a/node_modules/jquery/package.json'.",
|
||||
"'package.json' has 'types' field 'dist/jquery.d.ts' that references '/a/node_modules/jquery/dist/jquery.d.ts'.",
|
||||
|
||||
@ -2,10 +2,8 @@
|
||||
"======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory not set. ========",
|
||||
"Root directory cannot be determined, skipping primary search paths.",
|
||||
"Looking up in 'node_modules' folder, initial location '/src'",
|
||||
"File '/src/node_modules/jquery.ts' does not exist.",
|
||||
"File '/src/node_modules/jquery.d.ts' does not exist.",
|
||||
"File '/src/node_modules/jquery/package.json' does not exist.",
|
||||
"File '/src/node_modules/jquery/index.ts' does not exist.",
|
||||
"File '/src/node_modules/jquery/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'jquery' was successfully resolved to '/src/node_modules/jquery/index.d.ts', primary: false. ========"
|
||||
]
|
||||
@ -4,20 +4,14 @@
|
||||
"File '/src/foo/package.json' does not exist.",
|
||||
"File '/src/foo/index.d.ts' does not exist.",
|
||||
"Looking up in 'node_modules' folder, initial location '/src'",
|
||||
"File '/src/node_modules/foo.ts' does not exist.",
|
||||
"File '/src/node_modules/foo.d.ts' does not exist.",
|
||||
"File '/src/node_modules/foo/package.json' does not exist.",
|
||||
"File '/src/node_modules/foo/index.ts' does not exist.",
|
||||
"File '/src/node_modules/foo/index.d.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/foo.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/foo.d.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/foo/package.json' does not exist.",
|
||||
"File '/src/node_modules/@types/foo/index.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/foo/index.d.ts' does not exist.",
|
||||
"File '/node_modules/foo.ts' does not exist.",
|
||||
"File '/node_modules/foo.d.ts' does not exist.",
|
||||
"File '/node_modules/foo/package.json' does not exist.",
|
||||
"File '/node_modules/foo/index.ts' does not exist.",
|
||||
"File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'foo' was successfully resolved to '/node_modules/foo/index.d.ts', primary: false. ========",
|
||||
"======== Resolving type reference directive 'bar', containing file '/src/root.ts', root directory '/src'. ========",
|
||||
@ -25,20 +19,14 @@
|
||||
"File '/src/bar/package.json' does not exist.",
|
||||
"File '/src/bar/index.d.ts' does not exist.",
|
||||
"Looking up in 'node_modules' folder, initial location '/src'",
|
||||
"File '/src/node_modules/bar.ts' does not exist.",
|
||||
"File '/src/node_modules/bar.d.ts' does not exist.",
|
||||
"File '/src/node_modules/bar/package.json' does not exist.",
|
||||
"File '/src/node_modules/bar/index.ts' does not exist.",
|
||||
"File '/src/node_modules/bar/index.d.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/bar.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/bar.d.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/bar/package.json' does not exist.",
|
||||
"File '/src/node_modules/@types/bar/index.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/bar/index.d.ts' does not exist.",
|
||||
"File '/node_modules/bar.ts' does not exist.",
|
||||
"File '/node_modules/bar.d.ts' does not exist.",
|
||||
"File '/node_modules/bar/package.json' does not exist.",
|
||||
"File '/node_modules/bar/index.ts' does not exist.",
|
||||
"File '/node_modules/bar/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'bar' was successfully resolved to '/node_modules/bar/index.d.ts', primary: false. ========",
|
||||
"======== Resolving type reference directive 'alpha', containing file '/node_modules/foo/index.d.ts', root directory '/src'. ========",
|
||||
@ -46,10 +34,8 @@
|
||||
"File '/src/alpha/package.json' does not exist.",
|
||||
"File '/src/alpha/index.d.ts' does not exist.",
|
||||
"Looking up in 'node_modules' folder, initial location '/node_modules/foo'",
|
||||
"File '/node_modules/foo/node_modules/alpha.ts' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha.d.ts' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha/package.json' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha/index.ts' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'alpha' was successfully resolved to '/node_modules/foo/node_modules/alpha/index.d.ts', primary: false. ========",
|
||||
"======== Resolving type reference directive 'alpha', containing file '/node_modules/bar/index.d.ts', root directory '/src'. ========",
|
||||
@ -57,10 +43,8 @@
|
||||
"File '/src/alpha/package.json' does not exist.",
|
||||
"File '/src/alpha/index.d.ts' does not exist.",
|
||||
"Looking up in 'node_modules' folder, initial location '/node_modules/bar'",
|
||||
"File '/node_modules/bar/node_modules/alpha.ts' does not exist.",
|
||||
"File '/node_modules/bar/node_modules/alpha.d.ts' does not exist.",
|
||||
"File '/node_modules/bar/node_modules/alpha/package.json' does not exist.",
|
||||
"File '/node_modules/bar/node_modules/alpha/index.ts' does not exist.",
|
||||
"File '/node_modules/bar/node_modules/alpha/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'alpha' was successfully resolved to '/node_modules/bar/node_modules/alpha/index.d.ts', primary: false. ========"
|
||||
]
|
||||
@ -4,20 +4,14 @@
|
||||
"File 'types/foo/package.json' does not exist.",
|
||||
"File 'types/foo/index.d.ts' does not exist.",
|
||||
"Looking up in 'node_modules' folder, initial location '/src'",
|
||||
"File '/src/node_modules/foo.ts' does not exist.",
|
||||
"File '/src/node_modules/foo.d.ts' does not exist.",
|
||||
"File '/src/node_modules/foo/package.json' does not exist.",
|
||||
"File '/src/node_modules/foo/index.ts' does not exist.",
|
||||
"File '/src/node_modules/foo/index.d.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/foo.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/foo.d.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/foo/package.json' does not exist.",
|
||||
"File '/src/node_modules/@types/foo/index.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/foo/index.d.ts' does not exist.",
|
||||
"File '/node_modules/foo.ts' does not exist.",
|
||||
"File '/node_modules/foo.d.ts' does not exist.",
|
||||
"File '/node_modules/foo/package.json' does not exist.",
|
||||
"File '/node_modules/foo/index.ts' does not exist.",
|
||||
"File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'foo' was successfully resolved to '/node_modules/foo/index.d.ts', primary: false. ========",
|
||||
"======== Resolving type reference directive 'bar', containing file '/src/root.ts', root directory 'types'. ========",
|
||||
@ -25,20 +19,14 @@
|
||||
"File 'types/bar/package.json' does not exist.",
|
||||
"File 'types/bar/index.d.ts' does not exist.",
|
||||
"Looking up in 'node_modules' folder, initial location '/src'",
|
||||
"File '/src/node_modules/bar.ts' does not exist.",
|
||||
"File '/src/node_modules/bar.d.ts' does not exist.",
|
||||
"File '/src/node_modules/bar/package.json' does not exist.",
|
||||
"File '/src/node_modules/bar/index.ts' does not exist.",
|
||||
"File '/src/node_modules/bar/index.d.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/bar.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/bar.d.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/bar/package.json' does not exist.",
|
||||
"File '/src/node_modules/@types/bar/index.ts' does not exist.",
|
||||
"File '/src/node_modules/@types/bar/index.d.ts' does not exist.",
|
||||
"File '/node_modules/bar.ts' does not exist.",
|
||||
"File '/node_modules/bar.d.ts' does not exist.",
|
||||
"File '/node_modules/bar/package.json' does not exist.",
|
||||
"File '/node_modules/bar/index.ts' does not exist.",
|
||||
"File '/node_modules/bar/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'bar' was successfully resolved to '/node_modules/bar/index.d.ts', primary: false. ========",
|
||||
"======== Resolving type reference directive 'alpha', containing file '/node_modules/foo/index.d.ts', root directory 'types'. ========",
|
||||
@ -46,10 +34,8 @@
|
||||
"File 'types/alpha/package.json' does not exist.",
|
||||
"File 'types/alpha/index.d.ts' does not exist.",
|
||||
"Looking up in 'node_modules' folder, initial location '/node_modules/foo'",
|
||||
"File '/node_modules/foo/node_modules/alpha.ts' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha.d.ts' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha/package.json' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha/index.ts' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'alpha' was successfully resolved to '/node_modules/foo/node_modules/alpha/index.d.ts', primary: false. ========",
|
||||
"======== Resolving type reference directive 'alpha', containing file '/node_modules/bar/index.d.ts', root directory 'types'. ========",
|
||||
@ -57,10 +43,8 @@
|
||||
"File 'types/alpha/package.json' does not exist.",
|
||||
"File 'types/alpha/index.d.ts' does not exist.",
|
||||
"Looking up in 'node_modules' folder, initial location '/node_modules/bar'",
|
||||
"File '/node_modules/bar/node_modules/alpha.ts' does not exist.",
|
||||
"File '/node_modules/bar/node_modules/alpha.d.ts' does not exist.",
|
||||
"File '/node_modules/bar/node_modules/alpha/package.json' does not exist.",
|
||||
"File '/node_modules/bar/node_modules/alpha/index.ts' does not exist.",
|
||||
"File '/node_modules/bar/node_modules/alpha/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'alpha' was successfully resolved to '/node_modules/bar/node_modules/alpha/index.d.ts', primary: false. ========"
|
||||
]
|
||||
@ -2,10 +2,8 @@
|
||||
"======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory not set. ========",
|
||||
"Root directory cannot be determined, skipping primary search paths.",
|
||||
"Looking up in 'node_modules' folder, initial location '/src'",
|
||||
"File '/src/node_modules/jquery.ts' does not exist.",
|
||||
"File '/src/node_modules/jquery.d.ts' does not exist.",
|
||||
"File '/src/node_modules/jquery/package.json' does not exist.",
|
||||
"File '/src/node_modules/jquery/index.ts' does not exist.",
|
||||
"File '/src/node_modules/jquery/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'jquery' was successfully resolved to '/src/node_modules/jquery/index.d.ts', primary: false. ========"
|
||||
]
|
||||
@ -5,24 +5,22 @@
|
||||
"File '/node_modules/shortid.ts' does not exist.",
|
||||
"File '/node_modules/shortid.tsx' does not exist.",
|
||||
"File '/node_modules/shortid.d.ts' does not exist.",
|
||||
"File '/node_modules/shortid.js' does not exist.",
|
||||
"File '/node_modules/shortid.jsx' does not exist.",
|
||||
"File '/node_modules/shortid/package.json' does not exist.",
|
||||
"File '/node_modules/shortid/index.ts' does not exist.",
|
||||
"File '/node_modules/shortid/index.tsx' does not exist.",
|
||||
"File '/node_modules/shortid/index.d.ts' does not exist.",
|
||||
"File '/node_modules/shortid/index.js' exist - use it as a name resolution result.",
|
||||
"File '/node_modules/@types/shortid.ts' does not exist.",
|
||||
"File '/node_modules/@types/shortid.tsx' does not exist.",
|
||||
"File '/node_modules/@types/shortid.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/shortid.js' does not exist.",
|
||||
"File '/node_modules/@types/shortid.jsx' does not exist.",
|
||||
"File '/node_modules/@types/shortid/package.json' does not exist.",
|
||||
"File '/node_modules/@types/shortid/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/shortid/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/shortid/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/shortid/index.js' does not exist.",
|
||||
"File '/node_modules/@types/shortid/index.jsx' does not exist.",
|
||||
"Loading module 'shortid' from 'node_modules' folder.",
|
||||
"File '/node_modules/shortid.js' does not exist.",
|
||||
"File '/node_modules/shortid.jsx' does not exist.",
|
||||
"File '/node_modules/shortid/package.json' does not exist.",
|
||||
"File '/node_modules/shortid/index.js' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/node_modules/shortid/index.js', result '/node_modules/shortid/index.js'",
|
||||
"======== Module name 'shortid' was successfully resolved to '/node_modules/shortid/index.js'. ========"
|
||||
]
|
||||
@ -25,7 +25,7 @@ import z2 from "./z";
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports["default"] = 0;
|
||||
//// [y.js]
|
||||
//// [y.jsx]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports["default"] = 0;
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
/a.ts(1,17): error TS6142: Module './tsx' was resolved to '/tsx.tsx', but '--jsx' is not set.
|
||||
/a.ts(2,17): error TS6142: Module './jsx' was resolved to '/jsx.jsx', but '--jsx' is not set.
|
||||
/a.ts(3,16): error TS6143: Module './js' was resolved to '/js.js', but '--allowJs' is not set.
|
||||
|
||||
|
||||
==== /a.ts (3 errors) ====
|
||||
import tsx from "./tsx";
|
||||
~~~~~~~
|
||||
!!! error TS6142: Module './tsx' was resolved to '/tsx.tsx', but '--jsx' is not set.
|
||||
import jsx from "./jsx";
|
||||
~~~~~~~
|
||||
!!! error TS6142: Module './jsx' was resolved to '/jsx.jsx', but '--jsx' is not set.
|
||||
import js from "./js";
|
||||
~~~~~~
|
||||
!!! error TS6143: Module './js' was resolved to '/js.js', but '--allowJs' is not set.
|
||||
|
||||
==== /tsx.tsx (0 errors) ====
|
||||
|
||||
|
||||
==== /jsx.jsx (0 errors) ====
|
||||
|
||||
==== /js.js (0 errors) ====
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
//// [tests/cases/compiler/moduleResolutionWithExtensions_notSupported.ts] ////
|
||||
|
||||
//// [tsx.tsx]
|
||||
|
||||
|
||||
//// [jsx.jsx]
|
||||
|
||||
//// [js.js]
|
||||
|
||||
//// [a.ts]
|
||||
import tsx from "./tsx";
|
||||
import jsx from "./jsx";
|
||||
import js from "./js";
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
@ -0,0 +1,38 @@
|
||||
[
|
||||
"======== Resolving module './tsx' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module as file / folder, candidate module location '/tsx'.",
|
||||
"File '/tsx.ts' does not exist.",
|
||||
"File '/tsx.tsx' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/tsx.tsx', result '/tsx.tsx'",
|
||||
"======== Module name './tsx' was successfully resolved to '/tsx.tsx'. ========",
|
||||
"======== Resolving module './jsx' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module as file / folder, candidate module location '/jsx'.",
|
||||
"File '/jsx.ts' does not exist.",
|
||||
"File '/jsx.tsx' does not exist.",
|
||||
"File '/jsx.d.ts' does not exist.",
|
||||
"File '/jsx/package.json' does not exist.",
|
||||
"File '/jsx/index.ts' does not exist.",
|
||||
"File '/jsx/index.tsx' does not exist.",
|
||||
"File '/jsx/index.d.ts' does not exist.",
|
||||
"Loading module as file / folder, candidate module location '/jsx'.",
|
||||
"File '/jsx.js' does not exist.",
|
||||
"File '/jsx.jsx' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/jsx.jsx', result '/jsx.jsx'",
|
||||
"======== Module name './jsx' was successfully resolved to '/jsx.jsx'. ========",
|
||||
"======== Resolving module './js' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module as file / folder, candidate module location '/js'.",
|
||||
"File '/js.ts' does not exist.",
|
||||
"File '/js.tsx' does not exist.",
|
||||
"File '/js.d.ts' does not exist.",
|
||||
"File '/js/package.json' does not exist.",
|
||||
"File '/js/index.ts' does not exist.",
|
||||
"File '/js/index.tsx' does not exist.",
|
||||
"File '/js/index.d.ts' does not exist.",
|
||||
"Loading module as file / folder, candidate module location '/js'.",
|
||||
"File '/js.js' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/js.js', result '/js.js'",
|
||||
"======== Module name './js' was successfully resolved to '/js.js'. ========"
|
||||
]
|
||||
@ -0,0 +1,12 @@
|
||||
/a.ts(1,17): error TS6142: Module './jsx' was resolved to '/jsx.jsx', but '--jsx' is not set.
|
||||
|
||||
|
||||
==== /a.ts (1 errors) ====
|
||||
import jsx from "./jsx";
|
||||
~~~~~~~
|
||||
!!! error TS6142: Module './jsx' was resolved to '/jsx.jsx', but '--jsx' is not set.
|
||||
|
||||
==== /jsx.jsx (0 errors) ====
|
||||
// Test the error message if we have `--allowJs` but not `--jsx`.
|
||||
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
//// [tests/cases/compiler/moduleResolutionWithExtensions_notSupported2.ts] ////
|
||||
|
||||
//// [jsx.jsx]
|
||||
// Test the error message if we have `--allowJs` but not `--jsx`.
|
||||
|
||||
|
||||
//// [a.ts]
|
||||
import jsx from "./jsx";
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
@ -0,0 +1,17 @@
|
||||
[
|
||||
"======== Resolving module './jsx' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module as file / folder, candidate module location '/jsx'.",
|
||||
"File '/jsx.ts' does not exist.",
|
||||
"File '/jsx.tsx' does not exist.",
|
||||
"File '/jsx.d.ts' does not exist.",
|
||||
"File '/jsx/package.json' does not exist.",
|
||||
"File '/jsx/index.ts' does not exist.",
|
||||
"File '/jsx/index.tsx' does not exist.",
|
||||
"File '/jsx/index.d.ts' does not exist.",
|
||||
"Loading module as file / folder, candidate module location '/jsx'.",
|
||||
"File '/jsx.js' does not exist.",
|
||||
"File '/jsx.jsx' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/jsx.jsx', result '/jsx.jsx'",
|
||||
"======== Module name './jsx' was successfully resolved to '/jsx.jsx'. ========"
|
||||
]
|
||||
@ -0,0 +1,18 @@
|
||||
//// [tests/cases/compiler/moduleResolutionWithExtensions_preferTs.ts] ////
|
||||
|
||||
//// [b.js]
|
||||
|
||||
|
||||
//// [index.ts]
|
||||
export default 0;
|
||||
|
||||
//// [a.ts]
|
||||
import b from "./b";
|
||||
|
||||
|
||||
//// [index.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports["default"] = 0;
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
@ -0,0 +1,8 @@
|
||||
=== /a.ts ===
|
||||
import b from "./b";
|
||||
>b : Symbol(b, Decl(a.ts, 0, 6))
|
||||
|
||||
=== /b/index.ts ===
|
||||
export default 0;
|
||||
No type information for this code.
|
||||
No type information for this code.
|
||||
@ -0,0 +1,12 @@
|
||||
[
|
||||
"======== Resolving module './b' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module as file / folder, candidate module location '/b'.",
|
||||
"File '/b.ts' does not exist.",
|
||||
"File '/b.tsx' does not exist.",
|
||||
"File '/b.d.ts' does not exist.",
|
||||
"File '/b/package.json' does not exist.",
|
||||
"File '/b/index.ts' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/b/index.ts', result '/b/index.ts'",
|
||||
"======== Module name './b' was successfully resolved to '/b/index.ts'. ========"
|
||||
]
|
||||
@ -0,0 +1,8 @@
|
||||
=== /a.ts ===
|
||||
import b from "./b";
|
||||
>b : 0
|
||||
|
||||
=== /b/index.ts ===
|
||||
export default 0;
|
||||
No type information for this code.
|
||||
No type information for this code.
|
||||
@ -0,0 +1,18 @@
|
||||
//// [tests/cases/compiler/moduleResolutionWithExtensions_withAmbientPresent.ts] ////
|
||||
|
||||
//// [index.js]
|
||||
// Allowjs is false, but this should *not* warn about the unused 'index.js'
|
||||
|
||||
|
||||
//// [declarations.d.ts]
|
||||
declare module "js" {
|
||||
export const x = 0;
|
||||
}
|
||||
|
||||
//// [a.ts]
|
||||
/// <reference path="declarations.d.ts" />
|
||||
import { x } from "js";
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
@ -0,0 +1,11 @@
|
||||
=== /a.ts ===
|
||||
/// <reference path="declarations.d.ts" />
|
||||
import { x } from "js";
|
||||
>x : Symbol(x, Decl(a.ts, 1, 8))
|
||||
|
||||
=== /declarations.d.ts ===
|
||||
declare module "js" {
|
||||
export const x = 0;
|
||||
>x : Symbol(x, Decl(declarations.d.ts, 1, 16))
|
||||
}
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
[
|
||||
"======== Resolving module 'js' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module 'js' from 'node_modules' folder.",
|
||||
"File '/node_modules/js.ts' does not exist.",
|
||||
"File '/node_modules/js.tsx' does not exist.",
|
||||
"File '/node_modules/js.d.ts' does not exist.",
|
||||
"File '/node_modules/js/package.json' does not exist.",
|
||||
"File '/node_modules/js/index.ts' does not exist.",
|
||||
"File '/node_modules/js/index.tsx' does not exist.",
|
||||
"File '/node_modules/js/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/js.ts' does not exist.",
|
||||
"File '/node_modules/@types/js.tsx' does not exist.",
|
||||
"File '/node_modules/@types/js.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/js/package.json' does not exist.",
|
||||
"File '/node_modules/@types/js/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/js/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/js/index.d.ts' does not exist.",
|
||||
"Loading module 'js' from 'node_modules' folder.",
|
||||
"File '/node_modules/js.js' does not exist.",
|
||||
"File '/node_modules/js.jsx' does not exist.",
|
||||
"File '/node_modules/js/package.json' does not exist.",
|
||||
"File '/node_modules/js/index.js' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/node_modules/js/index.js', result '/node_modules/js/index.js'",
|
||||
"======== Module name 'js' was successfully resolved to '/node_modules/js/index.js'. ========"
|
||||
]
|
||||
@ -0,0 +1,12 @@
|
||||
=== /a.ts ===
|
||||
/// <reference path="declarations.d.ts" />
|
||||
import { x } from "js";
|
||||
>x : 0
|
||||
|
||||
=== /declarations.d.ts ===
|
||||
declare module "js" {
|
||||
export const x = 0;
|
||||
>x : 0
|
||||
>0 : 0
|
||||
}
|
||||
|
||||
@ -64,5 +64,36 @@
|
||||
"File '/node_modules/@types/library-a/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/library-a/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/library-a/index.d.ts' does not exist.",
|
||||
"Loading module 'library-a' from 'node_modules' folder.",
|
||||
"File '/src/library-b/node_modules/library-a.js' does not exist.",
|
||||
"File '/src/library-b/node_modules/library-a.jsx' does not exist.",
|
||||
"File '/src/library-b/node_modules/library-a/package.json' does not exist.",
|
||||
"File '/src/library-b/node_modules/library-a/index.js' does not exist.",
|
||||
"File '/src/library-b/node_modules/library-a/index.jsx' does not exist.",
|
||||
"File '/src/library-b/node_modules/@types/library-a.js' does not exist.",
|
||||
"File '/src/library-b/node_modules/@types/library-a.jsx' does not exist.",
|
||||
"File '/src/library-b/node_modules/@types/library-a/package.json' does not exist.",
|
||||
"File '/src/library-b/node_modules/@types/library-a/index.js' does not exist.",
|
||||
"File '/src/library-b/node_modules/@types/library-a/index.jsx' does not exist.",
|
||||
"File '/src/node_modules/library-a.js' does not exist.",
|
||||
"File '/src/node_modules/library-a.jsx' does not exist.",
|
||||
"File '/src/node_modules/library-a/package.json' does not exist.",
|
||||
"File '/src/node_modules/library-a/index.js' does not exist.",
|
||||
"File '/src/node_modules/library-a/index.jsx' does not exist.",
|
||||
"File '/src/node_modules/@types/library-a.js' does not exist.",
|
||||
"File '/src/node_modules/@types/library-a.jsx' does not exist.",
|
||||
"File '/src/node_modules/@types/library-a/package.json' does not exist.",
|
||||
"File '/src/node_modules/@types/library-a/index.js' does not exist.",
|
||||
"File '/src/node_modules/@types/library-a/index.jsx' does not exist.",
|
||||
"File '/node_modules/library-a.js' does not exist.",
|
||||
"File '/node_modules/library-a.jsx' does not exist.",
|
||||
"File '/node_modules/library-a/package.json' does not exist.",
|
||||
"File '/node_modules/library-a/index.js' does not exist.",
|
||||
"File '/node_modules/library-a/index.jsx' does not exist.",
|
||||
"File '/node_modules/@types/library-a.js' does not exist.",
|
||||
"File '/node_modules/@types/library-a.jsx' does not exist.",
|
||||
"File '/node_modules/@types/library-a/package.json' does not exist.",
|
||||
"File '/node_modules/@types/library-a/index.js' does not exist.",
|
||||
"File '/node_modules/@types/library-a/index.jsx' does not exist.",
|
||||
"======== Module name 'library-a' was not resolved. ========"
|
||||
]
|
||||
@ -14,10 +14,13 @@
|
||||
"'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'file4'",
|
||||
"Resolving module name 'file4' relative to base url 'c:/root' - 'c:/root/file4'.",
|
||||
"File 'c:/root/file4.ts' does not exist.",
|
||||
"File 'c:/root/file4.tsx' does not exist.",
|
||||
"File 'c:/root/file4.d.ts' does not exist.",
|
||||
"File 'c:/root/folder2/file4.ts' does not exist.",
|
||||
"File 'c:/root/folder2/file4.tsx' does not exist.",
|
||||
"File 'c:/root/folder2/file4.d.ts' does not exist.",
|
||||
"File 'c:/root/file4.ts' does not exist.",
|
||||
"File 'c:/root/file4.tsx' does not exist.",
|
||||
"File 'c:/root/file4.d.ts' does not exist.",
|
||||
"File 'c:/file4.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name 'file4' was successfully resolved to 'c:/file4.ts'. ========"
|
||||
|
||||
@ -14,10 +14,13 @@
|
||||
"'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'file4'",
|
||||
"Resolving module name 'file4' relative to base url 'c:/root' - 'c:/root/file4'.",
|
||||
"File 'c:/root/file4.ts' does not exist.",
|
||||
"File 'c:/root/file4.tsx' does not exist.",
|
||||
"File 'c:/root/file4.d.ts' does not exist.",
|
||||
"File 'c:/root/folder2/file4.ts' does not exist.",
|
||||
"File 'c:/root/folder2/file4.tsx' does not exist.",
|
||||
"File 'c:/root/folder2/file4.d.ts' does not exist.",
|
||||
"File 'c:/root/file4.ts' does not exist.",
|
||||
"File 'c:/root/file4.tsx' does not exist.",
|
||||
"File 'c:/root/file4.d.ts' does not exist.",
|
||||
"File 'c:/file4.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name 'file4' was successfully resolved to 'c:/file4.ts'. ========"
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
"Module name 'folder3/file2', matched pattern '*'.",
|
||||
"Trying substitution '*', candidate module location: 'folder3/file2'.",
|
||||
"File 'c:/root/folder3/file2.ts' does not exist.",
|
||||
"File 'c:/root/folder3/file2.tsx' does not exist.",
|
||||
"File 'c:/root/folder3/file2.d.ts' does not exist.",
|
||||
"Trying substitution 'generated/*', candidate module location: 'generated/folder3/file2'.",
|
||||
"File 'c:/root/generated/folder3/file2.ts' exist - use it as a name resolution result.",
|
||||
@ -33,13 +34,17 @@
|
||||
"Module name 'file4', matched pattern '*'.",
|
||||
"Trying substitution '*', candidate module location: 'file4'.",
|
||||
"File 'c:/root/file4.ts' does not exist.",
|
||||
"File 'c:/root/file4.tsx' does not exist.",
|
||||
"File 'c:/root/file4.d.ts' does not exist.",
|
||||
"Trying substitution 'generated/*', candidate module location: 'generated/file4'.",
|
||||
"File 'c:/root/generated/file4.ts' does not exist.",
|
||||
"File 'c:/root/generated/file4.tsx' does not exist.",
|
||||
"File 'c:/root/generated/file4.d.ts' does not exist.",
|
||||
"File 'c:/root/folder1/file4.ts' does not exist.",
|
||||
"File 'c:/root/folder1/file4.tsx' does not exist.",
|
||||
"File 'c:/root/folder1/file4.d.ts' does not exist.",
|
||||
"File 'c:/root/file4.ts' does not exist.",
|
||||
"File 'c:/root/file4.tsx' does not exist.",
|
||||
"File 'c:/root/file4.d.ts' does not exist.",
|
||||
"File 'c:/file4.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name 'file4' was successfully resolved to 'c:/file4.ts'. ========"
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
"Longest matching prefix for 'c:/root/src/project/file3' is 'c:/root/src/'",
|
||||
"Loading 'project/file3' from the root dir 'c:/root/src/', candidate location 'c:/root/src/project/file3'",
|
||||
"File 'c:/root/src/project/file3.ts' does not exist.",
|
||||
"File 'c:/root/src/project/file3.tsx' does not exist.",
|
||||
"File 'c:/root/src/project/file3.d.ts' does not exist.",
|
||||
"Trying other entries in 'rootDirs'",
|
||||
"Loading 'project/file3' from the root dir 'c:/root/generated/src', candidate location 'c:/root/generated/src/project/file3'",
|
||||
@ -20,10 +21,12 @@
|
||||
"Longest matching prefix for 'c:/root/generated/src/file2' is 'c:/root/generated/src/'",
|
||||
"Loading 'file2' from the root dir 'c:/root/generated/src/', candidate location 'c:/root/generated/src/file2'",
|
||||
"File 'c:/root/generated/src/file2.ts' does not exist.",
|
||||
"File 'c:/root/generated/src/file2.tsx' does not exist.",
|
||||
"File 'c:/root/generated/src/file2.d.ts' does not exist.",
|
||||
"Trying other entries in 'rootDirs'",
|
||||
"Loading 'file2' from the root dir 'c:/root/src', candidate location 'c:/root/src/file2'",
|
||||
"File 'c:/root/src/file2.ts' does not exist.",
|
||||
"File 'c:/root/src/file2.tsx' does not exist.",
|
||||
"File 'c:/root/src/file2.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name '../file2' was successfully resolved to 'c:/root/src/file2.d.ts'. ========"
|
||||
]
|
||||
@ -7,6 +7,7 @@
|
||||
"Longest matching prefix for 'c:/root/src/project/file2' is 'c:/root/src/'",
|
||||
"Loading 'project/file2' from the root dir 'c:/root/src/', candidate location 'c:/root/src/project/file2'",
|
||||
"File 'c:/root/src/project/file2.ts' does not exist.",
|
||||
"File 'c:/root/src/project/file2.tsx' does not exist.",
|
||||
"File 'c:/root/src/project/file2.d.ts' does not exist.",
|
||||
"Trying other entries in 'rootDirs'",
|
||||
"Loading 'project/file2' from the root dir 'c:/root/generated/src', candidate location 'c:/root/generated/src/project/file2'",
|
||||
@ -19,15 +20,20 @@
|
||||
"Module name 'module3', matched pattern '*'.",
|
||||
"Trying substitution '*', candidate module location: 'module3'.",
|
||||
"File 'c:/root/module3.ts' does not exist.",
|
||||
"File 'c:/root/module3.tsx' does not exist.",
|
||||
"File 'c:/root/module3.d.ts' does not exist.",
|
||||
"Trying substitution 'c:/shared/*', candidate module location: 'c:/shared/module3'.",
|
||||
"File 'c:/shared/module3.ts' does not exist.",
|
||||
"File 'c:/shared/module3.tsx' does not exist.",
|
||||
"File 'c:/shared/module3.d.ts' does not exist.",
|
||||
"File 'c:/root/src/module3.ts' does not exist.",
|
||||
"File 'c:/root/src/module3.tsx' does not exist.",
|
||||
"File 'c:/root/src/module3.d.ts' does not exist.",
|
||||
"File 'c:/root/module3.ts' does not exist.",
|
||||
"File 'c:/root/module3.tsx' does not exist.",
|
||||
"File 'c:/root/module3.d.ts' does not exist.",
|
||||
"File 'c:/module3.ts' does not exist.",
|
||||
"File 'c:/module3.tsx' does not exist.",
|
||||
"File 'c:/module3.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name 'module3' was successfully resolved to 'c:/module3.d.ts'. ========",
|
||||
"======== Resolving module 'module1' from 'c:/root/generated/src/project/file2.ts'. ========",
|
||||
@ -37,9 +43,11 @@
|
||||
"Module name 'module1', matched pattern '*'.",
|
||||
"Trying substitution '*', candidate module location: 'module1'.",
|
||||
"File 'c:/root/module1.ts' does not exist.",
|
||||
"File 'c:/root/module1.tsx' does not exist.",
|
||||
"File 'c:/root/module1.d.ts' does not exist.",
|
||||
"Trying substitution 'c:/shared/*', candidate module location: 'c:/shared/module1'.",
|
||||
"File 'c:/shared/module1.ts' does not exist.",
|
||||
"File 'c:/shared/module1.tsx' does not exist.",
|
||||
"File 'c:/shared/module1.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name 'module1' was successfully resolved to 'c:/shared/module1.d.ts'. ========",
|
||||
"======== Resolving module 'templates/module2' from 'c:/root/generated/src/project/file2.ts'. ========",
|
||||
@ -58,10 +66,12 @@
|
||||
"Longest matching prefix for 'c:/root/generated/src/file3' is 'c:/root/generated/src/'",
|
||||
"Loading 'file3' from the root dir 'c:/root/generated/src/', candidate location 'c:/root/generated/src/file3'",
|
||||
"File 'c:/root/generated/src/file3.ts' does not exist.",
|
||||
"File 'c:/root/generated/src/file3.tsx' does not exist.",
|
||||
"File 'c:/root/generated/src/file3.d.ts' does not exist.",
|
||||
"Trying other entries in 'rootDirs'",
|
||||
"Loading 'file3' from the root dir 'c:/root/src', candidate location 'c:/root/src/file3'",
|
||||
"File 'c:/root/src/file3.ts' does not exist.",
|
||||
"File 'c:/root/src/file3.tsx' does not exist.",
|
||||
"File 'c:/root/src/file3.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name '../file3' was successfully resolved to 'c:/root/src/file3.d.ts'. ========"
|
||||
]
|
||||
@ -44,6 +44,37 @@
|
||||
"File '/node_modules/@types/xyz/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/xyz/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/xyz/index.d.ts' does not exist.",
|
||||
"Loading module 'xyz' from 'node_modules' folder.",
|
||||
"File '/foo/bar/node_modules/xyz.js' does not exist.",
|
||||
"File '/foo/bar/node_modules/xyz.jsx' does not exist.",
|
||||
"File '/foo/bar/node_modules/xyz/package.json' does not exist.",
|
||||
"File '/foo/bar/node_modules/xyz/index.js' does not exist.",
|
||||
"File '/foo/bar/node_modules/xyz/index.jsx' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/xyz.js' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/xyz.jsx' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/xyz/package.json' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/xyz/index.js' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/xyz/index.jsx' does not exist.",
|
||||
"File '/foo/node_modules/xyz.js' does not exist.",
|
||||
"File '/foo/node_modules/xyz.jsx' does not exist.",
|
||||
"File '/foo/node_modules/xyz/package.json' does not exist.",
|
||||
"File '/foo/node_modules/xyz/index.js' does not exist.",
|
||||
"File '/foo/node_modules/xyz/index.jsx' does not exist.",
|
||||
"File '/foo/node_modules/@types/xyz.js' does not exist.",
|
||||
"File '/foo/node_modules/@types/xyz.jsx' does not exist.",
|
||||
"File '/foo/node_modules/@types/xyz/package.json' does not exist.",
|
||||
"File '/foo/node_modules/@types/xyz/index.js' does not exist.",
|
||||
"File '/foo/node_modules/@types/xyz/index.jsx' does not exist.",
|
||||
"File '/node_modules/xyz.js' does not exist.",
|
||||
"File '/node_modules/xyz.jsx' does not exist.",
|
||||
"File '/node_modules/xyz/package.json' does not exist.",
|
||||
"File '/node_modules/xyz/index.js' does not exist.",
|
||||
"File '/node_modules/xyz/index.jsx' does not exist.",
|
||||
"File '/node_modules/@types/xyz.js' does not exist.",
|
||||
"File '/node_modules/@types/xyz.jsx' does not exist.",
|
||||
"File '/node_modules/@types/xyz/package.json' does not exist.",
|
||||
"File '/node_modules/@types/xyz/index.js' does not exist.",
|
||||
"File '/node_modules/@types/xyz/index.jsx' does not exist.",
|
||||
"======== Module name 'xyz' was not resolved. ========",
|
||||
"======== Resolving module 'pdq' from '/foo/bar/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
@ -90,6 +121,37 @@
|
||||
"File '/node_modules/@types/pdq/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/pdq/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/pdq/index.d.ts' does not exist.",
|
||||
"Loading module 'pdq' from 'node_modules' folder.",
|
||||
"File '/foo/bar/node_modules/pdq.js' does not exist.",
|
||||
"File '/foo/bar/node_modules/pdq.jsx' does not exist.",
|
||||
"File '/foo/bar/node_modules/pdq/package.json' does not exist.",
|
||||
"File '/foo/bar/node_modules/pdq/index.js' does not exist.",
|
||||
"File '/foo/bar/node_modules/pdq/index.jsx' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/pdq.js' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/pdq.jsx' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/pdq/package.json' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/pdq/index.js' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/pdq/index.jsx' does not exist.",
|
||||
"File '/foo/node_modules/pdq.js' does not exist.",
|
||||
"File '/foo/node_modules/pdq.jsx' does not exist.",
|
||||
"File '/foo/node_modules/pdq/package.json' does not exist.",
|
||||
"File '/foo/node_modules/pdq/index.js' does not exist.",
|
||||
"File '/foo/node_modules/pdq/index.jsx' does not exist.",
|
||||
"File '/foo/node_modules/@types/pdq.js' does not exist.",
|
||||
"File '/foo/node_modules/@types/pdq.jsx' does not exist.",
|
||||
"File '/foo/node_modules/@types/pdq/package.json' does not exist.",
|
||||
"File '/foo/node_modules/@types/pdq/index.js' does not exist.",
|
||||
"File '/foo/node_modules/@types/pdq/index.jsx' does not exist.",
|
||||
"File '/node_modules/pdq.js' does not exist.",
|
||||
"File '/node_modules/pdq.jsx' does not exist.",
|
||||
"File '/node_modules/pdq/package.json' does not exist.",
|
||||
"File '/node_modules/pdq/index.js' does not exist.",
|
||||
"File '/node_modules/pdq/index.jsx' does not exist.",
|
||||
"File '/node_modules/@types/pdq.js' does not exist.",
|
||||
"File '/node_modules/@types/pdq.jsx' does not exist.",
|
||||
"File '/node_modules/@types/pdq/package.json' does not exist.",
|
||||
"File '/node_modules/@types/pdq/index.js' does not exist.",
|
||||
"File '/node_modules/@types/pdq/index.jsx' does not exist.",
|
||||
"======== Module name 'pdq' was not resolved. ========",
|
||||
"======== Resolving module 'abc' from '/foo/bar/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
@ -136,6 +198,37 @@
|
||||
"File '/node_modules/@types/abc/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/abc/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/abc/index.d.ts' does not exist.",
|
||||
"Loading module 'abc' from 'node_modules' folder.",
|
||||
"File '/foo/bar/node_modules/abc.js' does not exist.",
|
||||
"File '/foo/bar/node_modules/abc.jsx' does not exist.",
|
||||
"File '/foo/bar/node_modules/abc/package.json' does not exist.",
|
||||
"File '/foo/bar/node_modules/abc/index.js' does not exist.",
|
||||
"File '/foo/bar/node_modules/abc/index.jsx' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/abc.js' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/abc.jsx' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/abc/package.json' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/abc/index.js' does not exist.",
|
||||
"File '/foo/bar/node_modules/@types/abc/index.jsx' does not exist.",
|
||||
"File '/foo/node_modules/abc.js' does not exist.",
|
||||
"File '/foo/node_modules/abc.jsx' does not exist.",
|
||||
"File '/foo/node_modules/abc/package.json' does not exist.",
|
||||
"File '/foo/node_modules/abc/index.js' does not exist.",
|
||||
"File '/foo/node_modules/abc/index.jsx' does not exist.",
|
||||
"File '/foo/node_modules/@types/abc.js' does not exist.",
|
||||
"File '/foo/node_modules/@types/abc.jsx' does not exist.",
|
||||
"File '/foo/node_modules/@types/abc/package.json' does not exist.",
|
||||
"File '/foo/node_modules/@types/abc/index.js' does not exist.",
|
||||
"File '/foo/node_modules/@types/abc/index.jsx' does not exist.",
|
||||
"File '/node_modules/abc.js' does not exist.",
|
||||
"File '/node_modules/abc.jsx' does not exist.",
|
||||
"File '/node_modules/abc/package.json' does not exist.",
|
||||
"File '/node_modules/abc/index.js' does not exist.",
|
||||
"File '/node_modules/abc/index.jsx' does not exist.",
|
||||
"File '/node_modules/@types/abc.js' does not exist.",
|
||||
"File '/node_modules/@types/abc.jsx' does not exist.",
|
||||
"File '/node_modules/@types/abc/package.json' does not exist.",
|
||||
"File '/node_modules/@types/abc/index.js' does not exist.",
|
||||
"File '/node_modules/@types/abc/index.jsx' does not exist.",
|
||||
"======== Module name 'abc' was not resolved. ========",
|
||||
"======== Resolving type reference directive 'grumpy', containing file '/src/__inferred type names__.ts', root directory '/foo/node_modules/@types,/node_modules/@types'. ========",
|
||||
"Resolving with primary search path '/foo/node_modules/@types, /node_modules/@types'",
|
||||
|
||||
@ -30,6 +30,27 @@
|
||||
"File '/node_modules/@types/xyz/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/xyz/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/xyz/index.d.ts' does not exist.",
|
||||
"Loading module 'xyz' from 'node_modules' folder.",
|
||||
"File '/src/node_modules/xyz.js' does not exist.",
|
||||
"File '/src/node_modules/xyz.jsx' does not exist.",
|
||||
"File '/src/node_modules/xyz/package.json' does not exist.",
|
||||
"File '/src/node_modules/xyz/index.js' does not exist.",
|
||||
"File '/src/node_modules/xyz/index.jsx' does not exist.",
|
||||
"File '/src/node_modules/@types/xyz.js' does not exist.",
|
||||
"File '/src/node_modules/@types/xyz.jsx' does not exist.",
|
||||
"File '/src/node_modules/@types/xyz/package.json' does not exist.",
|
||||
"File '/src/node_modules/@types/xyz/index.js' does not exist.",
|
||||
"File '/src/node_modules/@types/xyz/index.jsx' does not exist.",
|
||||
"File '/node_modules/xyz.js' does not exist.",
|
||||
"File '/node_modules/xyz.jsx' does not exist.",
|
||||
"File '/node_modules/xyz/package.json' does not exist.",
|
||||
"File '/node_modules/xyz/index.js' does not exist.",
|
||||
"File '/node_modules/xyz/index.jsx' does not exist.",
|
||||
"File '/node_modules/@types/xyz.js' does not exist.",
|
||||
"File '/node_modules/@types/xyz.jsx' does not exist.",
|
||||
"File '/node_modules/@types/xyz/package.json' does not exist.",
|
||||
"File '/node_modules/@types/xyz/index.js' does not exist.",
|
||||
"File '/node_modules/@types/xyz/index.jsx' does not exist.",
|
||||
"======== Module name 'xyz' was not resolved. ========",
|
||||
"======== Resolving type reference directive 'foo', containing file '/src/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
|
||||
"Resolving with primary search path '/node_modules/@types'",
|
||||
|
||||
@ -68,6 +68,8 @@
|
||||
"Found 'package.json' at '/node_modules/@types/kquery/package.json'.",
|
||||
"'package.json' has 'typings' field 'kquery' that references '/node_modules/@types/kquery/kquery'.",
|
||||
"File '/node_modules/@types/kquery/kquery' does not exist.",
|
||||
"File '/node_modules/@types/kquery/kquery.ts' does not exist.",
|
||||
"File '/node_modules/@types/kquery/kquery.tsx' does not exist.",
|
||||
"File '/node_modules/@types/kquery/kquery.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'kquery' was successfully resolved to '/node_modules/@types/kquery/kquery.d.ts', primary: true. ========",
|
||||
"======== Resolving type reference directive 'lquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
|
||||
@ -75,19 +77,6 @@
|
||||
"Found 'package.json' at '/node_modules/@types/lquery/package.json'.",
|
||||
"'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.",
|
||||
"File '/node_modules/@types/lquery/lquery' does not exist.",
|
||||
"File '/node_modules/@types/lquery/lquery.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/lquery/index.d.ts' does not exist.",
|
||||
"Looking up in 'node_modules' folder, initial location '/'",
|
||||
"File '/node_modules/lquery.ts' does not exist.",
|
||||
"File '/node_modules/lquery.d.ts' does not exist.",
|
||||
"File '/node_modules/lquery/package.json' does not exist.",
|
||||
"File '/node_modules/lquery/index.ts' does not exist.",
|
||||
"File '/node_modules/lquery/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/lquery.ts' does not exist.",
|
||||
"File '/node_modules/@types/lquery.d.ts' does not exist.",
|
||||
"Found 'package.json' at '/node_modules/@types/lquery/package.json'.",
|
||||
"'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.",
|
||||
"File '/node_modules/@types/lquery/lquery' does not exist.",
|
||||
"File '/node_modules/@types/lquery/lquery.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'lquery' was successfully resolved to '/node_modules/@types/lquery/lquery.ts', primary: false. ========"
|
||||
"======== Type reference directive 'lquery' was successfully resolved to '/node_modules/@types/lquery/lquery.ts', primary: true. ========"
|
||||
]
|
||||
@ -2,53 +2,73 @@
|
||||
"======== Resolving module 'b' from '/x/y/foo.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'Classic'.",
|
||||
"File '/x/y/b.ts' does not exist.",
|
||||
"File '/x/y/b.tsx' does not exist.",
|
||||
"File '/x/y/b.d.ts' does not exist.",
|
||||
"File '/x/b.ts' does not exist.",
|
||||
"File '/x/b.tsx' does not exist.",
|
||||
"File '/x/b.d.ts' does not exist.",
|
||||
"File '/b.ts' does not exist.",
|
||||
"File '/b.tsx' does not exist.",
|
||||
"File '/b.d.ts' does not exist.",
|
||||
"File '/x/y/node_modules/@types/b.ts' does not exist.",
|
||||
"File '/x/y/node_modules/@types/b.tsx' does not exist.",
|
||||
"File '/x/y/node_modules/@types/b.d.ts' does not exist.",
|
||||
"File '/x/y/node_modules/@types/b/package.json' does not exist.",
|
||||
"File '/x/y/node_modules/@types/b/index.ts' does not exist.",
|
||||
"File '/x/y/node_modules/@types/b/index.tsx' does not exist.",
|
||||
"File '/x/y/node_modules/@types/b/index.d.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/b.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/b.tsx' does not exist.",
|
||||
"File '/x/node_modules/@types/b.d.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/b/package.json' does not exist.",
|
||||
"File '/x/node_modules/@types/b/index.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/b/index.tsx' does not exist.",
|
||||
"File '/x/node_modules/@types/b/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name 'b' was successfully resolved to '/x/node_modules/@types/b/index.d.ts'. ========",
|
||||
"======== Resolving module 'a' from '/x/node_modules/@types/b/index.d.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'Classic'.",
|
||||
"File '/x/node_modules/@types/b/a.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/b/a.tsx' does not exist.",
|
||||
"File '/x/node_modules/@types/b/a.d.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/a.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/a.tsx' does not exist.",
|
||||
"File '/x/node_modules/@types/a.d.ts' does not exist.",
|
||||
"File '/x/node_modules/a.ts' does not exist.",
|
||||
"File '/x/node_modules/a.tsx' does not exist.",
|
||||
"File '/x/node_modules/a.d.ts' does not exist.",
|
||||
"File '/x/a.ts' does not exist.",
|
||||
"File '/x/a.tsx' does not exist.",
|
||||
"File '/x/a.d.ts' does not exist.",
|
||||
"File '/a.ts' does not exist.",
|
||||
"File '/a.tsx' does not exist.",
|
||||
"File '/a.d.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/b/node_modules/@types/a.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/b/node_modules/@types/a.tsx' does not exist.",
|
||||
"File '/x/node_modules/@types/b/node_modules/@types/a.d.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/b/node_modules/@types/a/package.json' does not exist.",
|
||||
"File '/x/node_modules/@types/b/node_modules/@types/a/index.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/b/node_modules/@types/a/index.tsx' does not exist.",
|
||||
"File '/x/node_modules/@types/b/node_modules/@types/a/index.d.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/node_modules/@types/a.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/node_modules/@types/a.tsx' does not exist.",
|
||||
"File '/x/node_modules/@types/node_modules/@types/a.d.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/node_modules/@types/a/package.json' does not exist.",
|
||||
"File '/x/node_modules/@types/node_modules/@types/a/index.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/node_modules/@types/a/index.tsx' does not exist.",
|
||||
"File '/x/node_modules/@types/node_modules/@types/a/index.d.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/a.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/a.tsx' does not exist.",
|
||||
"File '/x/node_modules/@types/a.d.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/a/package.json' does not exist.",
|
||||
"File '/x/node_modules/@types/a/index.ts' does not exist.",
|
||||
"File '/x/node_modules/@types/a/index.tsx' does not exist.",
|
||||
"File '/x/node_modules/@types/a/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/a.ts' does not exist.",
|
||||
"File '/node_modules/@types/a.tsx' does not exist.",
|
||||
"File '/node_modules/@types/a.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/a/package.json' does not exist.",
|
||||
"File '/node_modules/@types/a/index.ts' does not exist.",
|
||||
"File '/node_modules/@types/a/index.tsx' does not exist.",
|
||||
"File '/node_modules/@types/a/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name 'a' was successfully resolved to '/node_modules/@types/a/index.d.ts'. ========",
|
||||
"======== Resolving type reference directive 'a', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
// @jsx: Preserve
|
||||
// @filename: x.ts
|
||||
export default 0;
|
||||
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
|
||||
// @Filename: /tsx.tsx
|
||||
|
||||
// @Filename: /jsx.jsx
|
||||
|
||||
// @Filename: /js.js
|
||||
|
||||
// @Filename: /a.ts
|
||||
import tsx from "./tsx";
|
||||
import jsx from "./jsx";
|
||||
import js from "./js";
|
||||
@ -0,0 +1,9 @@
|
||||
// @noImplicitReferences: true
|
||||
// @allowJs: true
|
||||
// @traceResolution: true
|
||||
// Test the error message if we have `--allowJs` but not `--jsx`.
|
||||
|
||||
// @Filename: /jsx.jsx
|
||||
|
||||
// @Filename: /a.ts
|
||||
import jsx from "./jsx";
|
||||
@ -0,0 +1,10 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
|
||||
// @Filename: /b.js
|
||||
|
||||
// @Filename: /b/index.ts
|
||||
export default 0;
|
||||
|
||||
// @Filename: /a.ts
|
||||
import b from "./b";
|
||||
@ -0,0 +1,14 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// Allowjs is false, but this should *not* warn about the unused 'index.js'
|
||||
|
||||
// @Filename: /node_modules/js/index.js
|
||||
|
||||
// @Filename: /declarations.d.ts
|
||||
declare module "js" {
|
||||
export const x = 0;
|
||||
}
|
||||
|
||||
// @Filename: /a.ts
|
||||
/// <reference path="declarations.d.ts" />
|
||||
import { x } from "js";
|
||||
@ -1,3 +1,4 @@
|
||||
// @allowJs: true
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// @currentDirectory: /
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user