【问题标题】:Uglify with r.js throws a parsing error使用 r.js 进行 Uglify 会引发解析错误
【发布时间】:2013-07-28 06:28:59
【问题描述】:

我正在使用 r.js 来优化/丑化我使用 RequireJS 的 JavaScript 代码。

我的一个模块是一个 polyfill 模块:

define(function(){
    if (!Array.prototype.filter)
    {  /* ... */ }

    var isPolyfillNeeded = function () { /* ... */ }

    if (isPolyfillNeeded()) {
        /* polyfill implementation */
    }
});

该模块在尝试对其进行丑化时导致 r.js 抛出解析错误,说:

Tracing dependencies for: ../scripts/main-app
Error: Parse error using UglifyJS for file: C:/.../polyfill.js
Unexpected character '?' (line: .., col: .., pos: ..)

undefined
In module tree:
    ../scripts/main-main-app
      moduleA
        moduleB

var isPolyfillNeeded = function () 替换为function isPolyfillNeeded() 时,它可以正常工作。 这是为什么呢?

【问题讨论】:

  • 该函数的主体是什么样的?
  • @Blender 显然我有一个坏角色躲在某个地方(见stackoverflow.com/questions/12719859/…)。我仍然无法解释为什么 var-function 更改解决了它,但无论如何 - 删除一个坏字符修复它。谢谢。

标签: requirejs js-amd uglifyjs r.js


【解决方案1】:

问题是一个坏字符隐藏在我的代码中,因为我从一些 sn-p 复制粘贴。它是看不见的,所以很难被发现。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-01
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 2017-11-26
    • 1970-01-01
    相关资源
    最近更新 更多