@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; }
private CompilerOptions createCompilerOptions() { CompilerOptions options = new CompilerOptions(); options.setEnvironment(this.environment); options.setPrettyPrint(this.prettyPrint); options.setPrintInputDelimiter(this.printInputDelimiter); options.setPreferSingleQuotes(this.preferSingleQuotes); options.setGenerateExports(this.generateExports); options.setLanguageIn(this.languageIn); options.setLanguageOut(this.languageOut); options.setOutputCharset(this.outputEncoding); options.setManageClosureDependencies(manageDependencies); convertEntryPointParameters(options); options.setTrustedStrings(true); options.setAngularPass(angularPass); options.setWarningLevel(group, level); options.setSourceMapFormat(Format.valueOf(sourceMapFormat)); String[] tokens = sourceMapLocationMapping.split("\\|", -1); LocationMapping lm = new LocationMapping(tokens[0], tokens[1]); options.setSourceMapLocationMappings(Arrays.asList(lm)); options.setSourceMapOutputPath(parentFile.getAbsolutePath());
log.debug("Using Google Closure Compiler engine."); CompilerOptions options = new CompilerOptions(); closureConfig.getCompilationLevel().setOptionsForCompilationLevel(options); options.setOutputCharset(charset); options.setLanguageIn(closureConfig.getLanguageIn()); options.setLanguageOut(closureConfig.getLanguageOut()); options.setDependencyOptions(closureConfig.getDependencyOptions()); options.setColorizeErrorOutput(closureConfig.getColorizeErrorOutput()); options.setAngularPass(closureConfig.getAngularPass()); options.setExtraAnnotationNames(closureConfig.getExtraAnnotations()); options.setDefineReplacements(closureConfig.getDefineReplacements()); options.setSourceMapFormat(closureConfig.getSourceMapFormat()); options.setSourceMapOutputPath(sourceMapResult.getPath()); options.setWarningLevel(warningLevel.getKey(), warningLevel.getValue());
options_.setDefineToBooleanLiteral("goog.DEBUG", false); options_.setLanguageIn(LanguageMode.ECMASCRIPT5_STRICT); options_.setPreferSingleQuotes(true); options_.setFoldConstants(true); options_.setDeadAssignmentElimination(true); options_.setInlineConstantVars(true); options_.setInlineFunctions(true); options_.setInlineLocalVariables(true); options_.setCrossChunkCodeMotion(true); options_.setCoalesceVariableNames(true); options_.setCrossChunkMethodMotion(true); options_.setInlineProperties(true); options_.setInlineVariables(true); options_.setSmartNameRemoval(true); options_.setRemoveDeadCode(true); options_.setExtractPrototypeMemberDeclarations(true); options_.setRemoveUnusedPrototypeProperties(true); options_.setRemoveUnusedPrototypePropertiesInExterns(false); options_.setRemoveUnusedClassProperties(true); options_.setRemoveUnusedVariables(CompilerOptions.Reach.ALL); options_.setCollapseVariableDeclarations(true); options_.setCollapseAnonymousFunctions(true); options_.setAliasAllStrings(true); options_.setConvertToDottedProperties(true); options_.setRewriteFunctionExpressions(true); options_.setOptimizeCalls(true);
options_.setDefineToBooleanLiteral("goog.DEBUG", false); options_.setLanguageIn(LanguageMode.ECMASCRIPT5_STRICT); options_.setPreferSingleQuotes(true); options_.setFoldConstants(true); options_.setDeadAssignmentElimination(true); options_.setInlineConstantVars(true); options_.setInlineFunctions(true); options_.setInlineLocalFunctions(true); options_.setCrossModuleCodeMotion(true); options_.setCoalesceVariableNames(true); options_.setCrossModuleMethodMotion(true); options_.setInlineProperties(true); options_.setInlineVariables(true); options_.setSmartNameRemoval(true); options_.setRemoveDeadCode(true); options_.setExtractPrototypeMemberDeclarations(true); options_.setRemoveUnusedPrototypeProperties(true); options_.setRemoveUnusedPrototypePropertiesInExterns(false); options_.setRemoveUnusedClassProperties(true); options_.setRemoveUnusedVariables(CompilerOptions.Reach.ALL); options_.setCollapseVariableDeclarations(true); options_.setCollapseAnonymousFunctions(true); options_.setAliasAllStrings(true); options_.setConvertToDottedProperties(true); options_.setRewriteFunctionExpressions(true); options_.setOptimizeParameters(true);
CompilerOptions options = new CompilerOptions(); options.setTrustedStrings(true); options.setEnvironment(CompilerOptions.Environment.BROWSER); options.setProcessCommonJSModules(true); options.setConvertToDottedProperties(false); options.setModuleResolutionMode(ModuleLoader.ResolutionMode.NODE); options.setDependencyOptions(new DependencyOptions() .setDependencyPruning(true) .setDependencySorting(true) options.setRenamingPolicy(VariableRenamingPolicy.OFF, PropertyRenamingPolicy.OFF); options.setInlineVariables(Reach.NONE); options.setInlineFunctions(Reach.NONE); options.setPrettyPrint(true); options.setFoldConstants(false); options.setCoalesceVariableNames(false); options.setCollapseVariableDeclarations(false); options.setSourceMapOutputPath(args.sourceMap.getPath()); options.setEmitUseStrict(false); options.setLanguageIn(CompilerOptions.LanguageMode.ECMASCRIPT5_STRICT); options.setLanguageOut(CompilerOptions.LanguageMode.ECMASCRIPT5_STRICT); } else { options.setLanguageIn(CompilerOptions.LanguageMode.ECMASCRIPT_2015);
@Override protected CompilerOptions createOptions() { CompilerOptions options = new CompilerOptions(); CompilerOptions.LanguageMode.fromString(flags.languageIn); if (languageMode != null) { options.setLanguageIn(languageMode); } else { throw new FlagUsageException("Unknown language `" + flags.languageIn + "' specified."); options.setLanguageOut(options.getLanguageIn()); } else { CompilerOptions.LanguageMode languageMode = CompilerOptions.LanguageMode.fromString(flags.languageOut); if (languageMode != null) { options.setLanguageOut(languageMode); } else { throw new FlagUsageException("Unknown language `" + flags.languageOut + "' specified."); options.setCodingConvention(new ClosureCodingConvention()); options.setExtraAnnotationNames(flags.extraAnnotationName); options.setNumParallelThreads(flags.numParallelThreads); options.setEnvironment(flags.environment); options.setChecksOnly(flags.checksOnly); if (flags.checksOnly) { options.setOutputJs(CompilerOptions.OutputJs.NONE);
/** * Allow subclasses to override the default CompileOptions object. */ protected CompilerOptions newCompilerOptions() { return new CompilerOptions(); }
options.setDependencyOptions(DependencyOptions.sortOnly()); options.setCheckSymbols(true); options.setCheckTypes(true); options.setClosurePass(true); options.setFoldConstants(true); options.setCoalesceVariableNames(true); options.setDeadAssignmentElimination(true); options.setExtractPrototypeMemberDeclarations(true); options.setCollapseVariableDeclarations(true); options.setConvertToDottedProperties(true); options.setLabelRenaming(true); options.setRemoveDeadCode(true); options.setOptimizeArgumentsArray(true); options.setCollapseObjectLiterals(true); options.setProtectHiddenSideEffects(true); options.setRemoveClosureAsserts(true); options.setRemoveAbstractMethods(true); options.setReserveRawExports(true); options.setRenamingPolicy(VariableRenamingPolicy.ALL, PropertyRenamingPolicy.ALL_UNQUOTED); options.setShadowVariables(true); options.setRemoveUnusedPrototypeProperties(true); options.setRemoveUnusedPrototypePropertiesInExterns(false); options.setRemoveUnusedClassProperties(true); options.setCollapseAnonymousFunctions(true); options.setCollapsePropertiesLevel(PropertyCollapseLevel.ALL); options.setCheckGlobalThisLevel(CheckLevel.WARNING);
@Override protected CompilerOptions createOptions() { CompilerOptions options = new CompilerOptions(); CompilerOptions.LanguageMode.fromString(flags.languageIn); if (languageMode != null) { options.setLanguageIn(languageMode); } else { throw new FlagUsageException("Unknown language `" + flags.languageIn + "' specified."); options.setLanguageOut(options.getLanguageIn()); } else { CompilerOptions.LanguageMode languageMode = CompilerOptions.LanguageMode.fromString(flags.languageOut); if (languageMode != null) { options.setLanguageOut(languageMode); } else { throw new FlagUsageException("Unknown language `" + flags.languageOut + "' specified."); options.setCodingConvention(new JqueryCodingConvention()); } else { options.setCodingConvention(new ClosureCodingConvention()); options.setExtraAnnotationNames(flags.extraAnnotationName); options.setEnvironment(flags.environment); options.setChecksOnly(flags.checksOnly); options.setGenerateExports(flags.generateExports);
public CompilerOptions getCompilerOptions() { final CompilerOptions options = new CompilerOptions(); options.setClosurePass(true); options.setTracerMode(this.tracerMode); options.setDependencyOptions(DependencyOptions.sortOnly()); } else { ImmutableList<ModuleIdentifier> entryPointIdentifiers = this.entryPoints.stream().map(ModuleIdentifier::forClosure).collect(toImmutableList()); options.setDependencyOptions( DependencyOptions.pruneLegacyForEntryPoints(entryPointIdentifiers)); options.setCheckGlobalNamesLevel(CheckLevel.ERROR); options.setWarningLevel(DiagnosticGroups.DUPLICATE_VARS, CheckLevel.ERROR); options.setWarningLevel(DiagnosticGroups.LATE_PROVIDE, CheckLevel.OFF); options.setLanguage(LanguageMode.ECMASCRIPT_NEXT); options.setLanguageOut(LanguageMode.ECMASCRIPT5); options.setModuleResolutionMode(ModuleLoader.ResolutionMode.BROWSER_WITH_TRANSFORMED_PREFIXES); ImmutableMap.Builder builder = ImmutableMap.builder(); for (String str : browserResolverStrippedPrefixes) { builder.put(str, "/"); options.setBrowserResolverPrefixReplacements(builder.build()); options.setEnvironment(closureEnv);
public CompilerOptions getCompilerOptions() { final CompilerOptions options = new CompilerOptions(); options.setClosurePass(true); // Turns off common warning messages, when PhaseOptimizer decides to skip some passes due to // unsupported code constructs. They are not very actionable to users and do not matter to // gents. Logger phaseLogger = Logger.getLogger("com.google.javascript.jscomp.PhaseOptimizer"); phaseLogger.setLevel(Level.OFF); 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_NEXT); 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); options.clearConformanceConfigs(); return options; }
static void lint(Path path, Compiler compiler) throws IOException { SourceFile file = SourceFile.fromFile(path.toString()); CompilerOptions options = new CompilerOptions(); options.setLanguage(LanguageMode.ECMASCRIPT_NEXT); options.setParseJsDocDocumentation(JsDocParsing.INCLUDE_DESCRIPTIONS_WITH_WHITESPACE); options.setPreserveDetailedSourceInfo(true); options.setPrettyPrint(true); options.setPreserveTypeAnnotations(true); options.setPreferSingleQuotes(true); options.setEmitUseStrict(false); options.setParseJsDocDocumentation(INCLUDE_DESCRIPTIONS_WITH_WHITESPACE); options.setCodingConvention(new GoogleCodingConvention()); options.setWarningLevel(DiagnosticGroups.CHECK_TYPES, CheckLevel.WARNING); options.setWarningLevel(DiagnosticGroups.JSDOC_MISSING_TYPE, CheckLevel.ERROR); options.setWarningLevel(DiagnosticGroups.MISPLACED_MSG_ANNOTATION, CheckLevel.WARNING); options.setWarningLevel(DiagnosticGroups.UNNECESSARY_ESCAPE, CheckLevel.WARNING); options.setWarningLevel(DiagnosticGroups.LINT_CHECKS, CheckLevel.WARNING); options.setWarningLevel(DiagnosticGroups.UNUSED_LOCAL_VARIABLE, CheckLevel.WARNING); options.setWarningLevel(DiagnosticGroups.UNUSED_PRIVATE_PROPERTY, CheckLevel.WARNING); options.setWarningLevel(DiagnosticGroups.STRICT_MISSING_REQUIRE, CheckLevel.ERROR); options.setWarningLevel(DiagnosticGroups.EXTRA_REQUIRE, CheckLevel.ERROR); options.setWarningLevel(DiagnosticGroups.USE_OF_GOOG_BASE, CheckLevel.WARNING); options.setWarningLevel(DiagnosticGroups.MISPLACED_SUPPRESS, CheckLevel.WARNING); options.setWarningLevel(DiagnosticGroups.TYPE_IMPORT_CODE_REFERENCES, CheckLevel.ERROR); options.setSummaryDetailLevel(0); compiler.setPassConfig(new LintPassConfig(options));
@VisibleForTesting public static CompilerOptions getCompilerOptions() { CompilerOptions options = new CompilerOptions(); DependencyOptions deps = new DependencyOptions(); deps.setDependencySorting(true); options.setDependencyOptions(deps); options.setIdeMode(true); options.setCheckSuspiciousCode(true); options.setCheckSymbols(true); options.setCheckTypes(true); options.setClosurePass(true); options.setGenerateExports(true); options.setPreserveGoogRequires(true); options.setWarningLevel(DiagnosticGroups.MISSING_REQUIRE, CheckLevel.ERROR); 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; }
private static void lint(String filename, boolean fix) throws IOException { SourceFile file = SourceFile.fromFile(filename); Compiler compiler = new Compiler(System.out); CompilerOptions options = new CompilerOptions(); options.setLanguage(LanguageMode.ECMASCRIPT6_STRICT); options.setSkipTranspilationAndCrash(true); options.setIdeMode(true); options.setCodingConvention(new GoogleCodingConvention()); options.setWarningLevel(DiagnosticGroups.CHECK_TYPES, CheckLevel.WARNING); options.setWarningLevel(DiagnosticGroups.LINT_CHECKS, CheckLevel.WARNING); options.setWarningLevel(DiagnosticGroups.MISSING_REQUIRE, CheckLevel.WARNING); options.setWarningLevel(DiagnosticGroups.EXTRA_REQUIRE, CheckLevel.WARNING); compiler.setPassConfig(new LintPassConfig(options)); compiler.disableThreads();
/** * @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()); //set it to warning, otherwise compiler will fail options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); //Initialise source map options if (googleClosureMap) { options.setSourceMapFormat(SourceMap.Format.DEFAULT); } return options; }
protected void setOptions(CompilerOptions options) { options.setLanguageIn(LanguageMode.ECMASCRIPT_NEXT); options.setOutputFeatureSet(outputFeatureSet.without(Feature.MODULES)); options.setEmitUseStrict(false); options.setQuoteKeywordProperties(true); options.setSkipNonTranspilationPasses(true); options.setVariableRenaming(VariableRenamingPolicy.OFF); options.setPropertyRenaming(PropertyRenamingPolicy.OFF); options.setWrapGoogModulesForWhitespaceOnly(false); options.setPrettyPrint(true); options.setWarningLevel(ES5_WARNINGS, CheckLevel.OFF); options.setWarningLevel(DiagnosticGroups.NON_STANDARD_JSDOC, CheckLevel.OFF); options.setEs6ModuleTranspilation(Es6ModuleTranspilation.TO_COMMON_JS_LIKE_MODULES); options.setModuleResolutionMode(moduleResolution); options.setModuleRoots(moduleRoots); options.setBrowserResolverPrefixReplacements(prefixReplacements); options.setPathEscaper(PathEscaper.CANONICALIZE_ONLY); options.setSourceMapOutputPath("/dev/null"); options.setSourceMapIncludeSourcesContent(true); options.setSourceMapLocationMappings( ImmutableList.of((location) -> { try {
/** * @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; } }