{"name":"espurify","description":"Clone new AST without extra properties","version":"2.0.0","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"}],"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":"690ce28cff6a2a0614ed3d1b820306836f8b7e0a","_id":"espurify@2.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.11.0","_npmUser":{"name":"twada","email":"takuto.wada@gmail.com"},"dist":{"integrity":"sha512-oL6Cm9tPs7wFRWaNmUkIZxCLUnQUJWnrpd5U546PO6QsvVKva2caK11fwIynzHDu0cLHWY9rZG9b2NnPOPUc9A==","shasum":"655952ed16002a6fefa5608d8acaaf4abad1f75e","tarball":"http://registry-npm.ywwl.com/espurify/download/espurify-2.0.0.tgz","fileCount":8,"unpackedSize":19098,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb90OUCRA9TVsSAnZWagAA3dkP/1MjqRfKNwOEdH6C3fYo\nnBsUGdYtc20Ftt8urJPsErxHBjS8ALrQ6D+lXKEEcRPVwasTDTjOzDe15m54\nsnoj/J08vaqhphHqLZ+qOA6Co4qrcxjtRhkHmDNzk4FiKrMXpAwHx8OQVZO5\nXehoeXpnukqnN60nWrL1s7tIsCu/6tR8AFuUGojq8h5ZHB2YXIH2t/Z2XYwJ\nFFkxiW4imFg2e2wXy3F0lKRjCvSWQRhlCTHcir/qLCg+B+Qa5GYbr6G0IxCo\n23fp18n0ipj4p9gF8ppuVjR45o1q3x4MOD+Xdse06+ubZZiBuuLXRRqjnogr\nqbv8N8oCjB+rwIOa5xnWHdyvhL4AM/6es+cOset/rH9tr7pgRoCBMj/6FZx0\n1C6wPrwFdsR6aYyrdNDej92xdbChqrPWi3Op8mK1BPlm3T/FgofIdBOHby3w\ngE4uk0jEQ3sGiHEFNdy8PQR3VXbY3kAMIMLXc6qxlF0Kzt3k458RNTgSjj+A\nXu6or12Ee2ErBJ4Thy9EnYnVLW3J84zFvawBQ06O8bRP6kCLv9Ia3pes0O3E\nYbUD7N5mjbCkEcD4hHsKWLLX7tWjpUKlN4xlgpQiiO/lRnttneOA32J9TBhB\n0/2mKt6ivMlV7LZwjDHwyFvj6DmE5IAziOlt3Ylm3XzpCgm3EjMqhmSex4le\nn/pm\r\n=CG32\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDV25R8s2rtenxK6K0L9SW2W0uZQ796RuoD7eeHzeRRkgIhAKPdhsvrfVL3Wt70o6dkKE3lX7MwcKH4KOKU2PENgdU6"}],"size":6038,"noattachment":false,"key":"/espurify/-/espurify-2.0.0.tgz"},"maintainers":[{"name":"twada","email":"takuto.wada@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/espurify_2.0.0_1542931347915_0.2933727851085266"},"_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":1542931348080,"_cnpm_publish_time":1542931348080,"dist-tags":{"latest":"3.2.0"}}