Skip to content

Commit f058117

Browse files
committed
Merge pull request #6858 from Microsoft/emitImportsInDts
emit import declarations without import clause in .d.ts files
2 parents 6f261f5 + 2c24f81 commit f058117

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+194
-41
lines changed

src/compiler/declarationEmitter.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,6 @@ namespace ts {
698698
}
699699

700700
function writeImportDeclaration(node: ImportDeclaration) {
701-
if (!node.importClause && !(node.flags & NodeFlags.Export)) {
702-
// do not write non-exported import declarations that don't have import clauses
703-
return;
704-
}
705701
emitJsDocComments(node);
706702
if (node.flags & NodeFlags.Export) {
707703
write("export ");

tests/baselines/reference/es6ImportWithoutFromClause.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ import "es6ImportWithoutFromClause_0";
1717
//// [es6ImportWithoutFromClause_0.d.ts]
1818
export declare var a: number;
1919
//// [es6ImportWithoutFromClause_1.d.ts]
20+
import "es6ImportWithoutFromClause_0";

tests/baselines/reference/es6ImportWithoutFromClauseAmd.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ export declare var a: number;
3636
//// [es6ImportWithoutFromClauseAmd_1.d.ts]
3737
export declare var b: number;
3838
//// [es6ImportWithoutFromClauseAmd_2.d.ts]
39+
import "es6ImportWithoutFromClauseAmd_0";
40+
import "es6ImportWithoutFromClauseAmd_2";

tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ require("es6ImportWithoutFromClauseInEs5_0");
1818
//// [es6ImportWithoutFromClauseInEs5_0.d.ts]
1919
export declare var a: number;
2020
//// [es6ImportWithoutFromClauseInEs5_1.d.ts]
21+
import "es6ImportWithoutFromClauseInEs5_0";

tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ import "es6ImportWithoutFromClauseNonInstantiatedModule_0";
1717
export interface i {
1818
}
1919
//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.d.ts]
20+
import "es6ImportWithoutFromClauseNonInstantiatedModule_0";
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [tests/cases/compiler/keepImportsInDts1.ts] ////
2+
3+
//// [test.d.ts]
4+
5+
export {};
6+
//// [main.ts]
7+
import "test"
8+
9+
//// [main.js]
10+
define(["require", "exports", "test"], function (require, exports) {
11+
"use strict";
12+
});
13+
14+
15+
//// [main.d.ts]
16+
import "test";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== c:/test.d.ts ===
2+
3+
No type information for this code.export {};
4+
No type information for this code.=== c:/app/main.ts ===
5+
import "test"
6+
No type information for this code.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== c:/test.d.ts ===
2+
3+
No type information for this code.export {};
4+
No type information for this code.=== c:/app/main.ts ===
5+
import "test"
6+
No type information for this code.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [tests/cases/compiler/keepImportsInDts2.ts] ////
2+
3+
//// [test.ts]
4+
5+
export {};
6+
//// [main.ts]
7+
import "./folder/test"
8+
9+
//// [test.js]
10+
define(["require", "exports"], function (require, exports) {
11+
"use strict";
12+
});
13+
//// [main.js]
14+
define(["require", "exports", "./folder/test"], function (require, exports) {
15+
"use strict";
16+
});
17+
18+
19+
//// [test.d.ts]
20+
export { };
21+
//// [main.d.ts]
22+
import "./folder/test";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/folder/test.ts ===
2+
3+
No type information for this code.export {};
4+
No type information for this code.=== tests/cases/compiler/main.ts ===
5+
import "./folder/test"
6+
No type information for this code.

0 commit comments

Comments
 (0)