1

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

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

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

4

1 回答 1

3

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

于 2013-08-30T19:42:51.070 回答