@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); }
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; }
/** * Allow subclasses to override the default CompileOptions object. */ protected CompilerOptions newCompilerOptions() { return new CompilerOptions(); }
public JsMessageExtractor( JsMessage.IdGenerator idGenerator, JsMessage.Style style, CompilerOptions options, boolean extractExternalMessages) { this.idGenerator = idGenerator; this.style = style; this.options = options; this.extractExternalMessages = extractExternalMessages; }
public GoogleClosureOptionsHandler(Log log) { this.compilerOptions = new CompilerOptions(); this.log = log; }
public GoogleClosureOptionsHandler(Log log) { this.compilerOptions = new CompilerOptions(); this.log = log; }
/** * Allow subclasses to override the default CompileOptions object. */ protected CompilerOptions newCompilerOptions() { return new CompilerOptions(); }
public JsMessageExtractor( JsMessage.IdGenerator idGenerator, JsMessage.Style style, CompilerOptions options, boolean extractExternalMessages) { this.idGenerator = idGenerator; this.style = style; this.options = options; this.extractExternalMessages = extractExternalMessages; }
protected CompilerOptions options() { CompilerOptions options = new CompilerOptions(); setOptions(options); return options; }
@Override public ErrorManager getErrorManager() { if (options == null) { initOptions(new CompilerOptions()); } return errorManager; }
public CompilerSupplier(FeatureSet outputFeatureSet) { // Use the default resolution mode this( outputFeatureSet, new CompilerOptions().getModuleResolutionMode(), ImmutableList.of(), ImmutableMap.of()); }
protected CompilerOptions options() { CompilerOptions options = new CompilerOptions(); setOptions(options); return options; }
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; }
/** * @return default {@link CompilerOptions} object to be used by compressor. */ protected CompilerOptions newCompilerOptions() { CompilerOptions options = new CompilerOptions(); /** * According to John Lenz from the Closure Compiler project, if you are using the Compiler API directly, you should specify a * CodingConvention. {@link http://code.google.com/p/wro4j/issues/detail?id=155} */ options.setCodingConvention(new ClosureCodingConvention()); // set it to warning, otherwise compiler will fail options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); return options; } }
@Override public void compress(Reader reader, Writer writer) throws CompressorException { com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler(); compiler.disableThreads(); CompilerOptions options = new CompilerOptions(); CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options); try { SourceFile inputFile = SourceFile.fromReader("input.js", reader); List<SourceFile> inputFiles = new ArrayList<>(); inputFiles.add(inputFile); List<SourceFile> externFiles = new ArrayList<>(); compiler.compile(externFiles, inputFiles, options); writer.write(compiler.toSource()); } catch(IOException x) { throw new CompressorException("Error while compressing javascript", x); } }
public ClosureCompiler() { //We have to ensure a safe concurrency as ModuleGenerator is session-scoped and //multiple sessions can generate the script at the same time. synchronized (lock) { this.options = new CompilerOptions(); CompilationLevel.WHITESPACE_ONLY.setOptionsForCompilationLevel(options); options.setVariableRenaming(VariableRenamingPolicy.OFF); options.setAngularPass(true); options.setTightenTypes(false); options.prettyPrint = false; } }
/** * @return default {@link com.google.javascript.jscomp.CompilerOptions} object to be used by compressor. */ protected CompilerOptions newCompilerOptions() { final CompilerOptions options = new CompilerOptions(); /** * According to John Lenz from the Closure Compiler project, if you are using the Compiler API directly, you * should specify a CodingConvention. {@link http://code.google.com/p/wro4j/issues/detail?id=155} */ options.setCodingConvention(new ClosureCodingConvention()); options.setOutputCharset(getEncoding()); //set it to warning, otherwise compiler will fail options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); return options; }
/** * @return default {@link CompilerOptions} object to be used by compressor. */ protected CompilerOptions newCompilerOptions() { final CompilerOptions options = new CompilerOptions(); /** * According to John Lenz from the Closure Compiler project, if you are using the Compiler API directly, you should * specify a CodingConvention. {@link http://code.google.com/p/wro4j/issues/detail?id=155} */ options.setCodingConvention(new ClosureCodingConvention()); // use the wro4j encoding by default options.setOutputCharset(getEncoding()); // set it to warning, otherwise compiler will fail options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); return options; }
private static CompilerOptions getOptions() { CompilerOptions options = new CompilerOptions(); options.setLanguageIn(LanguageMode.ECMASCRIPT6_STRICT); options.setLanguageOut(LanguageMode.ECMASCRIPT5); // Quoting keyword properties is only needed in ES3, so basically only in IE8. // But we set it explicitly here because the way the test bundler works, it invokes // the compiler without giving information about the browser, so we have to quote // every time to be safe :-/ options.setQuoteKeywordProperties(true); options.setSkipNonTranspilationPasses(true); options.setVariableRenaming(VariableRenamingPolicy.OFF); options.setPropertyRenaming(PropertyRenamingPolicy.OFF); options.setWrapGoogModulesForWhitespaceOnly(false); options.setPrettyPrint(true); return options; }