Skip to content

Commit b60d9fb

Browse files
committed
documented the logic for checking directives
1 parent 906999d commit b60d9fb

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/analysis/ASTParser.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,20 @@ class ASTParser {
141141
}
142142
}
143143

144+
/**
145+
* Return true if:
146+
* 1. there is no directive
147+
* 2. there is a directive named inlcude and the value is true
148+
* 3. there is a directive named skip and the value is false
149+
*/
144150
directiveCheck(directive: DirectiveNode): boolean {
145-
// let directive;
146-
// if (directives) [directive] = directives;
147151
if (directive?.arguments) {
152+
// get the first argument
148153
const argument = directive.arguments[0];
154+
// ensure the argument name is 'if'
149155
const argumentHasVariables =
150156
argument.value.kind === Kind.VARIABLE && argument.name.value === 'if';
151-
157+
// access the value of the argument depending on whether it is passed as a variable or not
152158
let directiveArgumentValue;
153159
if (argument.value.kind === Kind.BOOLEAN) {
154160
directiveArgumentValue = Boolean(argument.value.value);
@@ -166,6 +172,12 @@ class ASTParser {
166172

167173
private selectionNode(node: SelectionNode, parentName: string): number {
168174
let complexity = 0;
175+
/**
176+
* process this node if:
177+
* 1. there is no directive
178+
* 2. there is a directive named inlcude and the value is true
179+
* 3. there is a directive named skip and the value is false
180+
*/
169181
const directive = node.directives;
170182
if (directive && this.directiveCheck(directive[0])) {
171183
this.depth += 1;

0 commit comments

Comments
 (0)