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

Exclude JsxImport during finding references #53328

Closed
wants to merge 2 commits into from

Conversation

armanio123
Copy link
Member

Fixes #53159 (comment)

Synthetic nodes cause an Assert exception when finding references. This PR excludes the jsx import when finding references as they are created as synthetize declaration.

@armanio123 armanio123 requested a review from sandersn March 17, 2023 23:31
@sandersn sandersn requested a review from andrewbranch March 17, 2023 23:34
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Needs a find-all-refs test. Those are in $ts/tests/cases/fourslash/findAllRef* -- I hope there are some existing JSX ones that you can copy to get the structure from.

@DanielRosenwasser
Copy link
Member

Can you discuss whether this or #51319 is the right fix, and mark this PR as fixing #51221 ?

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

If you just wanna quickly fix the crash, just doing the nodeIsSynthesized check (and skipping all the jsx-specific-filtering stuff) should broadly fix the crash and any similar ones with tslib imports. The other PR goes farther, though, which may be more what we want. Given the other PR has approvals already, @DanielRosenwasser would you prefer that change? IIRC, it's good to merge provided you're fine with FAR on a tslib import landing you on the first JSX tag in a file if present (rather than, say, the first statement which actually uses a helper when transpiled (which I don't think is easily tracked)).

forEachImport(referencingFile, (_importDecl, moduleSpecifier) => {
const moduleSymbol = checker.getSymbolAtLocation(moduleSpecifier);
if (moduleSymbol === searchModuleSymbol) {

if (moduleSymbol === searchModuleSymbol && !(moduleSpecifier.text === jsxImport && nodeIsSynthesized(moduleSpecifier))) {
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to specifically check for the jsxImport, any node for which nodeIsSynthesized is true is going to be a hassle for the import tracker, since it has no associated positions to report. Just checking that will also remove any errors related to finding all references on the synthetic tslib import we also add. However, just skipping the result leaves a bit lacking, no? That's why the other PR adds a new reference type and actually records the file as a reference for the import.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have specified jsxImport because we still want to hit the assertion in case a bug is introduced.

@DanielRosenwasser
Copy link
Member

On the other PR, I was waiting for you to address Sheetal's feedback regarding the tslib changes. If you go to the first statement for those cases (or for all cases even) I think that's better than the crash.

@weswigham
Copy link
Member

If you go to the first statement for those cases (or for all cases even) I think that's better than the crash.

Alright, it was a bit unclear what the tslib reference should be, given where the references in the generated code actually end up. If we're fine with the first statement of the file, that's easy.

@armanio123
Copy link
Member Author

Closing in favor of #51319

@armanio123 armanio123 closed this Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ServerErrors][TypeScript] 5.1.0-dev.20230307
4 participants