@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); }
void initCompilerOptionsIfTesting() { if (options == null) { // initialization for tests that don't initialize the compiler // by the normal mechanisms. initOptions(newCompilerOptions()); } }
@Override public ErrorManager getErrorManager() { if (options == null) { initOptions(new CompilerOptions()); } return errorManager; }
void initCompilerOptionsIfTesting() { if (options == null) { // initialization for tests that don't initialize the compiler // by the normal mechanisms. initOptions(newCompilerOptions()); } }
@Override public ErrorManager getErrorManager() { if (options == null) { initOptions(newCompilerOptions()); } return errorManager; }
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 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; }
compiler.initOptions(compilerOptions);
compiler.initOptions(compilerOptions);
compiler.initOptions(options); final Result result = compiler.compile(externs, inputs, options); listErrors(result);
@Override public CharSequence minify(final Config config, final CharSequence source) { final CompilerOptions options = new CompilerOptions(); options.setCodingConvention(new ClosureCodingConvention()); options.setOutputCharset("UTF-8"); options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); compilationLevel.setOptionsForCompilationLevel(options); Compiler.setLoggingLevel(Level.SEVERE); Compiler compiler = new Compiler(); compiler.disableThreads(); compiler.initOptions(options); String fname = removeExtension(config.getName()) + ".js"; Result result = compiler.compile(defaultExterns, Arrays.asList(SourceFile.fromCode(fname, source.toString())), options); if (result.success) { return compiler.toSource(); } JSError[] errors = result.errors; throw new IllegalStateException(errors[0].toString()); }
compiler.initOptions(options); final Result result = compiler.compile(externs, inputs, options); listErrors(result);
/** * Initializes the instance state needed for a compile job if the sources * are in modules. */ public <T extends SourceFile> void initModules( List<T> externs, List<JSModule> modules, CompilerOptions options) { initOptions(options); checkFirstModule(modules); this.externs = makeExternInputs(externs); // Generate the module graph, and report any errors in the module specification as errors. try { this.moduleGraph = new JSModuleGraph(modules); } catch (JSModuleGraph.ModuleDependenceException e) { // problems with the module format. Report as an error. The // message gives all details. report(JSError.make(MODULE_DEPENDENCY_ERROR, e.getModule().getName(), e.getDependentModule().getName())); return; } // Creating the module graph can move weak source around, and end up with empty modules. fillEmptyModules(getModules()); this.commentsPerFile = new ConcurrentHashMap<>(moduleGraph.getInputCount()); initBasedOnOptions(); initInputsByIdMap(); initAST(); }
private void initializeCompiler() { jscompiler = new Compiler(); options = new JXCompilerOptions(); //options.setLanguageIn(LanguageMode.ECMASCRIPT6_TYPED); //options.setLanguageOut(LanguageMode.ECMASCRIPT6_TYPED); options.setPreserveTypeAnnotations(true); options.setPrettyPrint(true); options.setLineLengthThreshold(80); options.setPreferSingleQuotes(true); //options.setIdeMode(true); options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE); options.setExternExports(false); options.setExtraAnnotationNames(Arrays.asList(asdocTags)); options.setLanguageIn(LanguageMode.ECMASCRIPT_2015); options.setLanguageIn(LanguageMode.ECMASCRIPT5_STRICT); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new NamespaceResolutionPass(model, jscompiler)); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new ResolvePackagesPass(model, jscompiler)); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new CollectTypesPass(model, jscompiler)); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new AddMemberPass(model, jscompiler)); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new CollectImportsPass(model, jscompiler)); //compiler.setErrorManager(testErrorManager); jscompiler.initOptions(options); // don't need custom error manager with es6->es5 language options //jscompiler.setErrorManager(wrapErrorManager(jscompiler.getErrorManager())); model.setJSCompiler(jscompiler); }
private void initializeCompiler() { jscompiler = new Compiler(); options = new JXCompilerOptions(); //options.setLanguageIn(LanguageMode.ECMASCRIPT6_TYPED); //options.setLanguageOut(LanguageMode.ECMASCRIPT6_TYPED); options.setPreserveTypeAnnotations(true); options.setPrettyPrint(true); options.setLineLengthThreshold(80); options.setPreferSingleQuotes(true); options.setIdeMode(true); options.setParseJsDocDocumentation(true); options.setExternExports(false); options.setExtraAnnotationNames(Arrays.asList(asdocTags)); options.setLanguageIn(LanguageMode.ECMASCRIPT6_STRICT); options.setLanguageIn(LanguageMode.ECMASCRIPT5_STRICT); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new NamespaceResolutionPass(model, jscompiler)); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new ResolvePackagesPass(model, jscompiler)); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new CollectTypesPass(model, jscompiler)); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new AddMemberPass(model, jscompiler)); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new CollectImportsPass(model, jscompiler)); //compiler.setErrorManager(testErrorManager); jscompiler.initOptions(options); // don't need custom error manager with es6->es5 language options //jscompiler.setErrorManager(wrapErrorManager(jscompiler.getErrorManager())); model.setJSCompiler(jscompiler); }
private void initializeCompiler() { jscompiler = new Compiler(); options = new JXCompilerOptions(); //options.setLanguageIn(LanguageMode.ECMASCRIPT6_TYPED); //options.setLanguageOut(LanguageMode.ECMASCRIPT6_TYPED); options.setPreserveTypeAnnotations(true); options.setPrettyPrint(true); options.setLineLengthThreshold(80); options.setPreferSingleQuotes(true); options.setIdeMode(true); options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE); options.setExternExports(false); options.setExtraAnnotationNames(Arrays.asList(asdocTags)); options.setLanguageIn(LanguageMode.ECMASCRIPT_2015); options.setLanguageIn(LanguageMode.ECMASCRIPT5_STRICT); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new NamespaceResolutionPass(model, jscompiler)); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new ResolvePackagesPass(model, jscompiler)); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new CollectTypesPass(model, jscompiler)); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new AddMemberPass(model, jscompiler)); options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new CollectImportsPass(model, jscompiler)); //compiler.setErrorManager(testErrorManager); jscompiler.initOptions(options); // don't need custom error manager with es6->es5 language options //jscompiler.setErrorManager(wrapErrorManager(jscompiler.getErrorManager())); model.setJSCompiler(jscompiler); }