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

ast-eval

v0.8.0

Published

Statically evaluate AST

Downloads

33

Readme

ast-eval Build Status experimental

Statically evaluate expressions in AST, also known as constants folding. Useful for precompilation tasks.

Use

npm install --save ast-eval
var esprima = require('esprima');
var gen = require('escodegen').generate;
var astEval = require('ast-eval');

var ast = esprima.parse('[1, 2 === "2", 3+4*10, [2] === 2]');
ast = astEval(ast);

gen(ast); //'[1, false, 43, false]'

API

preeval(Node, options) → Node

Evaluate expressions in a Node, return a new Node with optimized shorten expression nodes.

Features

  • [x] Fold expressions

    • [x] Binary expressions: 1000 * 60 * 6036e6
    • [x] Logical expressions: {a:1} && {b:2}true
    • [x] Math expressions: Math.sin(Math.Pi / 2 )1
  • [x] Fold arrays

    • [x] Safe methods: [1,2,3,new Date].concat(4, [5], new Date)[1,2,3,new Date,4,5, new Date]
    • [x] Unsafe methods: [1,2,3].map(function(x){ return x*2})[2,4,6]
    • [ ] Static methods: Array.from([1, 2, 3], function(x){ return x*2; })[2,4,6]
    • [ ] Prototype methods: Array.prototype.slice.call([1,2,3], 1,2)[2]
  • [ ] Fold static globals (what’s that?)

  • [x] Decompute object access (optionally)

    • [x] a['x'] = 1a.x = 1
  • [x] Fold strings

    • [x] 'a b c'.split(' ')['a', 'b', 'c']
  • [ ] Propagate constants

    • [ ] Simple flow analysis: var x = 1; x + 2;3;
    • [ ] Scope analysis
    • [ ] Method substitution: var slice = Array.prototype.slice; var x = [1,2,3]; var y = slice(x)'
  • [ ] Fold loops

    • [ ] var x = []; for (var i = 0; i < 10; i++) {x[i] = 10*i;}
  • [ ] Fold proxy functions

  • [ ] Remove unused props

  • [ ] Undead code

    • [ ] Empty isolated functions
    • [ ] Remove unused variables (after enabling constants)
    • [ ] Remove unused functions
    • [ ] Remove unused properties
  • [ ] Fold clone-code

    • a.x×3 → var _a = a; _a.x
  • [ ] Data-flow analysis

    • [ ] Precall functions
    • [ ] Substitute variables
  • [ ] Provide exports

  • [ ] Fold primitives

    • [ ] new Array([1,2,3,...])
    • [ ] [1,2,3,...]
  • [ ] Rearrange things

    • [ ] Hoist functions (place after first use)
    • [ ] Fold variable declarations

References

NPM