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

标签 javascript angularjs ant build google-closure-compiler

我正在尝试使用 google 闭包编译器编译一个用 angularjs 编写的 javascript 应用程序。我的 Ant 构建看起来像这样:

<?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]);

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

最佳答案

int 是一个 ecmascript 3 reserved word .您需要使用编译器的 --language_in 选项来指定两个 ecmascript 5 选项之一。较新的编译器版本使用 ecmascript 5 作为默认语言。

关于javascript - AngularJS 无法使用 Google Closure App + Ant 进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18539486/

相关文章:

javascript - 使用自定义 Knockout 映射时获取索引值

javascript - 使用 Angular 和 Django 发送文件

ant - 无法解析 IntelliJ IDEA 11 Ant 构建脚本中的符号 'scp'

javascript - 如何在javascript中对数据数组求和

jquery - ng-repeat 排序在 jQuery 中抛出异常

web-services - ANT build.xml 中包的 Javac 排除

Javac Ant 构建错误

javascript - React Web 应用程序的默认 css 显示值是多少?

javascript - Mongodb更新子数组内的操作

javascript - 当我运行 animate 函数时没有任何反应,我能做些什么来解决这个问题?