AngularJS无法使用Google Closure App + Ant进行编译

时间:2013-08-30 18:38:47

标签: javascript angularjs ant build google-closure-compiler

我正在尝试用google closure编译器编译一个用angularjs编写的javascript应用程序。我的ant build看起来像这样:

<?xml version="1.0"?>
<project basedir="../public_html/" default="compile">

  <taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask" classpath="../../global/build/compiler.jar"/>

  <target name="compile">

    <jscomp compilationLevel="simple" warning="verbose" debug="false" output="${basedir}/js/main.js">

      <sources dir="${basedir}/js/">
        <file name="angular.js"/>
        <file name="angular-strap.js"/>
        <file name="underscore.js"/>
        <file name="app.js"/>
      </sources>


    </jscomp>

  </target>

</project>

但构建基于angular.js中的错误而破坏,如:

[jscomp] widgets/public_html/js/angular.js:57: ERROR - Parse error. identifier is a reserved word
   [jscomp]     msie              = int((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1]),
   [jscomp] ^
   [jscomp] widgets/public_html/js/angular.js:245: ERROR - Parse error. identifier is a reserved word
   [jscomp] function int(str) {
   [jscomp] ^
   [jscomp] widgets/public_html/js/angular.js:5066: ERROR - Parse error. identifier is a reserved word
   [jscomp]       port: int(match[5]) || DEFAULT_PORTS[match[1]] || null,
   [jscomp] ^
   [jscomp] widgets/public_html/js/angular.js:8373: ERROR - Parse error. identifier is a reserved word
   [jscomp]         android = int((/android (\d+)/.exec(lowercase($window.navigator.userAgent)) || [])[1]);
   [jscomp] ^
   [jscomp] widgets/public_html/js/angular.js:10128: ERROR - Parse error. identifier is a reserved word
   [jscomp]         tzHour = int(match[9] + match[10]);
   [jscomp] ^
   [jscomp] widgets/public_html/js/angular.js:10129: ERROR - Parse error. identifier is a reserved word
   [jscomp]         tzMin = int(match[9] + match[11]);

我应该如何解决这些“错误”?

1 个答案:

答案 0 :(得分:3)

intecmascript 3 reserved word。您需要使用编译器的--language_in选项指定两个ecmascript 5选项之一。较新的编译器构建使用ecmascript 5作为默认语言。