Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8dc9b76

Browse filesBrowse files
committed
Add undefined guard
1 parent 6af5d8b commit 8dc9b76
Copy full SHA for 8dc9b76

5 files changed

+99-8Lines changed: 99 additions & 8 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/transformers/declarations.ts‎

Copy file name to clipboardExpand all lines: src/compiler/transformers/declarations.ts
+10-8Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,18 @@ namespace ts {
217217

218218
function getFileReferenceForTypeName(typeName: string): FileReference | undefined {
219219
// Elide type references for which we have imports
220-
for (const importStatement of emittedImports) {
221-
if (isImportEqualsDeclaration(importStatement) && isExternalModuleReference(importStatement.moduleReference)) {
222-
const expr = importStatement.moduleReference.expression;
223-
if (isStringLiteralLike(expr) && expr.text === typeName) {
220+
if (emittedImports) {
221+
for (const importStatement of emittedImports) {
222+
if (isImportEqualsDeclaration(importStatement) && isExternalModuleReference(importStatement.moduleReference)) {
223+
const expr = importStatement.moduleReference.expression;
224+
if (isStringLiteralLike(expr) && expr.text === typeName) {
225+
return undefined;
226+
}
227+
}
228+
else if (isImportDeclaration(importStatement) && isStringLiteral(importStatement.moduleSpecifier) && importStatement.moduleSpecifier.text === typeName) {
224229
return undefined;
225230
}
226231
}
227-
else if (isImportDeclaration(importStatement) && isStringLiteral(importStatement.moduleSpecifier) && importStatement.moduleSpecifier.text === typeName) {
228-
return undefined;
229-
}
230232
}
231233
return { fileName: typeName, pos: -1, end: -1 };
232234
}
@@ -1325,4 +1327,4 @@ namespace ts {
13251327
}
13261328
return false;
13271329
}
1328-
}
1330+
}
Collapse file
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//// [tests/cases/compiler/declarationFilesGeneratingTypeReferences.ts] ////
2+
3+
//// [index.d.ts]
4+
interface JQuery {
5+
6+
}
7+
8+
//// [app.ts]
9+
/// <reference types="jquery"/>
10+
namespace Test {
11+
export var x: JQuery;
12+
}
13+
14+
//// [out.js]
15+
/// <reference types="jquery"/>
16+
var Test;
17+
(function (Test) {
18+
})(Test || (Test = {}));
19+
20+
21+
//// [out.d.ts]
22+
/// <reference types="jquery" />
23+
declare namespace Test {
24+
var x: JQuery;
25+
}
26+
27+
28+
//// [DtsFileErrors]
29+
30+
31+
out.d.ts(1,23): error TS2688: Cannot find type definition file for 'jquery'.
32+
33+
34+
==== /a/node_modules/@types/jquery/index.d.ts (0 errors) ====
35+
interface JQuery {
36+
37+
}
38+
39+
==== out.d.ts (1 errors) ====
40+
/// <reference types="jquery" />
41+
~~~~~~
42+
!!! error TS2688: Cannot find type definition file for 'jquery'.
43+
declare namespace Test {
44+
var x: JQuery;
45+
}
46+
Collapse file
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== /a/node_modules/@types/jquery/index.d.ts ===
2+
interface JQuery {
3+
>JQuery : Symbol(JQuery, Decl(index.d.ts, 0, 0))
4+
5+
}
6+
7+
=== /a/app.ts ===
8+
/// <reference types="jquery"/>
9+
namespace Test {
10+
>Test : Symbol(Test, Decl(app.ts, 0, 0))
11+
12+
export var x: JQuery;
13+
>x : Symbol(x, Decl(app.ts, 2, 14))
14+
>JQuery : Symbol(JQuery, Decl(index.d.ts, 0, 0))
15+
}
Collapse file
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== /a/node_modules/@types/jquery/index.d.ts ===
2+
interface JQuery {
3+
>JQuery : JQuery
4+
5+
}
6+
7+
=== /a/app.ts ===
8+
/// <reference types="jquery"/>
9+
namespace Test {
10+
>Test : typeof Test
11+
12+
export var x: JQuery;
13+
>x : JQuery
14+
>JQuery : JQuery
15+
}
Collapse file
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @declaration: true
2+
// @outFile: out.js
3+
4+
// @filename: /a/node_modules/@types/jquery/index.d.ts
5+
interface JQuery {
6+
7+
}
8+
9+
// @filename: /a/app.ts
10+
/// <reference types="jquery"/>
11+
namespace Test {
12+
export var x: JQuery;
13+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.