Skip to content

Commit

Permalink
Merge pull request #10340 from Microsoft/lower_case_types
Browse files Browse the repository at this point in the history
Use lowercase names for type reference directives
  • Loading branch information
Andy committed Aug 17, 2016
2 parents 11c5c4e + 54735ed commit ef4fefc
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2010,15 +2010,16 @@ namespace ts {
}

function processTypeReferenceDirectives(file: SourceFile) {
const typeDirectives = map(file.typeReferenceDirectives, l => l.fileName);
const typeDirectives = map(file.typeReferenceDirectives, ref => ref.fileName.toLocaleLowerCase());
const resolutions = resolveTypeReferenceDirectiveNamesWorker(typeDirectives, file.fileName);

for (let i = 0; i < typeDirectives.length; i++) {
const ref = file.typeReferenceDirectives[i];
const resolvedTypeReferenceDirective = resolutions[i];
// store resolved type directive on the file
setResolvedTypeReferenceDirective(file, ref.fileName, resolvedTypeReferenceDirective);
processTypeReferenceDirective(ref.fileName, resolvedTypeReferenceDirective, file, ref.pos, ref.end);
const fileName = ref.fileName.toLocaleLowerCase();
setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective);
processTypeReferenceDirective(fileName, resolvedTypeReferenceDirective, file, ref.pos, ref.end);
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/baselines/reference/typingsLookup3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [tests/cases/conformance/typings/typingsLookup3.ts] ////

//// [index.d.ts]
declare var $: { x: any };

//// [a.ts]
/// <reference types="JqUeRy" />
$.x;


//// [a.js]
/// <reference types="JqUeRy" />
$.x;
12 changes: 12 additions & 0 deletions tests/baselines/reference/typingsLookup3.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== /a.ts ===
/// <reference types="JqUeRy" />
$.x;
>$.x : Symbol(x, Decl(index.d.ts, 0, 16))
>$ : Symbol($, Decl(index.d.ts, 0, 11))
>x : Symbol(x, Decl(index.d.ts, 0, 16))

=== /node_modules/@types/jquery/index.d.ts ===
declare var $: { x: any };
>$ : Symbol($, Decl(index.d.ts, 0, 11))
>x : Symbol(x, Decl(index.d.ts, 0, 16))

12 changes: 12 additions & 0 deletions tests/baselines/reference/typingsLookup3.trace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
"======== Resolving type reference directive 'jquery', containing file '/a.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' exist - use it as a name resolution result.",
"======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========",
"======== 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' exist - use it as a name resolution result.",
"======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========"
]
12 changes: 12 additions & 0 deletions tests/baselines/reference/typingsLookup3.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== /a.ts ===
/// <reference types="JqUeRy" />
$.x;
>$.x : any
>$ : { x: any; }
>x : any

=== /node_modules/@types/jquery/index.d.ts ===
declare var $: { x: any };
>$ : { x: any; }
>x : any

14 changes: 14 additions & 0 deletions tests/cases/conformance/typings/typingsLookup3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @traceResolution: true
// @noImplicitReferences: true
// @currentDirectory: /
// This tests that `types` references are automatically lowercased.

// @filename: /tsconfig.json
{ "files": "a.ts" }

// @filename: /node_modules/@types/jquery/index.d.ts
declare var $: { x: any };

// @filename: /a.ts
/// <reference types="JqUeRy" />
$.x;

0 comments on commit ef4fefc

Please sign in to comment.