Skip to content

Commit

Permalink
visitor: remove 4th form of visitor (#2957)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
IvanGoncharov committed Mar 12, 2021
1 parent 3ce28ce commit 2c2d87e
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 293 deletions.
28 changes: 5 additions & 23 deletions src/language/__tests__/visitor-test.js
Expand Up @@ -56,6 +56,11 @@ function getValue(node: ASTNode) {
}

describe('Visitor', () => {
it('handles empty visitor', () => {
const ast = parse('{ a }', { noLocation: true });
expect(() => visit(ast, {})).to.not.throw();
});

it('validates path argument', () => {
const visited = [];

Expand Down Expand Up @@ -114,29 +119,6 @@ describe('Visitor', () => {
});
});

it('allows visiting only specified nodes', () => {
const ast = parse('{ a }', { noLocation: true });
const visited = [];

visit(ast, {
enter: {
Field(node) {
visited.push(['enter', node.kind]);
},
},
leave: {
Field(node) {
visited.push(['leave', node.kind]);
},
},
});

expect(visited).to.deep.equal([
['enter', 'Field'],
['leave', 'Field'],
]);
});

it('allows editing a node both on enter and on leave', () => {
const ast = parse('{ a, b, c { a, b, c } }', { noLocation: true });

Expand Down

0 comments on commit 2c2d87e

Please sign in to comment.