{"name":"astravel","version":"0.5.0","description":"ESTree-compliant AST walker and modifier.","main":"./dist/astravel.js","scripts":{"test:build":"cross-env BABEL_ENV=test babel test/index.js --out-file test/_index.js","test":"npm run prettier && npm run test:build && tap test/_index.js --coverage","codecov":"tap --coverage-report=lcov && codecov","coverage":"tap --coverage-report=html","prepublish":"npm run build && npm run build:minified","build":"cross-env BABEL_ENV=production babel src --out-dir dist --source-maps=true","build:minified":"cross-env BABEL_ENV=minified browserify --debug --transform [ babelify --no-sourceMaps ] --no-builtins --standalone astravel --require ./src/astravel.js:astravel --outfile dist/astravel.min.js","start":"cross-env BABEL_ENV=development babel src --watch --out-dir dist --source-maps=true","prettier":"prettier --print-width 80 --tab-width 2 --no-semi --single-quote --trailing-comma all --parser babylon --list-different \"src/**/*.js\" \"test/index.js\"","prettify":"prettier --print-width 80 --tab-width 2 --no-semi --single-quote --trailing-comma all --parser babylon --write \"src/**/*.js\" \"test/index.js\"","prepush":"npm test","release":"standard-version"},"keywords":["ast","ast walker","ast traveler","ast modifier","estree","astring"],"repository":{"type":"git","url":"git+https://github.com/davidbonnet/astravel.git"},"author":{"name":"David Bonnet","email":"david@bonnet.cc"},"license":"MIT","devDependencies":{"acorn":"^5.7.1","astring":"^1.0.5","babel-cli":"^6.24.0","babel-preset-env":"^1.5.2","babel-preset-minify":"^0.4.3","babelify":"^8.0.0","browserify":"^16.2.2","codecov":"^3.0.0","cross-env":"^5.2.0","eslint":"^5.0.0","eslint-plugin-import":"^2.6.0","husky":"^0.14.3","normalize-newline":"^3.0.0","prettier":"^1.13.5","standard-version":"^4.4.0","tap":"^12.0.1"},"gitHead":"26e40d77f8a99cedf8fcc4ed236690cecc64b106","bugs":{"url":"https://github.com/davidbonnet/astravel/issues"},"homepage":"https://github.com/davidbonnet/astravel#readme","_id":"astravel@0.5.0","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"davidbonnet","email":"david@bonnet.cc"},"dist":{"integrity":"sha512-bA3cq0dqwjxfUneiAJZW2kE9NPIrv7h6dTaPfGOP0hwO/5yS4CVuZzPxuL5g8V1oeevbUK8Os3Igr+vnOv74pw==","shasum":"77d971493421c2a5e49609d21662b7daab9c0e6e","tarball":"http://registry-npm.ywwl.com/astravel/download/astravel-0.5.0.tgz","fileCount":17,"unpackedSize":152370,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbLiIQCRA9TVsSAnZWagAAWgQQAI4hhXQaeJHncRUQhk8O\nIQmAhFKBHnVKz281ENkIXOp+QplptArT1jwsuqhrgwxDzgYS2GBxylGc/mMO\nB2ZLmDJ4eQHcw1l6O8m9N4hTaKw5Dt4xfneE53DuJtBJ/ZZEw39zSIF4JeDo\nWqdUID7g/WK3gj1qzj2jerX8zU99Ic0rVfaPnNO3Uify28lj8eVJHxtJGz/t\n2glXJS0QIVTffdb9U+A/7K/JIOr0Gduiry+ZoWSc3WBczIzqI4mYGSNIFaxs\n5W5V6lbGZa2LJikQaX83F9qWrBykcPLg3XVikSH6Z1hNbV5GKGiV94I5BVSj\n/iKnlzRIHedWoD5StapyxJUTEasvxC3iLc0jXV6uNTdtJOcMaTZ5Jn+/8Wc4\nhIjIGAbMXpQ/7ZkWTFh3YeMI3kUUsyOh1wzSrX0IvrCrd+cxxUJbN5mlRfh2\nOVgFc8OHdVfSbDMTlFPnxzysYvTCc6iFWClGXHZKNwwtyCE+CQwJP1+ONDO4\nd+F2S/4tGwDeuBpLwxvez1JoU/MXAULa9OWf38XMgW99m5eo5JyxXZ6wzw8W\nM+9XaSWLwZGrvxuX0oGgj1uJA3CUYfKNYpcGCW7qBhghtl0atc5vqfxyolHA\nOf1wDr5LId8oGeeL6Q3OmiHpnDTigXeqm1cnpXf67m8YtGmVRfP7G2XKPaEV\nZRDZ\r\n=XlLQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDJlwADTF0mPFz+6MQzcJXE7lWV+1lRvUyPzoqk2pHbxAiBUO7Xr+nU7pJEFcwXPMS/Sj2493n1A5831TPh8BCNTqg=="}],"size":34062,"noattachment":false,"key":"/astravel/-/astravel-0.5.0.tgz"},"maintainers":[{"name":"davidbonnet","email":"david@bonnet.cc"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/astravel_0.5.0_1529750032892_0.5160760740277539"},"_hasShrinkwrap":false,"readme":"# Astravel\n\n[![NPM Version](https://img.shields.io/npm/v/astravel.svg)](https://www.npmjs.org/package/astravel)\n[![Build Status](https://travis-ci.org/davidbonnet/astravel.svg?branch=master)](https://travis-ci.org/davidbonnet/astravel)\n[![Coverage](https://codecov.io/gh/davidbonnet/astravel/branch/master/graph/badge.svg)](https://codecov.io/gh/davidbonnet/astravel)\n[![devDependency Status](https://david-dm.org/davidbonnet/astravel/dev-status.svg)](https://david-dm.org/davidbonnet/astravel#info=devDependencies)\n[![Greenkeeper](https://badges.greenkeeper.io/davidbonnet/astravel.svg)](https://greenkeeper.io/)\n\n👟 A tiny and fast [ESTree](https://github.com/estree/estree)-compliant AST walker and modifier.\n\n### Key features\n\n- Works on [ESTree](https://github.com/estree/estree)-compliant ASTs (JavaScript [version 13 (2022)](https://tc39.github.io/ecma262/)), such as the ones produced by [Meriyah](https://github.com/meriyah/meriyah).\n- Out-of-the-box functions such as source code comments insertion for [Astring](https://github.com/davidbonnet/astring).\n- Extensible with custom nodes.\n- No dependencies and small footprint.\n\n## Installation\n\nInstall with the [Node Package Manager](https://www.npmjs.com/package/astravel):\n\n```bash\nnpm install astravel\n```\n\nAlternatively, checkout this repository and install the development dependencies to build the module file:\n\n```bash\ngit clone https://github.com/davidbonnet/astravel.git\ncd astravel\nnpm install\n```\n\n## Usage\n\nThe `astravel` module exports the following items:\n\n<!-- MarkdownTOC autolink=\"true\" levels=\"4\" -->\n\n- [`defaultTraveler`](#defaulttraveler)\n- [`makeTraveler()`](#maketraveler)\n- [`attachComments()`](#attachcomments)\n\n<!-- /MarkdownTOC -->\n\n#### `defaultTraveler`\n\n> ⬅️ `traveler`\n\n> ⚠️ Deprecated in favor of ES6 class notation.\n\nThis object describes a basic AST traveler. It contains the following methods:\n\n- `go(node, state)`: Travels through the provided AST `node` with a given `state` (an object that can be of any type) by recursively calling this method.\n- `find(predicate, node, state) ➞ { node, state }?`: Returns `{ node, state }` for which `predicate(node, state)` returns truthy, starting at the specified AST `node` and with the provided `state`. Otherwise, returns `undefined`.\n- `[NodeType](node, state)`: Method handler for a specific `NodeType`.\n- `makeChild(properties) ➞ traveler`: Returns a custom AST traveler that inherits from `this` traveler with its own provided `properties` and the property `super` that points to `this` traveler.\n\n#### `makeTraveler()`\n\n> ➡️ `(properties)`\n> ⬅️ `traveler`\n\n> ⚠️ Deprecated in favor of ES6 class notation.\n\nThis function is similar to `astravel.defaultTraveler.makeChild`: it returns a traveler that inherits from the `defaultTraveler` with its own provided `properties` and the property `super` that points to the `defaultTraveler` object. These properties should redefine the traveler's behavior by implementing the `go(node, state)` method and/or any node handler.\n\nWhen redefining the `go` method, make sure its basic functionality is kept by calling the parent's `go` method to keep traveling through the AST:\n\n```javascript\nconst customTraveler = makeTraveler({\n  go: function (node, state) {\n    // Code before entering the node\n    console.log('Entering ' + node.type)\n    // Call the parent's `go` method\n    this.super.go.call(this, node, state)\n    // Code after leaving the node\n    console.log('Leaving ' + node.type)\n  },\n})\n```\n\nTo skip specific node types, the most effective way is to replace the corresponding node handlers with a function that does nothing:\n\n```javascript\nimport { makeTraveler } from 'astravel'\n\nconst ignore = Function.prototype\nconst customTraveler = makeTraveler({\n  FunctionDeclaration: ignore,\n  FunctionExpression: ignore,\n  ArrowFunctionExpression: ignore,\n})\n```\n\n#### `attachComments()`\n\n> ➡️ `(ast, comments)`\n> ⬅️ `ast`\n\nThis function attaches a list of `comments` to the corresponding nodes of a provided `ast` and returns that same `ast`. The `ast` is modified in-place and only the nodes getting comments are augmented with a `comments` and/or a `trailingComments` array property.\n\nEach comment should be an object with the following properties:\n\n- `type`: `\"Line\"` or `\"Block\"`\n- `value`: Comment string value\n- `start`: Comment starting character offset number\n- `end`: Comment ending character offset number\n- `loc`: Location object with `start` and `end` properties containing one-based `line` number and zero-based `column` number properties.\n\nThe following examples show how to obtain a proper list of `comments` of a given source `code` and how to attach them on the generated `ast`:\n\n##### Usage with [Meriyah](https://github.com/meriyah/meriyah)\n\n```javascript\nimport { parse } from 'meriyah'\nimport { attachComments } from 'astravel'\n\nconst comments = []\nconst ast = parse(code, {\n  // Comments are stored in this array\n  onComment: comments,\n})\n// Attach comments on the AST\nattachComments(ast, comments)\n```\n\n##### Usage with [Acorn](https://github.com/acornjs/acorn)\n\n```javascript\nimport { parse } from 'acorn'\nimport { attachComments } from 'astravel'\n\nconst comments = []\nconst ast = parse(code, {\n  // This ensures that the `loc` property is present on comment objects\n  locations: true,\n  onComment: comments,\n})\nattachComments(ast, comments)\n```\n\nThe algorithm assumes that comments are not put in exotic places, such as in-between function arguments, and proceeds as follows:\n\n- For a given statement, it stores all comments right above it and on the same line to it's right side in a `comments` property.\n- If a comment block is at the beginning of a code block, it is attached to that code block.\n- Comments not followed by any statement in a code block are attached as `trailingComments` to that code block.\n\nIn this example, the comments tell to which statement they are attached:\n\n```javascript\n// Attached to the variable declaration just below\nconst point = {\n  // Attached to the property definition just below\n  x: 0,\n  y: 0, // Attached to the property definition on its left\n}\n/*\nAttached to the function declaration just below.\n*/\nfunction add(a, b) {\n  /*\n   Attached to the function body because it is the first comment block.\n   */\n  return a + b // Attached to the return statement on its left\n  // Trailing comment attached as such to the function body\n}\n// Trailing comment attached as such to the program body\n```\n","publish_time":1529750032993,"_cnpm_publish_time":1529750032993,"dist-tags":{"latest":"0.6.1"}}