babel: transform-react-inline-elements throws on JSX fragments

Choose one: is this a bug report or feature request? bug report

When using the @babel/transform-react-inline-elements plugin, it throws an exception when it encounters a JSX fragment (i.e. <>...</>).

Input Code

export default class MyFragComp extends React.Component {
  render() {
    return <><div /><span /></>;
  }
}

Babel/Babylon Configuration (.babelrc, package.json, cli command)

{
  // ...
  "plugins": [ "@babel/transform-react-inline-elements" ]
}

Expected Behavior

Transpilation should succeed with no errors.

Current Behavior

Transpilation fails on JSX fragments.

Possible Solution

Quick solution: Bail out on JSX fragments (will send a PR for this now). Better solution: Optimize fragments the same way we optimize normal JSX tags.

Context

I use this plugin for production builds. Suddenly, builds started failing and I found out that a jsx fragment was causing it.

Your Environment

software version(s)
Babel 7.0.0-beta.36
Babylon
node 8.7.0
npm 5.4.2
Operating System macOS Sierra 10.12.6

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (17 by maintainers)

Most upvoted comments

@mdebbar I’m sorry, I did not explain my position well enough. I think we’re on the same side of the argument. I meant: avoid the error for now using a workaround and fix it with a proper implementation later.

While babel 7 is still in beta I’d say it would be better to just take more time and implement full solution of optimizing them, instead of bailing out tempprarily