Skip to content

Prevents auto-import in module: "none" #55328

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

Closed
wants to merge 82 commits into from

Conversation

hardikkoul
Copy link
Contributor

Fixes #55256

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Aug 10, 2023
Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

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

I looked a little closer, and I think updating compilerOptionsIndicateEs6Modules would be better. This also needs an accompanying test. Thanks!

@hardikkoul
Copy link
Contributor Author

I looked a little closer, and I think updating compilerOptionsIndicateEs6Modules would be better. This also needs an accompanying test. Thanks!

Got it, will update the method accordingly.

@hardikkoul
Copy link
Contributor Author

Hey @andrewbranch . I've removed the check and applied changes to the method. I'm not so familiar with the Unit Test scenarios , can you guide me a bit there and i will complete that part as well. Also let me know if the changes are not as per your satisfaction.

@andrewbranch
Copy link
Member

Take a look at some fourslash completions tests like https://github.com/microsoft/TypeScript/blob/main/tests/cases/fourslash/javaScriptModules18.ts

You can use // @Filename to set up two files, one with an export, one with a marker, and // @module: none.

@hardikkoul
Copy link
Contributor Author

Take a look at some fourslash completions tests like https://github.com/microsoft/TypeScript/blob/main/tests/cases/fourslash/javaScriptModules18.ts

You can use // @Filename to set up two files, one with an export, one with a marker, and // @module: none.

I have added a scratch Unit Test , please check and suggest changes accordingly. @andrewbranch

@hardikkoul
Copy link
Contributor Author

@hardikkoul please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

//// /**/

goTo.marker("");
verify.completions();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
verify.completions();
verify.completions({
excludes: ["f"],
preferences: {
includeCompletionsForModuleExports: true
}
});

@andrewbranch andrewbranch changed the title Prevents auto-import in non-module files Prevents auto-import in module: "none" Aug 14, 2023
Comment on lines 1843 to 1846
// Prevent ES6 module indication for non-module files
if(compilerOptions.module === ModuleKind.None){
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

  1. spacing
  2. --module none does not mean files are “non-modules.” It honestly doesn’t mean anything at all.
Suggested change
// Prevent ES6 module indication for non-module files
if(compilerOptions.module === ModuleKind.None){
return false;
}
if (compilerOptions.module === ModuleKind.None) {
return false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. spacing

    1. --module none does not mean files are “non-modules.” It honestly doesn’t mean anything at all.

On it

Copy link
Contributor Author

@hardikkoul hardikkoul Aug 27, 2023

Choose a reason for hiding this comment

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

  1. spacing

    1. --module none does not mean files are “non-modules.” It honestly doesn’t mean anything at all.

Do you have any suggestions or heads up of where i can get the file module configurations from instead of compilerOptions?

Copy link
Member

Choose a reason for hiding this comment

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

I’m only objecting to the comment, not the implementation. A file is considered a module if it has sourceFile.externalModuleIndicator set. But we don’t actually want to prevent auto-imports into non-module files because you might have a file that’s not yet a module but you intend to make it a module. --module none I guess makes it an error to have a module, but the option is implemented inconsistently, and we’ve thought at times about changing what it means, and I was a little surprised to hear about anyone using it at all. Auto-imports generally tries to avoid creating errors, so I’m fine with this feature, but I don’t like the comment because it seems to imply some level of coherence and intentionality behind --module none, and I’m not convinced there is any.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’m only objecting to the comment, not the implementation. A file is considered a module if it has sourceFile.externalModuleIndicator set. But we don’t actually want to prevent auto-imports into non-module files because you might have a file that’s not yet a module but you intend to make it a module. --module none I guess makes it an error to have a module, but the option is implemented inconsistently, and we’ve thought at times about changing what it means, and I was a little surprised to hear about anyone using it at all. Auto-imports generally tries to avoid creating errors, so I’m fine with this feature, but I don’t like the comment because it seems to imply some level of coherence and intentionality behind --module none, and I’m not convinced there is any.

ohh, my bad , i thought you were talking about the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the comment , you can check now @andrewbranch :)

@@ -1840,6 +1840,9 @@ namespace ts {
return program.getSourceFiles().some(s => !s.isDeclarationFile && !program.isSourceFileFromExternalLibrary(s) && !!s.externalModuleIndicator);
}
export function compilerOptionsIndicateEs6Modules(compilerOptions: CompilerOptions): boolean {
if (compilerOptions.module === ModuleKind.None){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (compilerOptions.module === ModuleKind.None){
if (compilerOptions.module === ModuleKind.None) {

@andrewbranch
Copy link
Member

One missing space and then there are some merge conflicts that need resolving, but otherwise looks good!

@hardikkoul
Copy link
Contributor Author

One missing space and then there are some merge conflicts that need resolving, but otherwise looks good!

got it , on it now

@typescript-bot
Copy link
Collaborator

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @mjbvz, @zkat, and @joj for you. Feel free to loop in other consumers/maintainers if necessary.

@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

@hardikkoul hardikkoul closed this Aug 29, 2023
hardikkoul added a commit to hardikkoul/TypeScript that referenced this pull request Aug 29, 2023
@hardikkoul hardikkoul deleted the bug55256-Hardik branch August 29, 2023 05:33
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
Archived in project
Development

Successfully merging this pull request may close these issues.

Unwanted auto-imports in script files