简体   繁体   English

Javascript YUICompressor错误

[英]Javascript YUICompressor error

Using YUICompressor I get the following error from my javascript code: 使用YUICompressor,我的javascript代码出现以下错误:

[ERROR] 270:201:missing name after . operator
    [ERROR] 292:6:missing ; before statement

Here's the javascript code at the following lines: 这是以下行中的javascript代码:

Line 270: 第270行:

new _ow.getScript(_ow.wwwurl+'/widget/save?title='+encodeURIComponent(this.obj.title.value)+'&url='+encodeURIComponent(this.obj.url.value)+'&tags='+this.obj.tags.value+'&private='+this.obj.private.checked+'&c='+this.obj.notes.value+'&service='+services+'&token='+(_ow.token ? encodeURIComponent(_ow.token): ''), function(data) {

Line 292: 第292行:

});

I can't figure out what the problem is since this Javascript code works fine on all browsers. 我无法弄清楚问题出在哪里,因为此Javascript代码在所有浏览器上都能正常工作。


EDIT : I split the line in multiple lines and figured out that the "missing name after . operator" is generated by this code: 编辑 :我将行拆分为多行,并找出此代码生成“。运算符后缺少名称”:

this.obj.private.checked

Is private a keyword that makes the YUI compressor go mad? private是使YUI压缩器发疯的关键字吗?

First, I'd reformat the code to make it more readable: 首先,我将重新格式化代码以使其更具可读性:

new _ow.getScript(_ow.wwwurl
    + '/widget/save?title='
    + encodeURIComponent(this.obj.title.value)
    + '&url='
    + encodeURIComponent(this.obj.url.value)
    + '&tags='
    + this.obj.tags.value
    + '&private='
    + this.obj.private.checked
    + '&c='
    + this.obj.notes.value
    + '&service='
    + services
    + '&token='
    + (_ow.token
        ? encodeURIComponent(_ow.token)
        : ''),
    function(data) {
    });

Then, the line # reported by the compressor should help you drill down on what the problem is. 然后,压缩机报告的行号应该可以帮助您深入了解问题所在。

请记住使用选项--type js ex。

yuicompressor --type js -o comressed.js filetocompress.js

you can download and install apache ant, download the yui source, edit the source code (in src folder, in the org and the com subfolders) to remove all references to the keyword blocking your progress (it goes quite fast, I edited about 3 to 4 files i think, had to run ant twice because the first time got a reference error, but all it took was deleting another line referring to the keyword) and once ant compiles successfully you have a brand new .jar and you can use this to compile your problematic js. 您可以下载并安装apache ant,下载yui源代码,编辑源代码(在src文件夹中,在org和com子文件夹中),以删除对阻止进度的关键字的所有引用(运行速度非常快,我编辑了约3到4个文件,我认为必须运行ant两次,因为第一次遇到参考错误,但是只需要删除引用关键字的另一行即可),一旦ant编译成功,您将拥有一个全新的.jar,您可以使用它编译有问题的js。 did this with yuicompressor2-4.7 and the "import" keyword (used quite extensively in mozilla extension code) 使用yuicompressor2-4.7和“ import”关键字(在mozilla扩展代码中广泛使用)完成了此操作

You could make your own life a lot easier just by breaking it out onto multiple lines. 您可以将自己的生活分解成多行,从而使自己的生活更加轻松。 You're compressing it anyway, so it's not like it's going to make a difference to the final size... 无论如何,您都在压缩它,所以这并不希望最终尺寸有所不同...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM