Java Code Examples for com.google.javascript.jscomp.CompilerOptions#setParseJsDocDocumentation()

The following examples show how to use com.google.javascript.jscomp.CompilerOptions#setParseJsDocDocumentation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Options.java    From clutz with MIT License 5 votes vote down vote up
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);
  // We have to emit _TYPED, as any other mode triggers optimizations
  // in the Closure code printer. Notably optimizations break typed
  // syntax for arrow functions, by removing the surrounding parens
  // emitting `foo(x:string => x)`, which is invalid.
  options.setLanguageOut(LanguageMode.ECMASCRIPT6_TYPED);

  // 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);
  // Changing this to INCLUDE_DESCRIPTIONS_WITH_WHITESPACE, which feels more natural to the goals
  // of gents, makes no difference in golden test. Likely we ignore this info.
  options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE);

  options.clearConformanceConfigs();

  return options;
}
 
Example 2
Source File: CompilerModule.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
@Provides
CompilerOptions provideCompilerOptions(
    ProvidedSymbolPass providedSymbolPass,
    TypeCollectionPass typeCollectionPass,
    @Modules ImmutableSet<Path> modulePaths,
    Environment environment) {
  CompilerOptions options = new CompilerOptions();

  switch (environment) {
    case BROWSER:
      options.setEnvironment(CompilerOptions.Environment.BROWSER);
      options.setModuleResolutionMode(ModuleLoader.ResolutionMode.BROWSER);
      break;

    case NODE:
      options.setEnvironment(CompilerOptions.Environment.CUSTOM);
      options.setModuleResolutionMode(ModuleLoader.ResolutionMode.NODE);
      break;

    default:
      throw new AssertionError("unexpected environment: " + environment);
  }

  options.setModuleRoots(ImmutableList.of());

  options.setLanguageIn(LanguageMode.STABLE_IN);
  options.setLanguageOut(LanguageMode.STABLE_OUT);

  options.setCodingConvention(new ClosureCodingConvention());
  CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
  CompilationLevel.ADVANCED_OPTIMIZATIONS.setTypeBasedOptimizationOptions(options);

  options.setChecksOnly(true);
  options.setContinueAfterErrors(true);
  options.setAllowHotswapReplaceScript(true);
  options.setPreserveDetailedSourceInfo(true);
  options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_WITH_WHITESPACE);

  // For easier debugging.
  options.setPrettyPrint(true);

  options.addCustomPass(CustomPassExecutionTime.BEFORE_CHECKS, providedSymbolPass);
  options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, typeCollectionPass);

  return options;
}