Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactJS Unexpected Token ) on Safari only

I'm getting an SyntaxError: Unexpected token ")" on Safari only - this code works on every other browser.

I'm using gulp to compile my files as follows:

browserify(componentPath + "app.jsx")
    .transform(reactify)
    .transform(babelify)
    .bundle()
    .pipe(source('app.js'))
    .pipe(gulp.dest(buildPath));

The syntax error is highlighting the following:

return React.createElement(If, {
     condition: !_.isEmpty(title)
 }, React.createElement("div", {
     className: "row wrapper border-bottom white-bg page-heading"
 }, React.createElement("div", {
     className: "col-lg-9"
 }, React.createElement("h2", null, title || 'Untitled'), React.createElement("ol", {
     className: "breadcrumb"
 }, React.createElement("li", null, React.createElement("a", {
     onClick: () => self.history.pushState(null, home)
 }, "Home")), links.map(function(link, index) {
     var url = link.url;

     return React.createElement("li", {
         onClick: () => self.history.pushState(null, url),
         key: url,
         className: "ptr-click"
     }, index == links.length - 1 ? React.createElement("strong", null, link.title || 'Untitled') : link.title);
 })))));

I commented the whole section out, just to see if it is this particular block of code, but then the error referred to another block of exactly the same React.createElement.

like image 541
Kousha Avatar asked Oct 19 '22 21:10

Kousha


1 Answers

Taking mattclemens comment into consideration, Safari currently does not execute arrow functions. So I updated my gulp script to:

browserify(componentPath + "app.jsx")
    .transform(reactify)
    .transform(babelify, {presets: ["es2015", "react"]})
    .bundle()
    .pipe(source('app.js'))
    .pipe(gulp.dest(buildPath));

Of course, don't forget to install the presets:

npm install babel-preset-es2015 babel-preset-react

This worked perfectly, and now my code runs on Safari as well :)

like image 186
Kousha Avatar answered Nov 03 '22 07:11

Kousha