com.google.javascript.jscomp.parsing.Config Java Examples

The following examples show how to use com.google.javascript.jscomp.parsing.Config. 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: Closure_59_Compiler_s.java    From coming with MIT License 6 votes vote down vote up
@Override
Config getParserConfig() {
  if (parserConfig == null) {
    Config.LanguageMode mode;
    switch (options.getLanguageIn()) {
      case ECMASCRIPT3:
        mode = Config.LanguageMode.ECMASCRIPT3;
        break;
      case ECMASCRIPT5:
        mode = Config.LanguageMode.ECMASCRIPT5;
        break;
      case ECMASCRIPT5_STRICT:
        mode = Config.LanguageMode.ECMASCRIPT5_STRICT;
        break;
      default:
        throw new IllegalStateException("unexpected language mode");
    }

    parserConfig = ParserRunner.createConfig(
      isIdeMode(),
      mode,
      acceptConstKeyword(),
      options.extraAnnotationNames);
  }
  return parserConfig;
}
 
Example #2
Source File: Closure_59_Compiler_t.java    From coming with MIT License 6 votes vote down vote up
@Override
Config getParserConfig() {
  if (parserConfig == null) {
    Config.LanguageMode mode;
    switch (options.getLanguageIn()) {
      case ECMASCRIPT3:
        mode = Config.LanguageMode.ECMASCRIPT3;
        break;
      case ECMASCRIPT5:
        mode = Config.LanguageMode.ECMASCRIPT5;
        break;
      case ECMASCRIPT5_STRICT:
        mode = Config.LanguageMode.ECMASCRIPT5_STRICT;
        break;
      default:
        throw new IllegalStateException("unexpected language mode");
    }

    parserConfig = ParserRunner.createConfig(
      isIdeMode(),
      mode,
      acceptConstKeyword(),
      options.extraAnnotationNames);
  }
  return parserConfig;
}
 
Example #3
Source File: Closure_18_Compiler_t.java    From coming with MIT License 6 votes vote down vote up
@Override
Config getParserConfig() {
  if (parserConfig == null) {
    Config.LanguageMode mode;
    switch (options.getLanguageIn()) {
      case ECMASCRIPT3:
        mode = Config.LanguageMode.ECMASCRIPT3;
        break;
      case ECMASCRIPT5:
        mode = Config.LanguageMode.ECMASCRIPT5;
        break;
      case ECMASCRIPT5_STRICT:
        mode = Config.LanguageMode.ECMASCRIPT5_STRICT;
        break;
      default:
        throw new IllegalStateException("unexpected language mode");
    }

    parserConfig = ParserRunner.createConfig(
      isIdeMode(),
      mode,
      acceptConstKeyword(),
      options.extraAnnotationNames);
  }
  return parserConfig;
}
 
Example #4
Source File: Closure_18_Compiler_s.java    From coming with MIT License 6 votes vote down vote up
@Override
Config getParserConfig() {
  if (parserConfig == null) {
    Config.LanguageMode mode;
    switch (options.getLanguageIn()) {
      case ECMASCRIPT3:
        mode = Config.LanguageMode.ECMASCRIPT3;
        break;
      case ECMASCRIPT5:
        mode = Config.LanguageMode.ECMASCRIPT5;
        break;
      case ECMASCRIPT5_STRICT:
        mode = Config.LanguageMode.ECMASCRIPT5_STRICT;
        break;
      default:
        throw new IllegalStateException("unexpected language mode");
    }

    parserConfig = ParserRunner.createConfig(
      isIdeMode(),
      mode,
      acceptConstKeyword(),
      options.extraAnnotationNames);
  }
  return parserConfig;
}
 
Example #5
Source File: Closure_64_Compiler_s.java    From coming with MIT License 6 votes vote down vote up
@Override
Config getParserConfig() {
  if (parserConfig == null) {
    Config.LanguageMode mode;
    switch (options.getLanguageIn()) {
      case ECMASCRIPT3:
        mode = Config.LanguageMode.ECMASCRIPT3;
        break;
      case ECMASCRIPT5:
        mode = Config.LanguageMode.ECMASCRIPT5;
        break;
      case ECMASCRIPT5_STRICT:
        mode = Config.LanguageMode.ECMASCRIPT5_STRICT;
        break;
      default:
        throw new IllegalStateException("unexpected language mode");
    }

    parserConfig = ParserRunner.createConfig(
      isIdeMode(),
      mode,
      acceptConstKeyword());
  }
  return parserConfig;
}
 
Example #6
Source File: Closure_64_Compiler_t.java    From coming with MIT License 6 votes vote down vote up
@Override
Config getParserConfig() {
  if (parserConfig == null) {
    Config.LanguageMode mode;
    switch (options.getLanguageIn()) {
      case ECMASCRIPT3:
        mode = Config.LanguageMode.ECMASCRIPT3;
        break;
      case ECMASCRIPT5:
        mode = Config.LanguageMode.ECMASCRIPT5;
        break;
      case ECMASCRIPT5_STRICT:
        mode = Config.LanguageMode.ECMASCRIPT5_STRICT;
        break;
      default:
        throw new IllegalStateException("unexpected language mode");
    }

    parserConfig = ParserRunner.createConfig(
      isIdeMode(),
      mode,
      acceptConstKeyword());
  }
  return parserConfig;
}
 
