ast-children
get the children of an AST node
Last updated 10 years ago by jkroso .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ast-children 
SYNC missed versions from official npm registry.

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]

Current Tags

  • 1.0.5                                ...           latest (10 years ago)

10 Versions

  • 1.0.5                                ...           10 years ago
  • 1.0.4                                ...           11 years ago
  • 1.0.3                                ...           11 years ago
  • 1.0.2                                ...           11 years ago
  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
  • 0.2.0                                ...           11 years ago
  • 0.1.2                                ...           12 years ago
  • 0.1.1                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (8)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |