Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Unexpected token, expected } for inline CSS block #9

Closed
fwielstra opened this issue Oct 30, 2017 · 5 comments
Closed

SyntaxError: Unexpected token, expected } for inline CSS block #9

fwielstra opened this issue Oct 30, 2017 · 5 comments

Comments

@fwielstra
Copy link

I have a logo generated by Adobe Illustrator's SVG export plugin (supplied by our designers). I had transformed it to a React component by hand first, until I found this package. It doesn't seem to handle a style block though; I think the parser tries to interpret it as a react template construction.

Very minimal example, probably not valid SVG but it reproduces the parse error:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 21.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.1" id="Layer_1">
    <style type="text/css">
      .st0{fill:#34107D;}
    </style>
</svg>

Error output:

$ svgr test.svg

(node:10071) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token, expected } (5:14)
  3 | const Test = (props) => <svg id="Layer_1" {...props}>
  4 |   <style>
> 5 |     .st0{fill:#34107d}
    |              ^
  6 |   </style>
  7 | </svg>
  8 |
(node:10071) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@gregberge
Copy link
Owner

gregberge commented Oct 30, 2017

@fwielstra ah style is not supported, we could easily fix it by adding a h2x transform. Feel free to submit a PR!

@fwielstra
Copy link
Author

Hmm, looking into this a bit further, it might be better to disallow styles completely; react doesn't do CSS isolation (yet?), so two svg's with a style tag can overwrite each other's styles if they match in name (which for Adobe Illustrator's exporter they do apparently).

@gregberge
Copy link
Owner

@fwielstra yes probably better to remove them completely.

@gregberge gregberge added the bug label Oct 30, 2017
@gregberge
Copy link
Owner

It can be easily done by adding a h2x plugin, similar to removeComments, difference will be that we remove a whole tag "style".

gregberge added a commit that referenced this issue Oct 30, 2017
@gregberge
Copy link
Owner

Fixed in v0.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants