npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

estree-builder

v1.12.0

Published

Handy functions for building estree nodes

Downloads

417

Readme

estree-builder

build status dependency status JavaScript Style Guide

Handy functions for building estree nodes

Example

var e = require('estree-builder')

var estree = e.number(1)
// -> { type: 'Literal', value: 1 }

//let's use astring to convert the estree into js code
var astring = require('astring').generate

astring(estree)
// -> '1'

estree = e.fn(['a', 'b'], [
  e('return', e('+', e.id('a'), e.id('b')))
], 'add')

astring(estree)
// -> 'function add(a, b) {return a + b}'

Usage

There are 3 ways to call a builder

e.number(1)
e['number'](1)
e('number', 1)

All builders can take a location object as the last argument. (i.e. for generating source maps)

var loc = {
  source: "some-file.js"
  start: { line: 1, column: 0 },
  end: { line: 1, column: 1 }
}

e('number', 1, loc)

List of builders

building block values

e('number', val) //aliases: 'num', 'float'
e('string', val) //aliases: 'str'
e('true')
e('false')
e('null')
e('undefined') //aliases: 'nil'
e('array', elements) //aliases: 'arr'
e('object-raw', pairs) //aliases: 'obj-raw'
e('object-property', key, value) //aliases: 'obj-prop'
e('object', obj) //aliases: 'obj'

given some json object, build the tree

e('json', val)

variables

e('var', id, val)
e('let', id, val)
e('const', id, val)
e('identifier', name) //aliases: 'id'

control flow

e('if', test, consequent, alternate)
e('ternary', test, consequent, alternate) //aliases: '?'
e('switch', discriminant, cases)
e('case', test, consequent)
e('default', consequent)
e('while', test, body)
e('for', init, test, update, body)
e('for-in', left, right, body)
e('for-of', left, right, body)
e('break')
e('continue')
e('return', arg)
e('throw', arg)
e('try', body, catchVar, catchStmt, finallyStmt)

functions

e('function', args, body, id) //aliases: 'fn', 'lambda'
e('call', callee, args)
e('arrow', args, body)

property access

e('.', obj, prop)
e('get', obj, prop)
e('get-in', obj, path) //aliases: '..'

language stuff

e('arguments') //aliases: 'args'
e('this')
e('statement', expr) //aliases: ';'
e('block', body)
e('new', callee, args)

infix operators

e('==', left, right)
e('!=', left, right)
e('===', left, right)
e('!==', left, right)
e('<', left, right)
e('<=', left, right)
e('>', left, right)
e('>=', left, right)
e('<<', left, right)
e('>>', left, right)
e('>>>', left, right)
e('*', left, right)
e('/', left, right)
e('%', left, right)
e('|', left, right)
e('^', left, right)
e('&', left, right)
e('in', left, right)
e('instanceof', left, right)
e('&&', left, right)
e('||', left, right)
e('+', a, b)
e('-', a, b)

unary operators

e('!', arg)
e('~', arg)
e('typeof', arg)
e('void', arg)
e('delete', arg)
e('++', arg)
e('--', arg)

assignments

e('=', left, right)
e('+=', left, right)
e('-=', left, right)
e('*=', left, right)
e('/=', left, right)
e('%=', left, right)
e('<<=', left, right)
e('>>=', left, right)
e('>>>=', left, right)
e('|=', left, right)
e('^=', left, right)
e('&=', left, right)

destructuring

e('assign', left, right)
e('assign-property', key, value) //aliases: 'assign-prop'
e('obj-pattern', properties)
e('arr-pattern', elements)

generator functions

e('genfn', args, body, id)
e('yield', arg, delegate)

classes

e('class', name, superClass, methods)
e('method', key, value, kind, computed, isStatic)

Contributing

Add tests to tests.js, run them like this:

$ npm test

or to automatically re-run them whenever you make a change

$ npm start

Re-generate the docs (README.md between the GEN-DOCS-BEGIN|END comments)

$ npm run build

License

MIT