MCPcopy Create free account
hub / github.com/angular/components / hasNestedTernary

Function hasNestedTernary

tools/tslint-rules/noNestedTernaryRule.ts:24–40  ·  view source on GitHub ↗

Checks whether a ternary expression has another ternary inside of it.

(rootNode: ts.ConditionalExpression)

Source from the content-addressed store, hash-verified

22
23/** Checks whether a ternary expression has another ternary inside of it. */
24function hasNestedTernary(rootNode: ts.ConditionalExpression): boolean {
25 let hasNestedTernaryDescendant = false;
26
27 // Start from the immediate children of the root node.
28 rootNode.forEachChild(function walk(node: ts.Node) {
29 // Stop checking if we've hit a ternary. Also note that we don't descend
30 // into call expressions, because it's valid to have a ternary expression
31 // inside of a callback which is one of the arguments of a ternary.
32 if (ts.isConditionalExpression(node)) {
33 hasNestedTernaryDescendant = true;
34 } else if (!ts.isCallExpression(node)) {
35 node.forEachChild(walk);
36 }
37 });
38
39 return hasNestedTernaryDescendant;
40}

Callers 1

applyMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected