com.google.javascript.jscomp.DiagnosticGroups Java Examples

The following examples show how to use com.google.javascript.jscomp.DiagnosticGroups. 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: ClosureJsInteropGenerator.java    From jsinterop-generator with Apache License 2.0 5 votes vote down vote up
private CompilerOptions createCompilerOptions() {
  CompilerOptions options = new CompilerOptions();

  options.setLanguageOut(ECMASCRIPT5);
  options.setChecksOnly(true);
  options.setStrictModeInput(true);
  options.setCheckTypes(true);
  options.setPreserveDetailedSourceInfo(true);
  options.setWarningLevel(DiagnosticGroups.UNRECOGNIZED_TYPE_ERROR, CheckLevel.ERROR);

  return options;
}
 
Example #2
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 #3
Source File: CompileTask.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private CompilerOptions createCompilerOptions() {
  CompilerOptions options = new CompilerOptions();

  this.compilationLevel.setOptionsForCompilationLevel(options);
  if (this.debugOptions) {
    this.compilationLevel.setDebugOptionsForCompilationLevel(options);
  }

  options.prettyPrint = this.prettyPrint;
  options.printInputDelimiter = this.printInputDelimiter;
  options.generateExports = this.generateExports;

  options.setLanguageIn(this.languageIn);

  this.warningLevel.setOptionsForWarningLevel(options);
  options.setManageClosureDependencies(manageDependencies);

  if (replaceProperties) {
    convertPropertiesMap(options);
  }

  convertDefineParameters(options);

  for (Warning warning : warnings) {
    CheckLevel level = warning.getLevel();
    String groupName = warning.getGroup();
    DiagnosticGroup group = new DiagnosticGroups().forName(groupName);
    if (group == null) {
      throw new BuildException(
          "Unrecognized 'warning' option value (" + groupName + ")");
    }
    options.setWarningLevel(group, level);
  }

  return options;
}
 
Example #4
Source File: CheckDebuggerStatementTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected CompilerOptions getOptions() {
  CompilerOptions options = super.getOptions();
  if (checkLevel != null) {
    options.setWarningLevel(
        DiagnosticGroups.DEBUGGER_STATEMENT_PRESENT,
        checkLevel);
  }
  return options;
}