{"name":"astravel","version":"0.6.0","description":"ESTree-compliant AST walker and modifier.","main":"./dist/es5/astravel.js","module":"./dist/module/astravel.mjs","exports":{"import":"./dist/astravel.mjs","require":"./dist/astring.js","browser":"./dist/astring.min.js"},"scripts":{"prepare":"rm -rf dist/*; mkdir dist/import; cp src/*.js dist/import/; ls -1 dist/import/*.js | xargs -L 1 -I {} bash -c 'mv $1 \"${1%.*}.mjs\"' _ {};  babel --config-file ./babel.config.js --no-comments --source-maps --out-dir dist/es5 --ignore \"**/tests/**/*.js\" src; cross-env BABEL_MODE=module babel --config-file ./babel.config.js --no-comments --source-maps --out-dir dist/module --ignore \"**/tests/**/*.js\" src","dev":"ava --watch","dev:update":"ava --watch --update-snapshots","test":"npm run eslint && npm run prettier:check && npm run test:coverage","test:coverage":"c8 --reporter=html --reporter=text --reporter=lcov --include='src/*.js' --exclude='src/tests/**/*.js' ava","eslint":"eslint src/","prettier":"prettier --write \"src/*.js\" \"src/tests/*.js\" \"src/tests/helpers/*.js\"","prettier:check":"prettier --list-different \"src/*.js\" \"src/tests/*.js\" \"src/tests/helpers/*.js\"","prepush":"npm test","release":"standard-version","deploy":"git push --follow-tags origin master && npm publish","release:deploy":"npm run release && npm run deploy"},"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":{"@babel/cli":"^7.11.6","@babel/core":"^7.11.6","@babel/plugin-transform-runtime":"^7.11.5","@babel/preset-env":"^7.11.5","@babel/runtime":"^7.11.2","astring":"^1.4.3","ava":"^3.12.1","c8":"^7.3.0","codecov":"^3.7.2","cross-env":"^7.0.2","eslint":"^7.9.0","eslint-config-prettier":"^6.11.0","eslint-plugin-import":"^2.22.0","esm":"^3.2.25","exorcist":"^1.0.1","husky":"^4.3.0","meriyah":"^2.1.1","normalize-newline":"^3.0.0","prettier":"^2.1.2","standard-version":"^4.4.0"},"prettier":{"arrowParens":"always","bracketSpacing":true,"printWidth":80,"semi":false,"singleQuote":true,"tabWidth":2,"trailingComma":"all","useTabs":false},"ava":{"files":["src/**/tests/*.js"],"require":["esm"]},"esm":"auto","gitHead":"4a26a81d00b4b38a456ade947ddb29f61aa5b4f1","bugs":{"url":"https://github.com/davidbonnet/astravel/issues"},"homepage":"https://github.com/davidbonnet/astravel#readme","_id":"astravel@0.6.0","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","dist":{"integrity":"sha512-2K2kMx4boYPHeoc1BPavU+QXy39yupkRZfuKvceP9HGLHxW3f9On28ofKSTue+VnNFqAIj4ehuUQQ+Ida+RIfw==","shasum":"d73cfc7dc614d88892dd4707cbf5035b9f905c78","tarball":"http://registry-npm.ywwl.com/astravel/download/astravel-0.6.0.tgz","fileCount":26,"unpackedSize":141661,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhmsBWCRA9TVsSAnZWagAAFrsP/RmwD7AyQ8kYTGMa/Ksa\nvbX9wALng5wEiOzeiZ1y4LXZZyVsWeNgTE386k9M68gFutmyuvKiS0ywbe9f\nvYQNkQQyk9rw9VIdfTtW1u9Of9Y8MOydVNt5Ryf3/IKqP9kJ+31gYZhmtFrV\nwz4krXvXWlnp3V++9Kjzeafns65v81IleTp1nT9RGyPm1Fvwbl12ucnPNeNA\npsWzfp4vJSG/XUcRcv4Auhu+4xM62hKBPKMzd01VmVp0weUbwVzAtP48Bl3z\n3Hmwoj8wTyJQIPndleX/z+5NM8mMU/eM03zqGhxVM6M8+rfz6rRFjr3Slpia\nJKxttG2lNW6/GGURgEuGfdoH+785TtEK+2eCutNhOLQR1Tgztz9kB3dGsqIJ\nJb8+qjBxxO8GrVYUPBYgGRMKBZbg98i2Sj+5/Pb7h1H9LUgL/6W2l0eTrFFf\nJAsYK0pbZocuK+RP8R6CEMwm9Br63bFkXFh0tNoiqzONCrBCsCd5heWuvinR\nE73vC0cLKa2ZbMPBtUIk3P0lRoQREF+08oGCz1lqDwL9iHSbCmM6T9P7f/Ws\nwIz7GsQAcDH3qGNRJCi23sw2G/7UEuBxPPvbm0C5nsGqhHDvovkRgNxGU1II\nLpnH8wEfoWqmCSI5HDMiyEQfkz38H2HtSa9Ue50rFW2nf9oLkIyoQUP9WhIo\nX5AP\r\n=ShKO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEMCHzLmCwHYUikWmFyDLcTUBfxWzX8+KVI681OliP3Uuh4CIGZ8hKroVVMIEHwKucYMBzR7FC/eY4LuMmY98EtZ4pc+"}],"size":22432,"noattachment":false,"key":"/astravel/-/astravel-0.6.0.tgz"},"_npmUser":{"name":"davidbonnet","email":"david@bonnet.cc"},"directories":{},"maintainers":[{"name":"davidbonnet","email":"david@bonnet.cc"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/astravel_0.6.0_1637531734323_0.11614998844164415"},"_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":1637531734490,"_cnpm_publish_time":1637531734490,"dist-tags":{"latest":"0.6.1"}}