admin管理员组文章数量:1200790
I am optimizing several js files into one using r.js
. It works fine before. Recently,I modified some js code, add the code as:
var x = 08;
then it shows
ERROR:parse error using esprima for file D://webroot/js/a.js
ERROR:line 45: Unexpected token ILLEGAL.
Line 45 is where I add var x = 08
, and 09
will show error too. It seemed that numbers begining with 0 meanwhile containing 8
or 9
is illegal. Maybe they were treated as bese 8 number .. ?
How can I let r.js
ignore this point and still optimizie js files?
I am optimizing several js files into one using r.js
. It works fine before. Recently,I modified some js code, add the code as:
var x = 08;
then it shows
ERROR:parse error using esprima for file D://webroot/js/a.js
ERROR:line 45: Unexpected token ILLEGAL.
Line 45 is where I add var x = 08
, and 09
will show error too. It seemed that numbers begining with 0 meanwhile containing 8
or 9
is illegal. Maybe they were treated as bese 8 number .. ?
How can I let r.js
ignore this point and still optimizie js files?
- 2 Looks like a (minor) bug in r.js, you could try reporting it on project's GitHub page. Why are you prefixing numbers with zeros, though? The simplest fix would be not to do that... – kryger Commented Nov 1, 2013 at 10:07
4 Answers
Reset to default 15i had the same problem
Turn out that it was just a double comma while requiring files. Ex
define([
'file1',
'file2',
'file3',,
'file4'
Hope this helps
The error is due to Esprima, which r.js
uses internally. To replicate the problem, you can go to this page and type in var x = 08;
Generally speaking, it seems that JavaScript interpreters will treat a number with a leading zero that can be interpreted as an octal number as an octal number but if it cannot be interpreted as an octal number (e.g. 08), then they will treat it as decimal.
I've done a test with Node.js and got this:
$ node
> 07
7
> 08
8
> 09
9
> 010
8
>
And for even more fun:
> (function () {'use strict'; var x = 08;})()
undefined
> (function () {'use strict'; var x = 012;})()
SyntaxError: Octal literals are not allowed in strict mode.
[ ... traceback deleted ...]
When strict mode is on, octals are illegal.
I would avoid octals and never prefix any number with zeros in JavaScript.
i had the same error when i forgot the question mark on my one-line if statement, inside a require js module.
Wrong line:
var check = self.currentScroll() > self.lastScroll() ? 1 : self.currentScroll() < self.lastScroll() -1 : 0
Corrected :
var check = self.currentScroll() > self.lastScroll() ? 1 : self.currentScroll() < self.lastScroll() ? -1 : 0
I had the same problem too, while parsing a very long string:
var styleHTML = "<style>....</style>"
It turns out that in the string I also included some comments like this:
/* ... */
When I delete all the css comments in the string, it works!
Hope this helps.
本文标签: javascriptparse error using esprima for file while optimizing js files with rjsStack Overflow
版权声明:本文标题:javascript - parse error using esprima for file while optimizing js files with r.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738559849a2099020.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论