Do not lowercase typeReference directive name (#58525)

This commit is contained in:
Sheetal Nandi 2024-05-13 16:35:49 -07:00 committed by GitHub
parent 524456ff5a
commit e51cbc8764
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 188 additions and 13 deletions

View File

@ -1058,8 +1058,7 @@ export function createModuleResolutionLoader(
}
function getTypeReferenceResolutionName<T extends FileReference | string>(entry: T) {
// We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
return !isString(entry) ? toFileNameLowerCase(entry.fileName) : entry;
return !isString(entry) ? entry.fileName : entry;
}
const typeReferenceResolutionNameAndModeGetter: ResolutionNameAndModeGetter<FileReference | string, SourceFile | undefined> = {
@ -2088,7 +2087,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}
function getResolvedTypeReferenceDirectiveFromTypeReferenceDirective(typeRef: FileReference, sourceFile: SourceFile) {
return getResolvedTypeReferenceDirective(sourceFile, toFileNameLowerCase(typeRef.fileName), typeRef.resolutionMode || sourceFile.impliedNodeFormat);
return getResolvedTypeReferenceDirective(sourceFile, typeRef.fileName, typeRef.resolutionMode || sourceFile.impliedNodeFormat);
}
function forEachResolvedModule(
@ -3994,7 +3993,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
const ref = file.typeReferenceDirectives[index];
const resolvedTypeReferenceDirective = resolutions[index];
// store resolved type directive on the file
const fileName = toFileNameLowerCase(ref.fileName);
const fileName = ref.fileName;
resolutionsInFile.set(fileName, getModeForFileReference(ref, file.impliedNodeFormat), resolvedTypeReferenceDirective);
const mode = ref.resolutionMode || getDefaultResolutionModeForFile(file);
processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: FileIncludeKind.TypeReferenceDirective, file: file.path, index });

View File

@ -26,4 +26,19 @@ describe("unittests:: tsc:: forceConsistentCasingInFileNames::", () => {
commandLineArgs: ["-p", "/home/src/projects/project/tsconfig.json", "--explainFiles"],
fs: () => loadProjectFromFiles(getFsContentsForMultipleErrorsForceConsistentCasingInFileNames()),
});
verifyTsc({
scenario: "forceConsistentCasingInFileNames",
subScenario: "with type ref from file",
commandLineArgs: ["-p", "/src/project/src", "--explainFiles", "--traceResolution"],
fs: () =>
loadProjectFromFiles({
"/src/project/src/fileOne.d.ts": `declare class c { }`,
"/src/project/src/file2.d.ts": dedent`
/// <reference types="./fileOne.d.ts"/>
declare const y: c;
`,
"/src/project/src/tsconfig.json": "{ }",
}),
});
});

View File

