final class CheckSideEffects extends NodeTraversal.AbstractPostOrderCallback implements HotSwapCompilerPass
var s = "this string is " "continued on the next line but you forgot the +"; x == foo(); // should that be '='? foo();; // probably just a stray-semicolon. Doesn't hurt to check thoughand generates warnings.
Modifier and Type | Class and Description |
---|---|
private class |
CheckSideEffects.GetNoSideEffectExterns
Get fully qualified function names which are marked
with @nosideeffects
TODO(ChadKillingsworth) Add support for object literals
|
(package private) static class |
CheckSideEffects.StripProtection
Remove side-effect sync functions.
|
Modifier and Type | Field and Description |
---|---|
private AbstractCompiler |
compiler |
private java.util.LinkedHashMap<java.lang.String,java.lang.String> |
noSideEffectExterns |
private java.util.List<Node> |
problemNodes |
(package private) static java.lang.String |
PROTECTOR_FN |
private boolean |
protectSideEffectFreeCode |
private boolean |
report |
(package private) static DiagnosticType |
USELESS_CODE_ERROR |
Constructor and Description |
---|
CheckSideEffects(AbstractCompiler compiler,
boolean report,
boolean protectSideEffectFreeCode) |
Modifier and Type | Method and Description |
---|---|
private void |
addExtern() |
void |
hotSwapScript(Node scriptRoot,
Node originalRoot)
Process the JS with root node root.
|
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
private void |
protectSideEffects()
Protect side-effect free nodes by making them parameters
to a extern function call.
|
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
shouldTraverse
static final DiagnosticType USELESS_CODE_ERROR
static final java.lang.String PROTECTOR_FN
private final boolean report
private final java.util.List<Node> problemNodes
private final java.util.LinkedHashMap<java.lang.String,java.lang.String> noSideEffectExterns
private final AbstractCompiler compiler
private final boolean protectSideEffectFreeCode
CheckSideEffects(AbstractCompiler compiler, boolean report, boolean protectSideEffectFreeCode)
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 void protectSideEffects()
private void addExtern()