Skip to content
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

fix55816: exclude files with re-exports if excluded by preferences.autoImportFileExcludePatterns #58537

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

iisaduan
Copy link
Member

Fixes #55816

This failure happened when a file foo.ts that re-exports some variable T is ignored by "typescript.preferences.autoImportFileExcludePatterns". foo.ts was properly ignored by exportMap, but the autoImports still attempted to generate the import with foo.ts instead of the file that originally exported T, which lead to a failure.

This PR allows the moduleSymbol found by autoImports to not match the moduleSymbol found by exportInfoMap if the moduleSymbol found by autoimports is excluded.

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label May 14, 2024
@iisaduan iisaduan requested a review from navya9singh May 14, 2024 19:11
@fatcerberus
Copy link

Fixes #55816

Is that the right issue? It seems unrelated.

@iisaduan
Copy link
Member Author

iisaduan commented May 14, 2024

It is the correct issue, see the call stack here. The quick fix is not offered because getting autoimports fails when the file is excluded in preferences

if (skipAlias(info[0].symbol, getChecker(info[0].isFromPackageJson)) === symbol && info.some(i => i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol)) {
if (
skipAlias(info[0].symbol, getChecker(info[0].isFromPackageJson)) === symbol
&& info.some(i => moduleSymbolExcluded || i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol)
Copy link
Member

Choose a reason for hiding this comment

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

Plot twist: all existing tests pass if you delete this entire info.some(...) part of the condition. That might be all that’s needed to fix the bug?

Copy link
Member Author

@iisaduan iisaduan May 15, 2024

Choose a reason for hiding this comment

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

I tried that and wasn't sure if that was the best fix, since I tracked it back to here, where it looked like it was intentionally added. :D if your opinion is that the check was unnecessary, I'll change it back to just deleting this extra check

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I remember something did break when I tried that-- tests/cases/fourslash/server/autoImportReExportFromAmbientModule.ts breaks with the info.some call removed. Since exporting ambient modules doesn't use filenames, I figured it would be alright to skip the check for ignored files

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
&& info.some(i => moduleSymbolExcluded || i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol)
&& (moduleSymbolExcluded || info.some(i => i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol))

if (skipAlias(info[0].symbol, getChecker(info[0].isFromPackageJson)) === symbol && info.some(i => i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol)) {
if (
skipAlias(info[0].symbol, getChecker(info[0].isFromPackageJson)) === symbol
&& info.some(i => moduleSymbolExcluded || i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol)
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
&& info.some(i => moduleSymbolExcluded || i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol)
&& (moduleSymbolExcluded || info.some(i => i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol))

src/services/codefixes/importFixes.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team 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.

TS is offering no quick fix to implement interface
4 participants