命令行Google Closure提供的标准extern是什么,以及如何通过Java接口获得它们

What are the standard externs provided by the command line Google Closure, and how do I get them through the Java interface?

本文关键字:Java 何通过 接口 Closure Google 是什么 extern 标准 命令行      更新时间:2023-09-26

我现在正在使用这个代码:

com.google.javascript.jscomp.Compiler.setLoggingLevel(Level.OFF);
com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
CompilerOptions options = new CompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
WarningLevel.VERBOSE.setOptionsForWarningLevel(options);
List<JSSourceFile> externs = new ArrayList<JSSourceFile>();
externs.add(JSSourceFile.fromFile(extern_src));
List<JSSourceFile> primary = new ArrayList<JSSourceFile>();
primary.add(JSSourceFile.fromFile(tmp));
compiler.compile(externs, primary, options);

然而,我得到很多这样的错误:

Error message: JSC_UNDEFINED_VARIABLE. variable Array is undefined
Error message: JSC_UNDEFINED_VARIABLE. variable TypeError is undefined
Error message: JSC_UNDEFINED_VARIABLE. variable Object is undefined 
Error message: JSC_UNDEFINED_VARIABLE. variable arguments is undefined
Error message: JSC_UNDEFINED_VARIABLE. variable Number is undefined
Error message: JSC_UNDEFINED_VARIABLE. variable Math is undefined

显然,这些是不正确的:像Objectarguments等东西是语言的核心部分。我能做些什么来解决这个问题?

您看过Michael Bolin关于使用Java API的博客了吗?

http://blog.bolinfest.com/2009/11/calling-closure-compiler-from-java.html