protected Compiler getCompiler() { return new Compiler(); }
@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 Compiler compiler() { return new Compiler(); }
protected Compiler compiler() { return new Compiler(); }
@Override protected Compiler createCompiler() { return new Compiler(getErrorPrintStream()); }
@Override protected Compiler createCompiler() { return new Compiler(getErrorPrintStream()); }
static void lint(String filename) throws IOException { lint(Paths.get(filename), new Compiler(System.out)); }
private Compiler createCompiler( List<SourceFile> inputs, List<SourceFile> externs, CompilerOptions compilerOptions) { Compiler compiler = new Compiler(); compiler.disableThreads(); compiler.compile(externs, inputs, compilerOptions); return compiler; }
@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); } }
private Compiler createCompiler(CompilerOptions options) { Compiler compiler = new Compiler(); MessageFormatter formatter = options.getErrorFormat().toFormatter(compiler, false); AntErrorManager errorManager = new AntErrorManager(formatter, this); compiler.setErrorManager(errorManager); return compiler; }
private Compiler newCompiler(final CompilerOptions compilerOptions) { Compiler.setLoggingLevel(Level.SEVERE); final Compiler compiler = new Compiler(); compilationLevel.setOptionsForCompilationLevel(compilerOptions); // make it play nice with GAE compiler.disableThreads(); compiler.initOptions(compilerOptions); return compiler; }
private Compiler newCompiler(final CompilerOptions compilerOptions) { Compiler.setLoggingLevel(Level.SEVERE); final Compiler compiler = new Compiler(); compilationLevel.setOptionsForCompilationLevel(compilerOptions); // make it play nice with GAE compiler.disableThreads(); compiler.initOptions(compilerOptions); return compiler; }
private Compiler createCompiler(CompilerOptions options) { Compiler compiler = new Compiler(); MessageFormatter formatter = options.getErrorFormat().toFormatter(compiler, false); AntErrorManager errorManager = new AntErrorManager(formatter, this); compiler.setErrorManager(errorManager); return compiler; }
TypeScriptGenerator(Options opts) { this.opts = opts; this.compiler = new Compiler(); compiler.disableThreads(); setErrorStream(System.err); this.pathUtil = new PathUtil(opts.root, opts.absolutePathPrefix); this.nameUtil = new NameUtil(compiler); }
private Compiler newCompiler(CompilerOptions compilerOptions, CompilationLevel compilationLevel) { Compiler.setLoggingLevel(Level.SEVERE); Compiler compiler = new Compiler(); compilationLevel.setOptionsForCompilationLevel(compilerOptions); // make it play nice with GAE compiler.disableThreads(); compiler.initOptions(compilerOptions); return compiler; }
/** @return Whether any fixes were applied. */ private static boolean fix(String filename, ImmutableSet<DiagnosticType> unfixableErrors) throws IOException { Compiler compiler = new Compiler(System.out); FixingErrorManager errorManager = new FixingErrorManager(unfixableErrors); compiler.setErrorManager(errorManager); errorManager.setCompiler(compiler); lint(Paths.get(filename), compiler); Collection<SuggestedFix> fixes = errorManager.getSureFixes(); if (!fixes.isEmpty()) { ApplySuggestedFixes.applySuggestedFixesToFiles(fixes); return true; } return false; } }
/** Generates the runtime by requesting the "es6_runtime" library from the compiler. */ private static String getEs6Runtime() { CompilerOptions options = getOptions(); options.setLanguageOut(LanguageMode.ECMASCRIPT3); // change .delete to ['delete'] options.setForceLibraryInjection(ImmutableList.of("es6_runtime")); Compiler compiler = new Compiler(); // Threads can't be used in small unit tests. compiler.disableThreads(); SourceFile externs = SourceFile.fromCode("externs", "function Symbol() {}"); SourceFile sourceFile = SourceFile.fromCode("source", ""); compiler.compile(ImmutableList.of(externs), ImmutableList.of(sourceFile), options); return compiler.toSource(); } }
public String compile(String code) { Compiler compiler = new Compiler(); compiler.disableThreads(); SourceFile extern = SourceFile.fromCode("externs.js","function alert(x) {}"); SourceFile input = SourceFile.fromCode("input.js", code); compiler.compile(extern, input, options); return compiler.toSource(); } }
public static String compile(String code) { Compiler compiler = new Compiler(); CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options); JSSourceFile extern = JSSourceFile.fromCode("externs.js","function alert(x) {}"); // The dummy input name "input.js" is used here so that any warnings or // errors will cite line numbers in terms of input.js. JSSourceFile input = JSSourceFile.fromCode("input.js", code); // compile() returns a Result, but it is not needed here. compiler.compile(extern, input, options); // The compiler is responsible for generating the compiled code; it is not // accessible via the Result. return compiler.toSource(); }
protected CompileResult doCompileContent(JsContent content, CompilerOptions options, List<SourceFile> externs) throws CompilerException { Compiler compiler = new Compiler(getErrorManager()); // We shouldn't reuse compilers // disable JS Closure Compiler internal thread compiler.disableThreads(); SourceFile source = SourceFile.fromCode(content.getSource(), content.get()); Result result = compiler.compile(externs, Lists.newArrayList(source), options); if (result.errors.length > 0) { throw new CompilerException(result.errors); } return new CompileResult(compiler, result); }