{"name":"espurify","description":"Clone AST without extra properties","version":"3.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"},{"name":"Andreas Lind","url":"https://github.com/papandreou"}],"devDependencies":{"acorn":"^8.0.0","babel-types":"^6.3.20","babylon":"^6.3.20","esprima":"^4.0.0","estraverse":"^5.0.0","mocha":"^9.0.0","semistandard":"^16.0.0","snazzy":"^9.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":"38a210159fc8ad1985704b31f1e30a7a5b26345c","_id":"espurify@3.0.0","_nodeVersion":"18.6.0","_npmVersion":"8.13.2","dist":{"integrity":"sha512-vn4TnoK+c5jvwFxMoktfFESWJJWUHHcvNjjIY8M3X6Pq7IG9wRVzjGC52DeJAV7Mwu8Sonhx8zsg34SvwGiNkw==","shasum":"4387f345a0e7b4612c27ed6d110beac0e315aa22","tarball":"http://registry-npm.ywwl.com/espurify/download/espurify-3.0.0.tgz","fileCount":14,"unpackedSize":41229,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCiIT7jCacYL3QtU7syewqxqzX3TebQCYjBozWGTHgtrwIhAIUmPfxNtfuMzxrHTLYgRpwhBxL5DhAn0J1vsHfW/lwP"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi1APJACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq5NA//b35y4Ew6YAKA5rnYDWRcwVcl2zxedbLG42TH+MfO9eTjPQlk\r\nVhURIY3GyVseVd8bhOmKFmHZh36b53IhcDiVJxmnKewnIIJQ8VVAznkGj9Uq\r\n8IHeJ9WYAZ4uEBj376n6hnk05VHjja2OSDDN5b6xWu4+YQnNJMZmNY55GT1b\r\ndz9Fi/wqH4VDbDLRKFUf/KDlsYHLpd08KN5FDlmf8cv7Y1iwJOyHkL1s+lNV\r\nYraJNANnp/OHdV3EB5oBg42j+H1phw2C8Wu3Atyn5TtSp6DrOLImESqapAKk\r\n9i6XivNL74yKAp4io5zQuLKRVJQ7UX7bqYeYo4+463oO93tfD3F6az49otoc\r\n/zuCCTEDDg1xr8m3gCXiR15mQ3qtatrbdnJZksNrIM2Q5QMHOSjP3Mo0YwQT\r\nW+oFAo13ulW8dTbgq0MaD/R6W5dX79Uc8wR07yQBRtBiz63RWNs55dUC9MhF\r\nmNDsTNn29KkDQf9OlV3a8hT0NVQqzdD/5Z4Z34fzZXnO3B9ITTYvJkjFUDsZ\r\nsxd2IJEnroQYzqtpllHIobLz4XloQsDMjT1fYHvQ2dagAZp8ShAl/tKlhcUv\r\nN+5PNpQCHwtKGoFwUZRheGEcPfNbk1mTemS6pggdzZzPwDdbETJOL1SvBONH\r\nKjW3y0BF+6ytVZYep5QCIIVO5wl41PBGXGw=\r\n=8tZ/\r\n-----END PGP SIGNATURE-----\r\n","size":7864,"noattachment":false,"key":"/espurify/-/espurify-3.0.0.tgz"},"_npmUser":{"name":"twada","email":"takuto.wada@gmail.com"},"directories":{},"maintainers":[{"name":"twada","email":"takuto.wada@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/espurify_3.0.0_1658061769023_0.6451957688195826"},"_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":1658061769198,"_cnpm_publish_time":1658061769198,"dist-tags":{"latest":"3.2.0"}}