【问题标题】:Can't Precompile Rails Assets Due to Uglifier Punc Error由于 Uglifier Punc 错误,无法预编译 Rails 资产
【发布时间】:2017-09-28 20:33:36
【问题描述】:

这是我在在线 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 的错误相同,但我查看的所有地方都说它要么已修复,要么我尝试的解决方案不起作用。

【问题讨论】:

    标签: javascript ruby-on-rails


    【解决方案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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-14
      • 1970-01-01
      • 2012-03-26
      • 1970-01-01
      • 2017-04-17
      相关资源
      最近更新 更多