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

Using template strings throws an error on Safari: Invalid character '`' #4143

Closed
josdejong opened this issue Jun 16, 2015 · 4 comments
Closed

Comments

@josdejong
Copy link

Using template strings in jsx files seems to be not supported by Safari because it doesn't like the backtick character '`'.

On Safari 8, the following code:

var container = document.getElementById('app');
var name = 'user';
var msg = `Hello ${name}!`;
React.render(<div>{msg}</div>, container);

Throws an error:

SyntaxError: Invalid character: '`' (line 3)

See this jsbin: http://jsbin.com/vurezi/edit?html,js,output

One solution for this is not to use in-browser transformation (which is good practice anyway). But does anybody know a workaround for this? I tried specifying charset="utf-8" in the jsx script tags but that didn't help.

@zpao
Copy link
Member

zpao commented Jun 16, 2015

You need to enable the other es6 transforms by adding some params to the type. type="text/jsx?harmony=true

I don't know how to trigger that on jsbin but I would suggest using Babel there anyway.

@zpao zpao closed this as completed Jun 16, 2015
@josdejong
Copy link
Author

Thanks for your quick reaction. I was under the impression that ES6 features like template strings where dealt with by the React transformer but if I understand it correctly that's not the case.

@syranide
Copy link
Contributor

@josdejong
Copy link
Author

Thanks @syranide. I just noticed that babel has support to transform jsx files too (http://babeljs.io/docs/usage/jsx/), and this works right out of the box using a build step. For some reason it didn't work when running the in-browser transform of babel: then html tags in react classes aren't compiled into JavaScript.

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

3 participants