{"name":"ts-clone-node","version":"2.0.4","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 && dotcjs dist/cjs","version":"pnpm run preversion && pnpm run generate:all && git add .","release":"np --no-cleanup --no-yarn --no-tests","update:check":"pnpx npm-check-updates -x typescript-* --dep dev,prod","update:commit":"pnpx npm-check-updates -u -x typescript-*,ava --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.13","@types/node":"^18.11.18","@types/prettier":"^2.7.2","@typescript-eslint/eslint-plugin":"^5.48.1","@typescript-eslint/parser":"^5.48.1","@wessberg/ts-config":"^2.0.4","@wessberg/prettier-config":"1.0.0","crosspath":"2.0.0","dotcjs":"1.0.1","rollup-plugin-ts":"^3.1.0","sandhog":"^2.0.2","ava":"^3.15.0","eslint":"^8.31.0","eslint-config-prettier":"^8.6.0","eslint-plugin-import":"^2.26.0","eslint-plugin-jsdoc":"^39.6.4","husky":"^8.0.3","np":"7.6.3","pnpm":"^7.23.0","prettier":"^2.8.2","pretty-quick":"^3.1.3","rimraf":"^3.0.2","rollup":"^3.9.1","standard-changelog":"^2.0.27","ts-node":"^10.9.1","semver":"^7.3.8","helpertypes":"^0.0.19","tslib":"^2.4.1","npm-check-updates":"^16.6.2","typescript":"^4.9.4","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","typescript-4-3-5":"npm:typescript@4.3.5","typescript-4-4-3":"npm:typescript@4.4.3","typescript-4-5-4":"npm:typescript@4.5.4","typescript-4-6-4":"npm:typescript@4.6.4","typescript-4-7-2":"npm:typescript@4.7.2","typescript-4-8-2":"npm:typescript@4.8.2"},"dependencies":{"compatfactory":"^2.0.9"},"peerDependencies":{"typescript":"^3.x || ^4.x"},"exports":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.cjs"},"type":"module","types":"./dist/esm/index.d.ts","main":"./dist/cjs/index.cjs","module":"./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":">=14.9.0"},"prettier":"@wessberg/prettier-config","ava":{"files":["test/**.test.ts"],"verbose":true,"timeout":"400s","nonSemVerExperiments":{"configurableModuleFormat":true},"extensions":{"ts":"module"},"nodeArguments":["--loader=ts-node/esm"],"environmentVariables":{"FORCE_COLOR":"3"}},"gitHead":"0aa23f57cc39697b698c3ee464d1204f667d1e05","homepage":"https://github.com/wessberg/ts-clone-node#readme","_id":"ts-clone-node@2.0.4","_nodeVersion":"19.3.0","_npmVersion":"9.2.0","dist":{"integrity":"sha512-eG6FAgmQsenhIJOIFhUcO6yyYejBKZIKcI3y21jiQmIOrth5pD6GElyPAyeihbPSyBs3u/9PVNXy+5I7jGy8jA==","shasum":"18f26c2d490f65c6925f7a841a44ca2476da3eee","tarball":"http://registry-npm.ywwl.com/ts-clone-node/download/ts-clone-node-2.0.4.tgz","fileCount":9,"unpackedSize":902161,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG39F6wOaoBwzdKqkrQ89qwoI1XAsWAQnB4L6G0tVNGmAiBDkXYrVO6GTvv9IPb/T/sRNuJ4MprVMlD1YIiNPpY8jA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjvKjxACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqiYA//fx81Y9PVKpvy5ML+h82VWi6rxlzhnBrwlqX2xgu4RQxDFbSr\r\npEyAKzT3E09DQCa3fQvcii0xTBkrStecYEC152cL2+Wx8ls638dnJ4cW1+MM\r\nMaG1laAqoGeBN4Pm30r+KYKa4zxkUy1SbaZjQjHFkh1TE5dpnNbzfZj3Dmff\r\n7BecRH6XcF+WNNebVA9YxR4VqN7Hc6LDTDTKVYOGFjYFVN/SGcJKRmM3yNNf\r\n2tyHJHrHY/xyVn/W7wSXXtlcs87AUSjizvwoBrhgFlm6ebaJZ2XJV46cBWlt\r\nBtLju3FSqlRmqfpz9m/ZBFBcTl19idlEefERRzcAzaSZ5E6NrnRbzhnr1HOV\r\nUyNboVryl5xJvOcFtUQ0jLXKZ0I1LLs61tPm9WUsD/leLX6O0BH6xjjp9DYe\r\nHtMvxUmxm25y12xorhEqeniR6Iyr58UCdK9elhRUZTbP4hYiUxfIaefR0RyW\r\njPUq9UUlEbe3NAHmfeeRvU+jlD4c1hNybcKvOoM11buMxIB48uB7LwuIeYjt\r\nteax33youz4oht9UGuAnB9bHX0vWD4CYgr1pPh5MDgvW71oswfMvRIoPQZwi\r\nOlnq+Fmqlvot0EdYLwnyU3pR75cVJftNhg89Kmdk5CvLojiK/MV23a1B5oQT\r\n6GnazpPOrGWAvN4w99XOG2Fj0eSzal8Mo7o=\r\n=Kx43\r\n-----END PGP SIGNATURE-----\r\n","size":90492,"noattachment":false,"key":"/ts-clone-node/-/ts-clone-node-2.0.4.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_2.0.4_1673308401586_0.28293020381188305"},"_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":1673308401741,"_cnpm_publish_time":1673308401741,"dist-tags":{"latest":"4.0.0"}}