diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 058c6ac44fe..8ae88d49438 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -321,6 +321,10 @@ namespace ts { isFilePath: true } }, + { + name: "typesRoot", + type: "string" + }, { name: "traceResolution", type: "boolean", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 26f213cca25..bceca5d8809 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}' with compilation root dir '{2}'. ========": { + "======== Resolving type reference directive '{0}' from '{1}', root dir '{2}'. ========": { "category": "Message", "code": 6115 }, @@ -2661,7 +2661,14 @@ "category": "Message", "code": 6120 }, - + "Root directory cannot be determined, skipping primary search paths.": { + "category": "Message", + "code": 6121 + }, + "======== Resolving type reference directive '{0}' from '{1}', root dir not set. ========": { + "category": "Message", + "code": 6122 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 283e2802288..0c1c987541c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -41,14 +41,8 @@ namespace ts { return normalizePath(referencedFileName); } - export function computeCompilationRoot(rootFileNames: string[], currentDirectory: string, options: CompilerOptions, getCanonicalFileName: (fileName: string) => string): string { - const rootDirOrConfigFilePath = options.rootDir || (options.configFilePath && getDirectoryPath(options.configFilePath)); - return rootDirOrConfigFilePath - ? getNormalizedAbsolutePath(rootDirOrConfigFilePath, currentDirectory) - : computeCommonSourceDirectoryOfFilenames(rootFileNames, currentDirectory, getCanonicalFileName); - } - - function computeCommonSourceDirectoryOfFilenames(fileNames: string[], currentDirectory: string, getCanonicalFileName: (fileName: string) => string): string { + /* @internal */ + export function computeCommonSourceDirectoryOfFilenames(fileNames: string[], currentDirectory: string, getCanonicalFileName: (fileName: string) => string): string { let commonPathComponents: string[]; const failed = forEach(fileNames, sourceFile => { // Each file contributes into common source file path @@ -196,7 +190,8 @@ namespace ts { } const typeReferenceExtensions = [".d.ts"]; - export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string, compilationRoot: string, options: CompilerOptions, host: ModuleResolutionHost): ResolvedTypeReferenceDirectiveWithFailedLookupLocations { + + export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost): ResolvedTypeReferenceDirectiveWithFailedLookupLocations { const traceEnabled = isTraceEnabled(options, host); const moduleResolutionState: ModuleResolutionState = { compilerOptions: options, @@ -205,30 +200,47 @@ namespace ts { traceEnabled }; - if (traceEnabled) { - trace(host, Diagnostics.Resolving_type_reference_directive_0_from_1_with_compilation_root_dir_2, typeReferenceDirectiveName, containingFile, compilationRoot); - } - const failedLookupLocations: string[] = []; - // Check primary library paths - const effectivePrimarySearchPaths = options.typesSearchPaths || defaultLibrarySearchPaths; - for (const searchPath of effectivePrimarySearchPaths) { - const primaryPath = combinePaths(compilationRoot, searchPath); - if (traceEnabled) { - trace(host, Diagnostics.Resolving_with_primary_search_path_0, primaryPath); - } - const candidate = combinePaths(primaryPath, typeReferenceDirectiveName); - const candidateDirectory = getDirectoryPath(candidate); - const resolvedFile = loadNodeModuleFromDirectory(typeReferenceExtensions, candidate, failedLookupLocations, - !directoryProbablyExists(candidateDirectory, host), moduleResolutionState); + // use typesRoot and fallback to directory that contains tsconfig if typesRoot is not set + const rootDir = options.typesRoot || (options.configFilePath ? getDirectoryPath(options.configFilePath) : undefined); - if (resolvedFile) { + if (traceEnabled) { + if (rootDir !== undefined) { + trace(host, Diagnostics.Resolving_type_reference_directive_0_from_1_root_dir_2, typeReferenceDirectiveName, containingFile, rootDir); + } + else { + trace(host, Diagnostics.Resolving_type_reference_directive_0_from_1_root_dir_not_set, typeReferenceDirectiveName, containingFile); + } + } + + const failedLookupLocations: string[] = []; + + // Check primary library paths + if (rootDir !== undefined) { + const effectivePrimarySearchPaths = options.typesSearchPaths || defaultLibrarySearchPaths; + for (const searchPath of effectivePrimarySearchPaths) { + const primaryPath = combinePaths(rootDir, searchPath); if (traceEnabled) { - trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFile, true); + trace(host, Diagnostics.Resolving_with_primary_search_path_0, primaryPath); } - return { - resolvedTypeReferenceDirective: { primary: true, resolvedFileName: resolvedFile }, - failedLookupLocations - }; + const candidate = combinePaths(primaryPath, typeReferenceDirectiveName); + const candidateDirectory = getDirectoryPath(candidate); + const resolvedFile = loadNodeModuleFromDirectory(typeReferenceExtensions, candidate, failedLookupLocations, + !directoryProbablyExists(candidateDirectory, host), moduleResolutionState); + + if (resolvedFile) { + if (traceEnabled) { + trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFile, true); + } + return { + resolvedTypeReferenceDirective: { primary: true, resolvedFileName: resolvedFile }, + failedLookupLocations + }; + } + } + } + else { + if (traceEnabled) { + trace(host, Diagnostics.Root_directory_cannot_be_determined_skipping_primary_search_paths); } } @@ -889,8 +901,6 @@ namespace ts { host = host || createCompilerHost(options); - const compilationRoot = computeCompilationRoot(rootNames, currentDirectory, options, getCanonicalFileName); - // Map storing if there is emit blocking diagnostics for given input const hasEmitBlockingDiagnostics = createFileMap(getCanonicalFileName); @@ -908,7 +918,7 @@ namespace ts { resolveTypeReferenceDirectiveNamesWorker = (typeDirectiveNames, containingFile) => host.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile); } else { - const loader = (typesRef: string, containingFile: string) => resolveTypeReferenceDirective(typesRef, containingFile, compilationRoot, options, host).resolvedTypeReferenceDirective; + const loader = (typesRef: string, containingFile: string) => resolveTypeReferenceDirective(typesRef, containingFile, options, host).resolvedTypeReferenceDirective; resolveTypeReferenceDirectiveNamesWorker = (typeReferenceDirectiveNames, containingFile) => loadWithLocalCache(typeReferenceDirectiveNames, containingFile, loader); } @@ -1690,7 +1700,7 @@ namespace ts { const basePath = getDirectoryPath(fileName); if (!options.noResolve) { processReferencedFiles(file, basePath, isDefaultLib); - processTypeReferenceDirectives(file, compilationRoot); + processTypeReferenceDirectives(file); } // always process imported modules to record module name resolutions @@ -1714,7 +1724,7 @@ namespace ts { }); } - function processTypeReferenceDirectives(file: SourceFile, compilationRoot: string) { + function processTypeReferenceDirectives(file: SourceFile) { const typeDirectives = map(file.typeReferenceDirectives, l => l.fileName); const resolutions = resolveTypeReferenceDirectiveNamesWorker(typeDirectives, file.fileName); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 144a21b8c0d..9497a7ebfe6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2473,6 +2473,9 @@ namespace ts { /* @internal */ // When options come from a config file, its path is recorded here configFilePath?: string; + /* @internal */ + // Path used to used to compute primary search locations + typesRoot?: string; list?: string[]; [option: string]: CompilerOptionsValue; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 3dad49d24b3..304b6bcc455 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -247,6 +247,10 @@ namespace FourSlash { // Create a new Services Adapter this.cancellationToken = new TestCancellationToken(); const compilationOptions = convertGlobalOptionsToCompilerOptions(this.testData.globalOptions); + if (compilationOptions.typesRoot) { + compilationOptions.typesRoot = ts.getNormalizedAbsolutePath(compilationOptions.typesRoot, this.basePath); + } + const languageServiceAdapter = this.getLanguageServiceAdapter(testType, this.cancellationToken, compilationOptions); this.languageServiceAdapterHost = languageServiceAdapter.getHost(); this.languageService = languageServiceAdapter.getLanguageService(); diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 5bcbb174676..b27d746390b 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -247,12 +247,9 @@ namespace Harness.LanguageService { const scriptInfo = this.getScriptInfo(fileName); const preprocessInfo = ts.preProcessFile(scriptInfo.content, /*readImportFiles*/ false); const resolutions: ts.Map = {}; - const rootFiles = this.getFilenames(); - const currentDirectory = this.getCurrentDirectory(); const settings = this.nativeHost.getCompilationSettings(); - const compilationRoot = ts.computeCompilationRoot(rootFiles, currentDirectory, settings, ts.createGetCanonicalFileName(false)); for (const typeReferenceDirective of preprocessInfo.typeReferenceDirectives) { - const resolutionInfo = ts.resolveTypeReferenceDirective(typeReferenceDirective.fileName, fileName, compilationRoot, settings, moduleResolutionHost); + const resolutionInfo = ts.resolveTypeReferenceDirective(typeReferenceDirective.fileName, fileName, settings, moduleResolutionHost); if (resolutionInfo.resolvedTypeReferenceDirective.resolvedFileName) { resolutions[typeReferenceDirective.fileName] = resolutionInfo.resolvedTypeReferenceDirective; } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 9b57c1687aa..4c054664a18 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -96,7 +96,6 @@ namespace ts.server { compilationSettings: ts.CompilerOptions; filenameToScript: ts.FileMap; roots: ScriptInfo[] = []; - compilationRoot: string; private resolvedModuleNames: ts.FileMap>; private resolvedTypeReferenceDirectives: ts.FileMap>; @@ -172,13 +171,7 @@ namespace ts.server { } resolveTypeReferenceDirectives(typeDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[] { - if (this.compilationRoot === undefined) { - this.compilationRoot = computeCompilationRoot(this.getScriptFileNames(), this.getCurrentDirectory(), this.getCompilationSettings(), this.getCanonicalFileName); - } - const loader = (name: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost) => { - return resolveTypeReferenceDirective(name, containingFile, this.compilationRoot, options, this.moduleResolutionHost); - }; - return this.resolveNamesWithLocalCache(typeDirectiveNames, containingFile, this.resolvedTypeReferenceDirectives, loader, m => m.resolvedTypeReferenceDirective); + return this.resolveNamesWithLocalCache(typeDirectiveNames, containingFile, this.resolvedTypeReferenceDirectives, resolveTypeReferenceDirective, m => m.resolvedTypeReferenceDirective); } resolveModuleNames(moduleNames: string[], containingFile: string): ResolvedModule[] { @@ -262,8 +255,6 @@ namespace ts.server { if (!this.filenameToScript.contains(info.path)) { this.filenameToScript.set(info.path, info); this.roots.push(info); - // reset compilation root - this.compilationRoot = undefined; } } @@ -273,8 +264,6 @@ namespace ts.server { this.roots = copyListRemovingItem(info, this.roots); this.resolvedModuleNames.remove(info.path); this.resolvedTypeReferenceDirectives.remove(info.path); - // reset compilation root - this.compilationRoot = undefined; } } diff --git a/src/services/shims.ts b/src/services/shims.ts index c99a16ca0cd..9155c057ef2 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -907,7 +907,6 @@ namespace ts { class CoreServicesShimObject extends ShimBase implements CoreServicesShim { private logPerformance = false; - private getCanonicalFileName = createGetCanonicalFileName(false); constructor(factory: ShimFactory, public logger: Logger, private host: CoreServicesShimHostAdapter) { super(factory); @@ -928,18 +927,10 @@ namespace ts { }); } - public computeCompilationRoot(filesJson: string, currentDirectory: string, compilerOptionsJson: string): string { - return this.forwardJSONCall("computeCompilationRoot", () => { - const files = JSON.parse(filesJson); - const compilerOptions = JSON.parse(compilerOptionsJson); - return computeCompilationRoot(files, currentDirectory, compilerOptions, this.getCanonicalFileName); - }); - } - - public resolveTypeReferenceDirective(fileName: string, typeReferenceDirective: string, compilationRoot: string, compilerOptionsJson: string): string { + public resolveTypeReferenceDirective(fileName: string, typeReferenceDirective: string, compilerOptionsJson: string): string { return this.forwardJSONCall(`resolveTypeReferenceDirective(${fileName})`, () => { const compilerOptions = JSON.parse(compilerOptionsJson); - const result = resolveTypeReferenceDirective(typeReferenceDirective, normalizeSlashes(fileName), compilationRoot, compilerOptions, this.host); + const result = resolveTypeReferenceDirective(typeReferenceDirective, normalizeSlashes(fileName), compilerOptions, this.host); return { resolvedFileName: result.resolvedTypeReferenceDirective ? result.resolvedTypeReferenceDirective.resolvedFileName : undefined, primary: result.resolvedTypeReferenceDirective ? result.resolvedTypeReferenceDirective.primary : true, diff --git a/tests/baselines/reference/library-reference-1.trace.json b/tests/baselines/reference/library-reference-1.trace.json index a5ce5985525..be96aa1d852 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' with compilation root dir '/'. ========", + "======== Resolving type reference directive 'jquery' from '/consumer.ts', root dir '/'. ========", "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 44ed04a2e57..1645195146d 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' with compilation root dir '/'. ========", + "======== Resolving type reference directive 'jquery' from '/consumer.ts', root dir '/'. ========", "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 aea446fcd78..912ff1d2114 100644 --- a/tests/baselines/reference/library-reference-11.trace.json +++ b/tests/baselines/reference/library-reference-11.trace.json @@ -1,14 +1,6 @@ [ - "======== Resolving type reference directive 'jquery' from '/a/b/consumer.ts' with compilation root dir '/a/b'. ========", - "Resolving with primary search path '/a/b/types/'", - "File '/a/b/types/jquery/package.json' does not exist.", - "File '/a/b/types/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/a/b/node_modules/'", - "File '/a/b/node_modules/jquery/package.json' does not exist.", - "File '/a/b/node_modules/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/a/b/node_modules/@types/'", - "File '/a/b/node_modules/@types/jquery/package.json' does not exist.", - "File '/a/b/node_modules/@types/jquery/index.d.ts' does not exist.", + "======== Resolving type reference directive 'jquery' from '/a/b/consumer.ts', root dir not set. ========", + "Root directory cannot be determined, skipping primary search paths.", "Resolving from node_modules folder...", "File '/a/b/node_modules/jquery.ts' does not exist.", "File '/a/b/node_modules/jquery.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-12.trace.json b/tests/baselines/reference/library-reference-12.trace.json index 2bf990d7c66..47a4d7f0220 100644 --- a/tests/baselines/reference/library-reference-12.trace.json +++ b/tests/baselines/reference/library-reference-12.trace.json @@ -1,14 +1,6 @@ [ - "======== Resolving type reference directive 'jquery' from '/a/b/consumer.ts' with compilation root dir '/a/b'. ========", - "Resolving with primary search path '/a/b/types/'", - "File '/a/b/types/jquery/package.json' does not exist.", - "File '/a/b/types/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/a/b/node_modules/'", - "File '/a/b/node_modules/jquery/package.json' does not exist.", - "File '/a/b/node_modules/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/a/b/node_modules/@types/'", - "File '/a/b/node_modules/@types/jquery/package.json' does not exist.", - "File '/a/b/node_modules/@types/jquery/index.d.ts' does not exist.", + "======== Resolving type reference directive 'jquery' from '/a/b/consumer.ts', root dir not set. ========", + "Root directory cannot be determined, skipping primary search paths.", "Resolving from node_modules folder...", "File '/a/b/node_modules/jquery.ts' does not exist.", "File '/a/b/node_modules/jquery.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-2.trace.json b/tests/baselines/reference/library-reference-2.trace.json index 82eddf3c7dc..f18c6548b7e 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' with compilation root dir '/'. ========", + "======== Resolving type reference directive 'jquery' from '/consumer.ts', root dir '/'. ========", "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 9bbedd4a22b..b1bd279e16c 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' with compilation root dir '/src'. ========", + "======== Resolving type reference directive 'jquery' from '/src/consumer.ts', root dir '/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 c0ac8c39512..363eb020afb 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' with compilation root dir '/src'. ========", + "======== Resolving type reference directive 'foo' from '/src/root.ts', root dir '/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.", @@ -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' with compilation root dir '/src'. ========", + "======== Resolving type reference directive 'bar' from '/src/root.ts', root dir '/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.", @@ -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' with compilation root dir '/src'. ========", + "======== Resolving type reference directive 'alpha' from '/node_modules/foo/index.d.ts', root dir '/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.", @@ -70,7 +70,7 @@ "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' with compilation root dir '/src'. ========", + "======== Resolving type reference directive 'alpha' from '/node_modules/bar/index.d.ts', root dir '/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.", diff --git a/tests/baselines/reference/library-reference-5.trace.json b/tests/baselines/reference/library-reference-5.trace.json index c0ac8c39512..718ccfc37e4 100644 --- a/tests/baselines/reference/library-reference-5.trace.json +++ b/tests/baselines/reference/library-reference-5.trace.json @@ -1,14 +1,6 @@ [ - "======== Resolving type reference directive 'foo' from '/src/root.ts' with compilation root dir '/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.", - "Resolving with primary search path '/src/node_modules/'", - "File '/src/node_modules/foo/package.json' does not exist.", - "File '/src/node_modules/foo/index.d.ts' does not exist.", - "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 type reference directive 'foo' from '/src/root.ts', root dir not set. ========", + "Root directory cannot be determined, skipping primary search paths.", "Resolving from node_modules folder...", "File '/src/node_modules/foo.ts' does not exist.", "File '/src/node_modules/foo.d.ts' does not exist.", @@ -26,16 +18,8 @@ "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' with compilation root dir '/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.", - "Resolving with primary search path '/src/node_modules/'", - "File '/src/node_modules/bar/package.json' does not exist.", - "File '/src/node_modules/bar/index.d.ts' does not exist.", - "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 type reference directive 'bar' from '/src/root.ts', root dir not set. ========", + "Root directory cannot be determined, skipping primary search paths.", "Resolving from node_modules folder...", "File '/src/node_modules/bar.ts' does not exist.", "File '/src/node_modules/bar.d.ts' does not exist.", @@ -53,16 +37,8 @@ "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' with compilation root dir '/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.", - "Resolving with primary search path '/src/node_modules/'", - "File '/src/node_modules/alpha/package.json' does not exist.", - "File '/src/node_modules/alpha/index.d.ts' does not exist.", - "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 type reference directive 'alpha' from '/node_modules/foo/index.d.ts', root dir not set. ========", + "Root directory cannot be determined, skipping primary search paths.", "Resolving from node_modules folder...", "File '/node_modules/foo/node_modules/alpha.ts' does not exist.", "File '/node_modules/foo/node_modules/alpha.d.ts' does not exist.", @@ -70,16 +46,8 @@ "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' with compilation root dir '/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.", - "Resolving with primary search path '/src/node_modules/'", - "File '/src/node_modules/alpha/package.json' does not exist.", - "File '/src/node_modules/alpha/index.d.ts' does not exist.", - "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 type reference directive 'alpha' from '/node_modules/bar/index.d.ts', root dir not set. ========", + "Root directory cannot be determined, skipping primary search paths.", "Resolving from node_modules folder...", "File '/node_modules/bar/node_modules/alpha.ts' does not exist.", "File '/node_modules/bar/node_modules/alpha.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-6.trace.json b/tests/baselines/reference/library-reference-6.trace.json index 0442a008dfb..7009af6b853 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' with compilation root dir '/'. ========", + "======== Resolving type reference directive 'alpha' from '/src/foo.ts', root dir '/'. ========", "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.js b/tests/baselines/reference/library-reference-7.js index fce1598b2fd..f1ef6ca4eab 100644 --- a/tests/baselines/reference/library-reference-7.js +++ b/tests/baselines/reference/library-reference-7.js @@ -2,15 +2,15 @@ //// [index.d.ts] -// The primary lookup folder is relative to tsconfig.json's 'root', if present +// Secondary references are possible -declare var alpha: { a: string }; +declare var $: { foo(): void }; -//// [foo.ts] -/// -var x: string = alpha.a; +//// [consumer.ts] +/// +$.foo(); -//// [foo.js] -/// -var x = alpha.a; +//// [consumer.js] +/// +$.foo(); diff --git a/tests/baselines/reference/library-reference-7.symbols b/tests/baselines/reference/library-reference-7.symbols index ec8c2f014ac..a1785fd77c9 100644 --- a/tests/baselines/reference/library-reference-7.symbols +++ b/tests/baselines/reference/library-reference-7.symbols @@ -1,16 +1,15 @@ -=== /base/src/foo.ts === -/// -var x: string = alpha.a; ->x : Symbol(x, Decl(foo.ts, 1, 3)) ->alpha.a : Symbol(a, Decl(index.d.ts, 3, 20)) ->alpha : Symbol(alpha, Decl(index.d.ts, 3, 11)) ->a : Symbol(a, Decl(index.d.ts, 3, 20)) +=== /src/consumer.ts === +/// +$.foo(); +>$.foo : Symbol(foo, Decl(index.d.ts, 3, 16)) +>$ : Symbol($, Decl(index.d.ts, 3, 11)) +>foo : Symbol(foo, Decl(index.d.ts, 3, 16)) -=== /base/types/alpha/index.d.ts === +=== /src/node_modules/jquery/index.d.ts === -// The primary lookup folder is relative to tsconfig.json's 'root', if present +// Secondary references are possible -declare var alpha: { a: string }; ->alpha : Symbol(alpha, Decl(index.d.ts, 3, 11)) ->a : Symbol(a, Decl(index.d.ts, 3, 20)) +declare var $: { foo(): void }; +>$ : Symbol($, Decl(index.d.ts, 3, 11)) +>foo : Symbol(foo, Decl(index.d.ts, 3, 16)) diff --git a/tests/baselines/reference/library-reference-7.trace.json b/tests/baselines/reference/library-reference-7.trace.json index d495e27cdc5..5d3e23564c7 100644 --- a/tests/baselines/reference/library-reference-7.trace.json +++ b/tests/baselines/reference/library-reference-7.trace.json @@ -1,7 +1,11 @@ [ - "======== Resolving type reference directive 'alpha' from '/base/src/foo.ts' with compilation root dir '/base'. ========", - "Resolving with primary search path '/base/types/'", - "File '/base/types/alpha/package.json' does not exist.", - "File '/base/types/alpha/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'alpha' was successfully resolved to '/base/types/alpha/index.d.ts', primary: true. ========" + "======== Resolving type reference directive 'jquery' from '/src/consumer.ts', root dir not set. ========", + "Root directory cannot be determined, skipping primary search paths.", + "Resolving from node_modules folder...", + "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. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-7.types b/tests/baselines/reference/library-reference-7.types index 3f6c720c882..ed7da59525f 100644 --- a/tests/baselines/reference/library-reference-7.types +++ b/tests/baselines/reference/library-reference-7.types @@ -1,16 +1,16 @@ -=== /base/src/foo.ts === -/// -var x: string = alpha.a; ->x : string ->alpha.a : string ->alpha : { a: string; } ->a : string +=== /src/consumer.ts === +/// +$.foo(); +>$.foo() : void +>$.foo : () => void +>$ : { foo(): void; } +>foo : () => void -=== /base/types/alpha/index.d.ts === +=== /src/node_modules/jquery/index.d.ts === -// The primary lookup folder is relative to tsconfig.json's 'root', if present +// Secondary references are possible -declare var alpha: { a: string }; ->alpha : { a: string; } ->a : string +declare var $: { foo(): void }; +>$ : { foo(): void; } +>foo : () => void diff --git a/tests/baselines/reference/library-reference-8.trace.json b/tests/baselines/reference/library-reference-8.trace.json index 0dec47d9375..1f0cced6c34 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' with compilation root dir '/'. ========", + "======== Resolving type reference directive 'alpha' from '/foo.ts', root dir '/'. ========", "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' with compilation root dir '/'. ========", + "======== Resolving type reference directive 'beta' from '/foo.ts', root dir '/'. ========", "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' with compilation root dir '/'. ========", + "======== Resolving type reference directive 'beta' from '/types/alpha/index.d.ts', root dir '/'. ========", "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' with compilation root dir '/'. ========", + "======== Resolving type reference directive 'alpha' from '/types/beta/index.d.ts', root dir '/'. ========", "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 36119298d07..d44abcac839 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' with compilation root dir '/'. ========", + "======== Resolving type reference directive 'alpha' from '/base/src/foo.ts', root dir '/'. ========", "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-1.ts b/tests/cases/conformance/references/library-reference-1.ts index 74c748043b5..ca25441521f 100644 --- a/tests/cases/conformance/references/library-reference-1.ts +++ b/tests/cases/conformance/references/library-reference-1.ts @@ -1,5 +1,6 @@ // @noImplicitReferences: true // @traceResolution: true +// @typesRoot: / // We can find typings in the ./types folder diff --git a/tests/cases/conformance/references/library-reference-10.ts b/tests/cases/conformance/references/library-reference-10.ts index fcacbd556ac..11e065b0a7d 100644 --- a/tests/cases/conformance/references/library-reference-10.ts +++ b/tests/cases/conformance/references/library-reference-10.ts @@ -1,5 +1,6 @@ // @noImplicitReferences: true // @traceResolution: true +// @typesRoot: / // package.json in a primary reference can refer to another file diff --git a/tests/cases/conformance/references/library-reference-2.ts b/tests/cases/conformance/references/library-reference-2.ts index d0882272a08..d8975664428 100644 --- a/tests/cases/conformance/references/library-reference-2.ts +++ b/tests/cases/conformance/references/library-reference-2.ts @@ -1,5 +1,6 @@ // @noImplicitReferences: true // @traceResolution: true +// @typesRoot: / // package.json in a primary reference can refer to another file diff --git a/tests/cases/conformance/references/library-reference-3.ts b/tests/cases/conformance/references/library-reference-3.ts index 64b1c8ddda8..1af6df89d19 100644 --- a/tests/cases/conformance/references/library-reference-3.ts +++ b/tests/cases/conformance/references/library-reference-3.ts @@ -1,6 +1,6 @@ // @noImplicitReferences: true // @traceResolution: true -// @traceResolution: true +// @typesRoot: /src // Secondary references are possible diff --git a/tests/cases/conformance/references/library-reference-4.ts b/tests/cases/conformance/references/library-reference-4.ts index a0ba4bff890..92f1b4008be 100644 --- a/tests/cases/conformance/references/library-reference-4.ts +++ b/tests/cases/conformance/references/library-reference-4.ts @@ -1,5 +1,6 @@ // @noImplicitReferences: true // @traceResolution: true +// @typesRoot: /src // Secondary references may be duplicated if they agree in content diff --git a/tests/cases/conformance/references/library-reference-7.ts b/tests/cases/conformance/references/library-reference-7.ts index 9d400604a63..e938aef7d3a 100644 --- a/tests/cases/conformance/references/library-reference-7.ts +++ b/tests/cases/conformance/references/library-reference-7.ts @@ -1,18 +1,11 @@ // @noImplicitReferences: true // @traceResolution: true -// The primary lookup folder is relative to tsconfig.json's 'root', if present +// Secondary references are possible -// @filename: /base/types/alpha/index.d.ts -declare var alpha: { a: string }; +// @filename: /src/node_modules/jquery/index.d.ts +declare var $: { foo(): void }; -// @filename: /base/src/foo.ts -/// -var x: string = alpha.a; - -// @filename: /tsconfig.json -{ - "compilerOptions": { - "rootDir": "base" - } -} +// @filename: /src/consumer.ts +/// +$.foo(); diff --git a/tests/cases/conformance/references/library-reference-8.ts b/tests/cases/conformance/references/library-reference-8.ts index 112ec18e446..9de93776989 100644 --- a/tests/cases/conformance/references/library-reference-8.ts +++ b/tests/cases/conformance/references/library-reference-8.ts @@ -1,5 +1,6 @@ // @noImplicitReferences: true // @traceResolution: true +// @typesRoot: / // Don't crash in circular library reference situations diff --git a/tests/cases/fourslash/goToDefinitionTypeReferenceDirective.ts b/tests/cases/fourslash/goToDefinitionTypeReferenceDirective.ts index 6d2fdc0112d..3aaa3ab980f 100644 --- a/tests/cases/fourslash/goToDefinitionTypeReferenceDirective.ts +++ b/tests/cases/fourslash/goToDefinitionTypeReferenceDirective.ts @@ -1,5 +1,6 @@ /// +// @typesRoot: src // @Filename: src/types/lib/index.d.ts /////*0*/declare let $: {x: number}; diff --git a/tests/cases/fourslash/shims-pp/goToDefinitionTypeReferenceDirective.ts b/tests/cases/fourslash/shims-pp/goToDefinitionTypeReferenceDirective.ts index 6d2fdc0112d..3aaa3ab980f 100644 --- a/tests/cases/fourslash/shims-pp/goToDefinitionTypeReferenceDirective.ts +++ b/tests/cases/fourslash/shims-pp/goToDefinitionTypeReferenceDirective.ts @@ -1,5 +1,6 @@ /// +// @typesRoot: src // @Filename: src/types/lib/index.d.ts /////*0*/declare let $: {x: number}; diff --git a/tests/cases/fourslash/shims/goToDefinitionTypeReferenceDirective.ts b/tests/cases/fourslash/shims/goToDefinitionTypeReferenceDirective.ts index 6d2fdc0112d..3aaa3ab980f 100644 --- a/tests/cases/fourslash/shims/goToDefinitionTypeReferenceDirective.ts +++ b/tests/cases/fourslash/shims/goToDefinitionTypeReferenceDirective.ts @@ -1,5 +1,6 @@ /// +// @typesRoot: src // @Filename: src/types/lib/index.d.ts /////*0*/declare let $: {x: number}; diff --git a/tests/cases/unittests/moduleResolution.ts b/tests/cases/unittests/moduleResolution.ts index e9677313409..29fde331892 100644 --- a/tests/cases/unittests/moduleResolution.ts +++ b/tests/cases/unittests/moduleResolution.ts @@ -956,9 +956,9 @@ import b = require("./moduleB.ts"); }); describe("Type reference directive resolution: ", () => { - function test(compilationRoot: string, typeDirective: string, primary: boolean, initialFile: File, targetFile: File, ...otherFiles: File[]) { + function test(typesRoot: string, typeDirective: string, primary: boolean, initialFile: File, targetFile: File, ...otherFiles: File[]) { const host = createModuleResolutionHost(false, ...[initialFile, targetFile].concat(...otherFiles)); - const result = resolveTypeReferenceDirective(typeDirective, initialFile.name, compilationRoot, {}, host); + const result = resolveTypeReferenceDirective(typeDirective, initialFile.name, {typesRoot}, host); assert(result.resolvedTypeReferenceDirective.resolvedFileName !== undefined, "expected type directive to be resolved"); assert.equal(result.resolvedTypeReferenceDirective.resolvedFileName, targetFile.name, "unexpected result of type reference resolution"); assert.equal(result.resolvedTypeReferenceDirective.primary, primary, "unexpected 'primary' value"); @@ -968,64 +968,64 @@ import b = require("./moduleB.ts"); { const f1 = { name: "/root/src/app.ts" } const f2 = { name: "/root/src/types/lib/index.d.ts" }; - test(/*libraryRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2); + test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2); } { const f1 = { name: "/root/src/app.ts" } const f2 = { name: "/root/src/types/lib/typings/lib.d.ts" }; const package = { name: "/root/src/types/lib/package.json", content: JSON.stringify({types: "typings/lib.d.ts"}) }; - test(/*libraryRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2, package); + test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2, package); } { const f1 = { name: "/root/src/app.ts" } const f2 = { name: "/root/src/node_modules/lib/index.d.ts" }; - test(/*libraryRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2); + test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2); } { const f1 = { name: "/root/src/app.ts" } const f2 = { name: "/root/src/node_modules/lib/typings/lib.d.ts" }; const package = { name: "/root/src/node_modules/lib/package.json", content: JSON.stringify({types: "typings/lib.d.ts"}) }; - test(/*libraryRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2, package); + test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2, package); } { const f1 = { name: "/root/src/app.ts" } const f2 = { name: "/root/src/node_modules/@types/lib/index.d.ts" }; - test(/*libraryRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2); + test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2); } { const f1 = { name: "/root/src/app.ts" } const f2 = { name: "/root/src/node_modules/@types/lib/typings/lib.d.ts" }; const package = { name: "/root/src/node_modules/@types/lib/package.json", content: JSON.stringify({types: "typings/lib.d.ts"}) }; - test(/*libraryRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2, package); + test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2, package); } }); it("Can be resolved from secondary location", () => { { const f1 = { name: "/root/src/app.ts" } const f2 = { name: "/root/node_modules/lib.d.ts" }; - test(/*libraryRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2); + test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2); } { const f1 = { name: "/root/src/app.ts" } const f2 = { name: "/root/node_modules/lib/index.d.ts" }; - test(/*libraryRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2); + test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2); } { const f1 = { name: "/root/src/app.ts" } const f2 = { name: "/root/node_modules/lib/typings/lib.d.ts" }; const package = { name: "/root/node_modules/lib/package.json", content: JSON.stringify({typings: "typings/lib.d.ts"}) }; - test(/*libraryRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2, package); + test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2, package); } { const f1 = { name: "/root/src/app.ts" } const f2 = { name: "/root/node_modules/@types/lib/index.d.ts" }; - test(/*libraryRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2); + test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2); } { const f1 = { name: "/root/src/app.ts" } const f2 = { name: "/root/node_modules/@types/lib/typings/lib.d.ts" }; const package = { name: "/root/node_modules/@types/lib/package.json", content: JSON.stringify({typings: "typings/lib.d.ts"}) }; - test(/*libraryRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2, package); + test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2, package); } }); it("Primary resolution overrides secondary resolutions", () => { @@ -1033,7 +1033,7 @@ import b = require("./moduleB.ts"); const f1 = { name: "/root/src/a/b/c/app.ts" }; const f2 = { name: "/root/src/types/lib/index.d.ts" }; const f3 = { name: "/root/src/a/b/node_modules/lib.d.ts" } - test(/*libraryRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2, f3); + test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2, f3); } }) it("Reused program keeps errors", () => { diff --git a/tests/cases/unittests/reuseProgramStructure.ts b/tests/cases/unittests/reuseProgramStructure.ts index 4b85e2fa827..036a58e0c99 100644 --- a/tests/cases/unittests/reuseProgramStructure.ts +++ b/tests/cases/unittests/reuseProgramStructure.ts @@ -333,40 +333,40 @@ module ts { it("resolved type directives cache follows type directives", () => { let files = [ - { name: "a.ts", text: SourceText.New("/// ", "", "var x = $") }, - { name: "types/typedefs/index.d.ts", text: SourceText.New("", "", "declare var $: number") }, + { name: "/a.ts", text: SourceText.New("/// ", "", "var x = $") }, + { name: "/types/typedefs/index.d.ts", text: SourceText.New("", "", "declare var $: number") }, ]; - var options: CompilerOptions = { target }; + var options: CompilerOptions = { target, typesRoot: "/" }; - var program_1 = newProgram(files, ["a.ts"], options); - checkResolvedTypeDirectivesCache(program_1, "a.ts", { "typedefs": { resolvedFileName: "types/typedefs/index.d.ts", primary: true } }); - checkResolvedTypeDirectivesCache(program_1, "types/typedefs/index.d.ts", undefined); + var program_1 = newProgram(files, ["/a.ts"], options); + checkResolvedTypeDirectivesCache(program_1, "/a.ts", { "typedefs": { resolvedFileName: "/types/typedefs/index.d.ts", primary: true } }); + checkResolvedTypeDirectivesCache(program_1, "/types/typedefs/index.d.ts", undefined); - var program_2 = updateProgram(program_1, ["a.ts"], options, files => { + var program_2 = updateProgram(program_1, ["/a.ts"], options, files => { files[0].text = files[0].text.updateProgram("var x = 2"); }); assert.isTrue(program_1.structureIsReused); // content of resolution cache should not change - checkResolvedTypeDirectivesCache(program_1, "a.ts", { "typedefs": { resolvedFileName: "types/typedefs/index.d.ts", primary: true } }); - checkResolvedTypeDirectivesCache(program_1, "types/typedefs/index.d.ts", undefined); + checkResolvedTypeDirectivesCache(program_1, "/a.ts", { "typedefs": { resolvedFileName: "/types/typedefs/index.d.ts", primary: true } }); + checkResolvedTypeDirectivesCache(program_1, "/types/typedefs/index.d.ts", undefined); // type reference directives has changed - program is not reused - var program_3 = updateProgram(program_2, ["a.ts"], options, files => { + var program_3 = updateProgram(program_2, ["/a.ts"], options, files => { files[0].text = files[0].text.updateReferences(""); }); assert.isTrue(!program_2.structureIsReused); - checkResolvedTypeDirectivesCache(program_3, "a.ts", undefined); + checkResolvedTypeDirectivesCache(program_3, "/a.ts", undefined); - var program_4 = updateProgram(program_3, ["a.ts"], options, files => { + var program_4 = updateProgram(program_3, ["/a.ts"], options, files => { let newReferences = `/// /// `; files[0].text = files[0].text.updateReferences(newReferences); }); assert.isTrue(!program_3.structureIsReused); - checkResolvedTypeDirectivesCache(program_1, "a.ts", { "typedefs": { resolvedFileName: "types/typedefs/index.d.ts", primary: true } }); + checkResolvedTypeDirectivesCache(program_1, "/a.ts", { "typedefs": { resolvedFileName: "/types/typedefs/index.d.ts", primary: true } }); }); }) } \ No newline at end of file