Skip to content

Commit 2c2d87e

Browse files
visitor: remove 4th form of visitor (#2957)
Visitor in 4th form can always be written as 2nd form. This is PR part of general effort to simplify `visit` typings before TS migration.
1 parent 3ce28ce commit 2c2d87e

File tree

4 files changed

+270
-293
lines changed

4 files changed

+270
-293
lines changed

src/language/__tests__/visitor-test.js

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ function getValue(node: ASTNode) {
5656
}
5757

5858
describe('Visitor', () => {
59+
it('handles empty visitor', () => {
60+
const ast = parse('{ a }', { noLocation: true });
61+
expect(() => visit(ast, {})).to.not.throw();
62+
});
63+
5964
it('validates path argument', () => {
6065
const visited = [];
6166

@@ -114,29 +119,6 @@ describe('Visitor', () => {
114119
});
115120
});
116121

117-
it('allows visiting only specified nodes', () => {
118-
const ast = parse('{ a }', { noLocation: true });
119-
const visited = [];
120-
121-
visit(ast, {
122-
enter: {
123-
Field(node) {
124-
visited.push(['enter', node.kind]);
125-
},
126-
},
127-
leave: {
128-
Field(node) {
129-
visited.push(['leave', node.kind]);
130-
},
131-
},
132-
});
133-
134-
expect(visited).to.deep.equal([
135-
['enter', 'Field'],
136-
['leave', 'Field'],
137-
]);
138-
});
139-
140122
it('allows editing a node both on enter and on leave', () => {
141123
const ast = parse('{ a, b, c { a, b, c } }', { noLocation: true });
142124

0 commit comments

Comments
 (0)