class ConstParamCheck extends NodeTraversal.AbstractPostOrderCallback implements CompilerPass
goog.string.Const.from
are
done with an argument which is a string literal.
This function parameter checker enforces that for all invocations of
method goog.string.Const.from
the actual argument satisfies one of
the following conditions:
Modifier and Type | Field and Description |
---|---|
private AbstractCompiler |
compiler |
private static java.lang.String |
CONST_FUNCTION_NAME |
private static java.lang.String |
CONST_FUNCTION_NAME_COLLAPSED |
(package private) static DiagnosticType |
CONST_NOT_ASSIGNED_STRING_LITERAL_ERROR |
(package private) static DiagnosticType |
CONST_NOT_STRING_LITERAL_ERROR |
Constructor and Description |
---|
ConstParamCheck(AbstractCompiler compiler) |
Modifier and Type | Method and Description |
---|---|
private void |
checkArgumentConstant(NodeTraversal traversal,
Node argument)
Check the method call argument to be constant string literal.
|
private static boolean |
isStringLiteralValue(Node node)
Returns true iff the value associated with the node is a JS string literal,
or a concatenation thereof.
|
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
void |
visit(NodeTraversal traversal,
Node node,
Node parent)
Callback to visit a node and check method call arguments of
goog.string.Const.from . |
shouldTraverse
private static final java.lang.String CONST_FUNCTION_NAME
private static final java.lang.String CONST_FUNCTION_NAME_COLLAPSED
static final DiagnosticType CONST_NOT_STRING_LITERAL_ERROR
static final DiagnosticType CONST_NOT_ASSIGNED_STRING_LITERAL_ERROR
private final AbstractCompiler compiler
public ConstParamCheck(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 visit(NodeTraversal traversal, Node node, Node parent)
goog.string.Const.from
.visit
in interface NodeTraversal.Callback
traversal
- The node traversal object that supplies context, such as
the scope chain to use in name lookups as well as error reporting.node
- The node being visited.parent
- The parent of the node.private void checkArgumentConstant(NodeTraversal traversal, Node argument)
This function argument checker will yield an error if:
traversal
- The node traversal object that supplies context, such as
the scope chain to use in name lookups as well as error reporting.argument
- The node of function argument to check.private static boolean isStringLiteralValue(@Nullable Node node)