{"name":"ts-clone-node","version":"0.3.22","description":"A library that helps you clone Nodes from a Typescript AST","scripts":{"generate:sandhog":"sandhog all --yes","generate:changelog":"standard-changelog --first-release","generate:all":"pnpm run generate:sandhog && pnpm run generate:changelog","clean":"rimraf dist","lint":"tsc --noEmit && eslint \"src/**/*.ts\" --color","prettier":"prettier --write \"{src,test,documentation}/**/*.{js,ts,json,html,xml,css,md}\"","test":"ava","prebuild":"pnpm run clean","build":"pnpm run prebuild && pnpm run rollup","prewatch":"pnpm run clean","watch":"pnpm run prewatch && pnpm run rollup -- --watch","rollup":"rollup -c rollup.config.js","preversion":"pnpm run lint && pnpm run build","version":"pnpm run preversion && pnpm run generate:all && git add .","release":"np --no-cleanup --no-yarn","update:check":"pnpx npm-check-updates -x typescript-* --dep dev,prod","update:commit":"pnpx npm-check-updates -u -x typescript-* --dep dev,prod && pnpm update && pnpm install"},"keywords":["typescript","ast","node","clone","copy","duplicate"],"contributors":[{"name":"Frederik Wessberg","email":"frederikwessberg@hotmail.com","url":"https://github.com/wessberg"}],"license":"MIT","devDependencies":{"@types/semver":"^7.3.6","@types/node":"^15.6.1","@types/prettier":"^2.2.3","@typescript-eslint/eslint-plugin":"^4.25.0","@typescript-eslint/parser":"^4.25.0","@wessberg/rollup-plugin-ts":"^1.3.14","@wessberg/ts-config":"^1.1.2","sandhog":"^1.0.41","ava":"^3.15.0","eslint":"^7.27.0","eslint-config-prettier":"^8.3.0","eslint-plugin-import":"^2.23.4","eslint-plugin-jsdoc":"^35.0.0","husky":"^6.0.0","np":"7.5.0","pnpm":"^6.6.1","prettier":"^2.3.0","pretty-quick":"^3.1.0","rimraf":"^3.0.2","rollup":"^2.50.4","standard-changelog":"^2.0.27","ts-node":"^10.0.0","semver":"^7.3.5","helpertypes":"^0.0.2","tslib":"^2.2.0","npm-check-updates":"^11.5.13","typescript":"^4.3.2","typescript-3-0-1":"npm:typescript@3.0.1","typescript-3-1-1":"npm:typescript@3.1.1","typescript-3-2-1":"npm:typescript@3.2.1","typescript-3-3-1":"npm:typescript@3.3.1","typescript-3-4-1":"npm:typescript@3.4.1","typescript-3-5-1":"npm:typescript@3.5.1","typescript-3-6-2":"npm:typescript@3.6.2","typescript-3-7-2":"npm:typescript@3.7.2","typescript-3-8-3":"npm:typescript@3.8.3","typescript-3-9-2":"npm:typescript@3.9.2","typescript-4-0-3":"npm:typescript@4.0.3","typescript-4-1-2":"npm:typescript@4.1.2","typescript-4-2-4":"npm:typescript@4.2.4"},"dependencies":{"compatfactory":"^0.0.6"},"peerDependencies":{"typescript":"^3.x || ^4.x"},"main":"./dist/cjs/index.js","module":"./dist/esm/index.js","browser":"./dist/esm/index.js","types":"./dist/esm/index.d.ts","typings":"./dist/esm/index.d.ts","es2015":"./dist/esm/index.js","funding":{"type":"github","url":"https://github.com/wessberg/ts-clone-node?sponsor=1"},"repository":{"type":"git","url":"git+https://github.com/wessberg/ts-clone-node.git"},"bugs":{"url":"https://github.com/wessberg/ts-clone-node/issues"},"engines":{"node":">=10.0.0"},"ava":{"files":["test/**.test.ts"],"verbose":true,"timeout":"40s","extensions":["ts"],"environmentVariables":{"NODE_OPTIONS":"--max_old_space_size=4096","FORCE_COLOR":"3"},"require":["ts-node/register/transpile-only"]},"gitHead":"99ee1036db72952e3f8dc65c18642933d8635a27","homepage":"https://github.com/wessberg/ts-clone-node#readme","_id":"ts-clone-node@0.3.22","_nodeVersion":"15.14.0","_npmVersion":"7.7.6","dist":{"integrity":"sha512-hSdegaNEUX/AKVhxKRPJgPAelP8Ps795hxz/llrTZz12mnYlQhyfa2xmVgOijKlRt37FPWBVwppNZAWR7GMurg==","shasum":"a6ef46675c401e2c8916bd119fdb776caa460f3a","tarball":"http://registry-npm.ywwl.com/ts-clone-node/download/ts-clone-node-0.3.22.tgz","fileCount":10,"unpackedSize":843886,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgsr1/CRA9TVsSAnZWagAAUkUP/2oxVTgIQJaq3ZE6ipYS\nWT9R07abUgYzjMmUaYX9OR79bvaMLXWLLlGyJ59+9SA5QUHfG8qHMFgbjv4y\nQXJlf6Hcl77z/J7X9sqWqoEqeRfsdTRBdUuc6zkQmao+Tfp4AzJrvtc0S3GT\n39DU8azqfQwJjH6f2QHdnrPAH52kdtLOfTYGTPP+JRHgoMv2b9f2MT/5522u\nXvgrcl75ZbBsCM6llKTfi6keAr5ypMz4NM3m/yGbu5V2faBV2NZVSgyXydgR\nLfQcjESAEDG/DVRJx/i9Qu2KOfLBJIv7JEc+jhgJbXQu/gR8aQJPlH/Fn+4K\nYlWPfw0anIyvWWjvUrkQD3jDEtobHopYXcrUZxNqOucCwuK1ABQZ4Vw7TIRq\n7HoEpfoM13h4wSBDqE3DKBTYP2TLnqSBf7jrmO+AxwdakBWQHRfF5hr5h03P\nN2pMqtP82c89S3OtZyKd4o19GSCw0o5YdJkuxQd903qjchgnFKbNnkhFViEX\ntje6MSfeQ+x4osAStuupMLunVD7PwxDFq4orJV8xBWfTb8KO2mpA7U1C6Lgu\nKunBrQaQMBIHQ1M/lZJiOonPXn0vQLwSrYhiKuGUJHO/jTeKEx3ET01yEVpw\nTLp2wa5/llGAls5xVw3CNjD1z99v+YygoqhPdXQyPw8SL68lRUFNMH7/5O/8\ncJSD\r\n=egc6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBIykkMIW2YGkBKQRomTZ1qp1q1j84sI2ZAtr/GHQVAwAiEAojSDlw+DvmkOcLK7a5XMDQDXVjtxHTqCAwhxJj4S0O4="}],"size":85110,"noattachment":false,"key":"/ts-clone-node/-/ts-clone-node-0.3.22.tgz"},"_npmUser":{"name":"wessberg","email":"frederikwessberg@gmail.com"},"directories":{},"maintainers":[{"name":"wessberg","email":"frederikwessberg@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-clone-node_0.3.22_1622326654873_0.7346610667806661"},"_hasShrinkwrap":false,"readme":"<!-- SHADOW_SECTION_LOGO_START -->\n\n<div><img alt=\"Logo\" src=\"https://raw.githubusercontent.com/wessberg/ts-clone-node/master/documentation/asset/logo.png\" height=\"100\"   /></div>\n\n<!-- SHADOW_SECTION_LOGO_END -->\n\n<!-- SHADOW_SECTION_DESCRIPTION_SHORT_START -->\n\n> A library that helps you clone Nodes from a Typescript AST\n\n<!-- SHADOW_SECTION_DESCRIPTION_SHORT_END -->\n\n<!-- SHADOW_SECTION_BADGES_START -->\n\n<a href=\"https://npmcharts.com/compare/ts-clone-node?minimal=true\"><img alt=\"Downloads per month\" src=\"https://img.shields.io/npm/dm/ts-clone-node.svg\"    /></a>\n<a href=\"https://www.npmjs.com/package/ts-clone-node\"><img alt=\"NPM version\" src=\"https://badge.fury.io/js/ts-clone-node.svg\"    /></a>\n<img alt=\"Dependencies\" src=\"https://img.shields.io/librariesio/github/wessberg%2Fts-clone-node.svg\"    />\n<a href=\"https://github.com/wessberg/ts-clone-node/graphs/contributors\"><img alt=\"Contributors\" src=\"https://img.shields.io/github/contributors/wessberg%2Fts-clone-node.svg\"    /></a>\n<a href=\"https://github.com/prettier/prettier\"><img alt=\"code style: prettier\" src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg\"    /></a>\n<a href=\"https://opensource.org/licenses/MIT\"><img alt=\"License: MIT\" src=\"https://img.shields.io/badge/License-MIT-yellow.svg\"    /></a>\n<a href=\"https://www.patreon.com/bePatron?u=11315442\"><img alt=\"Support on Patreon\" src=\"https://img.shields.io/badge/patreon-donate-green.svg\"    /></a>\n\n<!-- SHADOW_SECTION_BADGES_END -->\n\n<!-- SHADOW_SECTION_DESCRIPTION_LONG_START -->\n\n## Description\n\n<!-- SHADOW_SECTION_DESCRIPTION_LONG_END -->\n\nThe Typescript Compiler API is very powerful and comes with a lot of `create` and `update` functions that can be used for creating and updating nodes in [Custom transformers](https://github.com/Microsoft/TypeScript/pull/13940) while visiting\na `SourceFile`. Under such circumstances, it is easy to run into problems if you reuse a Node in another part of the tree without properly cloning it, since the `parent` chain, as well as the `pos` and `end` values will have wrong values and will lead to malformed output after your transformations have been applied.\n\nThis can be cumbersome for example when you want to simply add or remove a specific modifier from an arbitrary node in a given position.\nThis library exports a `cloneNode` function that makes it easy to deep-clone a Node from a Typescript AST without any faulty parent links.\nAdditionally, you get a simple hook with which you can do simple things such as edit the top-level properties of the cloned object such as its modifiers, decorators, etc.\n\n<!-- SHADOW_SECTION_FEATURES_START -->\n\n### Features\n\n<!-- SHADOW_SECTION_FEATURES_END -->\n\n- Simple to use\n- Extensible\n- Supports dynamic TypeScript versions\n\n<!-- SHADOW_SECTION_FEATURE_IMAGE_START -->\n\n<!-- SHADOW_SECTION_FEATURE_IMAGE_END -->\n\n<!-- SHADOW_SECTION_BACKERS_START -->\n\n## Backers\n\n[Become a sponsor/backer](https://github.com/wessberg/ts-clone-node?sponsor=1) and get your logo listed here.\n\n| <a href=\"https://changelog.me\"><img alt=\"Trent Raymond\" src=\"https://avatars.githubusercontent.com/u/1509616?v=4\" height=\"70\"   /></a> | <a href=\"https://scrubtheweb.com/computers/programming/1\"><img alt=\"scrubtheweb\" src=\"https://avatars.githubusercontent.com/u/41668218?v=4\" height=\"70\"   /></a> |\n| -------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| [Trent Raymond](https://changelog.me)                                                                                                  | [scrubtheweb](https://scrubtheweb.com/computers/programming/1)                                                                                                   |\n\n### Patreon\n\n<a href=\"https://www.patreon.com/bePatron?u=11315442\"><img alt=\"Patrons on Patreon\" src=\"https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dwessberg%26type%3Dpatrons\"  width=\"200\"  /></a>\n\n<!-- SHADOW_SECTION_BACKERS_END -->\n\n<!-- SHADOW_SECTION_TOC_START -->\n\n## Table of Contents\n\n- [Description](#description)\n  - [Features](#features)\n- [Backers](#backers)\n  - [Patreon](#patreon)\n- [Table of Contents](#table-of-contents)\n- [Install](#install)\n  - [npm](#npm)\n  - [Yarn](#yarn)\n  - [pnpm](#pnpm)\n  - [Peer Dependencies](#peer-dependencies)\n- [Usage](#usage)\n- [Configuration](#configuration)\n  - [Hooking into and altering transformations](#hooking-into-and-altering-transformations)\n  - [Passing in a specific TypeScript version](#passing-in-a-specific-typescript-version)\n  - [Passing in a specific NodeFactory](#passing-in-a-specific-nodefactory)\n  - [Setting parent pointers](#setting-parent-pointers)\n  - [Setting original node pointers](#setting-original-node-pointers)\n  - [Preserving comments](#preserving-comments)\n  - [Preserving symbols](#preserving-symbols)\n- [Contributing](#contributing)\n- [Maintainers](#maintainers)\n- [FAQ](#faq)\n  - [What is the point of this library](#what-is-the-point-of-this-library)\n- [License](#license)\n\n<!-- SHADOW_SECTION_TOC_END -->\n\n<!-- SHADOW_SECTION_INSTALL_START -->\n\n## Install\n\n### npm\n\n```\n$ npm install ts-clone-node\n```\n\n### Yarn\n\n```\n$ yarn add ts-clone-node\n```\n\n### pnpm\n\n```\n$ pnpm add ts-clone-node\n```\n\n### Peer Dependencies\n\n`ts-clone-node` depends on `typescript`, so you need to manually install this as well.\n\n<!-- SHADOW_SECTION_INSTALL_END -->\n\n<!-- SHADOW_SECTION_USAGE_START -->\n\n## Usage\n\n<!-- SHADOW_SECTION_USAGE_END -->\n\nTo clone a Node from a Typescript AST, all you have to do is:\n\n```typescript\nimport {cloneNode} from \"ts-clone-node\";\n\n// Clone the Node\nconst clonedNode = cloneNode(someNode);\n```\n\n## Configuration\n\n### Hooking into and altering transformations\n\nYou can pass in a hook that enables you to modify the clone, agnostic to the kind of Node it is.\nFor example:\n\n```typescript\nimport {cloneNode} from \"ts-clone-node\";\n\n// Clone the Node, and alter the modifiers such that they don't include a modifier pointing\n// to the 'declare' keyword\nconst clonedNode = cloneNode(someNode, {\n\thook: node => {\n\t\treturn {\n\t\t\tmodifiers: modifiers => ensureNoDeclareModifier(modifiers)\n\t\t};\n\t}\n});\n```\n\nThere is also a _'finalize'_ which is invoked after a node has been cloned at any recursive step from the top node, allowing you to perform\nfinal alterations or track the node for other purposes.\n\n```typescript\nconst clonedNode = cloneNode(someNode, {\n\tfinalize: (clonedNode, oldNode) => trackSomething(clonedNode, oldNode)\n});\n```\n\n### Passing in a specific TypeScript version\n\nYou can use pass a specific TypeScript to use as an option to `cloneNode`:\n\n```typescript\ncloneNode(someNode, {\n\ttypescript: specialTypescriptVersion\n});\n```\n\nThis can be useful, for example, in an environment where multiple packages in the same project depends\non different TypeScript versions and you're relying on `cloneNode`.\n\n### Passing in a specific NodeFactory\n\nFrom TypeScript v4 and forward, a `NodeFactory` can be retrieved from a `TransformationContext` to signal which transformer was responsible for creating or altering nodes. If you want to pass a specific `NodeFactory`, you can pass it as an option to `cloneNode`:\n\n```typescript\ncloneNode(someNode, {\n\tfactory: nodeFactoryFromTransformationContext\n});\n```\n\n### Setting parent pointers\n\nBy default, when you clone a node, it won't update the parent pointers such that you and TypeScripts compiler APIs can traverse the parent tree.\nYou can toggle this behavior with the `setParents` option:\n\n```typescript\ncloneNode(someNode, {\n\tsetParents: true\n});\n```\n\n### Setting original node pointers\n\nBy default, when you clone a node, it won't keep references to the original nodes recursively.\nYou can toggle this behavior with the `setOriginalNodes` option:\n\n```typescript\ncloneNode(someNode, {\n\tsetOriginalNodes: true\n});\n```\n\n### Preserving comments\n\nBy default, when you clone a node, comments will be preserved as much as possible and added to the cloned nodes as `emitNodes`.\nYou can toggle this behavior with the `preserveComments` option:\n\n```typescript\ncloneNode(someNode, {\n\tpreserveComments: false\n});\n```\n\n### Preserving symbols\n\nBy default, when you clone a node, it won't preserve symbols from the original nodes.\nYou can toggle this behavior with the `preserveSymbols` option:\n\n```typescript\ncloneNode(someNode, {\n\tpreserveSymbols: true\n});\n```\n\n<!-- SHADOW_SECTION_CONTRIBUTING_START -->\n\n## Contributing\n\nDo you want to contribute? Awesome! Please follow [these recommendations](./CONTRIBUTING.md).\n\n<!-- SHADOW_SECTION_CONTRIBUTING_END -->\n\n<!-- SHADOW_SECTION_MAINTAINERS_START -->\n\n## Maintainers\n\n| <a href=\"mailto:frederikwessberg@hotmail.com\"><img alt=\"Frederik Wessberg\" src=\"https://avatars2.githubusercontent.com/u/20454213?s=460&v=4\" height=\"70\"   /></a>                                                                |\n| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| [Frederik Wessberg](mailto:frederikwessberg@hotmail.com)<br><strong>Twitter</strong>: [@FredWessberg](https://twitter.com/FredWessberg)<br><strong>Github</strong>: [@wessberg](https://github.com/wessberg)<br>_Lead Developer_ |\n\n<!-- SHADOW_SECTION_MAINTAINERS_END -->\n\n<!-- SHADOW_SECTION_FAQ_START -->\n\n## FAQ\n\n<!-- SHADOW_SECTION_FAQ_END -->\n\n### What is the point of this library\n\nIf you've run into the kind of trouble I'm explaining here, you'll understand. If not, I'm happy for you. You can move along!\n\n<!-- SHADOW_SECTION_LICENSE_START -->\n\n## License\n\nMIT © [Frederik Wessberg](mailto:frederikwessberg@hotmail.com) ([@FredWessberg](https://twitter.com/FredWessberg)) ([Website](https://github.com/wessberg))\n\n<!-- SHADOW_SECTION_LICENSE_END -->\n","publish_time":1622326655086,"_cnpm_publish_time":1622326655086,"dist-tags":{"latest":"4.0.0"}}