由于Uglifier Punc错误,无法预编译Rails资产

时间:2017-09-28 20:33:36

标签: javascript ruby-on-rails

这是我在在线JavaScript Minifier中从public / assets / js检查我的application.js时收到的错误:

Parse error: Unexpected token: punc (})
Line 22315, column 33

22314:     url: "/products/per_amount",
22315:     data: {id: quantity, product},
22316:     dataType: "json",

这看起来像这样:

$.ajax({
url: "/products/per_amount",
data: {id: quantity, product},
dataType: "json",
type: "GET",
...

这与this的错误相同,但我看到的任何地方都说它已修复或我尝试的解决方案无效。

1 个答案:

答案 0 :(得分:1)

您似乎正在使用Uglifier不支持的ES6功能:http://es6-features.org/#PropertyShorthand

我认为Uglifier的目标是ES5,除了ES5代码之外不会接受任何其他内容。您可以通过在ES5中重写代码来快速修复:

$.ajax({
url: "/products/per_amount",
data: {id: quantity, product: product},
dataType: "json",
type: "GET",

如果您想保留语法好处,请使用Babel将您的代码转换为ES5。