使用Gulp Uglify与js数组时出现Javascript错误

时间:2017-09-20 18:23:43

标签: javascript gulp syntax-error

我在Gulp中运行uglify时出现以下错误。在文档头部的脚本中调用相同的代码时没有出错。请告知如何修复错误。

终端出错:

 { SyntaxError: Unexpected token punc «,», expected punc «:»
     at JS_Parse_Error.get (eval at <anonymous> (/Applications/MAMP/htdocs/site.com/node_modules/uglify-js/tools/node.js:1:0), <anonymous>:86:23)
     at formatError (util.js:644:15)
     at formatValue (util.js:550:18)
     at formatProperty (util.js:790:15)
     at util.js:650:12
     at Array.map (native)
     at formatObject (util.js:649:15)
     at formatValue (util.js:589:16)
     at inspect (util.js:183:10)
     at exports.format (util.js:69:24)
   message: 'Unexpected token punc «,», expected punc «:»',
   filename: 'jquery.main.js',
   line: 104,
   col: 18,
   pos: 2671 },
plugin: 'gulp-uglify',
fileName: '/Applications/MAMP/htdocs/site.com/src_assets/js/jquery.main.js',
showStack: false }

Javascript在线错误:104指的是行playerVars,

  window.onYouTubeIframeAPIReady = function() {
      playerVars = { 'autoplay': 1, 'controls': 0, 'rel': 0, 'showinfo': 0, 'loop': 1, 'modestbranding': 1 };

      return new YT.Player('youtubeVideoPlayer', {
        height: playerHeight,
        width: playerWidth,
        videoId: player.data('video-id'),
        playerVars,
        events: {
            onReady: function(e) {
              frame = holder.find('iframe');
              e.target.mute();
              resizeHandler();
            }
          }
      });
  }

1 个答案:

答案 0 :(得分:1)

Uglify显然不了解playerVars的ES6速记playerVars: playerVars

我认为您可以通过安装uglify-es来解决此问题。或者只是用传统语法替换速记。