本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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)));
}
示例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)));
}
示例6: testKeywordProperties1
public void testKeywordProperties1() {
languageMode = LanguageMode.ECMASCRIPT5;
assertPrintSame("x.foo=2");
assertPrintSame("x.function=2");
languageMode = LanguageMode.ECMASCRIPT3;
assertPrintSame("x.foo=2");
}
示例7: testKeywordProperties2
public void testKeywordProperties2() {
languageMode = LanguageMode.ECMASCRIPT5;
assertPrintSame("x={foo:2}");
assertPrintSame("x={function:2}");
languageMode = LanguageMode.ECMASCRIPT3;
assertPrintSame("x={foo:2}");
}
示例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);
}
示例9: setUp
@Override
protected void setUp() throws Exception {
super.setUp();
setAcceptedLanguage(LanguageMode.ECMASCRIPT_2015);
languageOut = LanguageMode.ECMASCRIPT3;
}
示例10: testKeywordProperties1a
public void testKeywordProperties1a() {
languageMode = LanguageMode.ECMASCRIPT5;
Node nodes = parse("x.function=2");
languageMode = LanguageMode.ECMASCRIPT3;
assertPrintNode("x[\"function\"]=2", nodes);
}
示例11: testKeywordProperties2a
public void testKeywordProperties2a() {
languageMode = LanguageMode.ECMASCRIPT5;
Node nodes = parse("x={function:2}");
languageMode = LanguageMode.ECMASCRIPT3;
assertPrintNode("x={\"function\":2}", nodes);
}