Kou*_*sha 5 javascript safari reactjs gulp
我SyntaxError: Unexpected token ")"
只在 Safari 上使用 - 此代码适用于所有其他浏览器。
我gulp
用来编译我的文件如下:
browserify(componentPath + "app.jsx")
.transform(reactify)
.transform(babelify)
.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest(buildPath));
Run Code Online (Sandbox Code Playgroud)
语法错误突出显示以下内容:
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);
})))));
Run Code Online (Sandbox Code Playgroud)
我将整个部分注释掉,只是想看看它是否是这个特定的代码块,但随后错误指向了另一个完全相同的React.createElement
.
考虑到mattclemens 的评论,Safari 目前不执行箭头功能。所以我将我的gulp
脚本更新为:
browserify(componentPath + "app.jsx")
.transform(reactify)
.transform(babelify, {presets: ["es2015", "react"]})
.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest(buildPath));
Run Code Online (Sandbox Code Playgroud)
当然,不要忘记安装预设:
npm install babel-preset-es2015 babel-preset-react
Run Code Online (Sandbox Code Playgroud)
这工作得很好,现在我的代码也可以在 Safari 上运行:)