@ -10,7 +10,7 @@ import {
libFile,
} from "../helpers/virtualFileSystemWithWatch.js";
describe("unittests:: tsserver:: typeReferenceDirectives", () => {
describe("unittests:: tsserver:: typeReferenceDirectives::", () => {
it("when typeReferenceDirective contains UpperCasePackage", () => {
const libProjectLocation = `/user/username/projects/myproject/lib`;
const typeLib: File = {
@ -52,6 +52,7 @@ declare class TestLib {
compilerOptions: {
module: "amd",
typeRoots: ["../lib/@types", "../lib/@app"],
traceResolution: true,
},
}),
};

View File

@ -0,0 +1,64 @@
currentDirectory:: / useCaseSensitiveFileNames: false
Input::
//// [/lib/lib.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
interface ReadonlyArray<T> {}
declare const console: { log(msg: any): void; };
//// [/src/project/src/file2.d.ts]
/// <reference types="./fileOne.d.ts"/>
declare const y: c;
//// [/src/project/src/fileOne.d.ts]
declare class c { }
//// [/src/project/src/tsconfig.json]
{ }
Output::
/lib/tsc -p /src/project/src --explainFiles --traceResolution
File '/src/project/src/package.json' does not exist.
File '/src/project/package.json' does not exist.
File '/src/package.json' does not exist.
File '/package.json' does not exist.
======== Resolving type reference directive './fileOne.d.ts', containing file '/src/project/src/file2.d.ts', root directory '/src/project/src/node_modules/@types,/src/project/node_modules/@types,/src/node_modules/@types,/node_modules/@types'. ========
Resolving with primary search path '/src/project/src/node_modules/@types, /src/project/node_modules/@types, /src/node_modules/@types, /node_modules/@types'.
Directory '/src/project/src/node_modules/@types' does not exist, skipping all lookups in it.
Directory '/src/project/node_modules/@types' does not exist, skipping all lookups in it.
Directory '/src/node_modules/@types' does not exist, skipping all lookups in it.
Directory '/node_modules/@types' does not exist, skipping all lookups in it.
Looking up in 'node_modules' folder, initial location '/src/project/src'.
Loading module as file / folder, candidate module location '/src/project/src/fileOne.d.ts', target file types: Declaration.
File name '/src/project/src/fileOne.d.ts' has a '.d.ts' extension - stripping it.
File '/src/project/src/fileOne.d.ts' exists - use it as a name resolution result.
Resolving real path for '/src/project/src/fileOne.d.ts', result '/src/project/src/fileOne.d.ts'.
======== Type reference directive './fileOne.d.ts' was successfully resolved to '/src/project/src/fileOne.d.ts', primary: false. ========
File '/src/project/src/package.json' does not exist according to earlier cached lookups.
File '/src/project/package.json' does not exist according to earlier cached lookups.
File '/src/package.json' does not exist according to earlier cached lookups.
File '/package.json' does not exist according to earlier cached lookups.
File '/lib/package.json' does not exist.
File '/package.json' does not exist according to earlier cached lookups.
lib/lib.d.ts
Default library for target 'es5'
src/project/src/fileOne.d.ts
Type library referenced via './fileOne.d.ts' from file 'src/project/src/file2.d.ts'
Matched by default include pattern '**/*'
src/project/src/file2.d.ts
Matched by default include pattern '**/*'
exitCode:: ExitStatus.Success

View File

@ -37,7 +37,8 @@ class TestClass1 {
"typeRoots": [
"../lib/@types",
"../lib/@app"
]
],
"traceResolution": true
}
}
@ -87,16 +88,64 @@ Info seq [hh:mm:ss:mss] Config: /user/username/projects/myproject/test/tsconfig
"/user/username/projects/myproject/lib/@types",
"/user/username/projects/myproject/lib/@app"
],
"traceResolution": true,
"configFilePath": "/user/username/projects/myproject/test/tsconfig.json"
}
}
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/test 1 undefined Config: /user/username/projects/myproject/test/tsconfig.json WatchType: Wild card directory
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/test 1 undefined Config: /user/username/projects/myproject/test/tsconfig.json WatchType: Wild card directory
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /user/username/projects/myproject/test/tsconfig.json
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/test/package.json' does not exist.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/package.json' does not exist.
Info seq [hh:mm:ss:mss] File '/user/username/projects/package.json' does not exist.
Info seq [hh:mm:ss:mss] File '/user/username/package.json' does not exist.
Info seq [hh:mm:ss:mss] File '/user/package.json' does not exist.
Info seq [hh:mm:ss:mss] File '/package.json' does not exist.
Info seq [hh:mm:ss:mss] ======== Resolving type reference directive 'UpperCasePackage', containing file '/user/username/projects/myproject/test/__inferred type names__.ts', root directory '/user/username/projects/myproject/lib/@types,/user/username/projects/myproject/lib/@app'. ========
Info seq [hh:mm:ss:mss] Resolving with primary search path '/user/username/projects/myproject/lib/@types, /user/username/projects/myproject/lib/@app'.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@types/UpperCasePackage.d.ts' does not exist.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@types/UpperCasePackage/package.json' does not exist.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@types/UpperCasePackage/index.d.ts' exists - use it as a name resolution result.
Info seq [hh:mm:ss:mss] Resolving real path for '/user/username/projects/myproject/lib/@types/UpperCasePackage/index.d.ts', result '/user/username/projects/myproject/lib/@types/UpperCasePackage/index.d.ts'.
Info seq [hh:mm:ss:mss] ======== Type reference directive 'UpperCasePackage' was successfully resolved to '/user/username/projects/myproject/lib/@types/UpperCasePackage/index.d.ts', primary: true. ========
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/lib 1 undefined Project: /user/username/projects/myproject/test/tsconfig.json WatchType: Failed Lookup Locations
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/lib 1 undefined Project: /user/username/projects/myproject/test/tsconfig.json WatchType: Failed Lookup Locations
Info seq [hh:mm:ss:mss] ======== Resolving type reference directive 'lib', containing file '/user/username/projects/myproject/test/__inferred type names__.ts', root directory '/user/username/projects/myproject/lib/@types,/user/username/projects/myproject/lib/@app'. ========
Info seq [hh:mm:ss:mss] Resolving with primary search path '/user/username/projects/myproject/lib/@types, /user/username/projects/myproject/lib/@app'.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@types/lib.d.ts' does not exist.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@app/lib.d.ts' does not exist.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@app/lib/package.json' does not exist.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@app/lib/index.d.ts' exists - use it as a name resolution result.
Info seq [hh:mm:ss:mss] Resolving real path for '/user/username/projects/myproject/lib/@app/lib/index.d.ts', result '/user/username/projects/myproject/lib/@app/lib/index.d.ts'.
Info seq [hh:mm:ss:mss] ======== Type reference directive 'lib' was successfully resolved to '/user/username/projects/myproject/lib/@app/lib/index.d.ts', primary: true. ========
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@types/UpperCasePackage/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@types/package.json' does not exist.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/package.json' does not exist.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/lib/@types/UpperCasePackage/index.d.ts 500 undefined WatchType: Closed Script info
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@app/lib/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@app/package.json' does not exist.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/lib/@app/lib/index.d.ts 500 undefined WatchType: Closed Script info
Info seq [hh:mm:ss:mss] ======== Resolving type reference directive 'UpperCasePackage', containing file '/user/username/projects/myproject/lib/@app/lib/index.d.ts', root directory '/user/username/projects/myproject/lib/@types,/user/username/projects/myproject/lib/@app'. ========
Info seq [hh:mm:ss:mss] Resolving with primary search path '/user/username/projects/myproject/lib/@types, /user/username/projects/myproject/lib/@app'.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@types/UpperCasePackage.d.ts' does not exist.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@types/UpperCasePackage/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@types/UpperCasePackage/index.d.ts' exists - use it as a name resolution result.
Info seq [hh:mm:ss:mss] Resolving real path for '/user/username/projects/myproject/lib/@types/UpperCasePackage/index.d.ts', result '/user/username/projects/myproject/lib/@types/UpperCasePackage/index.d.ts'.
Info seq [hh:mm:ss:mss] ======== Type reference directive 'UpperCasePackage' was successfully resolved to '/user/username/projects/myproject/lib/@types/UpperCasePackage/index.d.ts', primary: true. ========
Info seq [hh:mm:ss:mss] File '/a/lib/package.json' does not exist.
Info seq [hh:mm:ss:mss] File '/a/package.json' does not exist.
Info seq [hh:mm:ss:mss] File '/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 500 undefined WatchType: Closed Script info
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/lib/@types 1 undefined Project: /user/username/projects/myproject/test/tsconfig.json WatchType: Type roots
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/lib/@types 1 undefined Project: /user/username/projects/myproject/test/tsconfig.json WatchType: Type roots
@ -117,7 +166,6 @@ 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'
@ -159,7 +207,8 @@ Info seq [hh:mm:ss:mss] event:
"typeRoots": [
"",
""
]
],
"traceResolution": true
},
"typeAcquisition": {
"enable": false,
@ -292,6 +341,32 @@ ScriptInfos::
Info seq [hh:mm:ss:mss] Running: /user/username/projects/myproject/test/tsconfig.json
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /user/username/projects/myproject/test/tsconfig.json
Info seq [hh:mm:ss:mss] File '/a/lib/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/a/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/test/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@types/UpperCasePackage/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@types/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@app/lib/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/@app/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/lib/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/myproject/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/projects/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/username/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/user/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] File '/package.json' does not exist according to earlier cached lookups.
Info seq [hh:mm:ss:mss] Reusing resolution of type reference directive 'UpperCasePackage' from '/user/username/projects/myproject/lib/@app/lib/index.d.ts' of old program, it was successfully resolved to '/user/username/projects/myproject/lib/@types/UpperCasePackage/index.d.ts'.
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /user/username/projects/myproject/test/tsconfig.json projectStateVersion: 2 projectProgramVersion: 1 structureChanged: false structureIsReused:: Completely Elapsed:: *ms
Info seq [hh:mm:ss:mss] Project '/user/username/projects/myproject/test/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (4)

View File

@ -0,0 +1,15 @@
/a.ts(1,23): error TS2688: Cannot find type definition file for 'JqUeRy'.
==== /tsconfig.json (0 errors) ====
{ "files": "a.ts" }
==== /a.ts (1 errors) ====
/// <reference types="JqUeRy" />
~~~~~~
!!! error TS2688: Cannot find type definition file for 'JqUeRy'.
$.x;
==== /node_modules/@types/jquery/index.d.ts (0 errors) ====
declare var $: { x: any };

View File

@ -1,6 +1,13 @@
[
"File '/package.json' does not exist.",
"======== Resolving type reference directive 'jquery', containing file '/a.ts', root directory '/node_modules/@types'. ========",
"======== Resolving type reference directive 'JqUeRy', containing file '/a.ts', root directory '/node_modules/@types'. ========",
"Resolving with primary search path '/node_modules/@types'.",
"Looking up in 'node_modules' folder, initial location '/'.",
"Searching all ancestor node_modules directories for preferred extensions: Declaration.",
"File '/node_modules/JqUeRy.d.ts' does not exist.",
"File '/node_modules/@types/JqUeRy.d.ts' does not exist.",
"======== Type reference directive 'JqUeRy' was not resolved. ========",
"======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
"Resolving with primary search path '/node_modules/@types'.",
"File '/node_modules/@types/jquery/package.json' does not exist.",
"File '/node_modules/@types/jquery/index.d.ts' exists - use it as a name resolution result.",
@ -10,9 +17,6 @@
"File '/node_modules/@types/package.json' does not exist.",
"File '/node_modules/package.json' does not exist.",
"File '/package.json' does not exist according to earlier cached lookups.",
"======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts'. ========",
"Resolution for type reference directive 'jquery' was found in cache from location '/'.",
"======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========",
"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'. ========",

View File

@ -4,6 +4,7 @@
/// <reference types="JqUeRy" />
$.x;
>$.x : any
> : ^^^
>$ : { x: any; }
> : ^^^^^^^^^^^
>x : any
@ -14,4 +15,5 @@ declare var $: { x: any };
>$ : { x: any; }
> : ^^^^^ ^^^
>x : any
> : ^^^

View File

@ -1,7 +1,7 @@
// @traceResolution: true
// @noImplicitReferences: true
// @currentDirectory: /
// This tests that `types` references are automatically lowercased.
// This tests that `types` references are not lowercased.
// @filename: /tsconfig.json
{ "files": "a.ts" }