本文整理汇总了Java中com.google.javascript.jscomp.GlobalNamespace.Name.canEliminate方法的典型用法代码示例。如果您正苦于以下问题:Java Name.canEliminate方法的具体用法?Java Name.canEliminate怎么用?Java Name.canEliminate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.jscomp.GlobalNamespace.Name
的用法示例。
在下文中一共展示了Name.canEliminate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateObjLitOrFunctionDeclarationAtVarNode
import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
* Updates the first initialization (a.k.a "declaration") of a global name
* that occurs at a VAR node. See comment for
* {@link #updateObjLitOrFunctionDeclaration}.
*
* @param n An object representing a global name (e.g. "a")
*/
private void updateObjLitOrFunctionDeclarationAtVarNode(Name n) {
Ref ref = n.declaration;
String name = ref.node.getString();
Node rvalue = ref.node.getFirstChild();
Node varNode = ref.node.getParent();
Node gramps = varNode.getParent();
boolean isObjLit = rvalue.getType() == Token.OBJECTLIT;
int numChanges = 0;
if (isObjLit) {
boolean discardKeys = n.aliasingGets == 0;
numChanges += declareVarsForObjLitValues(
n, name, rvalue, varNode, gramps.getChildBefore(varNode),
gramps, discardKeys);
}
numChanges += addStubsForUndeclaredProperties(n, name, gramps, varNode);
if (isObjLit && n.canEliminate()) {
varNode.removeChild(ref.node);
if (!varNode.hasChildren()) {
gramps.removeChild(varNode);
}
numChanges++;
// Clear out the object reference, since we've eliminated it from the
// parse tree.
ref.node = null;
}
if (numChanges > 0) {
compiler.reportCodeChange();
}
}
示例2: updateObjLitOrFunctionDeclarationAtVarNode
import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
* Updates the first initialization (a.k.a "declaration") of a global name
* that occurs at a VAR node. See comment for
* {@link #updateObjLitOrFunctionDeclaration}.
*
* @param n An object representing a global name (e.g. "a")
*/
private void updateObjLitOrFunctionDeclarationAtVarNode(
Name n, boolean canCollapseChildNames) {
if (!canCollapseChildNames) {
return;
}
Ref ref = n.getDeclaration();
String name = ref.node.getString();
Node rvalue = ref.node.getFirstChild();
Node varNode = ref.node.getParent();
Node gramps = varNode.getParent();
boolean isObjLit = rvalue.isObjectLit();
int numChanges = 0;
if (isObjLit) {
numChanges += declareVarsForObjLitValues(
n, name, rvalue, varNode, gramps.getChildBefore(varNode),
gramps);
}
numChanges += addStubsForUndeclaredProperties(n, name, gramps, varNode);
if (isObjLit && n.canEliminate()) {
varNode.removeChild(ref.node);
if (!varNode.hasChildren()) {
gramps.removeChild(varNode);
}
numChanges++;
// Clear out the object reference, since we've eliminated it from the
// parse tree.
ref.node = null;
}
if (numChanges > 0) {
compiler.reportCodeChange();
}
}
示例3: canEliminate
import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
private boolean canEliminate(Name name) {
if (!name.canEliminate()) {
return false;
}
if (name.props == null
|| name.props.isEmpty()
|| propertyCollapseLevel != PropertyCollapseLevel.MODULE_EXPORT) {
return true;
}
return false;
}
示例4: updateObjLitOrFunctionDeclarationAtAssignNode
import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
* Updates the first initialization (a.k.a "declaration") of a global name
* that occurs at an ASSIGN node. See comment for
* {@link #updateObjLitOrFunctionDeclaration}.
*
* @param n An object representing a global name (e.g. "a", "a.b.c")
* @param alias The flattened name for {@code n} (e.g. "a", "a$b$c")
*/
private void updateObjLitOrFunctionDeclarationAtAssignNode(
Name n, String alias) {
// NOTE: It's important that we don't add additional nodes
// (e.g. a var node before the exprstmt) because the exprstmt might be
// the child of an if statement that's not inside a block).
Ref ref = n.declaration;
Node rvalue = ref.node.getNext();
Node varNode = new Node(Token.VAR);
Node varParent = ref.node.getAncestor(3);
Node gramps = ref.node.getAncestor(2);
boolean isObjLit = rvalue.getType() == Token.OBJECTLIT;
if (isObjLit && n.canEliminate()) {
// Eliminate the object literal altogether.
varParent.replaceChild(gramps, varNode);
ref.node = null;
} else {
if (rvalue.getType() == Token.FUNCTION) {
checkForHosedThisReferences(rvalue, n.docInfo, n);
}
ref.node.getParent().removeChild(rvalue);
Node nameNode = NodeUtil.newName(
alias, ref.node.getAncestor(2), n.fullName());
if (ref.node.getLastChild().getBooleanProp(Node.IS_CONSTANT_NAME)) {
nameNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
}
varNode.addChildToBack(nameNode);
nameNode.addChildToFront(rvalue);
varParent.replaceChild(gramps, varNode);
// Update the node ancestry stored in the reference.
ref.node = nameNode;
}
if (isObjLit) {
boolean discardKeys = n.aliasingGets == 0;
declareVarsForObjLitValues(
n, alias, rvalue,
varNode, varParent.getChildBefore(varNode), varParent,
discardKeys);
}
addStubsForUndeclaredProperties(n, alias, varParent, varNode);
if (!varNode.hasChildren()) {
varParent.removeChild(varNode);
}
compiler.reportCodeChange();
}
示例5: updateObjLitOrFunctionDeclarationAtAssignNode
import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
* Updates the first initialization (a.k.a "declaration") of a global name
* that occurs at an ASSIGN node. See comment for
* {@link #updateObjLitOrFunctionDeclaration}.
*
* @param n An object representing a global name (e.g. "a", "a.b.c")
* @param alias The flattened name for {@code n} (e.g. "a", "a$b$c")
*/
private void updateObjLitOrFunctionDeclarationAtAssignNode(
Name n, String alias, boolean canCollapseChildNames) {
// NOTE: It's important that we don't add additional nodes
// (e.g. a var node before the exprstmt) because the exprstmt might be
// the child of an if statement that's not inside a block).
Ref ref = n.getDeclaration();
Node rvalue = ref.node.getNext();
Node varNode = new Node(Token.VAR);
Node varParent = ref.node.getAncestor(3);
Node gramps = ref.node.getAncestor(2);
boolean isObjLit = rvalue.isObjectLit();
boolean insertedVarNode = false;
if (isObjLit && n.canEliminate()) {
// Eliminate the object literal altogether.
varParent.replaceChild(gramps, varNode);
ref.node = null;
insertedVarNode = true;
} else if (!n.isSimpleName()) {
// Create a VAR node to declare the name.
if (rvalue.isFunction()) {
checkForHosedThisReferences(rvalue, n.docInfo, n);
}
ref.node.getParent().removeChild(rvalue);
Node nameNode = NodeUtil.newName(
compiler.getCodingConvention(),
alias, ref.node.getAncestor(2), n.getFullName());
JSDocInfo info = ref.node.getParent().getJSDocInfo();
if (ref.node.getLastChild().getBooleanProp(Node.IS_CONSTANT_NAME) ||
(info != null && info.isConstant())) {
nameNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
}
if (info != null) {
varNode.setJSDocInfo(info);
}
varNode.addChildToBack(nameNode);
nameNode.addChildToFront(rvalue);
varParent.replaceChild(gramps, varNode);
// Update the node ancestry stored in the reference.
ref.node = nameNode;
insertedVarNode = true;
}
if (canCollapseChildNames) {
if (isObjLit) {
declareVarsForObjLitValues(
n, alias, rvalue,
varNode, varParent.getChildBefore(varNode), varParent);
}
addStubsForUndeclaredProperties(n, alias, varParent, varNode);
}
if (insertedVarNode) {
if (!varNode.hasChildren()) {
varParent.removeChild(varNode);
}
compiler.reportCodeChange();
}
}