diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 8ae88d49438..c01314ab47c 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -325,6 +325,15 @@ namespace ts { name: "typesRoot", type: "string" }, + { + name: "types", + type: "list", + element: { + name: "types", + type: "string" + }, + description: Diagnostics.Type_declaration_files_to_be_included_in_compilation + }, { name: "traceResolution", type: "boolean", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index bceca5d8809..a141db83aaa 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2637,7 +2637,7 @@ "category": "Error", "code": 6114 }, - "======== Resolving type reference directive '{0}' from '{1}', root dir '{2}'. ========": { + "======== Resolving type reference directive '{0}', containing file '{1}', root directory '{2}'. ========": { "category": "Message", "code": 6115 }, @@ -2665,10 +2665,30 @@ "category": "Message", "code": 6121 }, - "======== Resolving type reference directive '{0}' from '{1}', root dir not set. ========": { + "======== Resolving type reference directive '{0}', containing file '{1}', root directory not set. ========": { "category": "Message", "code": 6122 }, + "Type declaration files to be included in compilation.": { + "category": "Message", + "code": 6123 + }, + "Looking up in 'node_modules' folder, initial location '{0}'": { + "category": "Message", + "code": 6124 + }, + "Containing file is not specified and root directory cannot be determined, skipping lookup in 'node_modules' folder.": { + "category": "Message", + "code": 6125 + }, + "======== Resolving type reference directive '{0}', containing file not set, root directory '{1}'. ========": { + "category": "Message", + "code": 6126 + }, + "======== Resolving type reference directive '{0}', containing file not set, root directory not set. ========": { + "category": "Message", + "code": 6127 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 0c1c987541c..776fede9fbc 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -191,6 +191,11 @@ namespace ts { const typeReferenceExtensions = [".d.ts"]; + /** + * @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown. + * 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 { const traceEnabled = isTraceEnabled(options, host); const moduleResolutionState: ModuleResolutionState = { @@ -204,11 +209,21 @@ namespace ts { const rootDir = options.typesRoot || (options.configFilePath ? getDirectoryPath(options.configFilePath) : undefined); if (traceEnabled) { - if (rootDir !== undefined) { - trace(host, Diagnostics.Resolving_type_reference_directive_0_from_1_root_dir_2, typeReferenceDirectiveName, containingFile, rootDir); + if (containingFile === undefined) { + if (rootDir === undefined) { + trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set, typeReferenceDirectiveName); + } + else { + trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_not_set_root_directory_1, typeReferenceDirectiveName, rootDir); + } } else { - trace(host, Diagnostics.Resolving_type_reference_directive_0_from_1_root_dir_not_set, typeReferenceDirectiveName, containingFile); + if (rootDir === undefined) { + trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_1_root_directory_not_set, typeReferenceDirectiveName, containingFile); + } + else { + trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_1_root_directory_2, typeReferenceDirectiveName, containingFile, rootDir); + } } } @@ -244,17 +259,33 @@ namespace ts { } } - if (traceEnabled) { - trace(host, Diagnostics.Resolving_from_node_modules_folder); + let resolvedFile: string; + let initialLocationForSecondaryLookup: string; + if (containingFile) { + initialLocationForSecondaryLookup = getDirectoryPath(containingFile); } - // check secondary locations - const resolvedFile = loadModuleFromNodeModules(typeReferenceDirectiveName, getDirectoryPath(containingFile), failedLookupLocations, moduleResolutionState); - if (traceEnabled) { - if (resolvedFile) { - trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFile, false); + else { + initialLocationForSecondaryLookup = rootDir; + } + + if (initialLocationForSecondaryLookup !== undefined) { + // check secondary locations + if (traceEnabled) { + trace(host, Diagnostics.Looking_up_in_node_modules_folder_initial_location_0, initialLocationForSecondaryLookup); } - else { - trace(host, Diagnostics.Type_reference_directive_0_was_not_resolved, typeReferenceDirectiveName); + resolvedFile = loadModuleFromNodeModules(typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState); + if (traceEnabled) { + if (resolvedFile) { + trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFile, false); + } + else { + trace(host, Diagnostics.Type_reference_directive_0_was_not_resolved, typeReferenceDirectiveName); + } + } + } + else { + if (traceEnabled) { + trace(host, Diagnostics.Containing_file_is_not_specified_and_root_directory_cannot_be_determined_skipping_lookup_in_node_modules_folder); } } return { @@ -927,24 +958,15 @@ namespace ts { // used to track cases when two file names differ only in casing const filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? createFileMap(fileName => fileName.toLowerCase()) : undefined; - if (oldProgram) { - // check properties that can affect structure of the program or module resolution strategy - // if any of these properties has changed - structure cannot be reused - const oldOptions = oldProgram.getCompilerOptions(); - if ((oldOptions.module !== options.module) || - (oldOptions.noResolve !== options.noResolve) || - (oldOptions.target !== options.target) || - (oldOptions.noLib !== options.noLib) || - (oldOptions.jsx !== options.jsx) || - (oldOptions.allowJs !== options.allowJs) || - (oldOptions.rootDir !== options.rootDir) || - (oldOptions.typesSearchPaths !== options.typesSearchPaths) || - (oldOptions.configFilePath !== options.configFilePath)) { - oldProgram = undefined; - } - } - if (!tryReuseStructureFromOldProgram()) { + // load type declarations specified via 'types' argument + if (options.types && options.types.length) { + const resolutions = resolveTypeReferenceDirectiveNamesWorker(options.types, /*containingFile*/ undefined); + for (let i = 0; i < options.types.length; i++) { + processTypeReferenceDirective(options.types[i], resolutions[i]); + } + } + forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false)); // Do not process the default library if: // - The '--noLib' flag is used. @@ -1036,6 +1058,21 @@ namespace ts { return false; } + // check properties that can affect structure of the program or module resolution strategy + // if any of these properties has changed - structure cannot be reused + const oldOptions = oldProgram.getCompilerOptions(); + if ((oldOptions.module !== options.module) || + (oldOptions.noResolve !== options.noResolve) || + (oldOptions.target !== options.target) || + (oldOptions.noLib !== options.noLib) || + (oldOptions.jsx !== options.jsx) || + (oldOptions.allowJs !== options.allowJs) || + (oldOptions.rootDir !== options.rootDir) || + (oldOptions.typesSearchPaths !== options.typesSearchPaths) || + (oldOptions.configFilePath !== options.configFilePath)) { + return false; + } + Debug.assert(!oldProgram.structureIsReused); // there is an old program, check if we can reuse its structure @@ -1044,6 +1081,10 @@ namespace ts { return false; } + if (!arrayIsEqualTo(options.types, oldOptions.types)) { + return false; + } + // check if program source files has changed in the way that can affect structure of the program const newSourceFiles: SourceFile[] = []; const filePaths: Path[] = []; @@ -1733,45 +1774,61 @@ namespace ts { const resolvedTypeReferenceDirective = resolutions[i]; // store resolved type directive on the file setResolvedTypeReferenceDirective(file, ref.fileName, resolvedTypeReferenceDirective); - // If we already found this library as a primary reference - nothing to do - const previousResolution = resolvedTypeReferenceDirectives[ref.fileName]; - if (previousResolution && previousResolution.primary) { - continue; - } - let saveResolution = true; - if (resolvedTypeReferenceDirective) { - if (resolvedTypeReferenceDirective.primary) { - // resolved from the primary path - processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, /*isReference*/ true, file, ref.pos, ref.end); - } - else { - // If we already resolved to this file, it must have been a secondary reference. Check file contents - // for sameness and possibly issue an error - if (previousResolution) { - const otherFileText = host.readFile(resolvedTypeReferenceDirective.resolvedFileName); - if (otherFileText !== getSourceFile(previousResolution.resolvedFileName).text) { - fileProcessingDiagnostics.add(createFileDiagnostic(file, ref.pos, ref.end - ref.pos, - Diagnostics.Conflicting_library_definitions_for_0_found_at_1_and_2_Copy_the_correct_file_to_the_typings_folder_to_resolve_this_conflict, - ref.fileName, - resolvedTypeReferenceDirective.resolvedFileName, - previousResolution.resolvedFileName)); - } - // don't overwrite previous resolution result - saveResolution = false; - } - else { - // First resolution of this library - processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, /*isReference*/ true, file, ref.pos, ref.end); - } - } + processTypeReferenceDirective(ref.fileName, resolvedTypeReferenceDirective, file, ref.pos, ref.end); + } + } + + function processTypeReferenceDirective(typeReferenceDirective: string, resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective, + refFile?: SourceFile, refPos?: number, refEnd?: number): void { + + // If we already found this library as a primary reference - nothing to do + const previousResolution = resolvedTypeReferenceDirectives[typeReferenceDirective]; + if (previousResolution && previousResolution.primary) { + return; + } + let saveResolution = true; + if (resolvedTypeReferenceDirective) { + if (resolvedTypeReferenceDirective.primary) { + // resolved from the primary path + processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, /*isReference*/ true, refFile, refPos, refEnd); } else { - fileProcessingDiagnostics.add(createFileDiagnostic(file, ref.pos, ref.end - ref.pos, Diagnostics.Cannot_find_name_0, ref.fileName)); + // If we already resolved to this file, it must have been a secondary reference. Check file contents + // for sameness and possibly issue an error + if (previousResolution) { + const otherFileText = host.readFile(resolvedTypeReferenceDirective.resolvedFileName); + if (otherFileText !== getSourceFile(previousResolution.resolvedFileName).text) { + fileProcessingDiagnostics.add(createDiagnostic(refFile, refPos, refEnd, + Diagnostics.Conflicting_library_definitions_for_0_found_at_1_and_2_Copy_the_correct_file_to_the_typings_folder_to_resolve_this_conflict, + typeReferenceDirective, + resolvedTypeReferenceDirective.resolvedFileName, + previousResolution.resolvedFileName + )); + } + // don't overwrite previous resolution result + saveResolution = false; + } + else { + // First resolution of this library + processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, /*isReference*/ true, refFile, refPos, refEnd); + } } + } + else { + fileProcessingDiagnostics.add(createDiagnostic(refFile, refPos, refEnd, Diagnostics.Cannot_find_name_0, typeReferenceDirective)); + } - if (saveResolution) { - resolvedTypeReferenceDirectives[ref.fileName] = resolvedTypeReferenceDirective; - } + if (saveResolution) { + resolvedTypeReferenceDirectives[typeReferenceDirective] = resolvedTypeReferenceDirective; + } + } + + function createDiagnostic(refFile: SourceFile, refPos: number, refEnd: number, message: DiagnosticMessage, ...args: any[]): Diagnostic { + if (refFile === undefined || refPos === undefined || refEnd === undefined) { + return createCompilerDiagnostic(message, ...args); + } + else { + return createFileDiagnostic(refFile, refPos, refEnd - refPos, message, ...args); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9497a7ebfe6..e0e7ad95c34 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2476,6 +2476,7 @@ namespace ts { /* @internal */ // Path used to used to compute primary search locations typesRoot?: string; + types?: string[]; list?: string[]; [option: string]: CompilerOptionsValue; diff --git a/tests/baselines/reference/library-reference-1.trace.json b/tests/baselines/reference/library-reference-1.trace.json index be96aa1d852..1b8c237dff1 100644 --- a/tests/baselines/reference/library-reference-1.trace.json +++ b/tests/baselines/reference/library-reference-1.trace.json @@ -1,5 +1,5 @@ [ - "======== Resolving type reference directive 'jquery' from '/consumer.ts', root dir '/'. ========", + "======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/'. ========", "Resolving with primary search path '/types/'", "File '/types/jquery/package.json' does not exist.", "File '/types/jquery/index.d.ts' exist - use it as a name resolution result.", diff --git a/tests/baselines/reference/library-reference-10.trace.json b/tests/baselines/reference/library-reference-10.trace.json index 1645195146d..e6a1918a446 100644 --- a/tests/baselines/reference/library-reference-10.trace.json +++ b/tests/baselines/reference/library-reference-10.trace.json @@ -1,5 +1,5 @@ [ - "======== Resolving type reference directive 'jquery' from '/consumer.ts', root dir '/'. ========", + "======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/'. ========", "Resolving with primary search path '/types/'", "Found 'package.json' at '/types/jquery/package.json'.", "'package.json' has 'typings' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.", diff --git a/tests/baselines/reference/library-reference-11.trace.json b/tests/baselines/reference/library-reference-11.trace.json index 912ff1d2114..e0af1e39c5a 100644 --- a/tests/baselines/reference/library-reference-11.trace.json +++ b/tests/baselines/reference/library-reference-11.trace.json @@ -1,7 +1,7 @@ [ - "======== Resolving type reference directive 'jquery' from '/a/b/consumer.ts', root dir not set. ========", + "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory not set. ========", "Root directory cannot be determined, skipping primary search paths.", - "Resolving from node_modules folder...", + "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.", diff --git a/tests/baselines/reference/library-reference-12.trace.json b/tests/baselines/reference/library-reference-12.trace.json index 47a4d7f0220..2cdf1f5f20a 100644 --- a/tests/baselines/reference/library-reference-12.trace.json +++ b/tests/baselines/reference/library-reference-12.trace.json @@ -1,7 +1,7 @@ [ - "======== Resolving type reference directive 'jquery' from '/a/b/consumer.ts', root dir not set. ========", + "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory not set. ========", "Root directory cannot be determined, skipping primary search paths.", - "Resolving from node_modules folder...", + "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.", diff --git a/tests/baselines/reference/library-reference-13.js b/tests/baselines/reference/library-reference-13.js new file mode 100644 index 00000000000..be52aba1a39 --- /dev/null +++ b/tests/baselines/reference/library-reference-13.js @@ -0,0 +1,12 @@ +//// [tests/cases/conformance/references/library-reference-13.ts] //// + +//// [index.d.ts] +declare var $: { foo(): void }; + + +//// [consumer.ts] +$.foo(); + + +//// [consumer.js] +$.foo(); diff --git a/tests/baselines/reference/library-reference-13.symbols b/tests/baselines/reference/library-reference-13.symbols new file mode 100644 index 00000000000..04d50373caa --- /dev/null +++ b/tests/baselines/reference/library-reference-13.symbols @@ -0,0 +1,12 @@ +=== /a/b/consumer.ts === +$.foo(); +>$.foo : Symbol(foo, Decl(index.d.ts, 0, 16)) +>$ : Symbol($, Decl(index.d.ts, 0, 11)) +>foo : Symbol(foo, Decl(index.d.ts, 0, 16)) + +=== /a/types/jquery/index.d.ts === +declare var $: { foo(): void }; +>$ : Symbol($, Decl(index.d.ts, 0, 11)) +>foo : Symbol(foo, Decl(index.d.ts, 0, 16)) + + diff --git a/tests/baselines/reference/library-reference-13.trace.json b/tests/baselines/reference/library-reference-13.trace.json new file mode 100644 index 00000000000..2133414f414 --- /dev/null +++ b/tests/baselines/reference/library-reference-13.trace.json @@ -0,0 +1,7 @@ +[ + "======== Resolving type reference directive 'jquery', containing file not set, root directory '/a'. ========", + "Resolving with primary search path '/a/types/'", + "File '/a/types/jquery/package.json' does not exist.", + "File '/a/types/jquery/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'jquery' was successfully resolved to '/a/types/jquery/index.d.ts', primary: true. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-13.types b/tests/baselines/reference/library-reference-13.types new file mode 100644 index 00000000000..b00d778c5b2 --- /dev/null +++ b/tests/baselines/reference/library-reference-13.types @@ -0,0 +1,13 @@ +=== /a/b/consumer.ts === +$.foo(); +>$.foo() : void +>$.foo : () => void +>$ : { foo(): void; } +>foo : () => void + +=== /a/types/jquery/index.d.ts === +declare var $: { foo(): void }; +>$ : { foo(): void; } +>foo : () => void + + diff --git a/tests/baselines/reference/library-reference-14.js b/tests/baselines/reference/library-reference-14.js new file mode 100644 index 00000000000..0fb5ff04fb9 --- /dev/null +++ b/tests/baselines/reference/library-reference-14.js @@ -0,0 +1,13 @@ +//// [tests/cases/conformance/references/library-reference-14.ts] //// + +//// [index.d.ts] + +declare var $: { foo(): void }; + + +//// [consumer.ts] +$.foo(); + + +//// [consumer.js] +$.foo(); diff --git a/tests/baselines/reference/library-reference-14.symbols b/tests/baselines/reference/library-reference-14.symbols new file mode 100644 index 00000000000..162afc50ca7 --- /dev/null +++ b/tests/baselines/reference/library-reference-14.symbols @@ -0,0 +1,13 @@ +=== /a/b/consumer.ts === +$.foo(); +>$.foo : Symbol(foo, Decl(index.d.ts, 1, 16)) +>$ : Symbol($, Decl(index.d.ts, 1, 11)) +>foo : Symbol(foo, Decl(index.d.ts, 1, 16)) + +=== /a/types/jquery/index.d.ts === + +declare var $: { foo(): void }; +>$ : Symbol($, Decl(index.d.ts, 1, 11)) +>foo : Symbol(foo, Decl(index.d.ts, 1, 16)) + + diff --git a/tests/baselines/reference/library-reference-14.trace.json b/tests/baselines/reference/library-reference-14.trace.json new file mode 100644 index 00000000000..2133414f414 --- /dev/null +++ b/tests/baselines/reference/library-reference-14.trace.json @@ -0,0 +1,7 @@ +[ + "======== Resolving type reference directive 'jquery', containing file not set, root directory '/a'. ========", + "Resolving with primary search path '/a/types/'", + "File '/a/types/jquery/package.json' does not exist.", + "File '/a/types/jquery/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'jquery' was successfully resolved to '/a/types/jquery/index.d.ts', primary: true. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-14.types b/tests/baselines/reference/library-reference-14.types new file mode 100644 index 00000000000..f4196e10744 --- /dev/null +++ b/tests/baselines/reference/library-reference-14.types @@ -0,0 +1,14 @@ +=== /a/b/consumer.ts === +$.foo(); +>$.foo() : void +>$.foo : () => void +>$ : { foo(): void; } +>foo : () => void + +=== /a/types/jquery/index.d.ts === + +declare var $: { foo(): void }; +>$ : { foo(): void; } +>foo : () => void + + diff --git a/tests/baselines/reference/library-reference-15.errors.txt b/tests/baselines/reference/library-reference-15.errors.txt new file mode 100644 index 00000000000..a311633ca76 --- /dev/null +++ b/tests/baselines/reference/library-reference-15.errors.txt @@ -0,0 +1,15 @@ +error TS2304: Cannot find name 'jquery'. +/a/b/consumer.ts(1,1): error TS2304: Cannot find name '$'. + + +!!! error TS2304: Cannot find name 'jquery'. +==== /a/b/consumer.ts (1 errors) ==== + $.foo(); + ~ +!!! error TS2304: Cannot find name '$'. + +==== /a/types/jquery/index.d.ts (0 errors) ==== + + declare var $: { foo(): void }; + + \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-15.js b/tests/baselines/reference/library-reference-15.js new file mode 100644 index 00000000000..f9aa7038d53 --- /dev/null +++ b/tests/baselines/reference/library-reference-15.js @@ -0,0 +1,13 @@ +//// [tests/cases/conformance/references/library-reference-15.ts] //// + +//// [index.d.ts] + +declare var $: { foo(): void }; + + +//// [consumer.ts] +$.foo(); + + +//// [consumer.js] +$.foo(); diff --git a/tests/baselines/reference/library-reference-15.trace.json b/tests/baselines/reference/library-reference-15.trace.json new file mode 100644 index 00000000000..9a19d75ffac --- /dev/null +++ b/tests/baselines/reference/library-reference-15.trace.json @@ -0,0 +1,5 @@ +[ + "======== Resolving type reference directive 'jquery', containing file not set, root directory not set. ========", + "Root directory cannot be determined, skipping primary search paths.", + "Containing file is not specified and root directory cannot be determined, skipping lookup in 'node_modules' folder." +] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-2.trace.json b/tests/baselines/reference/library-reference-2.trace.json index f18c6548b7e..b5ef5f3e208 100644 --- a/tests/baselines/reference/library-reference-2.trace.json +++ b/tests/baselines/reference/library-reference-2.trace.json @@ -1,5 +1,5 @@ [ - "======== Resolving type reference directive 'jquery' from '/consumer.ts', root dir '/'. ========", + "======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/'. ========", "Resolving with primary search path '/types/'", "Found 'package.json' at '/types/jquery/package.json'.", "'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.", diff --git a/tests/baselines/reference/library-reference-3.trace.json b/tests/baselines/reference/library-reference-3.trace.json index b1bd279e16c..30dbbc3fca4 100644 --- a/tests/baselines/reference/library-reference-3.trace.json +++ b/tests/baselines/reference/library-reference-3.trace.json @@ -1,5 +1,5 @@ [ - "======== Resolving type reference directive 'jquery' from '/src/consumer.ts', root dir '/src'. ========", + "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory '/src'. ========", "Resolving with primary search path '/src/types/'", "File '/src/types/jquery/package.json' does not exist.", "File '/src/types/jquery/index.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-4.trace.json b/tests/baselines/reference/library-reference-4.trace.json index 363eb020afb..90b6eb7b01d 100644 --- a/tests/baselines/reference/library-reference-4.trace.json +++ b/tests/baselines/reference/library-reference-4.trace.json @@ -1,5 +1,5 @@ [ - "======== Resolving type reference directive 'foo' from '/src/root.ts', root dir '/src'. ========", + "======== Resolving type reference directive 'foo', containing file '/src/root.ts', root directory '/src'. ========", "Resolving with primary search path '/src/types/'", "File '/src/types/foo/package.json' does not exist.", "File '/src/types/foo/index.d.ts' does not exist.", @@ -9,7 +9,7 @@ "Resolving with primary search path '/src/node_modules/@types/'", "File '/src/node_modules/@types/foo/package.json' does not exist.", "File '/src/node_modules/@types/foo/index.d.ts' does not exist.", - "Resolving from node_modules folder...", + "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.", @@ -26,7 +26,7 @@ "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' from '/src/root.ts', root dir '/src'. ========", + "======== Resolving type reference directive 'bar', containing file '/src/root.ts', root directory '/src'. ========", "Resolving with primary search path '/src/types/'", "File '/src/types/bar/package.json' does not exist.", "File '/src/types/bar/index.d.ts' does not exist.", @@ -36,7 +36,7 @@ "Resolving with primary search path '/src/node_modules/@types/'", "File '/src/node_modules/@types/bar/package.json' does not exist.", "File '/src/node_modules/@types/bar/index.d.ts' does not exist.", - "Resolving from node_modules folder...", + "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.", @@ -53,7 +53,7 @@ "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' from '/node_modules/foo/index.d.ts', root dir '/src'. ========", + "======== Resolving type reference directive 'alpha', containing file '/node_modules/foo/index.d.ts', root directory '/src'. ========", "Resolving with primary search path '/src/types/'", "File '/src/types/alpha/package.json' does not exist.", "File '/src/types/alpha/index.d.ts' does not exist.", @@ -63,14 +63,14 @@ "Resolving with primary search path '/src/node_modules/@types/'", "File '/src/node_modules/@types/alpha/package.json' does not exist.", "File '/src/node_modules/@types/alpha/index.d.ts' does not exist.", - "Resolving from node_modules folder...", + "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' from '/node_modules/bar/index.d.ts', root dir '/src'. ========", + "======== Resolving type reference directive 'alpha', containing file '/node_modules/bar/index.d.ts', root directory '/src'. ========", "Resolving with primary search path '/src/types/'", "File '/src/types/alpha/package.json' does not exist.", "File '/src/types/alpha/index.d.ts' does not exist.", @@ -80,7 +80,7 @@ "Resolving with primary search path '/src/node_modules/@types/'", "File '/src/node_modules/@types/alpha/package.json' does not exist.", "File '/src/node_modules/@types/alpha/index.d.ts' does not exist.", - "Resolving from node_modules folder...", + "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.", diff --git a/tests/baselines/reference/library-reference-5.trace.json b/tests/baselines/reference/library-reference-5.trace.json index 718ccfc37e4..272009782b5 100644 --- a/tests/baselines/reference/library-reference-5.trace.json +++ b/tests/baselines/reference/library-reference-5.trace.json @@ -1,7 +1,7 @@ [ - "======== Resolving type reference directive 'foo' from '/src/root.ts', root dir not set. ========", + "======== Resolving type reference directive 'foo', containing file '/src/root.ts', root directory not set. ========", "Root directory cannot be determined, skipping primary search paths.", - "Resolving from node_modules folder...", + "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.", @@ -18,9 +18,9 @@ "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' from '/src/root.ts', root dir not set. ========", + "======== Resolving type reference directive 'bar', containing file '/src/root.ts', root directory not set. ========", "Root directory cannot be determined, skipping primary search paths.", - "Resolving from node_modules folder...", + "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.", @@ -37,18 +37,18 @@ "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' from '/node_modules/foo/index.d.ts', root dir not set. ========", + "======== Resolving type reference directive 'alpha', containing file '/node_modules/foo/index.d.ts', root directory not set. ========", "Root directory cannot be determined, skipping primary search paths.", - "Resolving from node_modules folder...", + "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' from '/node_modules/bar/index.d.ts', root dir not set. ========", + "======== Resolving type reference directive 'alpha', containing file '/node_modules/bar/index.d.ts', root directory not set. ========", "Root directory cannot be determined, skipping primary search paths.", - "Resolving from node_modules folder...", + "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.", diff --git a/tests/baselines/reference/library-reference-6.trace.json b/tests/baselines/reference/library-reference-6.trace.json index 7009af6b853..426214fdcfc 100644 --- a/tests/baselines/reference/library-reference-6.trace.json +++ b/tests/baselines/reference/library-reference-6.trace.json @@ -1,5 +1,5 @@ [ - "======== Resolving type reference directive 'alpha' from '/src/foo.ts', root dir '/'. ========", + "======== Resolving type reference directive 'alpha', containing file '/src/foo.ts', root directory '/'. ========", "Resolving with primary search path '/types/'", "File '/types/alpha/package.json' does not exist.", "File '/types/alpha/index.d.ts' exist - use it as a name resolution result.", diff --git a/tests/baselines/reference/library-reference-7.trace.json b/tests/baselines/reference/library-reference-7.trace.json index 5d3e23564c7..419fe6d055d 100644 --- a/tests/baselines/reference/library-reference-7.trace.json +++ b/tests/baselines/reference/library-reference-7.trace.json @@ -1,7 +1,7 @@ [ - "======== Resolving type reference directive 'jquery' from '/src/consumer.ts', root dir not set. ========", + "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory not set. ========", "Root directory cannot be determined, skipping primary search paths.", - "Resolving from node_modules folder...", + "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.", diff --git a/tests/baselines/reference/library-reference-8.trace.json b/tests/baselines/reference/library-reference-8.trace.json index 1f0cced6c34..b1dc6478688 100644 --- a/tests/baselines/reference/library-reference-8.trace.json +++ b/tests/baselines/reference/library-reference-8.trace.json @@ -1,20 +1,20 @@ [ - "======== Resolving type reference directive 'alpha' from '/foo.ts', root dir '/'. ========", + "======== Resolving type reference directive 'alpha', containing file '/foo.ts', root directory '/'. ========", "Resolving with primary search path '/types/'", "File '/types/alpha/package.json' does not exist.", "File '/types/alpha/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'alpha' was successfully resolved to '/types/alpha/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'beta' from '/foo.ts', root dir '/'. ========", + "======== Resolving type reference directive 'beta', containing file '/foo.ts', root directory '/'. ========", "Resolving with primary search path '/types/'", "File '/types/beta/package.json' does not exist.", "File '/types/beta/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'beta' was successfully resolved to '/types/beta/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'beta' from '/types/alpha/index.d.ts', root dir '/'. ========", + "======== Resolving type reference directive 'beta', containing file '/types/alpha/index.d.ts', root directory '/'. ========", "Resolving with primary search path '/types/'", "File '/types/beta/package.json' does not exist.", "File '/types/beta/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'beta' was successfully resolved to '/types/beta/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'alpha' from '/types/beta/index.d.ts', root dir '/'. ========", + "======== Resolving type reference directive 'alpha', containing file '/types/beta/index.d.ts', root directory '/'. ========", "Resolving with primary search path '/types/'", "File '/types/alpha/package.json' does not exist.", "File '/types/alpha/index.d.ts' exist - use it as a name resolution result.", diff --git a/tests/baselines/reference/library-reference-9.trace.json b/tests/baselines/reference/library-reference-9.trace.json index d44abcac839..e2fdfdc0550 100644 --- a/tests/baselines/reference/library-reference-9.trace.json +++ b/tests/baselines/reference/library-reference-9.trace.json @@ -1,5 +1,5 @@ [ - "======== Resolving type reference directive 'alpha' from '/base/src/foo.ts', root dir '/'. ========", + "======== Resolving type reference directive 'alpha', containing file '/base/src/foo.ts', root directory '/'. ========", "Resolving with primary search path '/share/typelib'", "File '/share/typelib/alpha/package.json' does not exist.", "File '/share/typelib/alpha/index.d.ts' exist - use it as a name resolution result.", diff --git a/tests/cases/conformance/references/library-reference-13.ts b/tests/cases/conformance/references/library-reference-13.ts new file mode 100644 index 00000000000..a96437f9b2c --- /dev/null +++ b/tests/cases/conformance/references/library-reference-13.ts @@ -0,0 +1,18 @@ +// @noImplicitReferences: true +// @traceResolution: true + +// load type declarations from types section of tsconfig + +// @filename: /a/tsconfig.json +{ + "compilerOptions": { + "types": [ "jquery" ] + } +} + +// @filename: /a/types/jquery/index.d.ts +declare var $: { foo(): void }; + + +// @filename: /a/b/consumer.ts +$.foo(); diff --git a/tests/cases/conformance/references/library-reference-14.ts b/tests/cases/conformance/references/library-reference-14.ts new file mode 100644 index 00000000000..53bca2ab40d --- /dev/null +++ b/tests/cases/conformance/references/library-reference-14.ts @@ -0,0 +1,11 @@ +// @noImplicitReferences: true +// @traceResolution: true +// @types: jquery +// @typesRoot: /a + +// @filename: /a/types/jquery/index.d.ts +declare var $: { foo(): void }; + + +// @filename: /a/b/consumer.ts +$.foo(); diff --git a/tests/cases/conformance/references/library-reference-15.ts b/tests/cases/conformance/references/library-reference-15.ts new file mode 100644 index 00000000000..92c96e74c97 --- /dev/null +++ b/tests/cases/conformance/references/library-reference-15.ts @@ -0,0 +1,10 @@ +// @noImplicitReferences: true +// @traceResolution: true +// @types: jquery + +// @filename: /a/types/jquery/index.d.ts +declare var $: { foo(): void }; + + +// @filename: /a/b/consumer.ts +$.foo();