{"name":"espurify","description":"Clone new AST without extra properties","version":"1.8.1","author":{"name":"Takuto Wada","email":"takuto.wada@gmail.com","url":"https://github.com/twada"},"bugs":{"url":"https://github.com/estools/espurify/issues"},"dependencies":{"core-js":"^2.0.0"},"devDependencies":{"acorn":"^5.0.0","babel-types":"^6.3.20","babylon":"^6.3.20","browserify":"^13.0.0","derequire":"^2.0.2","dereserve":"^1.0.0","esprima":"^4.0.0","estraverse":"^4.1.0","licensify":"^3.1.0","mocha":"^5.0.0","semistandard":"^12.0.0","snazzy":"^7.0.0"},"files":["CHANGELOG.md","MIT-LICENSE.txt","README.md","index.js","lib","build/espurify.js","package.json"],"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","version":"npm run dist && git add -A build","dist":"browserify index.js --plugin licensify --standalone espurify | dereserve | derequire > ./build/espurify.js","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":"8b13a4eb59fb09918dd71dc19c31659dfd0976a2","_id":"espurify@1.8.1","_npmVersion":"6.1.0","_nodeVersion":"10.5.0","_npmUser":{"name":"twada","email":"takuto.wada@gmail.com"},"maintainers":[{"name":"twada","email":"takuto.wada@gmail.com"}],"dist":{"integrity":"sha512-ZDko6eY/o+D/gHCWyHTU85mKDgYcS4FJj7S+YD6WIInm7GQ6AnOjmcL4+buFV/JOztVLELi/7MmuGU5NHta0Mg==","shasum":"5746c6c1ab42d302de10bd1d5bf7f0e8c0515056","tarball":"http://registry-npm.ywwl.com/espurify/download/espurify-1.8.1.tgz","fileCount":9,"unpackedSize":78863,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbRHCLCRA9TVsSAnZWagAAH0YP/2hzQ0U2uOkfeGOIVteM\nKi2bRFxXzjz0umHKSAF8AdUYzRuEuCADuK7DMq1toLs1REE6ZWkmtDRUN7zl\n4o4kYFo3LwfFJ3bDYHv6BVhMMobaEWFbIRuxnbq16XvX+0i6fSLAUEdqmptK\nW9OhOvYCRK8rnZbgE5YSOjDi/1EP8WGURzuj+RfowOxvyD7QyecQN84dGTuO\nGRHjR+cbu9MRPFczHLT+QpKba06j80jr7k2zkwuUrFc85XfgyUPdSyP7osB9\n55VlLHCQT6+1KmYvyG7EKpI3I66XbBIc39P0njOW66LYxDwJARg1Qv/NeKu9\njZN/SY/+2L6YQ2XMVVMyWQzV0Z9oyMZ9q7ZHYZaMTCTTJIMnc5F8wQBhKzqO\nkkdse/8QJK4hUfFj6EYeKsD7olf15I+hnheQSglKEh0QaUc4LELYXhNNYLaB\nAy7bk+joi27HPYuarvVXTlEQxYntgA+JtpXPaZW3JKBWz5iK9thd4F8rEFHM\nH+pQv0Ao+FCDOxW5CMagwBxduT+j9d9u+YBXKwpY2ZEs4NsJ6VYDfTpXoaNr\nFuzhNoafrBJlCa1CfhhffuwomnB95pJHf/+dqE6PsrvYlYV5X8iLFgrmU6+r\n54ou9Zmq7heJxB+vYBWFrm5+GPPnHUWmqrv/Vu12lhTpiwo73EJWAphIUHJ2\nkuxw\r\n=oZux\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDZqba6IGf8J1+sbyjqQBQq/gjoc274fFZLtwQFhgKjrAIgCrnM1pmDiq7blsVAiHHs+XTgS2z8AXZwsyi0WkWEJ/U="}],"size":21299,"noattachment":false,"key":"/espurify/-/espurify-1.8.1.tgz"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/espurify_1.8.1_1531211915468_0.6861359704746635"},"_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":1531211915591,"_cnpm_publish_time":1531211915591,"dist-tags":{"latest":"3.2.0"}}