Example #7
Source File: Closure_31_Compiler_s.java    From coming with MIT License 6 votes vote down vote up
@Override
Config getParserConfig() {
  if (parserConfig == null) {
    Config.LanguageMode mode;
    switch (options.getLanguageIn()) {
      case ECMASCRIPT3:
        mode = Config.LanguageMode.ECMASCRIPT3;
        break;
      case ECMASCRIPT5:
        mode = Config.LanguageMode.ECMASCRIPT5;
        break;
      case ECMASCRIPT5_STRICT:
        mode = Config.LanguageMode.ECMASCRIPT5_STRICT;
        break;
      default:
        throw new IllegalStateException("unexpected language mode");
    }

    parserConfig = ParserRunner.createConfig(
      isIdeMode(),
      mode,
      acceptConstKeyword(),
      options.extraAnnotationNames);
  }
  return parserConfig;
}
 
Example #8
Source File: Closure_31_Compiler_t.java    From coming with MIT License 6 votes vote down vote up
@Override
Config getParserConfig() {
  if (parserConfig == null) {
    Config.LanguageMode mode;
    switch (options.getLanguageIn()) {
      case ECMASCRIPT3:
        mode = Config.LanguageMode.ECMASCRIPT3;
        break;
      case ECMASCRIPT5:
        mode = Config.LanguageMode.ECMASCRIPT5;
        break;
      case ECMASCRIPT5_STRICT:
        mode = Config.LanguageMode.ECMASCRIPT5_STRICT;
        break;
      default:
        throw new IllegalStateException("unexpected language mode");
    }

    parserConfig = ParserRunner.createConfig(
      isIdeMode(),
      mode,
      acceptConstKeyword(),
      options.extraAnnotationNames);
  }
  return parserConfig;
}
 
Example #9
Source File: Compiler.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
Config getParserConfig() {
  if (parserConfig == null) {
    Config.LanguageMode mode;
    switch (options.getLanguageIn()) {
      case ECMASCRIPT3:
        mode = Config.LanguageMode.ECMASCRIPT3;
        break;
      case ECMASCRIPT5:
        mode = Config.LanguageMode.ECMASCRIPT5;
        break;
      case ECMASCRIPT5_STRICT:
        mode = Config.LanguageMode.ECMASCRIPT5_STRICT;
        break;
      default:
        throw new IllegalStateException("unexpected language mode");
    }

    parserConfig = ParserRunner.createConfig(
      isIdeMode(),
      mode,
      acceptConstKeyword(),
      options.extraAnnotationNames);
  }
  return parserConfig;
}
 
Example #10
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 #11
Source File: Options.java    From clutz with MIT License 4 votes vote down vote up
public CompilerOptions getCompilerOptions() {
  final CompilerOptions options = new CompilerOptions();
  options.setClosurePass(true);
  options.setTracerMode(this.tracerMode);
  // TODO(b/142973207): Set this to false after clutz supports native module checking
  options.setBadRewriteModulesBeforeTypecheckingThatWeWantToGetRidOf(true);

  if (this.entryPoints.isEmpty()) {
    options.setDependencyOptions(DependencyOptions.sortOnly());
  } else {
    ImmutableList<ModuleIdentifier> entryPointIdentifiers =
        this.entryPoints.stream().map(ModuleIdentifier::forClosure).collect(toImmutableList());
    options.setDependencyOptions(
        DependencyOptions.pruneLegacyForEntryPoints(entryPointIdentifiers));
  }

  // 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 seem to
  // affect the quality of produced .d.ts.
  Logger phaseLogger = Logger.getLogger("com.google.javascript.jscomp.PhaseOptimizer");
  phaseLogger.setLevel(Level.OFF);

  // All diagnostics are WARNINGs (or off) and thus ignored unless debug == true.
  // Only report issues (and fail for them) that are specifically causing problems for Clutz.
  // The idea is to not do a general sanity check of Closure code, just make sure Clutz works.
  // Report missing types as errors.
  options.setCheckGlobalNamesLevel(CheckLevel.ERROR);
  // Report duplicate definitions, e.g. for accidentally duplicated externs.
  options.setWarningLevel(DiagnosticGroups.DUPLICATE_VARS, CheckLevel.ERROR);

  // Late Provides are errors by default, but they do not prevent clutz from transpiling.
  options.setWarningLevel(DiagnosticGroups.LATE_PROVIDE, CheckLevel.OFF);

  // Always parse and analyze the latest language features closure supports.
  options.setLanguage(LanguageMode.ECMASCRIPT_NEXT);
  options.setLanguageOut(LanguageMode.ECMASCRIPT5);

  options.setModuleResolutionMode(ModuleLoader.ResolutionMode.BROWSER_WITH_TRANSFORMED_PREFIXES);
  ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
  for (String str : browserResolverStrippedPrefixes) {
    builder.put(str, "/");
  }
  options.setBrowserResolverPrefixReplacements(builder.build());

  if (closureEnv != null) {
    options.setEnvironment(closureEnv);
  }
  options.setCheckTypes(true);
  options.setInferTypes(true);
  // turns off optimizations.
  options.setChecksOnly(true);
  options.setPreserveDetailedSourceInfo(true);
  options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE);
  options.clearConformanceConfigs();
  options.setAssumeForwardDeclaredForMissingTypes(true);
  options.setWarningLevel(DiagnosticGroups.MISSING_SOURCES_WARNINGS, CheckLevel.OFF);
  return options;
}
 
Example #12
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;
}
 
Example #13
Source File: AbstractCompiler.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the parser configuration.
 */
abstract Config getParserConfig();