mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
remove compilationRoot parameter, use typesRoot/config file location as a root when computing primary locations
This commit is contained in:
@@ -321,6 +321,10 @@ namespace ts {
|
||||
isFilePath: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "typesRoot",
|
||||
type: "string"
|
||||
},
|
||||
{
|
||||
name: "traceResolution",
|
||||
type: "boolean",
|
||||
|
||||
@@ -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
|
||||
|
||||
+45
-35
@@ -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<boolean>(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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -247,12 +247,9 @@ namespace Harness.LanguageService {
|
||||
const scriptInfo = this.getScriptInfo(fileName);
|
||||
const preprocessInfo = ts.preProcessFile(scriptInfo.content, /*readImportFiles*/ false);
|
||||
const resolutions: ts.Map<ts.ResolvedTypeReferenceDirective> = {};
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,6 @@ namespace ts.server {
|
||||
compilationSettings: ts.CompilerOptions;
|
||||
filenameToScript: ts.FileMap<ScriptInfo>;
|
||||
roots: ScriptInfo[] = [];
|
||||
compilationRoot: string;
|
||||
|
||||
private resolvedModuleNames: ts.FileMap<Map<TimestampedResolvedModule>>;
|
||||
private resolvedTypeReferenceDirectives: ts.FileMap<Map<TimestampedResolvedTypeReferenceDirective>>;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-11
@@ -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 = <string[]>JSON.parse(filesJson);
|
||||
const compilerOptions = <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 = <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,
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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'.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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'.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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]
|
||||
/// <reference types="alpha" />
|
||||
var x: string = alpha.a;
|
||||
//// [consumer.ts]
|
||||
/// <reference types="jquery" />
|
||||
$.foo();
|
||||
|
||||
|
||||
//// [foo.js]
|
||||
/// <reference types="alpha" />
|
||||
var x = alpha.a;
|
||||
//// [consumer.js]
|
||||
/// <reference types="jquery" />
|
||||
$.foo();
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
=== /base/src/foo.ts ===
|
||||
/// <reference types="alpha" />
|
||||
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 ===
|
||||
/// <reference types="jquery" />
|
||||
$.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))
|
||||
|
||||
|
||||
@@ -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. ========"
|
||||
]
|
||||
@@ -1,16 +1,16 @@
|
||||
=== /base/src/foo.ts ===
|
||||
/// <reference types="alpha" />
|
||||
var x: string = alpha.a;
|
||||
>x : string
|
||||
>alpha.a : string
|
||||
>alpha : { a: string; }
|
||||
>a : string
|
||||
=== /src/consumer.ts ===
|
||||
/// <reference types="jquery" />
|
||||
$.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
|
||||
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// @typesRoot: /
|
||||
|
||||
// We can find typings in the ./types folder
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// @typesRoot: /
|
||||
|
||||
// package.json in a primary reference can refer to another file
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// @typesRoot: /
|
||||
|
||||
// package.json in a primary reference can refer to another file
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// @traceResolution: true
|
||||
// @typesRoot: /src
|
||||
|
||||
// Secondary references are possible
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// @typesRoot: /src
|
||||
|
||||
// Secondary references may be duplicated if they agree in content
|
||||
|
||||
|
||||
@@ -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
|
||||
/// <reference types="alpha" />
|
||||
var x: string = alpha.a;
|
||||
|
||||
// @filename: /tsconfig.json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"rootDir": "base"
|
||||
}
|
||||
}
|
||||
// @filename: /src/consumer.ts
|
||||
/// <reference types="jquery" />
|
||||
$.foo();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// @typesRoot: /
|
||||
|
||||
// Don't crash in circular library reference situations
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
// @typesRoot: src
|
||||
// @Filename: src/types/lib/index.d.ts
|
||||
/////*0*/declare let $: {x: number};
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
// @typesRoot: src
|
||||
// @Filename: src/types/lib/index.d.ts
|
||||
/////*0*/declare let $: {x: number};
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
// @typesRoot: src
|
||||
// @Filename: src/types/lib/index.d.ts
|
||||
/////*0*/declare let $: {x: number};
|
||||
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -333,40 +333,40 @@ module ts {
|
||||
|
||||
it("resolved type directives cache follows type directives", () => {
|
||||
let files = [
|
||||
{ name: "a.ts", text: SourceText.New("/// <reference types='typedefs'/>", "", "var x = $") },
|
||||
{ name: "types/typedefs/index.d.ts", text: SourceText.New("", "", "declare var $: number") },
|
||||
{ name: "/a.ts", text: SourceText.New("/// <reference types='typedefs'/>", "", "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 = `/// <reference types="typedefs"/>
|
||||
/// <reference types="typedefs2"/>
|
||||
`;
|
||||
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 } });
|
||||
});
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user