diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 1db3b8c70bc30..725a6b73aa450 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4200,10 +4200,6 @@ "category": "Error", "code": 4085 }, - "Conflicting definitions for '{0}' found at '{1}' and '{2}'. Consider installing a specific version of this library to resolve the conflict.": { - "category": "Error", - "code": 4090 - }, "Parameter '{0}' of index signature from exported interface has or is using name '{1}' from private module '{2}'.": { "category": "Error", "code": 4091 diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 1b50231bb61fe..51a5a2e727502 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1589,7 +1589,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg const cachedBindAndCheckDiagnosticsForFile: DiagnosticCache = {}; const cachedDeclarationDiagnosticsForFile: DiagnosticCache = {}; - let resolvedTypeReferenceDirectives = createModeAwareCache(); let fileProcessingDiagnostics: FilePreprocessingDiagnostics[] | undefined; let automaticTypeDirectiveNames: string[] | undefined; let automaticTypeDirectiveResolutions: ModeAwareCache; @@ -1929,7 +1928,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg resolvedLibProcessing = undefined; resolvedModulesProcessing = undefined; resolvedTypeReferenceDirectiveNamesProcessing = undefined; - resolvedTypeReferenceDirectives = undefined!; const program: Program = { getRootFileNames: () => rootNames, @@ -4022,55 +4020,18 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg reason: FileIncludeReason, ): void { addResolutionDiagnostics(resolution); - // If we already found this library as a primary reference - nothing to do - const previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective, mode)?.resolvedTypeReferenceDirective; - if (previousResolution && previousResolution.primary) { - return; - } - let saveResolution = true; const { resolvedTypeReferenceDirective } = resolution; if (resolvedTypeReferenceDirective) { if (resolvedTypeReferenceDirective.isExternalLibraryImport) currentNodeModulesDepth++; - if (resolvedTypeReferenceDirective.primary) { - // resolved from the primary path - processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, reason); // TODO: GH#18217 - } - else { - // If we already resolved to this file, it must have been a secondary reference. Check file contents - // for sameness and possibly issue an error - if (previousResolution) { - // Don't bother reading the file again if it's the same file. - if (resolvedTypeReferenceDirective.resolvedFileName !== previousResolution.resolvedFileName) { - const otherFileText = host.readFile(resolvedTypeReferenceDirective.resolvedFileName!); - const existingFile = getSourceFile(previousResolution.resolvedFileName!)!; - if (otherFileText !== existingFile.text) { - addFilePreprocessingFileExplainingDiagnostic( - existingFile, - reason, - Diagnostics.Conflicting_definitions_for_0_found_at_1_and_2_Consider_installing_a_specific_version_of_this_library_to_resolve_the_conflict, - [typeReferenceDirective, resolvedTypeReferenceDirective.resolvedFileName!, previousResolution.resolvedFileName!], - ); - } - } - // don't overwrite previous resolution result - saveResolution = false; - } - else { - // First resolution of this library - processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, reason); - } - } + // resolved from the primary path + processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, reason); // TODO: GH#18217 if (resolvedTypeReferenceDirective.isExternalLibraryImport) currentNodeModulesDepth--; } else { addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, Diagnostics.Cannot_find_type_definition_file_for_0, [typeReferenceDirective]); } - - if (saveResolution) { - resolvedTypeReferenceDirectives.set(typeReferenceDirective, mode, resolution); - } } function pathForLibFile(libFileName: string): string { diff --git a/tests/baselines/reference/library-reference-4.symbols b/tests/baselines/reference/library-reference-4.symbols index e89538c7fefed..d01989e6da117 100644 --- a/tests/baselines/reference/library-reference-4.symbols +++ b/tests/baselines/reference/library-reference-4.symbols @@ -12,10 +12,14 @@ declare var foo: any; === /node_modules/foo/node_modules/alpha/index.d.ts === declare var alpha: any; ->alpha : Symbol(alpha, Decl(index.d.ts, 0, 11)) +>alpha : Symbol(alpha, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 11)) === /node_modules/bar/index.d.ts === /// declare var bar: any; >bar : Symbol(bar, Decl(index.d.ts, 1, 11)) +=== /node_modules/bar/node_modules/alpha/index.d.ts === +declare var alpha: any; +>alpha : Symbol(alpha, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 11)) + diff --git a/tests/baselines/reference/library-reference-4.trace.json b/tests/baselines/reference/library-reference-4.trace.json index 9e5a5c07bdb1b..41861ad55ed95 100644 --- a/tests/baselines/reference/library-reference-4.trace.json +++ b/tests/baselines/reference/library-reference-4.trace.json @@ -54,6 +54,11 @@ "File '/node_modules/bar/node_modules/alpha/index.d.ts' exists - use it as a name resolution result.", "Resolving real path for '/node_modules/bar/node_modules/alpha/index.d.ts', result '/node_modules/bar/node_modules/alpha/index.d.ts'.", "======== Type reference directive 'alpha' was successfully resolved to '/node_modules/bar/node_modules/alpha/index.d.ts', primary: false. ========", + "File '/node_modules/bar/node_modules/alpha/package.json' does not exist according to earlier cached lookups.", + "File '/node_modules/bar/node_modules/package.json' does not exist.", + "File '/node_modules/bar/package.json' does not exist according to earlier cached lookups.", + "File '/node_modules/package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", "File '/.ts/package.json' does not exist.", "File '/package.json' does not exist according to earlier cached lookups.", "======== Resolving module '@typescript/lib-es5' from '/.src/test/__lib_node_modules_lookup_lib.es5.d.ts__.ts'. ========", diff --git a/tests/baselines/reference/library-reference-4.types b/tests/baselines/reference/library-reference-4.types index 464d152abd842..c60c0d6ef8e10 100644 --- a/tests/baselines/reference/library-reference-4.types +++ b/tests/baselines/reference/library-reference-4.types @@ -19,3 +19,7 @@ declare var alpha: any; declare var bar: any; >bar : any +=== /node_modules/bar/node_modules/alpha/index.d.ts === +declare var alpha: any; +>alpha : any + diff --git a/tests/baselines/reference/library-reference-5.errors.txt b/tests/baselines/reference/library-reference-5.errors.txt index b6f9feb10820e..45b62653faf4b 100644 --- a/tests/baselines/reference/library-reference-5.errors.txt +++ b/tests/baselines/reference/library-reference-5.errors.txt @@ -1,7 +1,4 @@ -/node_modules/bar/index.d.ts(1,23): error TS4090: Conflicting definitions for 'alpha' found at '/node_modules/bar/node_modules/alpha/index.d.ts' and '/node_modules/foo/node_modules/alpha/index.d.ts'. Consider installing a specific version of this library to resolve the conflict. - The file is in the program because: - Type library referenced via 'alpha' from file '/node_modules/foo/index.d.ts' - Type library referenced via 'alpha' from file '/node_modules/bar/index.d.ts' +/node_modules/bar/node_modules/alpha/index.d.ts(1,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'alpha' must be of type 'any', but here has type '{}'. ==== /src/root.ts (0 errors) ==== @@ -15,16 +12,13 @@ ==== /node_modules/foo/node_modules/alpha/index.d.ts (0 errors) ==== declare var alpha: any; -==== /node_modules/bar/index.d.ts (1 errors) ==== +==== /node_modules/bar/index.d.ts (0 errors) ==== /// - ~~~~~ -!!! error TS4090: Conflicting definitions for 'alpha' found at '/node_modules/bar/node_modules/alpha/index.d.ts' and '/node_modules/foo/node_modules/alpha/index.d.ts'. Consider installing a specific version of this library to resolve the conflict. -!!! error TS4090: The file is in the program because: -!!! error TS4090: Type library referenced via 'alpha' from file '/node_modules/foo/index.d.ts' -!!! error TS4090: Type library referenced via 'alpha' from file '/node_modules/bar/index.d.ts' -!!! related TS1404 /node_modules/foo/index.d.ts:1:23: File is included via type library reference here. declare var bar: any; -==== /node_modules/bar/node_modules/alpha/index.d.ts (0 errors) ==== +==== /node_modules/bar/node_modules/alpha/index.d.ts (1 errors) ==== declare var alpha: {}; + ~~~~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'alpha' must be of type 'any', but here has type '{}'. +!!! related TS6203 /node_modules/foo/node_modules/alpha/index.d.ts:1:13: 'alpha' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-5.symbols b/tests/baselines/reference/library-reference-5.symbols index 0ff754a955b27..1745362514476 100644 --- a/tests/baselines/reference/library-reference-5.symbols +++ b/tests/baselines/reference/library-reference-5.symbols @@ -12,10 +12,14 @@ declare var foo: any; === /node_modules/foo/node_modules/alpha/index.d.ts === declare var alpha: any; ->alpha : Symbol(alpha, Decl(index.d.ts, 0, 11)) +>alpha : Symbol(alpha, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 11)) === /node_modules/bar/index.d.ts === /// declare var bar: any; >bar : Symbol(bar, Decl(index.d.ts, 1, 11)) +=== /node_modules/bar/node_modules/alpha/index.d.ts === +declare var alpha: {}; +>alpha : Symbol(alpha, Decl(index.d.ts, 0, 11), Decl(index.d.ts, 0, 11)) + diff --git a/tests/baselines/reference/library-reference-5.trace.json b/tests/baselines/reference/library-reference-5.trace.json index 47d50c37a28ee..ce76eb7f46a7b 100644 --- a/tests/baselines/reference/library-reference-5.trace.json +++ b/tests/baselines/reference/library-reference-5.trace.json @@ -54,6 +54,11 @@ "File '/node_modules/bar/node_modules/alpha/index.d.ts' exists - use it as a name resolution result.", "Resolving real path for '/node_modules/bar/node_modules/alpha/index.d.ts', result '/node_modules/bar/node_modules/alpha/index.d.ts'.", "======== Type reference directive 'alpha' was successfully resolved to '/node_modules/bar/node_modules/alpha/index.d.ts', primary: false. ========", + "File '/node_modules/bar/node_modules/alpha/package.json' does not exist according to earlier cached lookups.", + "File '/node_modules/bar/node_modules/package.json' does not exist.", + "File '/node_modules/bar/package.json' does not exist according to earlier cached lookups.", + "File '/node_modules/package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", "File '/.ts/package.json' does not exist.", "File '/package.json' does not exist according to earlier cached lookups.", "======== Resolving module '@typescript/lib-es5' from '/__lib_node_modules_lookup_lib.es5.d.ts__.ts'. ========", diff --git a/tests/baselines/reference/library-reference-5.types b/tests/baselines/reference/library-reference-5.types index 99a40a79af27c..9648de7c0611b 100644 --- a/tests/baselines/reference/library-reference-5.types +++ b/tests/baselines/reference/library-reference-5.types @@ -22,3 +22,8 @@ declare var bar: any; >bar : any > : ^^^ +=== /node_modules/bar/node_modules/alpha/index.d.ts === +declare var alpha: {}; +>alpha : any +> : ^^^ + diff --git a/tests/baselines/reference/tsserver/typeReferenceDirectives/when-typeReferenceDirective-contains-UpperCasePackage.js b/tests/baselines/reference/tsserver/typeReferenceDirectives/when-typeReferenceDirective-contains-UpperCasePackage.js index b6cde6e156809..c2873a5e4b24c 100644 --- a/tests/baselines/reference/tsserver/typeReferenceDirectives/when-typeReferenceDirective-contains-UpperCasePackage.js +++ b/tests/baselines/reference/tsserver/typeReferenceDirectives/when-typeReferenceDirective-contains-UpperCasePackage.js @@ -166,6 +166,7 @@ Info seq [hh:mm:ss:mss] Files (4) Matched by default include pattern '**/*' ../lib/@types/UpperCasePackage/index.d.ts Entry point for implicit type library 'UpperCasePackage' + Type library referenced via 'UpperCasePackage' from file '../lib/@app/lib/index.d.ts' ../lib/@app/lib/index.d.ts Entry point for implicit type library 'lib'