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.
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.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/compiler/keepImportsInDts3.ts] ////
2+
3+
//// [test.ts]
4+
5+
export {};
6+
//// [main.ts]
7+
import "test"
8+
9+
//// [outputfile.js]
10+
define("test", ["require", "exports"], function (require, exports) {
11+
"use strict";
12+
});
13+
define("app/main", ["require", "exports", "test"], function (require, exports) {
14+
"use strict";
15+
});
16+
17+
18+
//// [outputfile.d.ts]
19+
declare module "test" {
20+
export { };
21+
}
22+
declare module "app/main" {
23+
import "test";
24+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== c:/test.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.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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/compiler/keepImportsInDts4.ts] ////
2+
3+
//// [test.ts]
4+
5+
export {};
6+
//// [main.ts]
7+
import "./folder/test"
8+
9+
//// [outputfile.js]
10+
define("folder/test", ["require", "exports"], function (require, exports) {
11+
"use strict";
12+
});
13+
define("main", ["require", "exports", "folder/test"], function (require, exports) {
14+
"use strict";
15+
});
16+
17+
18+
//// [outputfile.d.ts]
19+
declare module "folder/test" {
20+
export { };
21+
}
22+
declare module "main" {
23+
import "folder/test";
24+
}
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.
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.

tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,5 @@ declare module "./observable" {
7373
}
7474
export {};
7575
//// [main.d.ts]
76+
import "./map1";
77+
import "./map2";

tests/baselines/reference/moduleAugmentationDeclarationEmit1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ declare module "./observable" {
6666
}
6767
export {};
6868
//// [main.d.ts]
69+
import "./map";

tests/baselines/reference/moduleAugmentationDeclarationEmit2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ declare module "./observable" {
7171
}
7272
export {};
7373
//// [main.d.ts]
74+
import "./map";

tests/baselines/reference/moduleAugmentationExtendAmbientModule2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ declare module "observable" {
6363
export {};
6464
//// [main.d.ts]
6565
/// <reference path="observable.d.ts" />
66+
import "./map";

tests/baselines/reference/moduleAugmentationGlobal3.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ declare global {
5050
}
5151
export {};
5252
//// [f3.d.ts]
53+
import "./f2";

tests/baselines/reference/moduleAugmentationGlobal4.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ declare global {
4545
export { };
4646
export {};
4747
//// [f3.d.ts]
48+
import "./f1";
49+
import "./f2";

tests/baselines/reference/moduleAugmentationGlobal5.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ require("B");
3232
//// [f3.d.ts]
3333
/// <reference path="f1.d.ts" />
3434
/// <reference path="f2.d.ts" />
35+
import "A";
36+
import "B";

tests/baselines/reference/moduleAugmentationImportsAndExports1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,4 @@ declare module "./f1" {
6969
}
7070
}
7171
//// [f4.d.ts]
72+
import "./f3";

tests/baselines/reference/moduleAugmentationImportsAndExports2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ export declare class B {
7474
n: number;
7575
}
7676
//// [f4.d.ts]
77+
import "./f3";

tests/baselines/reference/moduleAugmentationImportsAndExports3.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ export declare class B {
7272
n: number;
7373
}
7474
//// [f4.d.ts]
75+
import "./f3";

tests/baselines/reference/moduleAugmentationImportsAndExports5.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ export declare class B {
7676
n: number;
7777
}
7878
//// [f4.d.ts]
79+
import "./f3";

tests/baselines/reference/moduleAugmentationImportsAndExports6.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,4 @@ declare module "./f1" {
9595
}
9696
}
9797
//// [f4.d.ts]
98+
import "./f3";

tests/baselines/reference/moduleAugmentationInAmbientModule5.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ var y = x.getA().x;
3333

3434
//// [f.d.ts]
3535
/// <reference path="array.d.ts" />
36+
import "array";

tests/baselines/reference/moduleAugmentationsBundledOutput1.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,6 @@ declare module "m4" {
139139
}
140140
}
141141
declare module "test" {
142+
import "m2";
143+
import "m4";
142144
}

tests/baselines/reference/moduleAugmentationsImports1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,5 @@ declare module "d" {
101101
}
102102
}
103103
declare module "main" {
104+
import "d";
104105
}

tests/baselines/reference/moduleAugmentationsImports2.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,6 @@ declare module "e" {
111111
}
112112
}
113113
declare module "main" {
114+
import "d";
115+
import "e";
114116
}

tests/baselines/reference/moduleAugmentationsImports3.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,6 @@ declare module "e" {
9898
}
9999
}
100100
declare module "main" {
101+
import "D";
102+
import "e";
101103
}

tests/baselines/reference/moduleAugmentationsImports4.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,6 @@ declare module "b" {
8787
}
8888
}
8989
declare module "main" {
90+
import "D";
91+
import "E";
9092
}

tests/baselines/reference/noErrorOnEmptyDts.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/baselines/reference/noErrorOnEmptyDts.symbols

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/baselines/reference/noErrorOnEmptyDts.types

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @module: amd
2+
// @declaration: true
3+
4+
// @filename: c:/test.d.ts
5+
export {};
6+
// @filename: c:/app/main.ts
7+
import "test"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @module: amd
2+
// @declaration: true
3+
4+
// @filename: folder/test.ts
5+
export {};
6+
// @filename: main.ts
7+
import "./folder/test"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @module: amd
2+
// @declaration: true
3+
// @out: outputfile.js
4+
5+
// @filename: c:/test.ts
6+
export {};
7+
// @filename: c:/app/main.ts
8+
import "test"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @module: amd
2+
// @declaration: true
3+
// @out: outputfile.js
4+
5+
// @filename: folder/test.ts
6+
export {};
7+
// @filename: main.ts
8+
import "./folder/test"

tests/cases/compiler/noErrorOnEmptyDts.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)