开发者

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

I'm currently using this code:

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(JSSource开发者_运维问答File.fromFile(extern_src));

List<JSSourceFile> primary = new ArrayList<JSSourceFile>();
primary.add(JSSourceFile.fromFile(tmp));
compiler.compile(externs, primary, options);

However, I get lots of errors like this:

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

Obviously, these are not correct: things like Object and arguments etc a core part of the language. What can I do to fix this?


Did you see Michael Bolin blog regarding using the Java API?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