Skip to content

Commit b413646

Browse files
committed
refactor!: make is* and has* methods properties
1 parent a463ed1 commit b413646

File tree

4 files changed

+44
-43
lines changed

4 files changed

+44
-43
lines changed

index.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,36 @@ class SyntaxNode {
104104
return NodeMethods.grammarName(this.tree);
105105
}
106106

107+
get isExtra() {
108+
marshalNode(this);
109+
return NodeMethods.isExtra(this.tree);
110+
}
111+
107112
get isNamed() {
108113
marshalNode(this);
109114
return NodeMethods.isNamed(this.tree);
110115
}
111116

117+
get isMissing() {
118+
marshalNode(this);
119+
return NodeMethods.isMissing(this.tree);
120+
}
121+
122+
get hasChanges() {
123+
marshalNode(this);
124+
return NodeMethods.hasChanges(this.tree);
125+
}
126+
127+
get hasError() {
128+
marshalNode(this);
129+
return NodeMethods.hasError(this.tree);
130+
}
131+
132+
get isError() {
133+
marshalNode(this);
134+
return NodeMethods.isError(this.tree);
135+
}
136+
112137
get text() {
113138
return this.tree.getText(this);
114139
}
@@ -215,31 +240,6 @@ class SyntaxNode {
215240
return NodeMethods.descendantCount(this.tree);
216241
}
217242

218-
hasChanges() {
219-
marshalNode(this);
220-
return NodeMethods.hasChanges(this.tree);
221-
}
222-
223-
hasError() {
224-
marshalNode(this);
225-
return NodeMethods.hasError(this.tree);
226-
}
227-
228-
isMissing() {
229-
marshalNode(this);
230-
return NodeMethods.isMissing(this.tree);
231-
}
232-
233-
isExtra() {
234-
marshalNode(this);
235-
return NodeMethods.isExtra(this.tree);
236-
}
237-
238-
isError() {
239-
marshalNode(this);
240-
return NodeMethods.isError(this.tree);
241-
}
242-
243243
toString() {
244244
marshalNode(this);
245245
return NodeMethods.toString(this.tree);

test/node_test.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ describe("Node", () => {
621621
});
622622
});
623623

624-
describe(".hasError()", () => {
624+
describe(".hasError", () => {
625625
it("returns true if the node contains an error", () => {
626626
const tree = parser.parse("1 + 2 * * 3");
627627
const node = tree.rootNode;
@@ -631,14 +631,14 @@ describe("Node", () => {
631631
);
632632

633633
const sum = node.firstChild.firstChild;
634-
assert(sum.hasError());
635-
assert(!sum.children[0].hasError());
636-
assert(!sum.children[1].hasError());
637-
assert(sum.children[2].hasError());
634+
assert(sum.hasError);
635+
assert(!sum.children[0].hasError);
636+
assert(!sum.children[1].hasError);
637+
assert(sum.children[2].hasError);
638638
});
639639
});
640640

641-
describe(".isMissing()", () => {
641+
describe(".isMissing)", () => {
642642
it("returns true if the node is missing from the source and was inserted via error recovery", () => {
643643
const tree = parser.parse("(2 ||)");
644644
const node = tree.rootNode;
@@ -649,23 +649,23 @@ describe("Node", () => {
649649

650650
const sum = node.firstChild.firstChild.firstNamedChild;
651651
assert.equal(sum.type, 'binary_expression')
652-
assert(sum.hasError());
653-
assert(!sum.children[0].isMissing());
654-
assert(!sum.children[1].isMissing());
655-
assert(sum.children[2].isMissing());
652+
assert(sum.hasError);
653+
assert(!sum.children[0].isMissing);
654+
assert(!sum.children[1].isMissing);
655+
assert(sum.children[2].isMissing);
656656
});
657657
});
658658

659-
describe(".isExtra()", () => {
659+
describe(".isExtra", () => {
660660
it("returns true if the node is an extra node like comments", () => {
661661
const tree = parser.parse("foo(/* hi */);");
662662
const node = tree.rootNode;
663663
const comment_node = node.descendantForIndex(7, 7);
664664

665665
assert.equal(node.type, "program");
666666
assert.equal(comment_node.type, "comment");
667-
assert(!node.isExtra());
668-
assert(comment_node.isExtra());
667+
assert(!node.isExtra);
668+
assert(comment_node.isExtra);
669669
});
670670
});
671671

@@ -907,6 +907,10 @@ describe("Node", () => {
907907
"type",
908908
"typeId",
909909
"isNamed",
910+
"isMissing",
911+
"hasChanges",
912+
"hasError",
913+
"isError",
910914
"text",
911915
"startPosition",
912916
"endPosition",
@@ -931,9 +935,6 @@ describe("Node", () => {
931935
}
932936

933937
const methods = [
934-
"hasChanges",
935-
"hasError",
936-
"isMissing",
937938
"toString",
938939
"walk",
939940
// these take arguments but the "this" check happens first

test/tree_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ function assertCursorState(cursor, params) {
579579
const node = cursor.currentNode
580580
assert.equal(node.type, params.nodeType);
581581
assert.equal(node.isNamed, params.nodeIsNamed);
582-
assert.equal(node.isMissing(), params.nodeIsMissing);
582+
assert.equal(node.isMissing, params.nodeIsMissing);
583583
assert.deepEqual(node.startPosition, params.startPosition);
584584
assert.deepEqual(node.endPosition, params.endPosition);
585585
assert.deepEqual(node.startIndex, params.startIndex);

0 commit comments

Comments
 (0)