orenelbaum / babel-plugin-solid-undestructure

A Babel plugin for SolidJS that allows you to destructure component props without losing reactivity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add new component detection mode based on eslint-plugin-solid's no-destructure rule

orenelbaum opened this issue · comments

Right now the plugin knows which functions to transform by finding functions annotated with the Component type or the component compile time function.
I came across this lint rule that warns when props are destructured in components. If I understand correctly detects components by looking for every function that has JSX somewhere in the body of the function, with a few exceptions.
This suggestion is about adding a detection mode that works the same way or in a similar way to detect components that will be transformed, and thus when enabled, annotating components in other ways won't be necessary.

Right now I can see are 2 main drawbacks to this:

  • False positives: a function that has JSX somewhere in the body, even if it returns JSX, doesn't necessarily means that this function will be called as a component. Technically, a function could even be called as a component in one place and as a normal function in another place.
  • False negatives: a component doesn't necessarily have to return JSX. Even though it doesn't necessarily work with TS and you'd have to cast the type, you could use components that return objects or anything else. A component can also return DOM elements like a normal component would, but without any JSX written in the component itself.

Even with those drawbacks I think that this heuristic would probably work for a lot of people or even most people, so probably worth adding as a separate mode.