Java Code Examples for com.google.javascript.rhino.Node#isStringKey()
The following examples show how to use
com.google.javascript.rhino.Node#isStringKey() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeConversionPass.java From clutz with MIT License | 5 votes |
/** Converts goog.defineClass calls into class definitions. */ private void convertDefineClassToClass(Node n) { Preconditions.checkState(n.isCall()); Node superClass = n.getSecondChild(); if (superClass.isNull()) { superClass = IR.empty(); } else { superClass.detach(); } Node classMembers = new Node(Token.CLASS_MEMBERS); classMembers.useSourceInfoFrom(n); for (Node child : n.getLastChild().children()) { if (child.isStringKey() || child.isMemberFunctionDef()) { // Handle static methods if ("statics".equals(child.getString())) { for (Node child2 : child.getFirstChild().children()) { convertObjectLiteral(classMembers, child2, true); } } else { // prototype methods convertObjectLiteral(classMembers, child, false); } } else { // Add all other members, such as EMPTY comment nodes, as is. child.detach(); classMembers.addChildToBack(child); } } Node classNode = new Node(Token.CLASS, IR.empty(), superClass, classMembers); classNode.useSourceInfoFrom(n); nodeComments.replaceWithComment(n, classNode); }
Example 2
Source File: TypeConversionPass.java From clutz with MIT License | 5 votes |
/** return if node n is a @constructor annotated function inside goog.defineClass */ private boolean isConstructorInGoogDefineClass(Node n) { // CALL // GETPROP // NAME goog // STRING defineClass // NULL|super class node // OBJECTLIT // STRING_KEY constructor // FUNCTION <- n if (n == null) { return false; } @Nullable Node stringKey = n.getParent(); if (stringKey == null || !stringKey.isStringKey() || !"constructor".equals(stringKey.getString())) { return false; } @Nullable Node objectlit = stringKey.getParent(); if (objectlit == null) { return false; } @Nullable Node call = objectlit.getParent(); if (call == null || !call.getFirstChild().matchesQualifiedName("goog.defineClass")) { return false; } return true; }
Example 3
Source File: ClosureRewriteClass.java From astor with GNU General Public License v2.0 | 5 votes |
private boolean isContainedInGoogDefineClass(Node n) { while (n != null) { n = n.getParent(); if (n.isCall()) { if (isGoogDefineClass(n)) { return true; } } else if (!n.isObjectLit() && !n.isStringKey()) { break; } } return false; }
Example 4
Source File: ClosureRewriteClass.java From astor with GNU General Public License v2.0 | 5 votes |
private boolean validateObjLit(Node objlit) { for (Node key : objlit.children()) { if (!key.isStringKey() || key.isQuotedString()) { return false; } } return true; }
Example 5
Source File: ClosureRewriteClass.java From astor with GNU General Public License v2.0 | 5 votes |
/** * @return The first property in the objlit that matches the key. */ private Node extractProperty(Node objlit, String keyName) { for (Node keyNode : objlit.children()) { if (keyNode.getString().equals(keyName)) { return keyNode.isStringKey() ? keyNode.getFirstChild() : null; } } return null; }
Example 6
Source File: InlineProperties.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public void visit(NodeTraversal t, Node n, Node parent) { boolean invalidatingPropRef = false; String propName = null; if (n.isGetProp()) { propName = n.getLastChild().getString(); if (t.getInput().isExtern()) { // Any extern reference invalidates invalidatingPropRef = true; } else if (parent.isAssign()) { invalidatingPropRef = !maybeCandidateDefinition(t, n, parent); } else if (NodeUtil.isLValue(n)) { // Other LValue references invalidate invalidatingPropRef = true; } else if (parent.isDelProp()) { // Deletes invalidate invalidatingPropRef = true; } else { // A property read doesn't invalidate invalidatingPropRef = false; } } else if (n.isStringKey()) { propName = n.getString(); if (t.getInput().isExtern()) { // Any extern reference invalidates invalidatingPropRef = true; } else { // For now, any object literal key invalidates // TODO(johnlenz): support prototype properties like: // foo.prototype = { a: 1, b: 2 }; invalidatingPropRef = true; } } if (invalidatingPropRef) { Preconditions.checkNotNull(propName); invalidateProperty(propName); } }
Example 7
Source File: DevirtualizePrototypeMethods.java From astor with GNU General Public License v2.0 | 5 votes |
private String getMethodName(Node node) { if (node.isGetProp()) { return node.getLastChild().getString(); } else if (node.isStringKey()) { return node.getString(); } else { throw new IllegalStateException("unexpected"); } }
Example 8
Source File: Normalize.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (NodeUtil.isExprAssign(n)) { Node assign = n.getFirstChild(); Node lhs = assign.getFirstChild(); if (lhs.isGetProp() && isMarkedExpose(assign)) { exposedProperties.add(lhs.getLastChild().getString()); } } else if (n.isStringKey() && isMarkedExpose(n)) { exposedProperties.add(n.getString()); } }
Example 9
Source File: Denormalize.java From astor with GNU General Public License v2.0 | 4 votes |
@Override public void visit(NodeTraversal t, Node node, Node parent) { if (node.isName() || node.isString() || node.isStringKey()) { node.removeProp(Node.IS_CONSTANT_NAME); } }
Example 10
Source File: GentsNodeUtil.java From clutz with MIT License | 3 votes |
/** * Returns true is the object is an object literal where all values are simple symbols references: * * <p>{A, B, C} -> true * * <p>{A, B: B} -> true * * <p>{A: C} -> true * * <p>{A: A + 1} -> false * * <p>{A: f(1)} -> false */ public static boolean isObjLitWithSimpleRefs(Node node) { if (!node.isObjectLit()) return false; for (Node child : node.children()) { if (!child.isStringKey() || !child.getFirstChild().isName()) { return false; } } return true; }