{"_id":"babel-walk","_rev":"3635671","name":"babel-walk","description":"Lightweight Babel AST traversal","dist-tags":{"canary":"3.0.1-canary-8","latest":"3.0.1"},"maintainers":[{"name":"babel-walk-bot","email":""},{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"time":{"modified":"2024-10-21T06:06:02.000Z","created":"2020-05-25T19:22:20.936Z","3.0.1":"2024-08-16T09:02:54.326Z","3.0.1-canary-8":"2024-08-16T09:00:17.801Z","3.0.0":"2020-05-25T22:23:46.236Z","3.0.0-canary-5":"2020-05-25T20:51:49.220Z","2.1.0-canary-4":"2020-05-25T20:30:53.749Z","2.0.0":"2020-05-25T20:10:05.673Z","2.0.0-canary-1":"2020-05-25T19:22:20.936Z"},"users":{},"author":{"name":"Timothy Gu","email":"timothygu99@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/pugjs/babel-walk.git"},"versions":{"3.0.1":{"name":"babel-walk","version":"3.0.1","description":"Lightweight Babel AST traversal","main":"lib/index.js","scripts":{"build":"tsc && node lib","postbuild":"rimraf lib/**/__tests__ && rimraf lib/.tsbuildinfo","lint":"tslint './src/**/*.{ts,tsx}' -t verbose -p .","prettier:write":"prettier --ignore-path .gitignore --write './**/*.{md,json,yaml,js,jsx,ts,tsx}'","prettier:check":"prettier --ignore-path .gitignore --list-different './**/*.{md,json,yaml,js,jsx,ts,tsx}'"},"repository":{"type":"git","url":"git+https://github.com/pugjs/babel-walk.git"},"engines":{"node":">= 10.0.0"},"author":{"name":"Timothy Gu","email":"timothygu99@gmail.com"},"license":"MIT","dependencies":{"@babel/types":"^7.9.6"},"devDependencies":{"@forbeslindesay/tsconfig":"^2.0.0","@types/node":"^14.0.5","prettier":"^2.0.5","rimraf":"^3.0.2","tslint":"^6.1.2","typescript":"^3.9.3"},"gitHead":"dec659376db7650e01ca7adf7fee8403f3585967","bugs":{"url":"https://github.com/pugjs/babel-walk/issues"},"homepage":"https://github.com/pugjs/babel-walk#readme","_id":"babel-walk@3.0.1","_nodeVersion":"12.22.12","_npmVersion":"6.14.16","dist":{"shasum":"f79cfb0a38fd9c990b5b63ccd4e695d513db5fd2","size":7095,"noattachment":false,"key":"/babel-walk/-/babel-walk-3.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-walk/download/babel-walk-3.0.1.tgz"},"_npmUser":{"name":"babel-walk-bot","email":"babel-walk-bot@rollingversions.com"},"directories":{},"maintainers":[{"name":"babel-walk-bot","email":""},{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-walk_3.0.1_1723798974184_0.9625840362240727"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-08-16T09:02:54.326Z","publish_time":1723798974326,"_source_registry_name":"default","_cnpm_publish_time":1723798974326},"3.0.1-canary-8":{"name":"babel-walk","version":"3.0.1-canary-8","author":{"name":"Timothy Gu","email":"timothygu99@gmail.com"},"license":"MIT","_id":"babel-walk@3.0.1-canary-8","maintainers":[{"name":"babel-walk-bot","email":""},{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"homepage":"https://github.com/pugjs/babel-walk#readme","bugs":{"url":"https://github.com/pugjs/babel-walk/issues"},"dist":{"shasum":"fd5d15084e53e5138d468b0f7c06c594ef6ad7f4","size":7105,"noattachment":false,"key":"/babel-walk/-/babel-walk-3.0.1-canary-8.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-walk/download/babel-walk-3.0.1-canary-8.tgz"},"main":"lib/index.js","engines":{"node":">= 10.0.0"},"gitHead":"dec659376db7650e01ca7adf7fee8403f3585967","scripts":{"lint":"tslint './src/**/*.{ts,tsx}' -t verbose -p .","build":"tsc && node lib","postbuild":"rimraf lib/**/__tests__ && rimraf lib/.tsbuildinfo","prettier:check":"prettier --ignore-path .gitignore --list-different './**/*.{md,json,yaml,js,jsx,ts,tsx}'","prettier:write":"prettier --ignore-path .gitignore --write './**/*.{md,json,yaml,js,jsx,ts,tsx}'"},"_npmUser":{"name":"babel-walk-bot","email":"babel-walk-bot@rollingversions.com"},"repository":{"url":"git+https://github.com/pugjs/babel-walk.git","type":"git"},"_npmVersion":"6.14.16","description":"Lightweight Babel AST traversal","directories":{},"_nodeVersion":"12.22.12","dependencies":{"@babel/types":"^7.9.6"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"rimraf":"^3.0.2","tslint":"^6.1.2","prettier":"^2.0.5","typescript":"^3.9.3","@types/node":"^14.0.5","@forbeslindesay/tsconfig":"^2.0.0"},"_npmOperationalInternal":{"tmp":"tmp/babel-walk_3.0.1-canary-8_1723798817610_0.6430648063746458","host":"s3://npm-registry-packages"},"_cnpmcore_publish_time":"2024-08-16T09:00:17.801Z","publish_time":1723798817801,"_source_registry_name":"default","_cnpm_publish_time":1723798817801},"3.0.0":{"name":"babel-walk","version":"3.0.0","description":"Lightweight Babel AST traversal","main":"lib/index.js","scripts":{"build":"tsc && node lib","postbuild":"rimraf lib/**/__tests__","lint":"tslint './src/**/*.{ts,tsx}' -t verbose -p .","prettier:write":"prettier --ignore-path .gitignore --write './**/*.{md,json,yaml,js,jsx,ts,tsx}'","prettier:check":"prettier --ignore-path .gitignore --list-different './**/*.{md,json,yaml,js,jsx,ts,tsx}'"},"repository":{"type":"git","url":"git+https://github.com/pugjs/babel-walk.git"},"engines":{"node":">= 10.0.0"},"author":{"name":"Timothy Gu","email":"timothygu99@gmail.com"},"license":"MIT","dependencies":{"@babel/types":"^7.9.6"},"devDependencies":{"@forbeslindesay/tsconfig":"^2.0.0","@types/node":"^14.0.5","prettier":"^2.0.5","rimraf":"^3.0.2","tslint":"^6.1.2","typescript":"^3.9.3"},"gitHead":"aea4d8fae63e4a4e93f04dcd7ee5858384593e0a","bugs":{"url":"https://github.com/pugjs/babel-walk/issues"},"homepage":"https://github.com/pugjs/babel-walk#readme","_id":"babel-walk@3.0.0","_nodeVersion":"12.16.3","_npmVersion":"6.14.4","dist":{"shasum":"71ea81ea1b8e2e7b37540ec8c899fe49d7fb1441","size":14524,"noattachment":false,"key":"/babel-walk/-/babel-walk-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-walk/download/babel-walk-3.0.0.tgz"},"maintainers":[{"name":"babel-walk-bot","email":""},{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"_npmUser":{"name":"babel-walk-bot","email":"babel-walk-bot@rollingversions.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-walk_3.0.0_1590445426094_0.7183379329197233"},"_hasShrinkwrap":false,"publish_time":1590445426236,"_cnpm_publish_time":1590445426236},"3.0.0-canary-5":{"name":"babel-walk","version":"3.0.0-canary-5","description":"Lightweight Babel AST traversal","main":"lib/index.js","scripts":{"build":"tsc && node lib","postbuild":"rimraf lib/**/__tests__","lint":"tslint './src/**/*.{ts,tsx}' -t verbose -p .","prettier:write":"prettier --ignore-path .gitignore --write './**/*.{md,json,yaml,js,jsx,ts,tsx}'","prettier:check":"prettier --ignore-path .gitignore --list-different './**/*.{md,json,yaml,js,jsx,ts,tsx}'"},"repository":{"type":"git","url":"git+https://github.com/pugjs/babel-walk.git"},"engines":{"node":">= 10.0.0"},"author":{"name":"Timothy Gu","email":"timothygu99@gmail.com"},"license":"MIT","dependencies":{"@babel/types":"^7.9.6"},"devDependencies":{"@forbeslindesay/tsconfig":"^2.0.0","@types/node":"^14.0.5","prettier":"^2.0.5","rimraf":"^3.0.2","tslint":"^6.1.2","typescript":"^3.9.3"},"readmeFilename":"README.md","gitHead":"aea4d8fae63e4a4e93f04dcd7ee5858384593e0a","bugs":{"url":"https://github.com/pugjs/babel-walk/issues"},"homepage":"https://github.com/pugjs/babel-walk#readme","_id":"babel-walk@3.0.0-canary-5","_nodeVersion":"12.16.3","_npmVersion":"6.14.4","dist":{"shasum":"f66ecd7298357aee44955f235a6ef54219104b11","size":14529,"noattachment":false,"key":"/babel-walk/-/babel-walk-3.0.0-canary-5.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-walk/download/babel-walk-3.0.0-canary-5.tgz"},"maintainers":[{"name":"babel-walk-bot","email":""},{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"_npmUser":{"name":"babel-walk-bot","email":"babel-walk-bot@rollingversions.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-walk_3.0.0-canary-5_1590439909023_0.8600387427590168"},"_hasShrinkwrap":false,"publish_time":1590439909220,"_cnpm_publish_time":1590439909220},"2.1.0-canary-4":{"name":"babel-walk","version":"2.1.0-canary-4","description":"Lightweight Babel AST traversal","main":"lib/index.js","scripts":{"build":"tsc && node lib","postbuild":"rimraf lib/**/__tests__","lint":"tslint './src/**/*.{ts,tsx}' -t verbose -p .","prettier:write":"prettier --ignore-path .gitignore --write './**/*.{md,json,yaml,js,jsx,ts,tsx}'","prettier:check":"prettier --ignore-path .gitignore --list-different './**/*.{md,json,yaml,js,jsx,ts,tsx}'"},"repository":{"type":"git","url":"git+https://github.com/pugjs/babel-walk.git"},"engines":{"node":">= 10.0.0"},"author":{"name":"Timothy Gu","email":"timothygu99@gmail.com"},"license":"MIT","dependencies":{"@babel/types":"^7.9.6"},"devDependencies":{"@forbeslindesay/tsconfig":"^2.0.0","prettier":"^2.0.5","rimraf":"^3.0.2","tslint":"^6.1.2","typescript":"^3.9.3"},"readmeFilename":"README.md","gitHead":"7fba472b09c2c5540f4d22b6b1822c5b3b93a710","bugs":{"url":"https://github.com/pugjs/babel-walk/issues"},"homepage":"https://github.com/pugjs/babel-walk#readme","_id":"babel-walk@2.1.0-canary-4","_nodeVersion":"12.16.3","_npmVersion":"6.14.4","dist":{"shasum":"867706b73be6e671b90967349fd1c2896d2aac6a","size":9312,"noattachment":false,"key":"/babel-walk/-/babel-walk-2.1.0-canary-4.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-walk/download/babel-walk-2.1.0-canary-4.tgz"},"maintainers":[{"name":"babel-walk-bot","email":""},{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"_npmUser":{"name":"babel-walk-bot","email":"babel-walk-bot@rollingversions.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-walk_2.1.0-canary-4_1590438653574_0.10377651444025582"},"_hasShrinkwrap":false,"publish_time":1590438653749,"_cnpm_publish_time":1590438653749},"2.0.0":{"name":"babel-walk","version":"2.0.0","description":"Lightweight Babel AST traversal","main":"lib/index.js","scripts":{"build":"tsc && node lib","postbuild":"rimraf lib/**/__tests__","lint":"tslint './src/**/*.{ts,tsx}' -t verbose -p .","prettier:write":"prettier --ignore-path .gitignore --write './**/*.{md,json,yaml,js,jsx,ts,tsx}'","prettier:check":"prettier --ignore-path .gitignore --list-different './**/*.{md,json,yaml,js,jsx,ts,tsx}'"},"repository":{"type":"git","url":"git+https://github.com/pugjs/babel-walk.git"},"engines":{"node":">= 10.0.0"},"author":{"name":"Timothy Gu","email":"timothygu99@gmail.com"},"license":"MIT","dependencies":{"@babel/types":"^7.9.6"},"devDependencies":{"@forbeslindesay/tsconfig":"^2.0.0","prettier":"^2.0.5","rimraf":"^3.0.2","tslint":"^6.1.2","typescript":"^3.9.3"},"gitHead":"8ac813176d565b71f46592cb092573063e199abf","bugs":{"url":"https://github.com/pugjs/babel-walk/issues"},"homepage":"https://github.com/pugjs/babel-walk#readme","_id":"babel-walk@2.0.0","_nodeVersion":"12.16.3","_npmVersion":"6.14.4","dist":{"shasum":"9c770920ca3e3fa24442468db6afc23438f9ae01","size":9330,"noattachment":false,"key":"/babel-walk/-/babel-walk-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-walk/download/babel-walk-2.0.0.tgz"},"maintainers":[{"name":"babel-walk-bot","email":""},{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"_npmUser":{"name":"babel-walk-bot","email":"babel-walk-bot@rollingversions.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-walk_2.0.0_1590437405525_0.9665288604644648"},"_hasShrinkwrap":false,"publish_time":1590437405673,"_cnpm_publish_time":1590437405673},"2.0.0-canary-1":{"name":"babel-walk","version":"2.0.0-canary-1","description":"Lightweight Babel AST traversal","main":"lib/index.js","scripts":{"build":"tsc && node lib","postbuild":"rimraf lib/**/__tests__","lint":"tslint './src/**/*.{ts,tsx}' -t verbose -p .","prettier:write":"prettier --ignore-path .gitignore --write './**/*.{md,json,yaml,js,jsx,ts,tsx}'","prettier:check":"prettier --ignore-path .gitignore --list-different './**/*.{md,json,yaml,js,jsx,ts,tsx}'"},"repository":{"type":"git","url":"git+https://github.com/pugjs/babel-walk.git"},"engines":{"node":">= 10.0.0"},"author":{"name":"Timothy Gu","email":"timothygu99@gmail.com"},"license":"MIT","dependencies":{"@babel/types":"^7.9.6"},"devDependencies":{"@forbeslindesay/tsconfig":"^2.0.0","prettier":"^2.0.5","rimraf":"^3.0.2","tslint":"^6.1.2","typescript":"^3.9.3"},"gitHead":"5988daaba441fb653e2d065363ff6ee03064834d","bugs":{"url":"https://github.com/pugjs/babel-walk/issues"},"homepage":"https://github.com/pugjs/babel-walk#readme","_id":"babel-walk@2.0.0-canary-1","_nodeVersion":"12.16.3","_npmVersion":"6.14.4","dist":{"shasum":"296627c48f4af2b861c79f5de859b7be65e24f27","size":9237,"noattachment":false,"key":"/babel-walk/-/babel-walk-2.0.0-canary-1.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-walk/download/babel-walk-2.0.0-canary-1.tgz"},"maintainers":[{"name":"babel-walk-bot","email":""},{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"_npmUser":{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-walk_2.0.0-canary-1_1590434540779_0.16785487685814338"},"_hasShrinkwrap":false,"publish_time":1590434540936,"_cnpm_publish_time":1590434540936}},"readme":"# babel-walk\n\nLightweight AST traversal tools for [Babel] ASTs.\n\n[Babel] supplies the wonderful [babel-traverse] module for walking Babel ASTs. Problem is, babel-traverse is very heavyweight, as it is designed to supply utilities to make all sorts of AST transformations possible. For simple AST walking without transformation, babel-traverse brings a lot of overhead.\n\nThis module loosely implements the API of Acorn parser's [walk module], which is a lightweight AST walker for the ESTree AST format.\n\nIn my tests, babel-walk's ancestor walker (the most complex walker provided by this module) is about 8 times faster than babel-traverse, if the visitors are cached and the same AST is used for all runs. It is about 16 times faster if a fresh AST is used every run.\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/pugjs/babel-walk/rollingversions-canary.yml?branch=master&style=for-the-badge)](https://github.com/pugjs/babel-walk/actions?query=workflow%3A%22Publish+Canary%22)\n[![Rolling Versions](https://img.shields.io/badge/Rolling%20Versions-Enabled-brightgreen?style=for-the-badge)](https://rollingversions.com/pugjs/babel-walk)\n[![NPM version](https://img.shields.io/npm/v/babel-walk?style=for-the-badge)](https://www.npmjs.com/package/babel-walk)\n\n[babel]: https://babeljs.io/\n[babel-traverse]: https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#toc-babel-traverse\n[walk module]: https://github.com/ternjs/acorn#distwalkjs\n\n## Installation\n\n```sh\n$ npm install babel-walk\n```\n\n## API\n\n```js\nvar walk = require('babel-walk');\n```\n\n### walk.simple(visitors)(node, state)\n\nDo a simple walk over the AST. `node` should be the AST node to walk, and `visitors` an object containing Babel [visitors]. Each visitor function will be called as `(node, state)`, where `node` is the AST node, and `state` is the same `state` passed to `walk.simple`.\n\nWhen `walk.simple` is called with a fresh set of visitors, it will first \"explode\" the visitors (e.g. expanding `Visitor(node, state) {}` to `Visitor() { enter(node, state) {} }`). This exploding process can take some time, so it is recommended to cache the result of calling `walk.simple(visitors)` and communicate state leveraging the `state` parameter.\n\nAll [babel-types] aliases (e.g. `Expression`) work, but the union syntax (e.g. `'Identifier|AssignmentPattern'(node, state) {}`) does not.\n\n### walk.ancestor(visitors)(node, state)\n\nDo a simple walk over the AST, but memoizing the ancestors of the node and making them available to the visitors. `node` should be the AST node to walk, and `visitors` an object containing Babel [visitors]. Each visitor function will be called as `(node, state, ancestors)`, where `node` is the AST node, `state` is the same `state` passed to `walk.ancestor`, and `ancestors` is an array of ancestors to the node (with the outermost node being `[0]` and the current node being `[ancestors.length - 1]`). If `state` is not specified in the call to `walk.ancestor`, the `state` parameter will be set to `ancestors`.\n\nWhen `walk.ancestor` is called with a fresh set of visitors, it will first \"explode\" the visitors (e.g. expanding `Visitor(node, state) {}` to `Visitor() { enter(node, state) {} }`). This exploding process can take some time, so it is recommended to cache the result of calling `walk.ancestor(visitors)` and communicate state leveraging the `state` parameter.\n\nAll [babel-types] aliases (e.g. `Expression`) work, but the union syntax (e.g. `'Identifier|AssignmentPattern'(node, state) {}`) does not.\n\n### walk.recursive(visitors)(node, state)\n\nDo a recursive walk over the AST, where the visitors are responsible for continuing the walk on the child nodes of their target node. `node` should be the AST node to walk, and `visitors` an object containing Babel [visitors]. Each visitor function will be called as `(node, state, c)`, where `node` is the AST node, `state` is the same `state` passed to `walk.recursive`, and `c` is a function that takes a single node as argument and continues walking _that_ node. If no visitor for a node is provided, the default walker algorithm will still be used.\n\nWhen `walk.recursive` is called with a fresh set of visitors, it will first \"explode\" the visitors (e.g. expanding `Visitor(node, state) {}` to `Visitor() { enter(node, state) {} }`). This exploding process can take some time, so it is recommended to cache the result of calling `walk.recursive(visitors)` and communicate state leveraging the `state` parameter.\n\nUnlike other babel-walk walkers, `walk.recursive` does not call the `exit` visitor, only the `enter` (the default) visitor, of a specific node type.\n\nAll [babel-types] aliases (e.g. `Expression`) work, but the union syntax (e.g. `'Identifier|AssignmentPattern'(node, state) {}`) does not.\n\nIn the following example, we are trying to count the number of functions in the outermost scope. This means, that we can simply walk all the statements and increment a counter if it is a function declaration or expression, and then stop walking. Note that we do not specify a visitor for the `Program` node, and the default algorithm for walking `Program` nodes is used (which is what we want). Also of note is how I bring the `visitors` object outside of `countFunctions` so that the object can be cached to improve performance.\n\n```js\nimport * as t from 'babel-types';\nimport {parse} from 'babel';\nimport * as walk from 'babel-walk';\n\nconst visitors = walk.recursive({\n  Statement(node, state, c) {\n    if (t.isVariableDeclaration(node)) {\n      for (let declarator of node.declarations) {\n        // Continue walking the declarator\n        c(declarator);\n      }\n    } else if (t.isFunctionDeclaration(node)) {\n      state.counter++;\n    }\n  },\n\n  VariableDeclarator(node, state) {\n    if (t.isFunction(node.init)) {\n      state.counter++;\n    }\n  },\n});\n\nfunction countFunctions(node) {\n  const state = {\n    counter: 0,\n  };\n  visitors(node, state);\n  return state.counter;\n}\n\nconst ast = parse(`\n  // Counts\n  var a = () => {};\n\n  // Counts\n  function b() {\n    // Doesn't count\n    function c() {\n    }\n  }\n\n  // Counts\n  const c = function d() {};\n`);\n\ncountFunctions(ast);\n// = 3\n```\n\n[babel-types]: https://github.com/babel/babel/tree/master/packages/babel-types\n[cache your visitors]: https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#toc-optimizing-nested-visitors\n[visitors]: https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#toc-visitors\n\n## Caveat\n\nFor those of you migrating from Acorn to Babel, there are a few things to be aware of.\n\n1. The visitor caching suggestions do not apply to Acorn's walk module, but do for babel-walk.\n\n2. babel-walk does not provide any of the other functions Acorn's walk module provides (e.g. `make`, `findNode*`).\n\n3. babel-walk does not use a `base` variable. The walker algorithm is the same as what babel-traverse uses.\n   - That means certain nodes that are not walked by Acorn, such as the `property` property of a non-computed `MemberExpression`, are walked by babel-walk.\n\n## License\n\nMIT\n","_attachments":{},"homepage":"https://github.com/pugjs/babel-walk#readme","bugs":{"url":"https://github.com/pugjs/babel-walk/issues"},"license":"MIT"}