Skip to content

fix(suggestion): Remove 80001 from cjs/cts files. #46270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 14, 2021

Conversation

sidharthv96
Copy link
Contributor

Removes the "File is a CommonJS module; it may be converted to an ES6 module. ts(80001)" hint in CommonJS Modules, cjs, cts Files.

Fixes #46240

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Oct 8, 2021
Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; I might try consolidating these all into a single test file though.

@sidharthv96
Copy link
Contributor Author

@DanielRosenwasser I did try to consolidate the tests before raising the PR.
When I added some tests with multiple files inside them, they weren't working as I expected.

Without the changes is suggestionDiagnostics.ts,

Passes (unexpected)

/// <reference path='fourslash.ts' />

// @allowJs: true
// @target: esnext

// @Filename: /a.ts
////const a = 0;

// @Filename: /b.js
////module.exports = 0;

verify.codeFixAvailable([]);

Fails (as Expected)

/// <reference path='fourslash.ts' />

// @allowJs: true
// @target: esnext

// @Filename: /b.js
////module.exports = 0;

verify.codeFixAvailable([]);

That is why I wrote 4 separate test files, If someone familiar with the system can point to how I should include tests in a single file, I'll gladly make the changes.

@andrewbranch
Copy link
Member

I think you would need to go to each file with goTo.file or similar and call verify.codeFixAvailable for each.

@sidharthv96
Copy link
Contributor Author

Thanks @andrewbranch !
I've modified the tests.
The tests with different @module: still had to be separate files as that's a global option.


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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aside: Some time we should change errors to use the term "ES module" not "ES6 module".

@sandersn sandersn merged commit 5185ef5 into microsoft:main Oct 14, 2021
mprobst pushed a commit to mprobst/TypeScript that referenced this pull request Jan 10, 2022
* fix(suggestion): Remove 80001 from cjs/cts files.

* tests: Cover more cases in a single file.

* tests: Cover more cases in a single file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"may be converted to an ES6 module" is a lie
5 participants