pugjs / babel-plugin-transform-react-pug

A plugin for transpiling pug templates to jsx
MIT License
811 stars 47 forks source link

Is babel-plugin-transform-react-jsx plugin really required #18

Closed mars-abd closed 6 years ago

mars-abd commented 7 years ago

Is babel-plugin-transform-react-jsx plugin really required? I have not read the sources, but I have thought that:

p This is my component using pug

will be compiled directly to:

React.createElement('p', null, 'This is my component using pug');

without jsx

ezhlobo commented 7 years ago

@mars-abd I don't know exactly but I can provide possible answers:

mars-abd commented 7 years ago

Thanks for the answer!

ForbesLindesay commented 6 years ago

Yes, we list the jsx transform as part of the README, so I don't think any further action is required here.

We generate our JSX and rely on the JSX transform for a few reasons:

  1. The React team have changed the element creation API in the past, using JSX insulates us from those changes.
  2. There are other libraries that use JSX for different targets, these can be supported by react-pug by simply swapping out the jsx transform for something else.
  3. There are a number of optimisations (e.g. constant elements) that are currently only supported when applied to JSX, not calls to React.createElement. By generating JSX, react-pug is compatible with these.