acorn-bfs

Breadth-first search traversal of an acorn-generated AST.

MIT 3 个版本
安装
npm install acorn-bfs
yarn add acorn-bfs
pnpm add acorn-bfs
bun add acorn-bfs
README

acorn-bfs

/**
 * Returns an array of nodes in the passed AST, traversed using BFS. Accepts an
 * optional maximum number, n, of nodes to return. The returned array always
 * begins with the root node.
 *
 * @param {Node} node The root node of the AST to traverse
 * @param {int}  [n]  Optional max number of nodes to return
 */

Build Status

Installation

npm install --save acorn-bfs

Example

var acorn = require('acorn');
var bfs   = require('acorn-bfs');

var ast = acorn.parse('function test() {\n' +
'  return true;\n' +
'}\n');

bfs(ast).map(function(node) {
  return node.type;
});

// =>
// ['Program', 'FunctionDeclaration', 'BlockStatement',
//  'ReturnStatement', 'Literal']
版本列表
0.2.0 2017-03-12
0.1.0 2015-11-18
0.0.1 2015-07-06