当前位置: 首页>>代码示例>>Java>>正文


Java LanguageMode类代码示例

本文整理汇总了Java中com.google.javascript.jscomp.CompilerOptions.LanguageMode的典型用法代码示例。如果您正苦于以下问题:Java LanguageMode类的具体用法?Java LanguageMode怎么用?Java LanguageMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LanguageMode类属于com.google.javascript.jscomp.CompilerOptions包,在下文中一共展示了LanguageMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTraverseAtScopeWithModuleScope

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public void testTraverseAtScopeWithModuleScope() {
  Compiler compiler = new Compiler();
  CompilerOptions options = new CompilerOptions();
  options.setLanguageIn(LanguageMode.ECMASCRIPT_NEXT);
  compiler.initOptions(options);
  Es6SyntacticScopeCreator creator = new Es6SyntacticScopeCreator(compiler);
  ExpectNodeOnEnterScope callback = new ExpectNodeOnEnterScope();
  NodeTraversal t = new NodeTraversal(compiler, callback, creator);

  String code = lines(
      "goog.module('example.module');",
      "",
      "var x;");

  Node tree = parse(compiler, code);
  Scope globalScope = creator.createScope(tree, null);
  Node moduleBody = tree.getFirstChild();
  Scope moduleScope = creator.createScope(moduleBody, globalScope);

  callback.expect(moduleBody, moduleBody);

  t.traverseAtScope(moduleScope);

  callback.assertEntered();
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:26,代码来源:NodeTraversalTest.java

示例2: testLanguageMode

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public void testLanguageMode() {
  CompilerOptions options = createCompilerOptions();
  options.setLanguageIn(LanguageMode.ECMASCRIPT3);

  String code = "var a = {get f(){}}";

  Compiler compiler = compile(options, code);
  checkUnexpectedErrorsOrWarnings(compiler, 1);
  assertEquals(
      "JSC_PARSE_ERROR. Parse error. " +
      "getters are not supported in older versions of JS. " +
      "If you are targeting newer versions of JS, " +
      "set the appropriate language_in option. " +
      "at i0 line 1 : 0",
      compiler.getErrors()[0].toString());

  options.setLanguageIn(LanguageMode.ECMASCRIPT5);

  testSame(options, code);

  options.setLanguageIn(LanguageMode.ECMASCRIPT5_STRICT);

  testSame(options, code);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:IntegrationTest.java

示例3: testIssue598

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public void testIssue598() {
  CompilerOptions options = createCompilerOptions();
  options.setLanguageIn(LanguageMode.ECMASCRIPT5_STRICT);
  WarningLevel.VERBOSE.setOptionsForWarningLevel(options);

  options.setLanguageIn(LanguageMode.ECMASCRIPT5);

  String code =
      "'use strict';\n" +
      "function App() {}\n" +
      "App.prototype = {\n" +
      "  get appData() { return this.appData_; },\n" +
      "  set appData(data) { this.appData_ = data; }\n" +
      "};";

  Compiler compiler = compile(options, code);
  testSame(options, code);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:IntegrationTest.java

示例4: getOptions

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
/**
 * Gets the compiler options to use for this test. Use getProcessor to
 * determine what passes should be run.
 */
protected CompilerOptions getOptions(CompilerOptions options) {
  if (this.acceptES5) {
    options.setLanguageIn(LanguageMode.ECMASCRIPT5);
  }

  // This doesn't affect whether checkSymbols is run--it just affects
  // whether variable warnings are filtered.
  options.checkSymbols = true;

  options.setWarningLevel(
      DiagnosticGroups.MISSING_PROPERTIES, CheckLevel.WARNING);
  options.setWarningLevel(
      DiagnosticGroups.CAST, CheckLevel.WARNING);
  options.setCodingConvention(getCodingConvention());
  return options;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:CompilerTestCase.java

示例5: testExtendedObjLitMethodDefinition4

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public void testExtendedObjLitMethodDefinition4() {
  testRewrite(
      lines(
          "var FancyClass = goog.defineClass(null, {",
          "  constructor() {},",
          "  statics:{",
          "    someMethod1() {}",
          "  },",
          "  someMethod2() {}",
          "});"),
      lines(
          "/** @constructor @struct */",
          "var FancyClass = function() {};",
          "FancyClass.someMethod1 = function() {};",
          "FancyClass.prototype.someMethod2 = function() {};"),
      LanguageMode.ECMASCRIPT_2015);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:18,代码来源:ClosureRewriteClassTest.java

示例6: parse

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
Node parse(String js, boolean checkTypes) {
  Compiler compiler = new Compiler();
  CompilerOptions options = new CompilerOptions();
  options.setTrustedStrings(trustedStrings);

  // Allow getters and setters.
  options.setLanguageIn(LanguageMode.ECMASCRIPT5);
  compiler.initOptions(options);
  Node n = compiler.parseTestCode(js);

  if (checkTypes) {
    DefaultPassConfig passConfig = new DefaultPassConfig(null);
    CompilerPass typeResolver = passConfig.resolveTypes.create(compiler);
    Node externs = new Node(Token.SCRIPT);
    externs.setInputId(new InputId("externs"));
    Node externAndJsRoot = new Node(Token.BLOCK, externs, n);
    externAndJsRoot.setIsSyntheticBlock(true);
    typeResolver.process(externs, n);
    CompilerPass inferTypes = passConfig.inferTypes.create(compiler);
    inferTypes.process(externs, n);
  }

  checkUnexpectedErrorsOrWarnings(compiler, 0);
  return n;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:CodePrinterTest.java

示例7: shouldTraverse

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
@Override
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
  switch (n.getToken()) {
    case GETTER_DEF:
    case SETTER_DEF:
      if (compiler.getOptions().getLanguageOut() == LanguageMode.ECMASCRIPT3) {
        Es6ToEs3Util.cannotConvert(
            compiler, n, "ES5 getters/setters (consider using --language_out=ES5)");
        return false;
      }
      break;
    case FUNCTION:
      if (n.isAsyncFunction()) {
        throw new IllegalStateException("async functions should have already been converted");
      }
      break;
    default:
      break;
  }
  return true;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:22,代码来源:LateEs6ToEs3Converter.java

示例8: testExtendedObjLitArrowFunction3

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public void testExtendedObjLitArrowFunction3() {
  testRewrite(
      lines(
          "var FancyClass = goog.defineClass(null, {",
          "  constructor: function() {},",
          "  statics:{",
          "    someFunction() {",
          "      return () => 42",
          "    }",
          "  }",
          "});"),
      lines(
          "/** @constructor @struct */",
          "  var FancyClass = function() {};",
          "  FancyClass.someFunction = function() {",
          "    return () => 42",
          "  };"),
      LanguageMode.ECMASCRIPT_2015);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:20,代码来源:ClosureRewriteClassTest.java

示例9: shouldTraverse

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
@Override
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
  switch (n.getToken()) {
    case GETTER_DEF:
    case SETTER_DEF:
      if (compiler.getOptions().getLanguageOut() == LanguageMode.ECMASCRIPT3) {
        cannotConvert(n, "ES5 getters/setters (consider using --language_out=ES5)");
        return false;
      }
      break;
    case NEW_TARGET:
      cannotConvertYet(n, "new.target");
      break;
    default:
      break;
  }
  return true;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:19,代码来源:Es6RewriteClass.java

示例10: testBlocksInCaseArePreserved

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public void testBlocksInCaseArePreserved() throws Exception {
  languageMode = LanguageMode.ECMASCRIPT_2015;
  String js = LINE_JOINER.join(
      "switch(something) {",
      "  case 0:",
      "    {",
      "      const x = 1;",
      "      break;",
      "    }",
      "  case 1:",
      "    break;",
      "  case 2:",
      "    console.log(`case 2!`);",
      "    {",
      "      const x = 2;",
      "      break;",
      "    }",
      "}",
      "");
  assertPrettyPrint(js, js);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:22,代码来源:CodePrinterTest.java

示例11: setOptions

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
protected void setOptions(CompilerOptions options) {
  options.setLanguageIn(LanguageMode.ECMASCRIPT_2017);
    // TODO(sdh): It would be nice to allow people to output code in
    // strict mode.  But currently we swallow all the input language
    // strictness checks, and there are various tests that are never
    // compiled and so are broken when we output 'use strict'.  We
    // could consider adding some sort of logging/warning/error in
    // cases where the input was not strict, though there could still
    // be semantic differences even if syntax is strict.  Possibly
    // the first step would be to allow the option of outputting strict
    // and then change the default and see what breaks.  b/33005948
    options.setLanguageOut(LanguageMode.ECMASCRIPT5);
    options.setQuoteKeywordProperties(true);
    options.setSkipNonTranspilationPasses(true);
    options.setVariableRenaming(VariableRenamingPolicy.OFF);
    options.setPropertyRenaming(PropertyRenamingPolicy.OFF);
    options.setWrapGoogModulesForWhitespaceOnly(false);
    options.setPrettyPrint(true);
    options.setSourceMapOutputPath("/dev/null");
    options.setSourceMapIncludeSourcesContent(true);
    options.setWarningLevel(ES5_WARNINGS, CheckLevel.OFF);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:23,代码来源:CompilerBasedTransformer.java

示例12: testImportedNames

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public void testImportedNames() throws Exception {
  List<SourceFile> inputs =
      ImmutableList.of(
          SourceFile.fromCode("/index[0].js", "import foo from './foo.js'; foo('hello');"),
          SourceFile.fromCode("/foo.js", "export default (foo) => { alert(foo); }"));

  List<ModuleIdentifier> entryPoints = ImmutableList.of(ModuleIdentifier.forFile("/index[0].js"));

  CompilerOptions options = new CompilerOptions();
  CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
  options.setLanguage(CompilerOptions.LanguageMode.ECMASCRIPT_2017);
  options.dependencyOptions.setDependencyPruning(true);
  options.dependencyOptions.setDependencySorting(true);
  options.dependencyOptions.setEntryPoints(entryPoints);

  List<SourceFile> externs =
      AbstractCommandLineRunner.getBuiltinExterns(options.getEnvironment());

  Compiler compiler = new Compiler();
  compiler.compile(externs, inputs, options);

  Result result = compiler.getResult();
  assertThat(result.errors).isEmpty();
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:25,代码来源:VarCheckTest.java

示例13: getDefaultOptions

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
@Override
protected CompilerOptions getDefaultOptions() {
  CompilerOptions options = new CompilerOptions();
  options.setLanguageIn(LanguageMode.ECMASCRIPT5);
  options.setWarningLevel(
      DiagnosticGroups.MISSING_PROPERTIES, CheckLevel.WARNING);
  options.setWarningLevel(
      DiagnosticGroups.MISPLACED_TYPE_ANNOTATION, CheckLevel.WARNING);
  options.setWarningLevel(
      DiagnosticGroups.INVALID_CASTS, CheckLevel.WARNING);
  options.setWarningLevel(DiagnosticGroups.LINT_CHECKS, CheckLevel.WARNING);
  options.setCodingConvention(getCodingConvention());
  options.setPreserveTypeAnnotations(true);
  options.setPrettyPrint(true);
  return options;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:17,代码来源:PolymerClassRewriterTest.java

示例14: testLanguageMode2

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public void testLanguageMode2() {
  CompilerOptions options = createCompilerOptions();
  options.setWarningLevel(DiagnosticGroups.ES5_STRICT, CheckLevel.OFF);

  String code = "var a  = 2; delete a;";

  options.setLanguageIn(LanguageMode.ECMASCRIPT3);
  testSame(options, code);

  options.setLanguageIn(LanguageMode.ECMASCRIPT5);
  testSame(options, code);

  options.setLanguageIn(LanguageMode.ECMASCRIPT5_STRICT);
  test(options,
      code,
      code,
      StrictModeCheck.DELETE_VARIABLE);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:19,代码来源:IntegrationTest.java

示例15: testArrowFunction

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public void testArrowFunction() {
  languageMode = LanguageMode.ECMASCRIPT_2015;
  assertPrintSame("()=>1");
  assertPrint("(()=>1)", "()=>1");
  assertPrintSame("()=>{}");
  assertPrint("a=>b", "(a)=>b");
  assertPrint("(a=>b)(1)", "((a)=>b)(1)");
  assertPrintSame("var z={x:(a)=>1}");
  assertPrint("(a,b)=>b", "(a,b)=>b");
  assertPrintSame("()=>(a,b)");
  assertPrint("(()=>a),b", "()=>a,b");
  assertPrint("()=>(a=b)", "()=>a=b");
  assertPrintSame("[1,2].forEach((x)=>y)");
  assertPrintSame("()=>({a:1})");
  assertPrintSame("()=>{return 1}");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:17,代码来源:CodePrinterTest.java


注:本文中的com.google.javascript.jscomp.CompilerOptions.LanguageMode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。