@goto-bus-stop/common-shake
Version:
CommonJS Tree Shake (fork)
24 lines (20 loc) • 599 B
JavaScript
;
const walk = require('acorn-walk');
const BASE = Object.assign({
// acorn < 7 support
Import: () => {}
}, walk.base);
// Pre-order walker
module.exports = (node, visitors) => {
const state = null;
const override = false;
const ancestors = [];
!function c(node, st, override) {
var type = override || node.type, found = visitors[type];
const isNew = node != ancestors[ancestors.length - 1];
if (isNew) ancestors.push(node);
if (found) found(node, st, ancestors);
BASE[type](node, st, c);
if (isNew) ancestors.pop();
}(node, state, override);
};