milesj / babel-plugin-typescript-to-proptypes

Generate React PropTypes from TypeScript interfaces or type aliases.
MIT License
367 stars 25 forks source link

new: Add JSX Pragma and Preact support #42

Open JoaoVictorLouro opened 3 years ago

JoaoVictorLouro commented 3 years ago

Problem

babel-plugin-typescript-to-proptypes does not support preact.

Solution

Allow the plugin to be configured to use different "pragmas", so it can switch between React, Preact, or Inferno.

--

First of all, thanks for the awesome library, I have been using it in many projects, even professional ones, it helps to debug and speeds up development nicely. One downside of this plugin is, however, that it does not support other JSX powered libraries, it is locked into React. I have been using Preact for some of my projects and would love for this plugin to support it as well! For that, I have forked your repository and made some changes, to allow the plugin to switch contexts between react and preact.

To use preact, a user can simply set up a "jsxPragma" config option to "preact". The plugin will then use preact references instead of React ones. I had to do some small code refactoring for this to work. That is, extract constants and use some helper methods. Please let me know what you think :)

(The code is still under development, and I am looking for feedback)

milesj commented 3 years ago

@JoaoVictorLouro Sorry for the late response. Looking good but can you run the entire test suite against this preact pragma so that all the snapshots exist?

henrikyt commented 3 years ago

Hi guys. This looks awesome, exactly the special sauce I would need. Any plans on merging?

milesj commented 3 years ago

@henrikyt Just waiting on @JoaoVictorLouro to add more tests. I currently don't have time myself to do it.