YUIcompressorJS压缩报错missing name after . operator

最近在webstorm上,利用yuicompressor对js文件进行压缩,总是报错,今天解决,总结如下。

html代码引用未压缩的代码时,并未出现任何报错,功能运行也没有问题,但是一旦使用yuicompressor对其进行压缩,就会有数行错误出现,其中第一行错误是:missing name after . operator。

是什么原因呢?

主要原因出自以下代码中使用了delete:

this.delete=function(list,index) {

            list.splice(index,1);

};

delete在ECMAscript中为关键字,因此在压缩之后,无法识别函数名delete,这导致之后爆了很多相关的错误。与此类似,很多时候,我们会错误的使用一些reserved keywords(保留关键字),例如,interface,这样也会报类似的错误。

一些常用关键字,摘抄如下,

Keyword :  break  else   new    var   case  finally    return      void   catch      for   switch      while  continue    function    this   with default    if    throw   delete      in          try  do          instanceof  typeof

FutureReservedWord : abstract    enum   int    short  boolean   export      interface  static byte    extends    long     super char        final      native      synchronized class    float package  throws const     goto    private   transient debugger    implements  protected  volatile double   import    public

参考文章:

http://lists.evolt.org/pipermail/javascript/2005-October/009767.html

http://www.myexception.cn/web/1658623.html

你可能感兴趣的:(YUIcompressorJS压缩报错missing name after . operator)