• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java LanguageMode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testStaticSetter

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public void testStaticSetter() {
  setLanguageOut(LanguageMode.ECMASCRIPT5);
  test(
      "class C { static set foo(x) {} }",
      lines(
          "/** @constructor @struct */",
          "let C = function() {};",
          "/** @nocollapse @type {?} */",
          "C.foo;",
          "$jscomp.global.Object.defineProperties(C, {",
          "  foo: {",
          "    configurable: true,",
          "    enumerable: true,",
          "    /** @this {C} */",
          "    set: function(x) {}",
          "  }",
          "});"));
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:19,代码来源:Es6RewriteClassTest.java


示例17: disabled_testRestObjectPatternParametersNonTranspiling

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public void disabled_testRestObjectPatternParametersNonTranspiling() {
  CompilerOptions options = createCompilerOptions();
  CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
  options.setLanguageIn(LanguageMode.ECMASCRIPT_2017);
  options.setLanguageOut(LanguageMode.ECMASCRIPT_2017);
  externs = DEFAULT_EXTERNS;

  test(
      options,
      LINE_JOINER.join(
          "function countArgs(x, ...{length}) {",
          "  return length;",
          "}",
          "alert(countArgs(1, 1, 1, 1, 1));"),
      "alert(4);");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:17,代码来源:IntegrationTest.java


示例18: overrideOptions

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
@Override
protected void overrideOptions(final CompilerOptions options) {
    super.overrideOptions(options);
    WarningLevel.QUIET.setOptionsForWarningLevel(options);
    //http://stackoverflow.com/questions/13261325/how-can-i-set-the-language-in-option-for-the-closure-compiler
    options.setLanguageIn(LanguageMode.ECMASCRIPT5);
}
 
开发者ID:subes,项目名称:invesdwin-nowicket,代码行数:8,代码来源:ConfiguredGoogleClosureJavaScriptCompressor.java


示例19: getCompilerOptions

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public CompilerOptions getCompilerOptions() {
  final CompilerOptions options = new CompilerOptions();
  options.setClosurePass(true);

  DependencyOptions deps = new DependencyOptions();
  deps.setDependencySorting(true);
  options.setDependencyOptions(deps);

  if (!this.entryPoints.isEmpty()) {
    options.setManageClosureDependencies(this.entryPoints);
  }

  // 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);

  options.setLanguage(LanguageMode.ECMASCRIPT_2017);
  options.setLanguageOut(LanguageMode.ECMASCRIPT5);
  options.setCheckTypes(true);
  options.setInferTypes(true);
  // turns off optimizations.
  options.setChecksOnly(true);
  options.setPreserveDetailedSourceInfo(true);
  options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE);
  if (partialInput) {
    options.setAssumeForwardDeclaredForMissingTypes(true);
    options.setWarningLevel(DiagnosticGroups.MISSING_SOURCES_WARNINGS, CheckLevel.OFF);
  }
  return options;
}
 
开发者ID:angular,项目名称:clutz,代码行数:38,代码来源:Options.java


示例20: testExtendedObjLitComputedPropName1

import com.google.javascript.jscomp.CompilerOptions.LanguageMode; //导入依赖的package包/类
public void testExtendedObjLitComputedPropName1() {
  testRewriteError(
      lines(
          "var FancyClass = goog.defineClass(null, {",
          "  ['someCompProp_' + 42]: 47,",
          "  someMember: 49,",
          "  constructor: function() {},",
          "});"),
      GOOG_CLASS_ES6_COMPUTED_PROP_NAMES_NOT_SUPPORTED,
      LanguageMode.ECMASCRIPT_2015);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:12,代码来源:ClosureRewriteClassTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DefaultIndenter类代码示例发布时间:2022-05-21
下一篇:
Java RemoteDevice类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap