Skip to content

Commit

Permalink
refactor: move AST walker to @jsdoc/parse package
Browse files Browse the repository at this point in the history
  • Loading branch information
hegemonic committed Jan 14, 2023
1 parent 6176387 commit 5be32e5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
2 changes: 2 additions & 0 deletions packages/jsdoc-parse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
const { AstBuilder } = require('./lib/ast-builder');
const astNode = require('./lib/ast-node');
const { Syntax } = require('./lib/syntax');
const { Walker } = require('./lib/walker');

module.exports = {
AstBuilder,
astNode,
Syntax,
Walker,
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
*/
/**
* Traversal utilities for ASTs that are compatible with the ESTree API.
*
* @module jsdoc/src/walker
*/
const { astNode } = require('@jsdoc/parse');
const astNode = require('./ast-node');
const { log } = require('@jsdoc/util');
const { Syntax } = require('@jsdoc/parse');
const { Syntax } = require('./syntax');

// TODO: docs
function getCurrentScope(scopes) {
Expand Down Expand Up @@ -642,9 +640,7 @@ walkers[Syntax.YieldExpression] = (node, parent, state, cb) => {
};

/**
* Create a walker that can traverse an ESTree AST.
*
* @memberof module:jsdoc/src/walker
* A walker that can traverse an ESTree AST.
*/
class Walker {
// TODO: docs
Expand Down
8 changes: 8 additions & 0 deletions packages/jsdoc-parse/test/specs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ describe('@jsdoc/parse', () => {
expect(parse.Syntax).toBe(Syntax);
});
});

describe('Walker', () => {
it('is lib/walker.Walker', () => {
const { Walker } = require('../../lib/walker');

expect(parse.Walker).toBe(Walker);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
describe('jsdoc/src/walker', () => {
const walker = require('jsdoc/src/walker');
describe('@jsdoc/parse/lib/walker', () => {
const walker = require('../../../lib/walker');

it('should exist', () => {
it('is an object', () => {
expect(walker).toBeObject();
});

it('should export a "walkers" object', () => {
it('has a `walkers` object', () => {
expect(walker.walkers).toBeObject();
});

it('should export a "Walker" class', () => {
it('has a `Walker` class', () => {
expect(walker.Walker).toBeFunction();
});

Expand All @@ -33,7 +33,7 @@ describe('jsdoc/src/walker', () => {

// TODO: tests for default functions

it('should contain a function for each known node type', () => {
it('has a function for each known node type', () => {
Object.keys(Syntax).forEach((nodeType) => {
expect(walker.walkers[nodeType]).toBeFunction();
});
Expand Down
3 changes: 1 addition & 2 deletions packages/jsdoc/lib/jsdoc/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
* @module jsdoc/src/parser
*/
const _ = require('lodash');
const { AstBuilder, astNode, Syntax } = require('@jsdoc/parse');
const { AstBuilder, astNode, Syntax, Walker } = require('@jsdoc/parse');
const { EventEmitter } = require('events');
const fs = require('fs');
const { log } = require('@jsdoc/util');
const { getBasename, LONGNAMES, SCOPE, toParts } = require('@jsdoc/core').name;
const { Visitor } = require('jsdoc/src/visitor');
const { Walker } = require('jsdoc/src/walker');

/* eslint-disable no-script-url */
// Prefix for JavaScript strings that were provided in lieu of a filename.
Expand Down
2 changes: 1 addition & 1 deletion packages/jsdoc/test/specs/jsdoc/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('jsdoc/src/parser', () => {

describe('walker', () => {
it('should contain an appropriate walker by default', () => {
const { Walker } = require('jsdoc/src/walker');
const { Walker } = require('@jsdoc/parse');

expect(parser.walker instanceof Walker).toBeTrue();
});
Expand Down

0 comments on commit 5be32e5

Please sign in to comment.