@@ -35,6 +35,16 @@ export abstract class QueryPredicateOperator<T extends HasSchema> {
3535 */
3636 abstract readonly schema : InferSchemaType < T > ;
3737
38+ /**
39+ * Whether it is ok for a node argument to be missing. If true, then the
40+ * operator will just accept the pattern if the given node is missing. If
41+ * false, then the operator will throw an error if the node is missing.
42+ *
43+ * This is useful if we want to set some flag on a node, but only if it's
44+ * present.
45+ */
46+ protected allowMissingNode : boolean = false ;
47+
3848 /**
3949 * Given a list of operands, return whether the operator accepts the given
4050 * operands. This is where the actual logic of the operator is implemented.
@@ -47,21 +57,6 @@ export abstract class QueryPredicateOperator<T extends HasSchema> {
4757 ...args : AcceptFunctionArgs < z . infer < InferSchemaType < T > > >
4858 ) : boolean ;
4959
50- /**
51- * Whether it is ok for a node argument to be missing. If true, then the
52- * operator will just accept the pattern if the given node is missing. If
53- * false, then the operator will throw an error if the node is missing.
54- *
55- * This is useful if we want to set some flag on a node, but only if it's
56- * present.
57- *
58- * @returns A boolean indicating whether it is ok for a node argument to be
59- * missing.
60- */
61- protected allowMissingNode ( ) : boolean {
62- return false ;
63- }
64-
6560 /**
6661 * Given a list of operands, return a predicate function that can be used to
6762 * test whether a given match satisfies the predicate.
@@ -84,7 +79,7 @@ export abstract class QueryPredicateOperator<T extends HasSchema> {
8479 } catch ( error ) {
8580 if (
8681 error instanceof CaptureNotFoundError &&
87- this . allowMissingNode ( )
82+ this . allowMissingNode
8883 ) {
8984 return true ;
9085 }
0 commit comments