Skip to content

Commit 6f4bd5f

Browse files
sidharthv96mprobst
authored andcommitted
fix(suggestion): Remove 80001 from cjs/cts files. (microsoft#46270)
* fix(suggestion): Remove 80001 from cjs/cts files. * tests: Cover more cases in a single file. * tests: Cover more cases in a single file.
1 parent ef78e59 commit 6f4bd5f

4 files changed

+92
-1
lines changed

src/services/suggestionDiagnostics.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ namespace ts {
66
program.getSemanticDiagnostics(sourceFile, cancellationToken);
77
const diags: DiagnosticWithLocation[] = [];
88
const checker = program.getTypeChecker();
9+
const isCommonJSFile = sourceFile.impliedNodeFormat === ModuleKind.CommonJS || fileExtensionIsOneOf(sourceFile.fileName, [Extension.Cts, Extension.Cjs]) ;
910

10-
if (sourceFile.commonJsModuleIndicator &&
11+
if (!isCommonJSFile &&
12+
sourceFile.commonJsModuleIndicator &&
1113
(programContainsEs6Modules(program) || compilerOptionsIndicateEs6Modules(program.getCompilerOptions())) &&
1214
containsTopLevelCommonjs(sourceFile)) {
1315
diags.push(createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module));
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @allowJs: true
4+
// @target: esnext
5+
6+
// @Filename: /a.cjs
7+
////module.exports = 0;
8+
9+
// @Filename: /b.cts
10+
////module.exports = 0;
11+
12+
// @Filename: /c.ts
13+
////module.exports = 0;
14+
15+
// @Filename: /d.js
16+
////module.exports = 0;
17+
18+
goTo.file("/a.cjs");
19+
verify.codeFixAvailable([]);
20+
21+
goTo.file("/b.cts");
22+
verify.codeFixAvailable([]);
23+
24+
goTo.file("/c.ts");
25+
verify.codeFixAvailable([]);
26+
27+
goTo.file("/d.js");
28+
verify.codeFix({
29+
description: "Convert to ES6 module",
30+
newFileContent: 'export default 0;',
31+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @allowJs: true
4+
// @target: esnext
5+
// @module: node12
6+
7+
// @Filename: /a.js
8+
////module.exports = 0;
9+
10+
// @Filename: /b.ts
11+
////module.exports = 0;
12+
13+
// @Filename: /c.cjs
14+
////module.exports = 0;
15+
16+
// @Filename: /d.cts
17+
////module.exports = 0;
18+
19+
goTo.file("/a.js");
20+
verify.codeFixAvailable([]);
21+
22+
goTo.file("/b.ts");
23+
verify.codeFixAvailable([]);
24+
25+
goTo.file("/c.cjs");
26+
verify.codeFixAvailable([]);
27+
28+
goTo.file("/d.cts");
29+
verify.codeFixAvailable([]);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @allowJs: true
4+
// @target: esnext
5+
// @module: nodenext
6+
7+
// @Filename: /a.js
8+
////module.exports = 0;
9+
10+
// @Filename: /b.ts
11+
////module.exports = 0;
12+
13+
// @Filename: /c.cjs
14+
////module.exports = 0;
15+
16+
// @Filename: /d.cts
17+
////module.exports = 0;
18+
19+
goTo.file("/a.js");
20+
verify.codeFixAvailable([]);
21+
22+
goTo.file("/b.ts");
23+
verify.codeFixAvailable([]);
24+
25+
goTo.file("/c.cjs");
26+
verify.codeFixAvailable([]);
27+
28+
goTo.file("/d.cts");
29+
verify.codeFixAvailable([]);

0 commit comments

Comments
 (0)