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


Java LanguageMode.ECMASCRIPT3属性代码示例

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


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

示例1: shouldTraverse

@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,代码行数:21,代码来源:LateEs6ToEs3Converter.java

示例2: shouldTraverse

@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,代码行数:18,代码来源:Es6RewriteClass.java

示例3: shouldTraverse

/**
 * Some nodes must be visited pre-order in order to rewrite the
 * references to {@code this} correctly.
 * Everything else is translated post-order in {@link #visit}.
 */
@Override
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
  switch (n.getToken()) {
    case REST:
      visitRestParam(t, n, parent);
      break;
    case FOR_OF:
      // We will need this when we transpile for/of in LateEs6ToEs3Converter,
      // but we want the runtime functions to be have TypeI applied to it by the type checker.
      Es6ToEs3Util.preloadEs6RuntimeFunction(compiler, "makeIterator");
      break;
    case YIELD:
      if (n.isYieldAll()) {
        Es6ToEs3Util.preloadEs6RuntimeFunction(compiler, "makeIterator");
      }
      Es6ToEs3Util.preloadEs6Symbol(compiler);
      break;
    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,代码行数:40,代码来源:EarlyEs6ToEs3Converter.java

示例4: testGetterInEs3

public void testGetterInEs3() {
  // Getters and setters and not supported in ES3 but if someone sets the
  // the ES3 output mode on an AST containing them we still produce them.
  languageMode = LanguageMode.ECMASCRIPT3;

  Node getter = Node.newString(Token.GETTER_DEF, "f");
  getter.addChildToBack(NodeUtil.emptyFunction());
  assertPrintNode("({get f(){}})",
      IR.exprResult(IR.objectlit(getter)));
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:10,代码来源:CodePrinterTest.java

示例5: testSetterInEs3

public void testSetterInEs3() {
  // Getters and setters and not supported in ES3 but if someone sets the
  // the ES3 output mode on an AST containing them we still produce them.
  languageMode = LanguageMode.ECMASCRIPT3;

  Node getter = Node.newString(Token.SETTER_DEF, "f");
  getter.addChildToBack(IR.function(IR.name(""), IR.paramList(IR.name("a")), IR.block()));
  assertPrintNode("({set f(a){}})",
      IR.exprResult(IR.objectlit(getter)));
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:10,代码来源:CodePrinterTest.java

示例6: testKeywordProperties1

public void testKeywordProperties1() {
  languageMode = LanguageMode.ECMASCRIPT5;
  assertPrintSame("x.foo=2");
  assertPrintSame("x.function=2");

  languageMode = LanguageMode.ECMASCRIPT3;
  assertPrintSame("x.foo=2");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:8,代码来源:CodePrinterTest.java

示例7: testKeywordProperties2

public void testKeywordProperties2() {
  languageMode = LanguageMode.ECMASCRIPT5;
  assertPrintSame("x={foo:2}");
  assertPrintSame("x={function:2}");

  languageMode = LanguageMode.ECMASCRIPT3;
  assertPrintSame("x={foo:2}");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:8,代码来源:CodePrinterTest.java

示例8: visitArrayLitOrCallWithSpread

/**
 * Processes array literals or calls containing spreads. Examples:
 * [1, 2, ...x, 4, 5] => [].concat([1, 2], $jscomp.arrayFromIterable(x), [4, 5])
 *
 * f(...arr) => f.apply(null, [].concat($jscomp.arrayFromIterable(arr)))
 *
 * new F(...args) =>
 *     new Function.prototype.bind.apply(F, [].concat($jscomp.arrayFromIterable(args)))
 */
private void visitArrayLitOrCallWithSpread(Node node, Node parent) {
  checkArgument(node.isCall() || node.isArrayLit() || node.isNew());
  List<Node> groups = new ArrayList<>();
  Node currGroup = null;
  Node callee = node.isArrayLit() ? null : node.removeFirstChild();
  Node currElement = node.removeFirstChild();
  while (currElement != null) {
    if (currElement.isSpread()) {
      if (currGroup != null) {
        groups.add(currGroup);
        currGroup = null;
      }
      groups.add(Es6ToEs3Util.arrayFromIterable(compiler, currElement.removeFirstChild()));
    } else {
      if (currGroup == null) {
        currGroup = IR.arraylit();
      }
      currGroup.addChildToBack(currElement);
    }
    currElement = node.removeFirstChild();
  }
  if (currGroup != null) {
    groups.add(currGroup);
  }
  Node result = null;
  Node firstGroup = node.isNew() ? IR.arraylit(IR.nullNode()) : IR.arraylit();
  Node joinedGroups =
      IR.call(IR.getprop(firstGroup, IR.string("concat")), groups.toArray(new Node[0]));
  if (node.isArrayLit()) {
    result = joinedGroups;
  } else if (node.isCall()) {
    if (NodeUtil.mayHaveSideEffects(callee) && callee.isGetProp()) {
      Node statement = node;
      while (!NodeUtil.isStatement(statement)) {
        statement = statement.getParent();
      }
      Node freshVar = IR.name(FRESH_SPREAD_VAR + compiler.getUniqueNameIdSupplier().get());
      Node n = IR.var(freshVar.cloneTree());
      n.useSourceInfoIfMissingFromForTree(statement);
      statement.getParent().addChildBefore(n, statement);
      callee.addChildToFront(IR.assign(freshVar.cloneTree(), callee.removeFirstChild()));
      result = IR.call(
          IR.getprop(callee, IR.string("apply")),
          freshVar,
          joinedGroups);
    } else {
      Node context = callee.isGetProp() ? callee.getFirstChild().cloneTree() : IR.nullNode();
      result = IR.call(IR.getprop(callee, IR.string("apply")), context, joinedGroups);
    }
  } else {
    if (compiler.getOptions().getLanguageOut() == LanguageMode.ECMASCRIPT3) {
      // TODO(tbreisacher): Support this in ES3 too by not relying on Function.bind.
      Es6ToEs3Util.cannotConvert(
          compiler, node, "\"...\" passed to a constructor (consider using --language_out=ES5)");
    }
    Node bindApply = NodeUtil.newQName(compiler,
        "Function.prototype.bind.apply");
    result = IR.newNode(IR.call(bindApply, callee, joinedGroups));
  }
  result.useSourceInfoIfMissingFromForTree(node);
  parent.replaceChild(node, result);
  compiler.reportChangeToEnclosingScope(result);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:72,代码来源:EarlyEs6ToEs3Converter.java

示例9: setUp

@Override
protected void setUp() throws Exception {
  super.setUp();
  setAcceptedLanguage(LanguageMode.ECMASCRIPT_2015);
  languageOut = LanguageMode.ECMASCRIPT3;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:6,代码来源:Es6RewriteArrowFunctionTest.java

示例10: testKeywordProperties1a

public void testKeywordProperties1a() {
  languageMode = LanguageMode.ECMASCRIPT5;
  Node nodes = parse("x.function=2");
  languageMode = LanguageMode.ECMASCRIPT3;
  assertPrintNode("x[\"function\"]=2", nodes);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:6,代码来源:CodePrinterTest.java

示例11: testKeywordProperties2a

public void testKeywordProperties2a() {
  languageMode = LanguageMode.ECMASCRIPT5;
  Node nodes = parse("x={function:2}");
  languageMode = LanguageMode.ECMASCRIPT3;
  assertPrintNode("x={\"function\":2}", nodes);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:6,代码来源:CodePrinterTest.java


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