Closure 编译器 Java API 转义 URL 个实体

Closure Compiler Java API escape URL entities

我正在尝试使用 Closure Compiler Java API 编译大量 JS 文件,但它在字符串文字 <>&= 中转义了这些字符,尽管它不是这样的从命令行调用。

CompilerOptions options = new CompilerOptions();
options.setLanguageIn(ECMASCRIPT5);
options.setLanguageOut(ECMASCRIPT5);
options.setOutputCharset(Charset.forName("UTF-8"));
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);

SourceFile extern = SourceFile.fromCode("externs.js", "");
SourceFile input = SourceFile.fromCode("input.js", "'<a>'");

Compiler compiler = new Compiler();
compiler.compile(extern, input, options);
System.out.println(compiler.toSource());

这是输出:

"\x3ca\x3e";

我通过测试每个 CompilerOptions 选项找到了答案:

options.setTrustedStrings(true);