Skip to content

Commit c68ae3b

Browse files
author
Richard Lynch
committed
Add tests for fixImportNonExportedMember
Signed-off-by: Richard Lynch <[email protected]>
1 parent f3ec897 commit c68ae3b

7 files changed

+188
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference path='fourslash.ts' />
2+
// @Filename: /a.ts
3+
////declare function zoo(): any;
4+
////export { zoo };
5+
6+
// @Filename: /b.ts
7+
////declare function foo(): any;
8+
////function bar(): any;
9+
////export { foo };
10+
11+
// @Filename: /c.ts
12+
////import { zoo } from "./a";
13+
////import { bar } from "./b";
14+
15+
goTo.file("/c.ts");
16+
verify.codeFixAvailable([
17+
{ description: `Export 'bar' from module './b'` },
18+
{ description: `Remove import from './a'` },
19+
{ description: `Remove import from './b'` },
20+
]);
21+
verify.codeFix({
22+
index: 0,
23+
description: `Export 'bar' from module './b'`,
24+
newFileContent: {
25+
"/b.ts": `declare function foo(): any;
26+
export function bar(): any;
27+
export { foo };`,
28+
},
29+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /a.ts
4+
////let a = 1, b = 2, c = 3;
5+
////export function whatever() {
6+
////}
7+
8+
// @Filename: /b.ts
9+
////let d = 4;
10+
////export function whatever2() {
11+
////}
12+
13+
// @Filename: /c.ts
14+
////import { a } from "./a"
15+
////import { d } from "./b"
16+
17+
goTo.file("/c.ts");
18+
verify.codeFixAvailable([
19+
{ description: `Export 'a' from module './a'` },
20+
{ description: `Export 'd' from module './b'` },
21+
{ description: `Remove import from './a'` },
22+
{ description: `Remove import from './b'` },
23+
]);
24+
verify.codeFix({
25+
index: 0,
26+
description: `Export 'a' from module './a'`,
27+
newFileContent: {
28+
"/a.ts": `let a = 1, b = 2, c = 3;
29+
export function whatever() {
30+
}
31+
32+
export { a };
33+
`,
34+
},
35+
});
36+
37+
verify.codeFix({
38+
index: 1,
39+
description: `Export 'd' from module './b'`,
40+
newFileContent: {
41+
"/b.ts": `export let d = 4;
42+
export function whatever2() {
43+
}`,
44+
},
45+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path='fourslash.ts' />
2+
// @Filename: /a.ts
3+
////let a = 1, b = 2, c = 3;
4+
////let d = 4;
5+
////export function whatever() {
6+
////}
7+
////export { d }
8+
9+
// @Filename: /b.ts
10+
////import { a, d } from "./a"
11+
12+
goTo.file("/b.ts");
13+
verify.codeFixAvailable([
14+
{ description: `Export 'a' from module './a'` },
15+
{ description: `Remove import from './a'` },
16+
]);
17+
verify.codeFix({
18+
index: 0,
19+
description: `Export 'a' from module './a'`,
20+
newFileContent: {
21+
"/a.ts": `let a = 1, b = 2, c = 3;
22+
let d = 4;
23+
export function whatever() {
24+
}
25+
export { a, d };`,
26+
},
27+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path='fourslash.ts' />
2+
// @Filename: /node_modules/foo/index.d.ts
3+
////let a = 0
4+
////module.exports = 0;
5+
6+
// @Filename: /a.ts
7+
////import { a } from "foo";
8+
9+
verify.not.codeFixAvailable();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference path='fourslash.ts' />
2+
// @Filename: /a.ts
3+
/////**
4+
//// * hello
5+
//// */
6+
////function a() {
7+
////}
8+
////export { d }
9+
10+
// @Filename: /b.ts
11+
////import { a, d } from "./a"
12+
13+
goTo.file("/b.ts");
14+
verify.codeFixAvailable([
15+
{ description: `Export 'a' from module './a'` },
16+
{ description: `Remove import from './a'` },
17+
]);
18+
verify.codeFix({
19+
index: 0,
20+
description: `Export 'a' from module './a'`,
21+
newFileContent: {
22+
"/a.ts": `/**
23+
* hello
24+
*/
25+
export function a() {
26+
}
27+
export { d }`,
28+
},
29+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path='fourslash.ts' />
2+
// @Filename: /a.ts
3+
////let a = 1, b = 2, c = 3;
4+
////let d = 4;
5+
////export function whatever() {
6+
////}
7+
////export { a }
8+
9+
// @Filename: /b.ts
10+
////import { a, b } from "./a"
11+
12+
goTo.file("/b.ts");
13+
verify.codeFixAvailable([
14+
{ description: `Export 'b' from module './a'` },
15+
{ description: `Remove import from './a'` },
16+
]);
17+
verify.codeFix({
18+
index: 0,
19+
description: `Export 'b' from module './a'`,
20+
newFileContent: {
21+
"/a.ts": `let a = 1, b = 2, c = 3;
22+
let d = 4;
23+
export function whatever() {
24+
}
25+
export { a, b };`,
26+
},
27+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /a.ts
4+
////declare function foo(): any;
5+
////declare function bar(): any;
6+
////declare function zoo(): any;
7+
////export { zoo }
8+
9+
// @Filename: /b.ts
10+
////import { foo, bar } from "./a";
11+
12+
goTo.file("/b.ts");
13+
verify.codeFixAll({
14+
fixId: "importNonExportedMember",
15+
fixAllDescription: ts.Diagnostics.Add_all_missing_exports.message,
16+
newFileContent: {
17+
"/a.ts": `export declare function foo(): any;
18+
export declare function bar(): any;
19+
declare function zoo(): any;
20+
export { zoo }`,
21+
},
22+
});

0 commit comments

Comments
 (0)