本文整理汇总了Java中com.google.javascript.jscomp.CompilerOptions类的典型用法代码示例。如果您正苦于以下问题:Java CompilerOptions类的具体用法?Java CompilerOptions怎么用?Java CompilerOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompilerOptions类属于com.google.javascript.jscomp包,在下文中一共展示了CompilerOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compressJs
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
private void compressJs(String sourceName, InputStream in, OutputStream out) throws IOException
{
CompilerOptions options = new CompilerOptions();
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
SourceFile input = SourceFile.fromInputStream(sourceName, in, Charset.forName("UTF-8"));
com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
compiler.compile(Collections.EMPTY_LIST, Collections.singletonList(input), options);
if (compiler.hasErrors())
{
throw new EvaluatorException(compiler.getErrors()[0].description);
}
String compressed = compiler.toSource();
IOUtils.copy(new StringReader(compressed), out);
}
示例2: execute
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
public void execute() {
if (this.outputFile == null) {
throw new BuildException("outputFile attribute must be set");
}
Compiler.setLoggingLevel(Level.OFF);
CompilerOptions options = createCompilerOptions();
Compiler compiler = createCompiler(options);
JSSourceFile[] externs = findExternFiles();
JSSourceFile[] sources = findSourceFiles();
log("Compiling " + sources.length + " file(s) with " +
externs.length + " extern(s)");
Result result = compiler.compile(externs, sources, options);
if (result.success) {
writeResult(compiler.toSource());
}
}
示例3: minify
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
public byte[] minify(byte[] jsFileContent, String path) {
List<SourceFile> externs = Collections.emptyList();
List<SourceFile> inputs = Arrays.asList(SourceFile.fromCode(path, new String(jsFileContent, StandardCharsets.UTF_8)));
CompilerOptions options = new CompilerOptions();
options.setAngularPass(true);
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
Result result = compiler.compile(externs, inputs, options);
if (result.success) {
return compiler.toSource().getBytes(StandardCharsets.UTF_8);
}
JSError[] errors = result.errors;
StringBuilder errorText = new StringBuilder();
for (JSError error: errors){
errorText.append(error.toString());
}
throw new IllegalArgumentException("Unable to minify, input source\n"+ errorText);
}
示例4: compileFiles
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private OOPSourceCodeModel compileFiles(List<RawFile> files, List<String> projectFileTypes) {
OOPSourceCodeModel model = new OOPSourceCodeModel();
for (RawFile file : files) {
try {
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();
options.setIdeMode(true);
options.setParseJsDocDocumentation(JsDocParsing.INCLUDE_DESCRIPTIONS_WITH_WHITESPACE);
compiler.initOptions(options);
Node root = new JsAst(SourceFile.fromCode(file.name(), file.content())).getAstRoot(compiler);
JavaScriptListener jsListener = new JavaScriptListener(model, file, projectFileTypes);
NodeTraversal.traverseEs6(compiler, root, jsListener);
} catch (Exception e) {
e.printStackTrace();
}
}
return model;
}
示例5: create
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
/**
* Creates a symbolic executor which will instrument the given file and then,
* when run, symbolically execute starting by calling entryFunction with the
* given inputs.
*
* @param filename a JavaScript file which will be instrumented and then
* symbolically executed
* @param loader a FileLoader to help load files
* @param newInputGenerator the object that will generate new inputs from old
* ones
* @param maxNumInputs symbolic execution will stop after this many inputs are
* generated. This isn't a strict maximum, though, because new inputs
* are generated in batches, and we stop after the first <em>batch</em>
* puts us at or past this limit.
* @param entryFunction the function at which symbolic execution will start
* @param inputs the initial inputs to use when calling entryFunction
*/
public static SymbolicExecutor create(String filename, FileLoader loader,
NewInputGenerator newInputGenerator, int maxNumInputs,
String entryFunction, String... inputs) {
CompilerOptions options = new CompilerOptions();
// Enable instrumentation
options.symbolicExecutionInstrumentation = true;
options.prettyPrint=true;
// Compile the program; this is where the instrumentation happens.
Compiler compiler = new Compiler();
compiler.compile(new ArrayList<JSSourceFile>(),
Lists.newArrayList(JSSourceFile.fromFile(loader.getPath(filename))),
options);
// Add the call to symbolicExecution.execute
String code = String.format("%s;symbolicExecution.execute(this,%s,inputs)",
compiler.toSource(), entryFunction);
return create(code, loader, newInputGenerator, inputs, maxNumInputs);
}
示例6: execute
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
public void execute() {
if (this.outputFile == null) {
throw new BuildException("outputFile attribute must be set");
}
Compiler.setLoggingLevel(Level.OFF);
CompilerOptions options = createCompilerOptions();
Compiler compiler = createCompiler(options);
JSSourceFile[] externs = findExternFiles();
JSSourceFile[] sources = findSourceFiles();
log("Compiling " + sources.length + " file(s) with " +
externs.length + " extern(s)");
Result result = compiler.compile(externs, sources, options);
if (result.success) {
writeResult(compiler.toSource());
} else {
throw new BuildException("Compilation failed.");
}
}
示例7: getCompilerOptions
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
public CompilerOptions getCompilerOptions() {
final CompilerOptions options = new CompilerOptions();
options.setClosurePass(true);
options.setCheckGlobalNamesLevel(CheckLevel.ERROR);
// Report duplicate definitions, e.g. for accidentally duplicated externs.
options.setWarningLevel(DiagnosticGroups.DUPLICATE_VARS, CheckLevel.ERROR);
options.setLanguage(CompilerOptions.LanguageMode.ECMASCRIPT_2015);
options.setLanguageOut(CompilerOptions.LanguageMode.NO_TRANSPILE);
// Do not transpile module declarations
options.setWrapGoogModulesForWhitespaceOnly(false);
// Stop escaping the characters "=&<>"
options.setTrustedStrings(true);
options.setPreferSingleQuotes(true);
// Compiler passes must be disabled to disable down-transpilation to ES5.
options.skipAllCompilerPasses();
// turns off optimizations.
options.setChecksOnly(true);
options.setPreserveDetailedSourceInfo(true);
options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE);
return options;
}
示例8: initCompilerOptions
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
protected CompilerOptions initCompilerOptions() {
CompilerOptions opts = new CompilerOptions();
opts.setSummaryDetailLevel(1);
opts.prettyPrint = true;
// MIT-LL's integrated demo script requires this setting since
// it uses trailing commas in object literals.
opts.setLanguageIn(LanguageMode.ECMASCRIPT5);
opts.setGenerateExports(false);
opts.setPreferLineBreakAtEndOfFile(false);
opts.setTrustedStrings(true);
/*
DependencyOptions dopts = new DependencyOptions();
dopts.setDependencyPruning(true);
dopts.setMoocherDropping(true);
opts.setDependencyOptions(dopts);
*/
return opts;
}
示例9: map
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
@Override
public Resource<String> map(Resource<String> resource) {
try {
CompilerOptions options = new CompilerOptions();
config.getCompilationLevel().setOptionsForCompilationLevel(options);
options.setOutputCharset("UTF-8");
options.setLanguageIn(config.getLanguage());
SourceFile input = SourceFile.fromInputStream("dummy.js",
new ByteArrayInputStream(resource.getContent().getBytes(Charsets.UTF_8)));
List<SourceFile> externs = config.getExterns();
Compiler compiler = new Compiler();
compiler.compile(externs, Lists.newArrayList(input), options);
if (compiler.hasErrors()) {
throw new EvaluatorException(compiler.getErrors()[0].description);
}
return new Resource<String>(resource.getMimeType(), compiler.toSource(), StringHasher.instance);
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
示例10: initCompilationResources
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
private CompilerOptions initCompilationResources() {
CompilerOptions options = new CompilerOptions();
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel( options );
options.setSourceMapOutputPath( "." );
WarningLevel.QUIET.setOptionsForWarningLevel( options );
options.setWarningLevel( DiagnosticGroups.LINT_CHECKS, CheckLevel.OFF );
options.setLanguageIn( CompilerOptions.LanguageMode.ECMASCRIPT5 );
// make sure these are clear
this.lastPrefix = null;
this.lastLocationMapping = null;
return options;
}
示例11: CompileTask
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
public CompileTask() {
this.languageIn = CompilerOptions.LanguageMode.ECMASCRIPT3;
this.warningLevel = WarningLevel.DEFAULT;
this.debugOptions = false;
this.compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
this.customExternsOnly = false;
this.manageDependencies = false;
this.prettyPrint = false;
this.printInputDelimiter = false;
this.generateExports = false;
this.replaceProperties = false;
this.forceRecompile = false;
this.replacePropertiesPrefix = "closure.define.";
this.defineParams = Lists.newLinkedList();
this.externFileLists = Lists.newLinkedList();
this.sourceFileLists = Lists.newLinkedList();
this.sourcePaths = Lists.newLinkedList();
this.warnings = Lists.newLinkedList();
}
示例12: convertPropertiesMap
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
/**
* Converts project properties beginning with the replacement prefix
* into Compiler {@code @define} replacements.
*
* @param options
*/
private void convertPropertiesMap(CompilerOptions options) {
@SuppressWarnings("unchecked")
Map<String, Object> props = getProject().getProperties();
for (Map.Entry<String, Object> entry : props.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (key.startsWith(replacePropertiesPrefix)) {
key = key.substring(replacePropertiesPrefix.length());
if (!setDefine(options, key, value)) {
log("Unexpected property value for key=" + key + "; value=" + value);
}
}
}
}
示例13: getSecureCompilerOptions
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
/**
* Returns compiler options which are safe for compilation of a cajoled
* module. The set of options is similar to the one which is used by
* CompilationLevel in simple mode. The main difference is that variable
* renaming and closurePass options are turned off.
*/
private CompilerOptions getSecureCompilerOptions() {
CompilerOptions options = new CompilerOptions();
options.variableRenaming = VariableRenamingPolicy.OFF;
options.setInlineVariables(Reach.LOCAL_ONLY);
options.inlineLocalFunctions = true;
options.checkGlobalThisLevel = CheckLevel.OFF;
options.coalesceVariableNames = true;
options.deadAssignmentElimination = true;
options.collapseVariableDeclarations = true;
options.convertToDottedProperties = true;
options.labelRenaming = true;
options.removeDeadCode = true;
options.optimizeArgumentsArray = true;
options.removeUnusedVars = false;
options.removeUnusedLocalVars = true;
return options;
}
示例14: setOptions
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
protected void setOptions(CompilerOptions options) {
options.setLanguageIn(LanguageMode.ECMASCRIPT_NEXT);
// TODO(sdh): It would be nice to allow people to output code in
// strict mode. But currently we swallow all the input language
// strictness checks, and there are various tests that are never
// compiled and so are broken when we output 'use strict'. We
// could consider adding some sort of logging/warning/error in
// cases where the input was not strict, though there could still
// be semantic differences even if syntax is strict. Possibly
// the first step would be to allow the option of outputting strict
// and then change the default and see what breaks. b/33005948
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setQuoteKeywordProperties(true);
options.setSkipNonTranspilationPasses(true);
options.setVariableRenaming(VariableRenamingPolicy.OFF);
options.setPropertyRenaming(PropertyRenamingPolicy.OFF);
options.setWrapGoogModulesForWhitespaceOnly(false);
options.setPrettyPrint(true);
options.setSourceMapOutputPath("/dev/null");
options.setSourceMapIncludeSourcesContent(true);
options.setWarningLevel(ES5_WARNINGS, CheckLevel.OFF);
}
示例15: CompileTask
import com.google.javascript.jscomp.CompilerOptions; //导入依赖的package包/类
public CompileTask() {
this.languageIn = CompilerOptions.LanguageMode.ECMASCRIPT_2015;
this.languageOut = CompilerOptions.LanguageMode.ECMASCRIPT3;
this.warningLevel = WarningLevel.DEFAULT;
this.debugOptions = false;
this.compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
this.environment = CompilerOptions.Environment.BROWSER;
this.manageDependencies = false;
this.prettyPrint = false;
this.printInputDelimiter = false;
this.preferSingleQuotes = false;
this.generateExports = false;
this.replaceProperties = false;
this.forceRecompile = false;
this.angularPass = false;
this.replacePropertiesPrefix = "closure.define.";
this.defineParams = new ArrayList<>();
this.entryPointParams = new ArrayList<>();
this.externFileLists = new ArrayList<>();
this.sourceFileLists = new ArrayList<>();
this.sourcePaths = new ArrayList<>();
this.warnings = new ArrayList<>();
}