-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
There was a problem hiding this 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!
Got it, will update the method accordingly. |
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. |
Take a look at some fourslash completions tests like https://github.com/microsoft/TypeScript/blob/main/tests/cases/fourslash/javaScriptModules18.ts You can use |
I have added a scratch Unit Test , please check and suggest changes accordingly. @andrewbranch |
@microsoft-github-policy-service agree |
//// /**/ | ||
|
||
goTo.marker(""); | ||
verify.completions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verify.completions(); | |
verify.completions({ | |
excludes: ["f"], | |
preferences: { | |
includeCompletionsForModuleExports: true | |
} | |
}); |
module: "none"
src/services/utilities.ts
Outdated
// Prevent ES6 module indication for non-module files | ||
if(compilerOptions.module === ModuleKind.None){ | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- spacing
--module none
does not mean files are “non-modules.” It honestly doesn’t mean anything at all.
// Prevent ES6 module indication for non-module files | |
if(compilerOptions.module === ModuleKind.None){ | |
return false; | |
} | |
if (compilerOptions.module === ModuleKind.None) { | |
return false; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacing
--module none
does not mean files are “non-modules.” It honestly doesn’t mean anything at all.
On it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacing
--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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
Co-authored-by: Damien Engels <[email protected]>
…r module resolution and type reference directive (microsoft#55376)
src/services/utilities.ts
Outdated
@@ -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){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (compilerOptions.module === ModuleKind.None){ | |
if (compilerOptions.module === ModuleKind.None) { |
One missing space and then there are some merge conflicts that need resolving, but otherwise looks good! |
got it , on it now |
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. |
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. |
Fixes #55256