fix(suggestion): Remove 80001 from cjs/cts files. (#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.
This commit is contained in:
parent
3b086e1813
commit
5185ef55e3
|
@ -6,8 +6,10 @@ namespace ts {
|
|||
program.getSemanticDiagnostics(sourceFile, cancellationToken);
|
||||
const diags: DiagnosticWithLocation[] = [];
|
||||
const checker = program.getTypeChecker();
|
||||
const isCommonJSFile = sourceFile.impliedNodeFormat === ModuleKind.CommonJS || fileExtensionIsOneOf(sourceFile.fileName, [Extension.Cts, Extension.Cjs]) ;
|
||||
|
||||
if (sourceFile.commonJsModuleIndicator &&
|
||||
if (!isCommonJSFile &&
|
||||
sourceFile.commonJsModuleIndicator &&
|
||||
(programContainsEs6Modules(program) || compilerOptionsIndicateEs6Modules(program.getCompilerOptions())) &&
|
||||
containsTopLevelCommonjs(sourceFile)) {
|
||||
diags.push(createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module));
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
// @target: esnext
|
||||
|
||||
// @Filename: /a.cjs
|
||||
////module.exports = 0;
|
||||
|
||||
// @Filename: /b.cts
|
||||
////module.exports = 0;
|
||||
|
||||
// @Filename: /c.ts
|
||||
////module.exports = 0;
|
||||
|
||||
// @Filename: /d.js
|
||||
////module.exports = 0;
|
||||
|
||||
goTo.file("/a.cjs");
|
||||
verify.codeFixAvailable([]);
|
||||
|
||||
goTo.file("/b.cts");
|
||||
verify.codeFixAvailable([]);
|
||||
|
||||
goTo.file("/c.ts");
|
||||
verify.codeFixAvailable([]);
|
||||
|
||||
goTo.file("/d.js");
|
||||
verify.codeFix({
|
||||
description: "Convert to ES6 module",
|
||||
newFileContent: 'export default 0;',
|
||||
});
|
|
@ -0,0 +1,29 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
// @target: esnext
|
||||
// @module: node12
|
||||
|
||||
// @Filename: /a.js
|
||||
////module.exports = 0;
|
||||
|
||||
// @Filename: /b.ts
|
||||
////module.exports = 0;
|
||||
|
||||
// @Filename: /c.cjs
|
||||
////module.exports = 0;
|
||||
|
||||
// @Filename: /d.cts
|
||||
////module.exports = 0;
|
||||
|
||||
goTo.file("/a.js");
|
||||
verify.codeFixAvailable([]);
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.codeFixAvailable([]);
|
||||
|
||||
goTo.file("/c.cjs");
|
||||
verify.codeFixAvailable([]);
|
||||
|
||||
goTo.file("/d.cts");
|
||||
verify.codeFixAvailable([]);
|
|
@ -0,0 +1,29 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
// @target: esnext
|
||||
// @module: nodenext
|
||||
|
||||
// @Filename: /a.js
|
||||
////module.exports = 0;
|
||||
|
||||
// @Filename: /b.ts
|
||||
////module.exports = 0;
|
||||
|
||||
// @Filename: /c.cjs
|
||||
////module.exports = 0;
|
||||
|
||||
// @Filename: /d.cts
|
||||
////module.exports = 0;
|
||||
|
||||
goTo.file("/a.js");
|
||||
verify.codeFixAvailable([]);
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.codeFixAvailable([]);
|
||||
|
||||
goTo.file("/c.cjs");
|
||||
verify.codeFixAvailable([]);
|
||||
|
||||
goTo.file("/d.cts");
|
||||
verify.codeFixAvailable([]);
|
Loading…
Reference in a new issue