2013-07-28 53 views
2

我正在使用r.js來優化/ uglify我使用RequireJS的JavaScript代碼。uglify與r.js拋出解析錯誤

我的一個模塊是一個填充工具模塊:

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 

function isPolyfillNeeded()更換var isPolyfillNeeded = function() ,它工作正常。 這是爲什麼?

+0

該函數的主體是什麼樣的? – Blender

+0

@Blender顯然我有一個隱藏在某處的壞字符(請參閱http://stackoverflow.com/questions/12719859/syntaxerror-unexpected-token-illegal)。我仍然無法解釋爲什麼var函數的變化解決了它,但無論如何 - 刪除壞字符修復了它。謝謝。 – Haji

回答

2

問題是一個隱藏在我的代碼中的壞字符,因爲我從一些片段複製粘貼。這是無形的,所以很難發現。

相關問題