-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
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.
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.
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 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))) { |
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.
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.
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 have specified jsxImport
because we still want to hit the assertion in case a bug is introduced.
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. |
Alright, it was a bit unclear what the |
Closing in favor of #51319 |
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.