1.0.5 • Published 9 years ago

ast-children v1.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

ast-children

get the children of an AST node

Installation

npm install ast-children

then in your app:

const children = require('ast-children')

API

children(node)

Takes a standard AST node and returns an Array of its child nodes

var ast = {
  type: 'Program',
  body: [
    {
      type: 'VariableDeclaration',
      declarations: [
        {
          type: 'VariableDeclarator',
          id: {type: 'Identifier', name: 'a'},
          init: {type: 'Literal', value: 1}
        },
        {
          type: 'VariableDeclarator',
          id: {type: 'Identifier', name: 'b'}
        }
      ]
    }
  ]
}
children(ast) // => ast.body
children(ast.body[0]) // => ast.body[0].declarations
var decs = ast.body[0].declarations
children(decs[0]) // => [decs[0].id, decs[0].init]
children(decs[1]) // => [decs[1].id]
1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.2.0

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago