class ExpandJqueryAliases extends NodeTraversal.AbstractPostOrderCallback implements CompilerPass
Modifier and Type | Class and Description |
---|---|
(package private) static class |
ExpandJqueryAliases.FindCallbackArgumentReferences
Given a jQuery.expandedEach callback function, traverse it and collect any
references to its parameter names.
|
Modifier and Type | Field and Description |
---|---|
private AbstractCompiler |
compiler |
private CodingConvention |
convention |
private static java.lang.String |
JQUERY_EXPANDED_EACH_NAME |
private static java.util.Set<java.lang.String> |
JQUERY_EXTEND_NAMES |
(package private) static DiagnosticType |
JQUERY_UNABLE_TO_EXPAND_INVALID_LIT_ERROR |
(package private) static DiagnosticType |
JQUERY_UNABLE_TO_EXPAND_INVALID_NAME_ERROR |
(package private) static DiagnosticType |
JQUERY_USELESS_EACH_EXPANSION |
private static java.util.logging.Logger |
logger |
private PeepholeOptimizationsPass |
peepholePasses |
Constructor and Description |
---|
ExpandJqueryAliases(AbstractCompiler compiler) |
Modifier and Type | Method and Description |
---|---|
private boolean |
isArrayLitValidForExpansion(Node n) |
boolean |
isJqueryExpandedEachCall(Node call,
java.lang.String qName) |
static boolean |
isJqueryExtendCall(Node n,
java.lang.String qname,
AbstractCompiler compiler)
Check that Node n is a call to one of the jQuery.extend methods that we
can expand.
|
private void |
maybeExpandJqueryEachCall(NodeTraversal t,
Node n)
Expand a jQuery.expandedEach call
Expanded jQuery.expandedEach calls will replace the GETELEM nodes of a
property assignment with GETPROP nodes to allow for renaming.
|
private void |
maybeExpandJqueryExtendCall(Node n)
Expand jQuery.extend (and derivative) calls into direct object assignments
Example: jQuery.extend(obj1, {prop1: val1, prop2: val2}) ->
obj1.prop1 = val1;
obj1.prop2 = val2;
|
private void |
maybeReplaceJqueryPrototypeAlias(Node n) |
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
private void |
replaceOriginalJqueryEachCall(Node n,
Node expandedBlock) |
private Node |
tryExpandJqueryEachCall(NodeTraversal t,
Node n,
Node callbackFunction,
java.util.List<Node> keyNodes,
java.util.List<Node> valueNodes) |
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
shouldTraverse
private final AbstractCompiler compiler
private final CodingConvention convention
private static final java.util.logging.Logger logger
static final DiagnosticType JQUERY_UNABLE_TO_EXPAND_INVALID_LIT_ERROR
static final DiagnosticType JQUERY_UNABLE_TO_EXPAND_INVALID_NAME_ERROR
static final DiagnosticType JQUERY_USELESS_EACH_EXPANSION
private static final java.util.Set<java.lang.String> JQUERY_EXTEND_NAMES
private static final java.lang.String JQUERY_EXPANDED_EACH_NAME
private final PeepholeOptimizationsPass peepholePasses
ExpandJqueryAliases(AbstractCompiler compiler)
public static boolean isJqueryExtendCall(Node n, java.lang.String qname, AbstractCompiler compiler)
public boolean isJqueryExpandedEachCall(Node call, java.lang.String qName)
public void visit(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in postorder (after its children have been visited).
A node is visited only if all its parents should be traversed
(NodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)
).
Implementations can have side effects (e.g. modifying the parse tree).
visit
in interface NodeTraversal.Callback
public void process(Node externs, Node root)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treeprivate void maybeReplaceJqueryPrototypeAlias(Node n)
private void maybeExpandJqueryExtendCall(Node n)
private void maybeExpandJqueryEachCall(NodeTraversal t, Node n)
private Node tryExpandJqueryEachCall(NodeTraversal t, Node n, Node callbackFunction, java.util.List<Node> keyNodes, java.util.List<Node> valueNodes)
private void replaceOriginalJqueryEachCall(Node n, Node expandedBlock)
private boolean isArrayLitValidForExpansion(Node n)