mirror of
https://github.com/github/codeql.git
synced 2026-07-28 22:36:50 +02:00
21 lines
692 B
Java
21 lines
692 B
Java
package com.semmle.js.ast;
|
|
|
|
/** A chainable expression, such as a member access or function call. */
|
|
public interface Chainable {
|
|
/** Is this step of the chain optional? */
|
|
abstract boolean isOptional();
|
|
|
|
/** Is this on an optional chain? */
|
|
abstract boolean isOnOptionalChain();
|
|
|
|
/**
|
|
* Returns true if a chainable node is on an optional chain.
|
|
*
|
|
* @param optional true if the node in question is itself optional (has the ?. token)
|
|
* @param base the calle or base of the optional access
|
|
*/
|
|
public static boolean isOnOptionalChain(boolean optional, Expression base) {
|
|
return optional || base instanceof Chainable && ((Chainable) base).isOnOptionalChain();
|
|
}
|
|
}
|