Skip to content

Commit ef4fefc

Browse files
author
Andy
authored
Merge pull request #10340 from Microsoft/lower_case_types
Use lowercase names for type reference directives
2 parents 11c5c4e + 54735ed commit ef4fefc

File tree

6 files changed

+67
-3
lines changed

6 files changed

+67
-3
lines changed

src/compiler/program.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,15 +2010,16 @@ namespace ts {
20102010
}
20112011

20122012
function processTypeReferenceDirectives(file: SourceFile) {
2013-
const typeDirectives = map(file.typeReferenceDirectives, l => l.fileName);
2013+
const typeDirectives = map(file.typeReferenceDirectives, ref => ref.fileName.toLocaleLowerCase());
20142014
const resolutions = resolveTypeReferenceDirectiveNamesWorker(typeDirectives, file.fileName);
20152015

20162016
for (let i = 0; i < typeDirectives.length; i++) {
20172017
const ref = file.typeReferenceDirectives[i];
20182018
const resolvedTypeReferenceDirective = resolutions[i];
20192019
// store resolved type directive on the file
2020-
setResolvedTypeReferenceDirective(file, ref.fileName, resolvedTypeReferenceDirective);
2021-
processTypeReferenceDirective(ref.fileName, resolvedTypeReferenceDirective, file, ref.pos, ref.end);
2020+
const fileName = ref.fileName.toLocaleLowerCase();
2021+
setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective);
2022+
processTypeReferenceDirective(fileName, resolvedTypeReferenceDirective, file, ref.pos, ref.end);
20222023
}
20232024
}
20242025

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [tests/cases/conformance/typings/typingsLookup3.ts] ////
2+
3+
//// [index.d.ts]
4+
declare var $: { x: any };
5+
6+
//// [a.ts]
7+
/// <reference types="JqUeRy" />
8+
$.x;
9+
10+
11+
//// [a.js]
12+
/// <reference types="JqUeRy" />
13+
$.x;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== /a.ts ===
2+
/// <reference types="JqUeRy" />
3+
$.x;
4+
>$.x : Symbol(x, Decl(index.d.ts, 0, 16))
5+
>$ : Symbol($, Decl(index.d.ts, 0, 11))
6+
>x : Symbol(x, Decl(index.d.ts, 0, 16))
7+
8+
=== /node_modules/@types/jquery/index.d.ts ===
9+
declare var $: { x: any };
10+
>$ : Symbol($, Decl(index.d.ts, 0, 11))
11+
>x : Symbol(x, Decl(index.d.ts, 0, 16))
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
"======== Resolving type reference directive 'jquery', containing file '/a.ts', root directory '/node_modules/@types'. ========",
3+
"Resolving with primary search path '/node_modules/@types'",
4+
"File '/node_modules/@types/jquery/package.json' does not exist.",
5+
"File '/node_modules/@types/jquery/index.d.ts' exist - use it as a name resolution result.",
6+
"======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========",
7+
"======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
8+
"Resolving with primary search path '/node_modules/@types'",
9+
"File '/node_modules/@types/jquery/package.json' does not exist.",
10+
"File '/node_modules/@types/jquery/index.d.ts' exist - use it as a name resolution result.",
11+
"======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========"
12+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== /a.ts ===
2+
/// <reference types="JqUeRy" />
3+
$.x;
4+
>$.x : any
5+
>$ : { x: any; }
6+
>x : any
7+
8+
=== /node_modules/@types/jquery/index.d.ts ===
9+
declare var $: { x: any };
10+
>$ : { x: any; }
11+
>x : any
12+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @traceResolution: true
2+
// @noImplicitReferences: true
3+
// @currentDirectory: /
4+
// This tests that `types` references are automatically lowercased.
5+
6+
// @filename: /tsconfig.json
7+
{ "files": "a.ts" }
8+
9+
// @filename: /node_modules/@types/jquery/index.d.ts
10+
declare var $: { x: any };
11+
12+
// @filename: /a.ts
13+
/// <reference types="JqUeRy" />
14+
$.x;

0 commit comments

Comments
 (0)