Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(babel-plugin-transform-svg-component): parsing error of JSX templ…
…ate exports defs (#225) When enabling the `ref` option the compilation will fail due to a `SyntaxError` on the _unexpected token_ `<`: ```sh ERROR in ./src/components/molecules/core/ErrorState404/styled/svg/fragments/space.svg Module build failed (from ./node_modules/@svgr/webpack/lib/index.js): SyntaxError: Unexpected token (2:52) 1 | /* @babel/template */; > 2 | const ForwardRef = React.forwardRef((props, ref) => <SvgSpace svgRef={ref} {...props} />) | ^ 3 | 4 | export default __webpack_public_path__ + "static/space.fea3855e.svg"; 5 | export { ForwardRef as ReactComponent } ``` This is caused by [util function `getExport`][src-util-func] that creates the JSX export statements. The problem causing the error is that the [Babel's AST template function][babel-doc-template] is called without adding the `jsx` plugin which results in the _unexpected token_ `<` which is part of the JSX spec. To fix the error the `jsx` plugin has been added to the array of enabled plugins for the Babel AST template. [babel-doc-template]: https://babeljs.io/docs/en/babel-template#templatecode-opts [src-util-func]: https://github.com/smooth-code/svgr/blob/master/packages/babel-plugin-transform-svg-component/src/util.js#L61 [src-default-template]: https://github.com/smooth-code/svgr/blob/master/packages/babel-plugin-transform-svg-component/src/index.js
- Loading branch information
1e56309
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aliasing was ignored due to a new commit existing for this branch, which will be aliased instead.