protected CompilerOptions getCompilerOptions() { CompilerOptions options = new CompilerOptions(); options.setLanguageIn(this.languageIn); options.setLanguageOut(this.languageOut); options.setCodingConvention(new ClosureCodingConvention()); CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options); WarningLevel.valueOf(this.warningLevel).setOptionsForWarningLevel(options); options.setClosurePass(true); options.skipAllCompilerPasses(); return options; }
public void setCompilationLevel(String compilationLevel) { this.compilationLevel = CompilationLevel.valueOf(compilationLevel); }
public void setOptionsForCompilationLevel(CompilerOptions options) { switch (this) { case WHITESPACE_ONLY: applyBasicCompilationOptions(options); break; case SIMPLE_OPTIMIZATIONS: applySafeCompilationOptions(options); break; case ADVANCED_OPTIMIZATIONS: applyFullCompilationOptions(options); break; default: throw new RuntimeException("Unknown compilation level."); } }
level.setOptionsForCompilationLevel(options); level.setDebugOptionsForCompilationLevel(options); level.setTypeBasedOptimizationOptions(options); level.setWrappedOutputOptimizations(options);
CompilationLevel level = CompilationLevel.fromString(args.compilationLevel); if (level == null) { System.err.println("Invalid value for compilation_level: " + args.compilationLevel); level.setOptionsForCompilationLevel(options); options.setTrustedStrings(true); options.setEnvironment(CompilerOptions.Environment.BROWSER); level.setWrappedOutputOptimizations(options); options.setProcessCommonJSModules(true); options.setConvertToDottedProperties(false);
@SuppressWarnings("unchecked") private static CompilerOptions buildCompilerOptionsFromConfig(FilterConfig config) { CompilerOptions compilerOptions = new CompilerOptions(); compilerOptions.setCodingConvention(CodingConventions.getDefault()); Enumeration<String> initParams = config.getInitParameterNames(); while (initParams.hasMoreElements()) { String name = initParams.nextElement().trim(); String value = config.getInitParameter(name); if ("charset".equals(name)) { if (value != null && Charset.isSupported(value)) { compilerOptions.setOutputCharset(Charset.forName(value)); } else { compilerOptions.setOutputCharset(StandardCharsets.UTF_8); } } else if ("compilationLevel".equals(name)) { CompilationLevel compilationLevel = CompilationLevel.valueOf(value); compilationLevel.setOptionsForCompilationLevel(compilerOptions); } else if ("formatting".equals(name)) { if ("PRETTY_PRINT".equals(value)) { compilerOptions.prettyPrint = true; } else if ("PRINT_INPUT_DELIMITER".equals(value)) { compilerOptions.printInputDelimiter = true; } } else if ("loggingLevel".equals(name)) { Compiler.setLoggingLevel(Level.parse(value)); //warning or error } } return compilerOptions; }
if (compilationLevel.equals(CompilationLevel.ADVANCED_OPTIMIZATIONS)) { compiler.disableThreads(); compilationLevel.setOptionsForCompilationLevel(compilerOptions); warningLevel.setOptionsForWarningLevel(compilerOptions);
private CompilerOptions createCompilerOptions() { CompilerOptions options = new CompilerOptions(); this.compilationLevel.setOptionsForCompilationLevel(options); if (this.debugOptions) { this.compilationLevel.setDebugOptionsForCompilationLevel(options);
level.setOptionsForCompilationLevel(options); level.setDebugOptionsForCompilationLevel(options); level.setTypeBasedOptimizationOptions(options); level.setWrappedOutputOptimizations(options);
theClosureOptions.setLanguageOut(CompilerOptions.LanguageMode.ECMASCRIPT5_STRICT); CompilationLevel.valueOf(closureOptimizationLevel).setOptionsForCompilationLevel(theClosureOptions);
if(compilationLevel.equals(CompilationLevel.ADVANCED_OPTIMIZATIONS)) { compiler.disableThreads(); compilationLevel.setOptionsForCompilationLevel(compilerOptions); warningLevel.setOptionsForWarningLevel(compilerOptions);
private CompilerOptions createCompilerOptions() { CompilerOptions options = new CompilerOptions(); this.compilationLevel.setOptionsForCompilationLevel(options); if (this.debugOptions) { this.compilationLevel.setDebugOptionsForCompilationLevel(options);
@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { final CompilerOptions copts = new CompilerOptions(); copts.setCodingConvention(new ClosureCodingConvention()); copts.setOutputCharset(StandardCharsets.UTF_8); copts.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); CompilationLevel level = level(get("level")); level.setOptionsForCompilationLevel(copts); Compiler.setLoggingLevel(Level.SEVERE); Compiler compiler = new Compiler(); compiler.disableThreads(); compiler.initOptions(copts); List<SourceFile> externs = externs(copts); Result result = compiler.compile(externs, ImmutableList.of(SourceFile.fromCode(filename, source)), copts); if (result.success) { return compiler.toSource(); } List<AssetProblem> errors = Arrays.stream(result.errors) .map(error -> new AssetProblem(error.sourceName, error.lineNumber, error.getCharno(), error.description, null)) .collect(Collectors.toList()); throw new AssetException(name(), errors); }
public void setOptionsForCompilationLevel(CompilerOptions options) { switch (this) { case BUNDLE: break; case WHITESPACE_ONLY: applyBasicCompilationOptions(options); break; case SIMPLE_OPTIMIZATIONS: applySafeCompilationOptions(options); break; case ADVANCED_OPTIMIZATIONS: applyFullCompilationOptions(options); break; default: throw new RuntimeException("Unknown compilation level."); } }
public void setCompilationLevel(String compilationLevel) { this.compilationLevel = CompilationLevel.valueOf(compilationLevel); }
public CompilerOptions defaultCompilerOptions() { CompilerOptions result = new CompilerOptions(); if (compileLevel.equals("advanced")) { CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(result); } else if (compileLevel.equals("whitespace_only")) { CompilationLevel.WHITESPACE_ONLY.setOptionsForCompilationLevel(result); } else { // If 'none', this complier will not run, @see compile CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(result); } return result; }
/** * Prepare options for the Compiler. */ private CompilerOptions getCompilerOptions() { CompilationLevel level = null; try { level = this.compilationLevel; } catch (IllegalArgumentException e) { throw new CoffeeException("Compilation level is invalid", e); } CompilerOptions options = new CompilerOptions(); level.setOptionsForCompilationLevel(options); return options; }
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel( options_);
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel( options_);
private void compress() throws UnsupportedEncodingException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = new ByteArrayInputStream(content); Writer out = new OutputStreamWriter(baos, charset); CompilerOptions options = new CompilerOptions(); CompilationLevel.SIMPLE_OPTIMIZATIONS .setOptionsForCompilationLevel(options); Compiler.setLoggingLevel(Level.OFF); Compiler compiler = new Compiler(); compiler.disableThreads(); Result result = compiler.compile(new JSSourceFile[] {}, new JSSourceFile[] { JSSourceFile.fromInputStream("is", is) }, options); if (result.success) { Pattern pattern = Pattern.compile("^/\\*.*?\\*/\\s?", Pattern.DOTALL); Matcher matcher = pattern.matcher(new String(content, charset)); while (matcher.find()) { out.write(matcher.group()); } out.write(compiler.toSource()); out.flush(); content = baos.toByteArray(); } is.close(); out.close(); } }