-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Filter out global keywords of UMD module export declarations in completion providing auto import suggestions #42141
Conversation
From reading the issue thread, this test incorrectly passes, right? As I understood it, you wanted to create a failing test to match your observations in the editor. Is that correct? |
What Oliver said is that it fails when it’s declared as a UMD module, which this isn’t. You’d need to add |
@aminpaks it sounds like you’re still working on this—do you want to convert the PR to a draft so it’s clear it’s not done? |
@andrewbranch Done. I'll look into that asap. |
@andrewbranch would you tell me what is the right test case for this issue? I can't seem to reproduce it. Update: Uh I think I understand why this test passes cos I removed the auto import suggestion from the test.
// @filename: /SomeReactComponent.tsx
//// import * as React from 'react';
////
//// const el1 = <div className={class/*1*/}>foo</div>;
goTo.marker("1");
verify.completions({
includes: [{
name: "classNames",
hasAction: true,
source: "/node_modules/@types/classnames/index",
sortText: completion.SortText.AutoImportSuggestions,
}],
preferences: {
includeCompletionsForModuleExports: true,
}
}); |
Figuring this out tends to be 90% of the work for these kinds of bugs 😄 |
I think I found the issue. When we add I just don't have enough insights to provide a fix in the right spot that said I think we could exclude it from the global or keywords if it already has an export, what do you think? |
I think for UMD exports, the global should be shadowed / filtered out if the file is already a module, unless |
Gotcha, so would you tell me if it's okay to remove the module from global symbols if it has exports? for (const file of host.getSourceFiles()) {
if (file.redirectInfo) {
continue;
}
if (!isExternalOrCommonJsModule(file)) {
// It is an error for a non-external-module (i.e. script) to declare its own `globalThis`.
// We can't use `builtinGlobals` for this due to synthetic expando-namespace generation in JS files.
const fileGlobalThisSymbol = file.locals!.get("globalThis" as __String);
if (fileGlobalThisSymbol) {
for (const declaration of fileGlobalThisSymbol.declarations) {
diagnostics.add(createDiagnosticForNode(declaration, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0, "globalThis"));
}
}
mergeSymbolTable(globals, file.locals!);
}
if (file.jsGlobalAugmentations) {
mergeSymbolTable(globals, file.jsGlobalAugmentations);
}
if (file.patternAmbientModules && file.patternAmbientModules.length) {
patternAmbientModules = concatenate(patternAmbientModules, file.patternAmbientModules);
}
if (file.moduleAugmentations.length) {
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
}
if (file.symbol && file.symbol.globalExports) {
// ^^ this line adds the module as part of global symbols
// adding !isExternalOrCommonJsModule(file) + the check for allowUmdGlobalAccess would fix it
// Merge in UMD exports with first-in-wins semantics (see #9771)
const source = file.symbol.globalExports;
source.forEach((sourceSymbol, id) => {
if (!globals.has(id)) {
globals.set(id, sourceSymbol);
}
});
}
} Update: We can't add the logic there in the checker. I didn't quite get where you meant to put the logic at first but now that I think about it we should alter the shadowing logic and make it work the way you describe it |
674a8e1
to
6ee5516
Compare
Yeah, I’m only talking about changes to completions.ts. |
16cd156
to
606910d
Compare
…of global keywords
How do you feel about this fix @andrewbranch? Added two test cases, one to assert auto suggestion for module exports and the other for global keywords. |
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.
Looks good after these small nits
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.
Thanks @aminpaks!
My pleasure @andrewbranch! |
Please verify that:
Backlog
milestone (required)master
branchgulp runtests
locallyFixes #41761