Babel JSX import plugin: Support short Fragment syntax #12207
Labels
[Feature] Extensibility
The ability to extend blocks or the editing experience
Good First Issue
An issue that's suitable for someone looking to contribute for the first time
[Status] In Progress
Tracking issues with work in progress
[Tool] Babel plugin import JSX pragma
/packages/babel-plugin-import-jsx-pragma
Is your feature request related to a problem? Please describe.
The
@wordpress/babel-plugin-import-jsx-pragma
package allows you to use JSX without adding the React import. In combination with@babel/transform-react-jsx
, this makes it simple to use@wordpress/element
to write JSX as the README describes.However, when using the JSX Fragment
<>short syntax</>
, the recommended@babel/transform-react-jsx
plugin errors if thepragma
option is set butpragmaFrag
is not set and it needs to transform<></>
.See the JSX transform options for details.
Describe the solution you'd like
The existing options for the don't make it clear where the plugin might be extended to support Fragment options. With
React.Fragment
, no additions should be necessary. However, when usingcreateElement
andFragment
from@wordpress/element
, aFragment
import is also necessary. It might look something like this, closely mirroring the JSX transform options:Then, when the transform is applied:
Describe alternatives you've considered
You can set the
pragmaFrag
for the@babel/transform-react-jsx
, but you need to ensure that the import is present, which seems to defeat the purpose of the way these plugins are designed to work.The text was updated successfully, but these errors were encountered: