class ClosureRewriteClass extends NodeTraversal.AbstractPostOrderCallback implements HotSwapCompilerPass
Modifier and Type | Class and Description |
---|---|
private static class |
ClosureRewriteClass.ClassDefinition |
private static class |
ClosureRewriteClass.MemberDefinition |
Constructor and Description |
---|
ClosureRewriteClass(AbstractCompiler compiler) |
Modifier and Type | Method and Description |
---|---|
private ClosureRewriteClass.ClassDefinition |
extractClassDefinition(Node targetName,
Node callNode)
Validates the class definition and if valid, destructively extracts
the class definition from the AST.
|
private static Node |
extractProperty(Node objlit,
java.lang.String keyName) |
private static Node |
fixupFreeCall(Node call) |
private static Node |
fixupSrcref(Node node) |
void |
hotSwapScript(Node scriptRoot,
Node originalRoot)
Process the JS with root node root.
|
private boolean |
isContainedInGoogDefineClass(Node n) |
private static boolean |
isGoogDefineClass(Node value) |
private static Node |
maybeDetach(Node node) |
private void |
maybeRewriteClassDefinition(Node n) |
private void |
maybeRewriteClassDefinition(Node n,
Node target,
Node value) |
private JSDocInfo |
mergeJsDocFor(ClosureRewriteClass.ClassDefinition cls,
Node associatedNode) |
private static java.util.List<ClosureRewriteClass.MemberDefinition> |
objectLitToList(Node objlit) |
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
private void |
reportErrorOnContext(Node parent) |
private void |
rewriteGoogDefineClass(Node exprRoot,
ClosureRewriteClass.ClassDefinition cls) |
private boolean |
validateObjLit(Node objlit,
Node parent) |
private boolean |
validateUsage(Node n) |
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
shouldTraverse
static final DiagnosticType GOOG_CLASS_TARGET_INVALID
static final DiagnosticType GOOG_CLASS_SUPER_CLASS_NOT_VALID
static final DiagnosticType GOOG_CLASS_DESCRIPTOR_NOT_VALID
static final DiagnosticType GOOG_CLASS_CONSTRUCTOR_MISSING
static final DiagnosticType GOOG_CLASS_CONSTRUCTOR_NOT_VALID
static final DiagnosticType GOOG_CLASS_CONSTRUCTOR_ON_INTERFACE
static final DiagnosticType GOOG_CLASS_STATICS_NOT_VALID
static final DiagnosticType GOOG_CLASS_UNEXPECTED_PARAMS
static final DiagnosticType GOOG_CLASS_ES6_COMPUTED_PROP_NAMES_NOT_SUPPORTED
static final DiagnosticType GOOG_CLASS_ES6_SHORTHAND_ASSIGNMENT_NOT_SUPPORTED
static final DiagnosticType GOOG_CLASS_ES6_ARROW_FUNCTION_NOT_SUPPORTED
static final DiagnosticType GOOG_CLASS_NG_INJECT_ON_CLASS
private final AbstractCompiler compiler
static final java.lang.String VIRTUAL_FILE
public ClosureRewriteClass(AbstractCompiler compiler)
public void process(Node externs, Node root)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treepublic void hotSwapScript(Node scriptRoot, Node originalRoot)
HotSwapCompilerPass
hotSwapScript
in interface HotSwapCompilerPass
scriptRoot
- Root node corresponding to the file that is modified,
should be of type Token.SCRIPT
.originalRoot
- Root node corresponding to the original version of the
file that is modified. Should be of type token.SCRIPT
.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
private boolean validateUsage(Node n)
private boolean isContainedInGoogDefineClass(Node n)
private void maybeRewriteClassDefinition(Node n)
private void maybeRewriteClassDefinition(Node n, Node target, Node value)
private ClosureRewriteClass.ClassDefinition extractClassDefinition(Node targetName, Node callNode)
private boolean validateObjLit(Node objlit, Node parent)
objlit
- the object literal being checked.parent
- the parent of the object literal nodeprivate void reportErrorOnContext(Node parent)
private static Node extractProperty(Node objlit, java.lang.String keyName)
private static java.util.List<ClosureRewriteClass.MemberDefinition> objectLitToList(Node objlit)
private void rewriteGoogDefineClass(Node exprRoot, ClosureRewriteClass.ClassDefinition cls)
private static boolean isGoogDefineClass(Node value)
private JSDocInfo mergeJsDocFor(ClosureRewriteClass.ClassDefinition cls, Node associatedNode)