Files
codeql/javascript/extractor/src/com/semmle/js/ast/Chainable.java
2019-11-04 07:54:38 +00:00

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();
}
}