{"name":"espurify","description":"Clone new AST without extra properties","version":"2.0.1","author":{"name":"Takuto Wada","email":"takuto.wada@gmail.com","url":"https://github.com/twada"},"bugs":{"url":"https://github.com/estools/espurify/issues"},"contributors":[{"name":"Renée Kooi","url":"https://github.com/goto-bus-stop"},{"name":"Andreas Lind","url":"https://github.com/papandreou"}],"devDependencies":{"acorn":"^6.0.0","babel-types":"^6.3.20","babylon":"^6.3.20","esprima":"^4.0.0","estraverse":"^4.1.0","mocha":"^5.0.0","semistandard":"^13.0.0","snazzy":"^8.0.0"},"homepage":"https://github.com/estools/espurify","keywords":["ast","estree","ecmascript","es6"],"license":"MIT","main":"index.js","repository":{"type":"git","url":"git://github.com/estools/espurify.git"},"scripts":{"preversion":"npm test","lint":"semistandard --verbose index.js lib test | snazzy","fmt":"semistandard --fix index.js lib test","test":"npm run lint && mocha test"},"semistandard":{"ignore":["/build/","/bench/","**/*.jsx"],"globals":["describe","beforeEach","it"]},"gitHead":"86f6dea6b9b3add2f3487660dc8779fe130c0ba2","_id":"espurify@2.0.1","_npmVersion":"6.4.1","_nodeVersion":"10.15.0","_npmUser":{"name":"twada","email":"takuto.wada@gmail.com"},"dist":{"integrity":"sha512-7w/dUrReI/QbJFHRwfomTlkQOXaB1NuCrBRn5Y26HXn5gvh18/19AgLbayVrNxXQfkckvgrJloWyvZDuJ7dhEA==","shasum":"c25b3bb613863daa142edcca052370a1a459f41d","tarball":"http://registry-npm.ywwl.com/espurify/download/espurify-2.0.1.tgz","fileCount":8,"unpackedSize":20091,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcZnbbCRA9TVsSAnZWagAAwjUQAJfoHJMgN9URz9JOCeTv\n1YuagOdSnWYTjEXsNbA/Lx+mudnAJHAwXNOsDXFuI9ilartDYryCWW+YuV5D\nHGp1tziBWyKrNt3Wd1CWtG3DZRuljKO00E9ydRLD00dl6uQORBfV/yeIWUo3\nHrbI2M1fF/iiLSOvevG/k4/qEtik/dlNkZ3wfNMQ9RGV4su53eAdIxslQi/H\nYtdM2p9RFuZXPkO6bIyk28LAWFfRmLQmglBffr1+JPqxYgF6/RrEI9hL40u/\nQEEYWKYgOg3nUoCdGJa8zoa31M6kfESOWsVdJVvpVCXOHUKIoIaVKqWsicxs\nmDAu5WagUuHCTZEbhenS+tRUai1HJj8DwFrOJ5JCMr+BSYn9Do294H1ulPYL\nC8bOu4cOv2DXIasZ1vUKhZeuaGh45it3JpzZ9/HwBImH2sqwO0CVR19FqoM6\nzuVtGrUmphNz84quACCQLWrKYNHPHnc1AvGYalNyTHcLEwDNvOKas6ex2VsX\ndiSsfC0hgn5R+HMxKLdfb04eTOtcWQn3YcYxnmVYb/4CfDKg3wa8vUSrmu7I\nFp61LhWBQeEVTsaO98P6vSeGxALpZx3/50nSUNgAZ+wf6By//HaFLAqDxTUS\nD5MsMu1m3KXxV35DZyiDgt79Amyw2b6/yJBbY7y8zMMdnlB0lGGAeQ9FwMI4\nPoQR\r\n=W1RK\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGDO6AdL3aeJJWgJ8pJIxoGOGiRrpoIMjweLO9iUv7fOAiEA8/WauiRLtl8HQNarHCblZfV0OKFMmDivsN7n3Dz+UFw="}],"size":6246,"noattachment":false,"key":"/espurify/-/espurify-2.0.1.tgz"},"maintainers":[{"name":"twada","email":"takuto.wada@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/espurify_2.0.1_1550218970413_0.3391579578387698"},"_hasShrinkwrap":false,"readme":"espurify\n================================\n\nClone AST without extra properties\n\n[![Build Status][ci-image]][ci-url]\n[![NPM version][npm-image]][npm-url]\n[![Code Style][style-image]][style-url]\n[![License][license-image]][license-url]\n\n\nAPI\n---------------------------------------\n\n### const purifiedAstClone = espurify.purifyAst(originalAst)\n\nReturns new clone of `originalAst` but without extra properties.\n\nLeaves properties defined in [The ESTree Spec](https://github.com/estree/estree) (formerly known as [Mozilla SpiderMonkey Parser API](https://speakerdeck.com/michaelficarra/spidermonkey-parser-api-a-standard-for-structured-js-representations)) only. Also note that extra informations (such as `loc`, `range` and `raw`) are eliminated too.\n\n(note: using `espurify` as a default exported function is deprecated in favor of named exports aiming ESM era, and will be removed in future major releases)\n\n#### Supported ECMAScript versions\n\n- [ES5](https://github.com/estree/estree/blob/master/es5.md)\n- [ES2015](https://github.com/estree/estree/blob/master/es2015.md)\n- [ES2016](https://github.com/estree/estree/blob/master/es2016.md)\n- [ES2017](https://github.com/estree/estree/blob/master/es2017.md)\n- [ES2018](https://github.com/estree/estree/blob/master/es2018.md)\n- [ES2019](https://github.com/estree/estree/blob/master/es2019.md)\n- [ES2020](https://github.com/estree/estree/blob/master/es2020.md)\n- [ES2021](https://github.com/estree/estree/blob/master/es2021.md)\n- [ES2022](https://github.com/estree/estree/blob/master/es2022.md)\n\n\n### const customizedCloneFunctionWithAllowList = espurify.cloneWithAllowlist(allowList)\n\nReturns customized function for cloning AST, with user-provided `allowList`.\n\n(note: `espurify.cloneWithWhitelist` is still exported but deprecated in favor of more inclusive language and will be removed in future major releases)\n\n### const purifiedAstClone = customizedCloneFunctionWithAllowList(originalAst)\n\nReturns new clone of `originalAst` by customized function.\n\n\n#### allowList\n\n| type     | default value |\n|:---------|:--------------|\n| `object` | N/A           |\n\n`allowList` is an object containing NodeType as keys and properties as values.\n\n```js\n{\n    ArrayExpression: ['type', 'elements'],\n    ArrayPattern: ['type', 'elements'],\n    ArrowFunctionExpression: ['type', 'id', 'params', 'body', 'generator', 'expression'],\n    AssignmentExpression: ['type', 'operator', 'left', 'right'],\n    ...\n```\n\n\n### const customizedCloneFunction = espurify.customize(options)\n\nReturns customized function for cloning AST, configured by custom `options`.\n\n\n### const purifiedAstClone = customizedCloneFunction(originalAst)\n\nReturns new clone of `originalAst` by customized function.\n\n\n\n#### options\n\n| type     | default value |\n|:---------|:--------------|\n| `object` | `{}`          |\n\nConfiguration options. If not passed, default options will be used.\n\n\n#### options.ecmaVersion\n\n| type                 | default value |\n|:---------------------|:--------------|\n| `string` or `number` | `2022`        |\n\nIndicates the ECMAScript version to clone. Must be either 5, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022.\n\n\n#### options.extra\n\n| type                | default value |\n|:--------------------|:--------------|\n| `array` of `string` | null          |\n\nList of extra properties to be left in result AST. For example, functions returned by `espurify.customize({extra: ['raw']})` will preserve `raw` properties of `Literal`. Functions return by `espurify.customize({extra: ['loc', 'range']})` will preserve `loc` and `range` properties of each Node.\n\n\nEXAMPLE\n---------------------------------------\n\n```javascript\nconst espurify = require('espurify');\nconst estraverse = require('estraverse');\nconst acorn = require('acorn');\nconst syntax = estraverse.Syntax;\nconst assert = require('assert');\n\nconst jsCode = 'assert(\"foo\")';\n\n// Adding extra informations to AST\nconst originalAst = acorn.parse(jsCode, { locations: true, ranges: true, ecmaVersion: 2022 });\nestraverse.replace(originalAst, {\n  leave: function (currentNode, parentNode) {\n    if (currentNode.type === syntax.Literal && typeof currentNode.raw !== 'undefined') {\n      currentNode['x-verbatim-bar'] = {\n        content : currentNode.raw,\n        precedence : 18  // escodegen.Precedence.Primary\n      };\n      return currentNode;\n    } else {\n      return undefined;\n    }\n  }\n});\n\n\n// purify AST\nconst purifiedClone = espurify.purifyAst(originalAst);\n\n\n// Extra properties are eliminated from cloned AST\nassert.deepEqual(purifiedClone, {\n  type: 'Program',\n  body: [\n    {\n      type: 'ExpressionStatement',\n      expression: {\n        type: 'CallExpression',\n        callee: {\n          type: 'Identifier',\n          name: 'assert'\n        },\n        arguments: [\n          {\n            type: 'Literal',\n            value: 'foo'\n          }\n        ],\n        optional: false\n      }\n    }\n  ],\n  sourceType: 'script'\n});\n\n\n// original AST is not modified\nassert.deepEqual(originalAst,{\n  type: 'Program',\n  start: 0,\n  end: 13,\n  loc: {\n    start: {\n      line: 1,\n      column: 0\n    },\n    end: {\n      line: 1,\n      column: 13\n    }\n  },\n  range: [\n    0,\n    13\n  ],\n  body: [\n    {\n      type: 'ExpressionStatement',\n      start: 0,\n      end: 13,\n      loc: {\n        start: {\n          line: 1,\n          column: 0\n        },\n        end: {\n          line: 1,\n          column: 13\n        }\n      },\n      range: [\n        0,\n        13\n      ],\n      expression: {\n        type: 'CallExpression',\n        start: 0,\n        end: 13,\n        loc: {\n          start: {\n            line: 1,\n            column: 0\n          },\n          end: {\n            line: 1,\n            column: 13\n          }\n        },\n        range: [\n          0,\n          13\n        ],\n        callee: {\n          type: 'Identifier',\n          start: 0,\n          end: 6,\n          loc: {\n            start: {\n              line: 1,\n              column: 0\n            },\n            end: {\n              line: 1,\n              column: 6\n            }\n          },\n          range: [\n            0,\n            6\n          ],\n          name: 'assert'\n        },\n        arguments: [\n          {\n            type: 'Literal',\n            start: 7,\n            end: 12,\n            loc: {\n              start: {\n                line: 1,\n                column: 7\n              },\n              end: {\n                line: 1,\n                column: 12\n              }\n            },\n            range: [\n              7,\n              12\n            ],\n            value: 'foo',\n            raw: '\"foo\"',\n            \"x-verbatim-bar\": {\n              content: '\"foo\"',\n              precedence: 18\n            }\n          }\n        ],\n        optional: false\n      }\n    }\n  ],\n  sourceType: 'script'\n});\n```\n\n\nINSTALL\n---------------------------------------\n\n### via npm\n\nInstall\n\n    $ npm install --save espurify\n\nUse\n\n```javascript\nconst espurify = require('espurify');\n```\n\n\nAUTHOR\n---------------------------------------\n* [Takuto Wada](https://github.com/twada)\n\n\nCONTRIBUTORS\n---------------------------------------\n* [Renée Kooi](https://github.com/goto-bus-stop)\n* [Andreas Lind](https://github.com/papandreou)\n\n\nLICENSE\n---------------------------------------\nLicensed under the [MIT](https://github.com/estools/espurify/blob/master/MIT-LICENSE.txt) license.\n\n\n[npm-url]: https://npmjs.org/package/espurify\n[npm-image]: https://badge.fury.io/js/espurify.svg\n\n[ci-image]: https://github.com/estools/espurify/workflows/Node.js%20CI/badge.svg\n[ci-url]: https://github.com/estools/espurify/actions?query=workflow%3A%22Node.js+CI%22\n\n[style-url]: https://github.com/Flet/semistandard\n[style-image]: https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg\n\n[license-url]: https://github.com/estools/espurify/blob/master/MIT-LICENSE.txt\n[license-image]: https://img.shields.io/badge/license-MIT-brightgreen.svg\n","publish_time":1550218970520,"_cnpm_publish_time":1550218970520,"dist-tags":{"latest":"3.2.0"}}