├── .gitattributes ├── .github ├── FUNDING.yml └── workflows │ └── workflow.yml ├── .gitignore ├── .husky ├── .gitignore └── pre-commit ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── documentation └── asset │ ├── logo-social-preview.png │ ├── logo.png │ └── logo.svg ├── eslint.config.js ├── package.json ├── pnpm-lock.yaml ├── sandhog.config.js ├── src ├── clone-node │ ├── clone-array-binding-pattern.ts │ ├── clone-array-literal-expression.ts │ ├── clone-array-type-node.ts │ ├── clone-arrow-function.ts │ ├── clone-as-expression.ts │ ├── clone-assert-clause.ts │ ├── clone-assert-entry.ts │ ├── clone-await-expression.ts │ ├── clone-big-int-literal.ts │ ├── clone-binary-expression.ts │ ├── clone-binding-element.ts │ ├── clone-block.ts │ ├── clone-boolean-literal.ts │ ├── clone-break-statement.ts │ ├── clone-call-expression.ts │ ├── clone-call-signature-declaration.ts │ ├── clone-case-block.ts │ ├── clone-case-clause.ts │ ├── clone-catch-clause.ts │ ├── clone-class-declaration.ts │ ├── clone-class-expression.ts │ ├── clone-class-static-block-declaration.ts │ ├── clone-comma-list-expression.ts │ ├── clone-computed-property-name.ts │ ├── clone-conditional-expression.ts │ ├── clone-conditional-type-node.ts │ ├── clone-construct-signature-declaration.ts │ ├── clone-constructor-declaration.ts │ ├── clone-constructor-type-node.ts │ ├── clone-continue-statement.ts │ ├── clone-debugger-statement.ts │ ├── clone-decorator.ts │ ├── clone-default-clause.ts │ ├── clone-delete-expression.ts │ ├── clone-do-statement.ts │ ├── clone-element-access-expression.ts │ ├── clone-empty-statement.ts │ ├── clone-enum-declaration.ts │ ├── clone-enum-member.ts │ ├── clone-export-assignment.ts │ ├── clone-export-declaration.ts │ ├── clone-export-specifier.ts │ ├── clone-expression-statement.ts │ ├── clone-expression-with-type-arguments.ts │ ├── clone-external-module-reference.ts │ ├── clone-for-in-statement.ts │ ├── clone-for-of-statement.ts │ ├── clone-for-statement.ts │ ├── clone-function-declaration.ts │ ├── clone-function-expression.ts │ ├── clone-function-type-node.ts │ ├── clone-get-accessor-declaration.ts │ ├── clone-heritage-clause.ts │ ├── clone-identifier.ts │ ├── clone-if-statement.ts │ ├── clone-import-attribute.ts │ ├── clone-import-attributes.ts │ ├── clone-import-clause.ts │ ├── clone-import-declaration.ts │ ├── clone-import-equals-declaration.ts │ ├── clone-import-specifier.ts │ ├── clone-import-type-assertion-container.ts │ ├── clone-import-type-node.ts │ ├── clone-index-signature-declaration.ts │ ├── clone-indexed-access-type-node.ts │ ├── clone-infer-type-node.ts │ ├── clone-interface-declaration.ts │ ├── clone-intersection-type-node.ts │ ├── clone-js-doc-all-type.ts │ ├── clone-js-doc-augments-tag.ts │ ├── clone-js-doc-author-tag.ts │ ├── clone-js-doc-callback-tag.ts │ ├── clone-js-doc-class-tag.ts │ ├── clone-js-doc-comment.ts │ ├── clone-js-doc-deprecated-tag.ts │ ├── clone-js-doc-enum-tag.ts │ ├── clone-js-doc-function-type.ts │ ├── clone-js-doc-import-tag.ts │ ├── clone-js-doc-link-code.ts │ ├── clone-js-doc-link-plain.ts │ ├── clone-js-doc-link.ts │ ├── clone-js-doc-member-name.ts │ ├── clone-js-doc-namepath-type.ts │ ├── clone-js-doc-non-nullable-type.ts │ ├── clone-js-doc-nullable-type.ts │ ├── clone-js-doc-optional-type.ts │ ├── clone-js-doc-overload-tag.ts │ ├── clone-js-doc-parameter-tag.ts │ ├── clone-js-doc-private-tag.ts │ ├── clone-js-doc-property-tag.ts │ ├── clone-js-doc-protected-tag.ts │ ├── clone-js-doc-public-tag.ts │ ├── clone-js-doc-readonly-tag.ts │ ├── clone-js-doc-return-tag.ts │ ├── clone-js-doc-satisfies-tag.ts │ ├── clone-js-doc-see-tag.ts │ ├── clone-js-doc-signature.ts │ ├── clone-js-doc-template-tag.ts │ ├── clone-js-doc-this-tag.ts │ ├── clone-js-doc-throws-tag.ts │ ├── clone-js-doc-type-expression.ts │ ├── clone-js-doc-type-literal.ts │ ├── clone-js-doc-type-tag.ts │ ├── clone-js-doc-typedef-tag.ts │ ├── clone-js-doc-unknown-tag.ts │ ├── clone-js-doc-unknown-type.ts │ ├── clone-js-doc-variadic-type.ts │ ├── clone-jsx-attribute.ts │ ├── clone-jsx-attributes.ts │ ├── clone-jsx-closing-element.ts │ ├── clone-jsx-closing-fragment.ts │ ├── clone-jsx-element.ts │ ├── clone-jsx-expression.ts │ ├── clone-jsx-fragment.ts │ ├── clone-jsx-namespaced-name.ts │ ├── clone-jsx-opening-element.ts │ ├── clone-jsx-opening-fragment.ts │ ├── clone-jsx-self-closing-element.ts │ ├── clone-jsx-spread-attribute.ts │ ├── clone-jsx-text.ts │ ├── clone-keyword-type-node.ts │ ├── clone-labeled-statement.ts │ ├── clone-literal-type-node.ts │ ├── clone-mapped-type-node.ts │ ├── clone-meta-property.ts │ ├── clone-method-declaration.ts │ ├── clone-method-signature.ts │ ├── clone-module-block.ts │ ├── clone-module-declaration.ts │ ├── clone-named-exports.ts │ ├── clone-named-imports.ts │ ├── clone-named-tuple-member.ts │ ├── clone-namespace-export-declaration.ts │ ├── clone-namespace-export.ts │ ├── clone-namespace-import.ts │ ├── clone-new-expression.ts │ ├── clone-no-substitution-template-literal.ts │ ├── clone-node-options.ts │ ├── clone-node.ts │ ├── clone-non-null-expression.ts │ ├── clone-not-emitted-statement.ts │ ├── clone-null-literal.ts │ ├── clone-numeric-literal.ts │ ├── clone-object-binding-pattern.ts │ ├── clone-object-literal-expression.ts │ ├── clone-omitted-expression.ts │ ├── clone-optional-type-node.ts │ ├── clone-parameter-declaration.ts │ ├── clone-parenthesized-expression.ts │ ├── clone-parenthesized-type-node.ts │ ├── clone-partially-omitted-expression.ts │ ├── clone-postfix-unary-expression.ts │ ├── clone-prefix-unary-expression.ts │ ├── clone-private-identifier.ts │ ├── clone-property-access-chain.ts │ ├── clone-property-access-expression.ts │ ├── clone-property-assignment.ts │ ├── clone-property-declaration.ts │ ├── clone-property-signature.ts │ ├── clone-qualified-name.ts │ ├── clone-regular-expression-literal.ts │ ├── clone-rest-type-node.ts │ ├── clone-return-statement.ts │ ├── clone-satisfies-expression.ts │ ├── clone-semicolon-class-element.ts │ ├── clone-set-accessor-declaration.ts │ ├── clone-shorthand-property-assignment.ts │ ├── clone-source-file.ts │ ├── clone-spread-assignment.ts │ ├── clone-spread-element.ts │ ├── clone-string-literal.ts │ ├── clone-super-expression.ts │ ├── clone-switch-statement.ts │ ├── clone-tagged-template-expression.ts │ ├── clone-template-expression.ts │ ├── clone-template-head.ts │ ├── clone-template-literal-type-node.ts │ ├── clone-template-literal-type-span.ts │ ├── clone-template-middle.ts │ ├── clone-template-span.ts │ ├── clone-template-tail.ts │ ├── clone-this-expression.ts │ ├── clone-this-type-node.ts │ ├── clone-throw-statement.ts │ ├── clone-token.ts │ ├── clone-try-statement.ts │ ├── clone-tuple-type-node.ts │ ├── clone-type-alias-declaration.ts │ ├── clone-type-assertion.ts │ ├── clone-type-literal-node.ts │ ├── clone-type-of-expression.ts │ ├── clone-type-operator-node.ts │ ├── clone-type-parameter-declaration.ts │ ├── clone-type-predicate-node.ts │ ├── clone-type-query-node.ts │ ├── clone-type-reference-node.ts │ ├── clone-union-type-node.ts │ ├── clone-variable-declaration-list.ts │ ├── clone-variable-declaration.ts │ ├── clone-variable-statement.ts │ ├── clone-void-expression.ts │ ├── clone-while-statement.ts │ ├── clone-with-statement.ts │ ├── clone-yield-expression.ts │ ├── type │ │ ├── meta-node.ts │ │ ├── set-parent-nodes-options.ts │ │ └── ts.ts │ └── util │ │ ├── ensure-node-array.ts │ │ ├── get-modifier-likes.ts │ │ ├── get-original-node.ts │ │ ├── is-boolean-literal.ts │ │ ├── is-comma-list-expression.ts │ │ ├── is-import-type-assertion-container.ts │ │ ├── is-js-doc-all-type.ts │ │ ├── is-js-doc-augments-tag.ts │ │ ├── is-js-doc-author-tag.ts │ │ ├── is-js-doc-callback-tag.ts │ │ ├── is-js-doc-class-tag.ts │ │ ├── is-js-doc-comment.ts │ │ ├── is-js-doc-deprecated-tag.ts │ │ ├── is-js-doc-enum-tag.ts │ │ ├── is-js-doc-function-type.ts │ │ ├── is-js-doc-import-tag.ts │ │ ├── is-js-doc-link-code.ts │ │ ├── is-js-doc-link-plain.ts │ │ ├── is-js-doc-link.ts │ │ ├── is-js-doc-member-name.ts │ │ ├── is-js-doc-namepath-type.ts │ │ ├── is-js-doc-non-nullable-type.ts │ │ ├── is-js-doc-nullable-type.ts │ │ ├── is-js-doc-optional-type.ts │ │ ├── is-js-doc-overload-tag.ts │ │ ├── is-js-doc-parameter-tag.ts │ │ ├── is-js-doc-private-tag.ts │ │ ├── is-js-doc-property-tag.ts │ │ ├── is-js-doc-protected-tag.ts │ │ ├── is-js-doc-public-tag.ts │ │ ├── is-js-doc-readonly-tag.ts │ │ ├── is-js-doc-return-tag.ts │ │ ├── is-js-doc-satisfies-tag.ts │ │ ├── is-js-doc-see-tag.ts │ │ ├── is-js-doc-signature.ts │ │ ├── is-js-doc-template-tag.ts │ │ ├── is-js-doc-this-tag.ts │ │ ├── is-js-doc-throws-tag.ts │ │ ├── is-js-doc-type-expression.ts │ │ ├── is-js-doc-type-literal.ts │ │ ├── is-js-doc-type-tag.ts │ │ ├── is-js-doc-typedef-tag.ts │ │ ├── is-js-doc-unknown-tag.ts │ │ ├── is-js-doc-unknown-type.ts │ │ ├── is-js-doc-variadic-type.ts │ │ ├── is-jsx-namespaced-name.ts │ │ ├── is-keyword-type-node.ts │ │ ├── is-named-tuple-member.ts │ │ ├── is-node-array.ts │ │ ├── is-not-emitted-statement.ts │ │ ├── is-null-literal.ts │ │ ├── is-optional-type-node.ts │ │ ├── is-partially-emitted-expression.ts │ │ ├── is-rest-type-node.ts │ │ ├── is-super-expression.ts │ │ ├── is-template-literal-type-node.ts │ │ ├── is-template-literal-type-span.ts │ │ ├── is-this-expression.ts │ │ ├── next-options.ts │ │ ├── payload.ts │ │ ├── preserve-comments.ts │ │ ├── set-parents.ts │ │ ├── to-internal-options.ts │ │ └── to-set-parent-nodes-options.ts └── index.ts ├── test ├── clone.test.ts ├── comment.test.ts └── util │ ├── clone-as-text.ts │ ├── format-code.ts │ ├── format-whitespace.ts │ ├── parse.ts │ ├── print.ts │ └── test-runner.ts └── tsconfig.json /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: wessberg 2 | patreon: wessberg 3 | -------------------------------------------------------------------------------- /.github/workflows/workflow.yml: -------------------------------------------------------------------------------- 1 | name: Main Workflow 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | run: 7 | name: Run 8 | 9 | runs-on: ${{ matrix.os }} 10 | 11 | strategy: 12 | matrix: 13 | os: [windows-latest, macos-latest, ubuntu-latest] 14 | node: [21, 22] 15 | 16 | steps: 17 | - name: Checkout code 18 | uses: actions/checkout@master 19 | 20 | - name: Setup Node.js 21 | uses: actions/setup-node@master 22 | with: 23 | node-version: ${{ matrix.node }} 24 | 25 | - name: Setup pnpm 26 | run: npm install pnpm -g 27 | 28 | - name: Install 29 | run: pnpm install 30 | 31 | - name: Lint 32 | run: pnpm run lint 33 | 34 | - name: Test 35 | run: pnpm test 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /compiled/ 2 | /.idea/ 3 | /.cache/ 4 | /.vscode/ 5 | *.log 6 | /test-app/ 7 | /test-app_old/ 8 | /logs/ 9 | npm-debug.log* 10 | /lib-cov/ 11 | /coverage/ 12 | /.nyc_output/ 13 | /.grunt/ 14 | *.7z 15 | *.dmg 16 | *.gz 17 | *.iso 18 | *.jar 19 | *.rar 20 | *.tar 21 | *.zip 22 | .tgz 23 | .env 24 | .DS_Store 25 | .DS_Store? 26 | ._* 27 | .Spotlight-V100 28 | .Trashes 29 | ehthumbs.db 30 | Thumbs.db 31 | *.pem 32 | *.p12 33 | *.crt 34 | *.csr 35 | /node_modules/ 36 | /dist/ 37 | package-lock.json -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx lint-staged --quiet -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | Contributor Covenant Code of Conduct 2 | 3 | Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | - Using welcoming and inclusive language 18 | - Being respectful of differing viewpoints and experiences 19 | - Gracefully accepting constructive criticism 20 | - Focusing on what is best for the community 21 | - Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | - The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | - Trolling, insulting/derogatory comments, and personal or political attacks 28 | - Public or private harassment 29 | - Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | - Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting any of the code of conduct enforcers: [Frederik Wessberg](mailto:frederikwessberg@hotmail.com) ([@FredWessberg](https://twitter.com/FredWessberg)) ([Website](https://github.com/wessberg)). 59 | All complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | Attribution 69 | 70 | This Code of Conduct is adapted from the Contributor Covenant, version 1.4, 71 | available at http://contributor-covenant.org/version/1/4/ 72 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | You are more than welcome to contribute to `ts-clone-node` in any way you please, including: 2 | 3 | - Updating documentation. 4 | - Fixing spelling and grammar 5 | - Adding tests 6 | - Fixing issues and suggesting new features 7 | - Blogging, tweeting, and creating tutorials about `ts-clone-node` 8 | - Reaching out to [@FredWessberg](https://twitter.com/FredWessberg) on Twitter 9 | - Submit an issue or a Pull Request 10 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2024 [Frederik Wessberg](mailto:frederikwessberg@hotmail.com) ([@FredWessberg](https://twitter.com/FredWessberg)) ([Website](https://github.com/wessberg)) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /documentation/asset/logo-social-preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wessberg/ts-clone-node/0ceb4932a8497429460d0a47f87b27e9974c0960/documentation/asset/logo-social-preview.png -------------------------------------------------------------------------------- /documentation/asset/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wessberg/ts-clone-node/0ceb4932a8497429460d0a47f87b27e9974c0960/documentation/asset/logo.png -------------------------------------------------------------------------------- /eslint.config.js: -------------------------------------------------------------------------------- 1 | import shared from "@wessberg/ts-config/eslint.config.js"; 2 | 3 | export default [ 4 | ...shared, 5 | { 6 | rules: { 7 | "@typescript-eslint/no-deprecated": "off", 8 | "@typescript-eslint/no-empty-object-type": "off" 9 | } 10 | } 11 | ]; 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts-clone-node", 3 | "version": "4.0.0", 4 | "description": "A library that helps you clone Nodes from a Typescript AST", 5 | "scripts": { 6 | "generate:sandhog": "sandhog all --yes", 7 | "generate:changelog": "standard-changelog --first-release", 8 | "generate:all": "pnpm run generate:sandhog && pnpm run generate:changelog", 9 | "clean": "rimraf dist", 10 | "lint": "tsc --noEmit && eslint \"src/**/*.ts\" --color", 11 | "prettier": "prettier --write \"{src,test,documentation}/**/*.{js,ts,json,html,xml,css,md}\"", 12 | "test": "node --import tsx --test \"./test/**/*.test.ts\"", 13 | "prebuild": "pnpm run clean", 14 | "build": "tsup \"src/index.ts\" --sourcemap --dts --format cjs,esm", 15 | "preversion": "pnpm run lint && pnpm run build", 16 | "version": "pnpm run preversion && pnpm run generate:all && git add .", 17 | "release": "np --no-cleanup --no-yarn --no-tests", 18 | "update:check": "pnpx npm-check-updates -x typescript-* --dep dev,prod", 19 | "update:commit": "pnpx npm-check-updates -u -x typescript-* --dep dev,prod && pnpm update && pnpm install" 20 | }, 21 | "keywords": [ 22 | "typescript", 23 | "ast", 24 | "node", 25 | "clone", 26 | "copy", 27 | "duplicate" 28 | ], 29 | "files": [ 30 | "dist/**/*.*" 31 | ], 32 | "contributors": [ 33 | { 34 | "name": "Frederik Wessberg", 35 | "email": "frederikwessberg@hotmail.com", 36 | "url": "https://github.com/wessberg", 37 | "imageUrl": "https://avatars2.githubusercontent.com/u/20454213?s=460&v=4", 38 | "github": "wessberg", 39 | "role": "Lead Developer", 40 | "twitter": "FredWessberg" 41 | } 42 | ], 43 | "license": "MIT", 44 | "devDependencies": { 45 | "@types/semver": "^7.5.8", 46 | "@types/node": "^22.7.0", 47 | "@types/prettier": "^3.0.0", 48 | "@wessberg/ts-config": "^5.0.16", 49 | "@wessberg/prettier-config": "1.0.0", 50 | "@prettier/sync": "0.5.2", 51 | "eslint": "^9.11.1", 52 | "eslint-config-prettier": "^9.1.0", 53 | "eslint-plugin-jsdoc": "^50.2.4", 54 | "eslint-plugin-prettier": "^5.2.1", 55 | "typescript-eslint": "^8.7.0", 56 | "crosspath": "2.0.0", 57 | "sandhog": "^2.0.2", 58 | "husky": "^9.1.6", 59 | "np": "10.0.7", 60 | "pnpm": "^9.11.0", 61 | "prettier": "^3.3.3", 62 | "lint-staged": "^15.2.10", 63 | "rimraf": "^6.0.1", 64 | "standard-changelog": "^6.0.0", 65 | "tsup": "^8.3.0", 66 | "tsx": "^4.19.1", 67 | "semver": "^7.6.3", 68 | "helpertypes": "^0.0.19", 69 | "tslib": "^2.7.0", 70 | "npm-check-updates": "^17.1.3", 71 | "typescript": "5.6.2", 72 | "typescript-3-0-1": "npm:typescript@3.0.1", 73 | "typescript-3-1-1": "npm:typescript@3.1.1", 74 | "typescript-3-2-1": "npm:typescript@3.2.1", 75 | "typescript-3-3-1": "npm:typescript@3.3.1", 76 | "typescript-3-4-1": "npm:typescript@3.4.1", 77 | "typescript-3-5-1": "npm:typescript@3.5.1", 78 | "typescript-3-6-2": "npm:typescript@3.6.2", 79 | "typescript-3-7-2": "npm:typescript@3.7.2", 80 | "typescript-3-8-3": "npm:typescript@3.8.3", 81 | "typescript-3-9-2": "npm:typescript@3.9.2", 82 | "typescript-4-0-3": "npm:typescript@4.0.3", 83 | "typescript-4-1-2": "npm:typescript@4.1.2", 84 | "typescript-4-2-4": "npm:typescript@4.2.4", 85 | "typescript-4-3-5": "npm:typescript@4.3.5", 86 | "typescript-4-4-3": "npm:typescript@4.4.3", 87 | "typescript-4-5-4": "npm:typescript@4.5.4", 88 | "typescript-4-6-4": "npm:typescript@4.6.4", 89 | "typescript-4-7-2": "npm:typescript@4.7.2", 90 | "typescript-4-8-2": "npm:typescript@4.8.2", 91 | "typescript-4-9-4": "npm:typescript@4.9.4", 92 | "typescript-5-0-4": "npm:typescript@5.0.4", 93 | "typescript-5-1-6": "npm:typescript@5.1.6", 94 | "typescript-5-2-2": "npm:typescript@5.2.2", 95 | "typescript-5-3-3": "npm:typescript@5.3.3", 96 | "typescript-5-4-5": "npm:typescript@5.4.5", 97 | "typescript-5-5-4": "npm:typescript@5.5.4", 98 | "typescript-5-6-2": "npm:typescript@5.6.2" 99 | }, 100 | "dependencies": { 101 | "compatfactory": "^4.0.2" 102 | }, 103 | "peerDependencies": { 104 | "typescript": "^3.x || ^4.x || ^5.x" 105 | }, 106 | "exports": { 107 | "import": "./dist/index.js", 108 | "require": "./dist/index.cjs" 109 | }, 110 | "type": "module", 111 | "types": "./dist/index.d.ts", 112 | "main": "./dist/index.cjs", 113 | "module": "./dist/index.js", 114 | "funding": { 115 | "type": "github", 116 | "url": "https://github.com/wessberg/ts-clone-node?sponsor=1" 117 | }, 118 | "repository": { 119 | "type": "git", 120 | "url": "https://github.com/wessberg/ts-clone-node.git" 121 | }, 122 | "bugs": { 123 | "url": "https://github.com/wessberg/ts-clone-node/issues" 124 | }, 125 | "engines": { 126 | "node": ">=18.20.0" 127 | }, 128 | "lint-staged": { 129 | "*": "prettier --ignore-unknown --write" 130 | }, 131 | "prettier": "@wessberg/prettier-config" 132 | } 133 | -------------------------------------------------------------------------------- /sandhog.config.js: -------------------------------------------------------------------------------- 1 | import baseConfig from "@wessberg/ts-config/sandhog.config.js"; 2 | 3 | export default { 4 | ...baseConfig, 5 | logo: { 6 | url: "https://raw.githubusercontent.com/wessberg/ts-clone-node/master/documentation/asset/logo.png", 7 | height: 100 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-array-binding-pattern.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 2 | import type {TS} from "./type/ts.js"; 3 | 4 | export function cloneArrayBindingPattern(node: TS.ArrayBindingPattern, options: CloneNodeVisitorOptions): TS.ArrayBindingPattern { 5 | return options.factory.createArrayBindingPattern(options.hook("elements", options.nextNodes(node.elements), node.elements)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-array-literal-expression.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 2 | import type {TS} from "./type/ts.js"; 3 | 4 | export function cloneArrayLiteralExpression(node: TS.ArrayLiteralExpression, options: CloneNodeVisitorOptions): TS.ArrayLiteralExpression { 5 | return options.factory.createArrayLiteralExpression(options.hook("elements", options.nextNodes(node.elements), node.elements)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-array-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneArrayTypeNode(node: TS.ArrayTypeNode, options: CloneNodeVisitorOptions): TS.ArrayTypeNode { 5 | return options.factory.createArrayTypeNode(options.hook("elementType", options.nextNode(node.elementType), node.elementType)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-arrow-function.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneArrowFunction(node: TS.ArrowFunction, options: CloneNodeVisitorOptions): TS.ArrowFunction { 5 | return options.factory.createArrowFunction( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 8 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 9 | options.hook("type", options.nextNode(node.type), node.type), 10 | options.hook("equalsGreaterThanToken", options.nextNode(node.equalsGreaterThanToken), node.equalsGreaterThanToken), 11 | options.hook("body", options.nextNode(node.body), node.body) 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-as-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneAsExpression(node: TS.AsExpression, options: CloneNodeVisitorOptions): TS.AsExpression { 5 | return options.factory.createAsExpression( 6 | options.hook("expression", options.nextNode(node.expression), node.expression), 7 | options.hook("type", options.nextNode(node.type), node.type) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-assert-clause.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {ensureNodeArray} from "./util/ensure-node-array.js"; 4 | 5 | export function cloneAssertClause(node: TS.AssertClause, options: CloneNodeVisitorOptions): TS.AssertClause { 6 | return options.factory.createAssertClause( 7 | ensureNodeArray(options.hook("elements", options.nextNodes(node.elements), node.elements), options.factory), 8 | options.hook("multiLine", node.multiLine, node.multiLine) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-assert-entry.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneAssertEntry(node: TS.AssertEntry, options: CloneNodeVisitorOptions): TS.AssertEntry { 5 | return options.factory.createAssertEntry(options.hook("name", options.nextNode(node.name), node.name), options.hook("value", options.nextNode(node.value), node.value)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-await-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneAwaitExpression(node: TS.AwaitExpression, options: CloneNodeVisitorOptions): TS.AwaitExpression { 5 | return options.factory.createAwaitExpression(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-big-int-literal.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneBigIntLiteral(node: TS.BigIntLiteral, options: CloneNodeVisitorOptions): TS.BigIntLiteral { 5 | return options.factory.createBigIntLiteral(options.hook("text", node.text, node.text)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-binary-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneBinaryExpression(node: TS.BinaryExpression, options: CloneNodeVisitorOptions): TS.BinaryExpression { 5 | return options.factory.createBinaryExpression( 6 | options.hook("left", options.nextNode(node.left), node.left), 7 | options.hook("operatorToken", options.nextNode(node.operatorToken), node.operatorToken), 8 | options.hook("right", options.nextNode(node.right), node.right) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-binding-element.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneBindingElement(node: TS.BindingElement, options: CloneNodeVisitorOptions): TS.BindingElement { 5 | return options.factory.createBindingElement( 6 | options.hook("dotDotDotToken", options.nextNode(node.dotDotDotToken), node.dotDotDotToken), 7 | options.hook("propertyName", options.nextNode(node.propertyName), node.propertyName), 8 | options.hook("name", options.nextNode(node.name), node.name), 9 | options.hook("initializer", options.nextNode(node.initializer), node.initializer) 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/clone-block.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneBlock(node: TS.Block, options: CloneNodeVisitorOptions): TS.Block { 5 | return options.factory.createBlock(options.hook("statements", options.nextNodes(node.statements), node.statements)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-boolean-literal.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneBooleanLiteral(node: TS.BooleanLiteral, options: CloneNodeVisitorOptions): TS.BooleanLiteral { 5 | if (node.kind === options.typescript.SyntaxKind.TrueKeyword) { 6 | return options.factory.createTrue(); 7 | } 8 | return options.factory.createFalse(); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-break-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneBreakStatement(node: TS.BreakStatement, options: CloneNodeVisitorOptions): TS.BreakStatement { 5 | return options.factory.createBreakStatement(options.hook("label", options.nextNode(node.label), node.label)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-call-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneCallExpression(node: TS.CallExpression, options: CloneNodeVisitorOptions): TS.CallExpression { 6 | const clonedCallExpression = options.factory.createCallExpression( 7 | options.hook("expression", options.nextNode(node.expression), node.expression), 8 | options.hook("typeArguments", options.nextNodes(node.typeArguments), node.typeArguments), 9 | options.hook("arguments", options.nextNodes(node.arguments), node.arguments) 10 | ); 11 | 12 | // createCallExpression may wrap the arguments in parentheses. We want to make sure that we're producing identical clones here, 13 | // so if the arguments of the new CallExpression has a ParenthesizedExpression that weren't there before, remove it. 14 | for (let i = 0; i < clonedCallExpression.arguments.length; i++) { 15 | const argument = clonedCallExpression.arguments[i]; 16 | const nodeArgument = node.arguments[i]; 17 | 18 | if (nodeArgument != null && argument != null && !options.typescript.isParenthesizedExpression(nodeArgument) && options.typescript.isParenthesizedExpression(argument)) { 19 | (clonedCallExpression.arguments[i] as Mutable) = argument.expression; 20 | } 21 | } 22 | 23 | return clonedCallExpression; 24 | } 25 | -------------------------------------------------------------------------------- /src/clone-node/clone-call-signature-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 2 | import type {TS} from "./type/ts.js"; 3 | 4 | export function cloneCallSignatureDeclaration(node: TS.CallSignatureDeclaration, options: CloneNodeVisitorOptions): TS.CallSignatureDeclaration { 5 | return options.factory.createCallSignature( 6 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 7 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 8 | options.hook("type", options.nextNode(node.type), node.type) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-case-block.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneCaseBlock(node: TS.CaseBlock, options: CloneNodeVisitorOptions): TS.CaseBlock { 5 | return options.factory.createCaseBlock(options.hook("clauses", options.nextNodes(node.clauses), node.clauses)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-case-clause.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneCaseClause(node: TS.CaseClause, options: CloneNodeVisitorOptions): TS.CaseClause { 5 | return options.factory.createCaseClause( 6 | options.hook("expression", options.nextNode(node.expression), node.expression), 7 | options.hook("statements", options.nextNodes(node.statements), node.statements) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-catch-clause.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneCatchClause(node: TS.CatchClause, options: CloneNodeVisitorOptions): TS.CatchClause { 5 | return options.factory.createCatchClause( 6 | options.hook("variableDeclaration", options.nextNode(node.variableDeclaration), node.variableDeclaration), 7 | options.hook("block", options.nextNode(node.block), node.block) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-class-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {getModifierLikes} from "./util/get-modifier-likes.js"; 4 | 5 | export function cloneClassDeclaration(node: TS.ClassDeclaration, options: CloneNodeVisitorOptions): TS.ClassDeclaration { 6 | const modifierLikes = getModifierLikes(node); 7 | return options.factory.createClassDeclaration( 8 | options.hook("modifiers", options.nextNodes(modifierLikes), modifierLikes), 9 | options.hook("name", options.nextNode(node.name), node.name), 10 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 11 | options.hook("heritageClauses", options.nextNodes(node.heritageClauses), node.heritageClauses), 12 | options.hook("members", options.nextNodes(node.members), node.members) 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-class-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {getModifierLikes} from "./util/get-modifier-likes.js"; 4 | 5 | export function cloneClassExpression(node: TS.ClassExpression, options: CloneNodeVisitorOptions): TS.ClassExpression { 6 | const modifierLikes = getModifierLikes(node); 7 | return options.factory.createClassExpression( 8 | options.hook("modifiers", options.nextNodes(modifierLikes), modifierLikes), 9 | options.hook("name", options.nextNode(node.name), node.name), 10 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 11 | options.hook("heritageClauses", options.nextNodes(node.heritageClauses), node.heritageClauses), 12 | options.hook("members", options.nextNodes(node.members), node.members) 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-class-static-block-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 2 | import type {TS} from "./type/ts.js"; 3 | 4 | export function cloneClassStaticBlockDeclaration( 5 | node: TS.ClassStaticBlockDeclaration, 6 | options: CloneNodeVisitorOptions 7 | ): TS.ClassStaticBlockDeclaration { 8 | return options.factory.createClassStaticBlockDeclaration(options.hook("body", options.nextNode(node.body), node.body)); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-comma-list-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneCommaListExpression(node: TS.CommaListExpression, options: CloneNodeVisitorOptions): TS.CommaListExpression { 5 | return options.factory.createCommaListExpression(options.hook("elements", options.nextNodes(node.elements), node.elements)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-computed-property-name.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneComputedPropertyName(node: TS.ComputedPropertyName, options: CloneNodeVisitorOptions): TS.ComputedPropertyName { 5 | return options.factory.createComputedPropertyName(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-conditional-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneConditionalExpression(node: TS.ConditionalExpression, options: CloneNodeVisitorOptions): TS.ConditionalExpression { 5 | return options.factory.createConditionalExpression( 6 | options.hook("condition", options.nextNode(node.condition), node.condition), 7 | options.hook("questionToken", options.nextNode(node.questionToken), node.questionToken), 8 | options.hook("whenTrue", options.nextNode(node.whenTrue), node.whenTrue), 9 | options.hook("colonToken", options.nextNode(node.colonToken), node.colonToken), 10 | options.hook("whenFalse", options.nextNode(node.whenFalse), node.whenFalse) 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /src/clone-node/clone-conditional-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneConditionalTypeNode(node: TS.ConditionalTypeNode, options: CloneNodeVisitorOptions): TS.ConditionalTypeNode { 5 | return options.factory.createConditionalTypeNode( 6 | options.hook("checkType", options.nextNode(node.checkType), node.checkType), 7 | options.hook("extendsType", options.nextNode(node.extendsType), node.extendsType), 8 | options.hook("trueType", options.nextNode(node.trueType), node.trueType), 9 | options.hook("falseType", options.nextNode(node.falseType), node.falseType) 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/clone-construct-signature-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneConstructSignatureDeclaration( 5 | node: TS.ConstructSignatureDeclaration, 6 | options: CloneNodeVisitorOptions 7 | ): TS.ConstructSignatureDeclaration { 8 | return options.factory.createConstructSignature( 9 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 10 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 11 | options.hook("type", options.nextNode(node.type), node.type) 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-constructor-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneConstructorDeclaration(node: TS.ConstructorDeclaration, options: CloneNodeVisitorOptions): TS.ConstructorDeclaration { 5 | return options.factory.createConstructorDeclaration( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 8 | options.hook("body", options.nextNode(node.body), node.body) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-constructor-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {ensureNodeArray} from "./util/ensure-node-array.js"; 4 | import type {Mutable} from "helpertypes"; 5 | 6 | export function cloneConstructorTypeNode(node: TS.ConstructorTypeNode, options: CloneNodeVisitorOptions): TS.ConstructorTypeNode { 7 | const updatedNode = options.factory.createConstructorTypeNode( 8 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 9 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 10 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 11 | options.hook("type", options.nextNode(node.type), node.type) 12 | ) as Mutable; 13 | 14 | // Make sure to also update the modifiers. The constructor function doesn't support this. 15 | updatedNode.modifiers = ensureNodeArray(options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), options.factory); 16 | return updatedNode; 17 | } 18 | -------------------------------------------------------------------------------- /src/clone-node/clone-continue-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneContinueStatement(node: TS.ContinueStatement, options: CloneNodeVisitorOptions): TS.ContinueStatement { 5 | return options.factory.createContinueStatement(options.hook("label", options.nextNode(node.label), node.label)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-debugger-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneDebuggerStatement(_node: TS.DebuggerStatement, options: CloneNodeVisitorOptions): TS.DebuggerStatement { 5 | return options.factory.createDebuggerStatement(); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-decorator.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneDecorator(node: TS.Decorator, options: CloneNodeVisitorOptions): TS.Decorator { 5 | return options.factory.createDecorator(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-default-clause.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneDefaultClause(node: TS.DefaultClause, options: CloneNodeVisitorOptions): TS.DefaultClause { 5 | return options.factory.createDefaultClause(options.hook("statements", options.nextNodes(node.statements), node.statements)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-delete-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneDeleteExpression(node: TS.DeleteExpression, options: CloneNodeVisitorOptions): TS.DeleteExpression { 5 | return options.factory.createDeleteExpression(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-do-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneDoStatement(node: TS.DoStatement, options: CloneNodeVisitorOptions): TS.DoStatement { 5 | return options.factory.createDoStatement( 6 | options.hook("statement", options.nextNode(node.statement), node.statement), 7 | options.hook("expression", options.nextNode(node.expression), node.expression) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-element-access-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneElementAccessExpression(node: TS.ElementAccessExpression, options: CloneNodeVisitorOptions): TS.ElementAccessExpression { 5 | return options.factory.createElementAccessExpression( 6 | options.hook("expression", options.nextNode(node.expression), node.expression), 7 | options.hook("argumentExpression", options.nextNode(node.argumentExpression), node.argumentExpression) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-empty-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneEmptyStatement(_node: TS.EmptyStatement, options: CloneNodeVisitorOptions): TS.EmptyStatement { 5 | return options.factory.createEmptyStatement(); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-enum-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneEnumDeclaration(node: TS.EnumDeclaration, options: CloneNodeVisitorOptions): TS.EnumDeclaration { 5 | return options.factory.createEnumDeclaration( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("members", options.nextNodes(node.members), node.members) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-enum-member.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneEnumMember(node: TS.EnumMember, options: CloneNodeVisitorOptions): TS.EnumMember { 5 | return options.factory.createEnumMember( 6 | options.hook("name", options.nextNode(node.name), node.name), 7 | options.hook("initializer", options.nextNode(node.initializer), node.initializer) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-export-assignment.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneExportAssignment(node: TS.ExportAssignment, options: CloneNodeVisitorOptions): TS.ExportAssignment { 5 | return options.factory.createExportAssignment( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("isExportEquals", node.isExportEquals, node.isExportEquals), 8 | options.hook("expression", options.nextNode(node.expression), node.expression) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-export-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneExportDeclaration(node: TS.ExportDeclaration, options: CloneNodeVisitorOptions): TS.ExportDeclaration { 5 | return options.factory.createExportDeclaration( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("isTypeOnly", node.isTypeOnly, node.isTypeOnly), 8 | options.hook("exportClause", options.nextNode(node.exportClause), node.exportClause), 9 | options.hook("moduleSpecifier", options.nextNode(node.moduleSpecifier), node.moduleSpecifier), 10 | options.hook("attributes", options.nextNode(node.attributes), node.attributes) 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /src/clone-node/clone-export-specifier.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneExportSpecifier(node: TS.ExportSpecifier, options: CloneNodeVisitorOptions): TS.ExportSpecifier { 5 | return options.factory.createExportSpecifier( 6 | options.hook("isTypeOnly", node.isTypeOnly, node.isTypeOnly), 7 | options.hook("propertyName", options.nextNode(node.propertyName), node.propertyName), 8 | options.hook("name", options.nextNode(node.name), node.name) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-expression-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneExpressionStatement(node: TS.ExpressionStatement, options: CloneNodeVisitorOptions): TS.ExpressionStatement { 5 | return options.factory.createExpressionStatement(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-expression-with-type-arguments.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneExpressionWithTypeArguments( 5 | node: TS.ExpressionWithTypeArguments, 6 | options: CloneNodeVisitorOptions 7 | ): TS.ExpressionWithTypeArguments { 8 | return options.factory.createExpressionWithTypeArguments( 9 | options.hook("expression", options.nextNode(node.expression), node.expression), 10 | options.hook("typeArguments", options.nextNodes(node.typeArguments), node.typeArguments) 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /src/clone-node/clone-external-module-reference.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneExternalModuleReference(node: TS.ExternalModuleReference, options: CloneNodeVisitorOptions): TS.ExternalModuleReference { 5 | return options.factory.createExternalModuleReference(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-for-in-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneForInStatement(node: TS.ForInStatement, options: CloneNodeVisitorOptions): TS.ForInStatement { 5 | return options.factory.createForInStatement( 6 | options.hook("initializer", options.nextNode(node.initializer), node.initializer), 7 | options.hook("expression", options.nextNode(node.expression), node.expression), 8 | options.hook("statement", options.nextNode(node.statement), node.statement) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-for-of-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneForOfStatement(node: TS.ForOfStatement, options: CloneNodeVisitorOptions): TS.ForOfStatement { 5 | return options.factory.createForOfStatement( 6 | options.hook("awaitModifier", options.nextNode(node.awaitModifier), node.awaitModifier), 7 | options.hook("initializer", options.nextNode(node.initializer), node.initializer), 8 | options.hook("expression", options.nextNode(node.expression), node.expression), 9 | options.hook("statement", options.nextNode(node.statement), node.statement) 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/clone-for-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneForStatement(node: TS.ForStatement, options: CloneNodeVisitorOptions): TS.ForStatement { 5 | return options.factory.createForStatement( 6 | options.hook("initializer", options.nextNode(node.initializer), node.initializer), 7 | options.hook("condition", options.nextNode(node.condition), node.condition), 8 | options.hook("incrementor", options.nextNode(node.incrementor), node.incrementor), 9 | options.hook("statement", options.nextNode(node.statement), node.statement) 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/clone-function-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {getModifierLikes} from "./util/get-modifier-likes.js"; 4 | 5 | export function cloneFunctionDeclaration(node: TS.FunctionDeclaration, options: CloneNodeVisitorOptions): TS.FunctionDeclaration { 6 | const modifierLikes = getModifierLikes(node); 7 | return options.factory.createFunctionDeclaration( 8 | options.hook("modifiers", options.nextNodes(modifierLikes), modifierLikes as TS.Modifier[]), 9 | options.hook("asteriskToken", options.nextNode(node.asteriskToken), node.asteriskToken), 10 | options.hook("name", options.nextNode(node.name), node.name), 11 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 12 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 13 | options.hook("type", options.nextNode(node.type), node.type), 14 | options.hook("body", options.nextNode(node.body), node.body) 15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /src/clone-node/clone-function-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneFunctionExpression(node: TS.FunctionExpression, options: CloneNodeVisitorOptions): TS.FunctionExpression { 5 | return options.factory.createFunctionExpression( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("asteriskToken", options.nextNode(node.asteriskToken), node.asteriskToken), 8 | options.hook("name", options.nextNode(node.name), node.name), 9 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 10 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 11 | options.hook("type", options.nextNode(node.type), node.type), 12 | options.hook("body", options.nextNode(node.body), node.body) 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-function-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneFunctionTypeNode(node: TS.FunctionTypeNode, options: CloneNodeVisitorOptions): TS.FunctionTypeNode { 5 | return options.factory.createFunctionTypeNode( 6 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 7 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 8 | options.hook("type", options.nextNode(node.type), node.type) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-get-accessor-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {getModifierLikes} from "./util/get-modifier-likes.js"; 4 | 5 | export function cloneGetAccessorDeclaration(node: TS.GetAccessorDeclaration, options: CloneNodeVisitorOptions): TS.GetAccessorDeclaration { 6 | const modifierLikes = getModifierLikes(node); 7 | return options.factory.createGetAccessorDeclaration( 8 | options.hook("modifiers", options.nextNodes(modifierLikes), modifierLikes), 9 | options.hook("name", options.nextNode(node.name), node.name), 10 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 11 | options.hook("type", options.nextNode(node.type), node.type), 12 | options.hook("body", options.nextNode(node.body), node.body) 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-heritage-clause.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneHeritageClause(node: TS.HeritageClause, options: CloneNodeVisitorOptions): TS.HeritageClause { 5 | return options.factory.createHeritageClause(options.hook("token", node.token, node.token), options.hook("types", options.nextNodes(node.types), node.types)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-identifier.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneIdentifier(node: TS.Identifier, options: CloneNodeVisitorOptions): TS.Identifier { 5 | const text = "text" in node ? node.text : options.typescript.unescapeLeadingUnderscores((node as TS.Identifier).escapedText); 6 | return options.factory.createIdentifier(options.hook("text", text, text)); 7 | } 8 | -------------------------------------------------------------------------------- /src/clone-node/clone-if-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneIfStatement(node: TS.IfStatement, options: CloneNodeVisitorOptions): TS.IfStatement { 5 | return options.factory.createIfStatement( 6 | options.hook("expression", options.nextNode(node.expression), node.expression), 7 | options.hook("thenStatement", options.nextNode(node.thenStatement), node.thenStatement), 8 | options.hook("elseStatement", options.nextNode(node.elseStatement), node.elseStatement) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-import-attribute.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneImportAttribute(node: TS.ImportAttribute, options: CloneNodeVisitorOptions): TS.ImportAttribute { 5 | return options.factory.createImportAttribute(options.hook("name", options.nextNode(node.name), node.name), options.hook("value", options.nextNode(node.value), node.value)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-import-attributes.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {ensureNodeArray} from "./util/ensure-node-array.js"; 4 | 5 | export function cloneImportAttributes(node: TS.ImportAttributes, options: CloneNodeVisitorOptions): TS.ImportAttributes { 6 | return options.factory.createImportAttributes( 7 | ensureNodeArray(options.hook("elements", options.nextNodes(node.elements), node.elements), options.factory), 8 | options.hook("multiLine", node.multiLine, node.multiLine) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-import-clause.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneImportClause(node: TS.ImportClause, options: CloneNodeVisitorOptions): TS.ImportClause { 5 | return options.factory.createImportClause( 6 | options.hook("isTypeOnly", node.isTypeOnly, node.isTypeOnly), 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("namedBindings", options.nextNode(node.namedBindings), node.namedBindings) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-import-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneImportDeclaration(node: TS.ImportDeclaration, options: CloneNodeVisitorOptions): TS.ImportDeclaration { 5 | return options.factory.createImportDeclaration( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("importClause", options.nextNode(node.importClause), node.importClause), 8 | options.hook("moduleSpecifier", options.nextNode(node.moduleSpecifier), node.moduleSpecifier), 9 | options.hook("attributes", options.nextNode(node.attributes), node.attributes) 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/clone-import-equals-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneImportEqualsDeclaration(node: TS.ImportEqualsDeclaration, options: CloneNodeVisitorOptions): TS.ImportEqualsDeclaration { 5 | return options.factory.createImportEqualsDeclaration( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("isTypeOnly", node.isTypeOnly, node.isTypeOnly), 8 | options.hook("name", options.nextNode(node.name), node.name), 9 | options.hook("moduleReference", options.nextNode(node.moduleReference), node.moduleReference) 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/clone-import-specifier.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneImportSpecifier(node: TS.ImportSpecifier, options: CloneNodeVisitorOptions): TS.ImportSpecifier { 5 | return options.factory.createImportSpecifier( 6 | options.hook("isTypeOnly", node.isTypeOnly, node.isTypeOnly), 7 | options.hook("propertyName", options.nextNode(node.propertyName), node.propertyName), 8 | options.hook("name", options.nextNode(node.name), node.name) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-import-type-assertion-container.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneImportTypeAssertionContainer( 5 | node: TS.ImportTypeAssertionContainer, 6 | options: CloneNodeVisitorOptions 7 | ): TS.ImportTypeAssertionContainer { 8 | return options.factory.createImportTypeAssertionContainer( 9 | options.hook("assertClause", options.nextNode(node.assertClause), node.assertClause), 10 | options.hook("multiLine", node.multiLine, node.multiLine) 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /src/clone-node/clone-import-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneImportTypeNode(node: TS.ImportTypeNode, options: CloneNodeVisitorOptions): TS.ImportTypeNode { 5 | return options.factory.createImportTypeNode( 6 | options.hook("argument", options.nextNode(node.argument), node.argument), 7 | options.hook("attributes", options.nextNode(node.attributes), node.attributes), 8 | options.hook("qualifier", options.nextNode(node.qualifier), node.qualifier), 9 | options.hook("typeArguments", options.nextNodes(node.typeArguments), node.typeArguments), 10 | options.hook("isTypeOf", node.isTypeOf, node.isTypeOf) 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /src/clone-node/clone-index-signature-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 2 | import type {TS} from "./type/ts.js"; 3 | 4 | export function cloneIndexSignatureDeclaration(node: TS.IndexSignatureDeclaration, options: CloneNodeVisitorOptions): TS.IndexSignatureDeclaration { 5 | return options.factory.createIndexSignature( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 8 | options.hook("type", options.nextNode(node.type), node.type) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-indexed-access-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneIndexedAccessTypeNode(node: TS.IndexedAccessTypeNode, options: CloneNodeVisitorOptions): TS.IndexedAccessTypeNode { 5 | return options.factory.createIndexedAccessTypeNode( 6 | options.hook("objectType", options.nextNode(node.objectType), node.objectType), 7 | options.hook("indexType", options.nextNode(node.indexType), node.indexType) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-infer-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneInferTypeNode(node: TS.InferTypeNode, options: CloneNodeVisitorOptions): TS.InferTypeNode { 5 | return options.factory.createInferTypeNode(options.hook("typeParameter", options.nextNode(node.typeParameter), node.typeParameter)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-interface-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneInterfaceDeclaration(node: TS.InterfaceDeclaration, options: CloneNodeVisitorOptions): TS.InterfaceDeclaration { 5 | return options.factory.createInterfaceDeclaration( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 9 | options.hook("heritageClauses", options.nextNodes(node.heritageClauses), node.heritageClauses), 10 | options.hook("members", options.nextNodes(node.members), node.members) 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /src/clone-node/clone-intersection-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneIntersectionTypeNode(node: TS.IntersectionTypeNode, options: CloneNodeVisitorOptions): TS.IntersectionTypeNode { 5 | return options.factory.createIntersectionTypeNode(options.hook("types", options.nextNodes(node.types), node.types)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-all-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocAllType(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocAllType { 6 | const baseNode = options.factory.createJSDocAllType() as Mutable; 7 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 8 | 9 | return baseNode; 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-augments-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocAugmentsTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocAugmentsTag { 6 | const baseNode = options.factory.createJSDocAugmentsTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("class", options.nextNode(node.class), node.class), 9 | options.hook("comment", node.comment, node.comment) 10 | ) as Mutable; 11 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 12 | return baseNode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-author-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocAuthorTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocAuthorTag { 6 | const baseNode = options.factory.createJSDocAuthorTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("comment", node.comment, node.comment) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | 12 | return baseNode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-callback-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocCallbackTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocCallbackTag { 6 | const baseNode = options.factory.createJSDocCallbackTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("typeExpression", options.nextNode(node.typeExpression), node.typeExpression), 9 | options.hook("fullName", options.nextNode(node.fullName), node.fullName), 10 | options.hook("comment", node.comment, node.comment) 11 | ) as Mutable; 12 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 13 | baseNode.name = options.hook("name", options.nextNode(node.name), node.name); 14 | 15 | return baseNode; 16 | } 17 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-class-tag.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 2 | import type {TS} from "./type/ts.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocClassTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocClassTag { 6 | const baseNode = options.factory.createJSDocClassTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("comment", node.comment, node.comment) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | return baseNode; 12 | } 13 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-comment.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {ensureNodeArray} from "./util/ensure-node-array.js"; 4 | import type {Mutable} from "helpertypes"; 5 | 6 | export function cloneJsDoc(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDoc { 7 | const baseNode = options.factory.createJSDocComment( 8 | options.hook("comment", node.comment, node.comment), 9 | ensureNodeArray(options.hook("tags", options.nextNodes(node.tags), node.tags), options.factory) 10 | ) as Mutable; 11 | 12 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 13 | 14 | return baseNode; 15 | } 16 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-deprecated-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocDeprecatedTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocDeprecatedTag { 6 | const baseNode = options.factory.createJSDocDeprecatedTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("comment", node.comment, node.comment) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | 12 | return baseNode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-enum-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocEnumTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocEnumTag { 6 | const baseNode = options.factory.createJSDocEnumTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("typeExpression", options.nextNode(node.typeExpression), node.typeExpression), 9 | options.hook("comment", node.comment, node.comment) 10 | ) as Mutable; 11 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 12 | 13 | return baseNode; 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-function-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocFunctionType(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocFunctionType { 6 | const baseNode = options.factory.createJSDocFunctionType( 7 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 8 | options.hook("type", node.type, node.type) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | 12 | return baseNode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-import-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocImportTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocImportTag { 6 | const baseNode = options.factory.createJSDocImportTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("importClause", options.nextNode(node.importClause), node.importClause), 9 | options.hook("moduleSpecifier", options.nextNode(node.moduleSpecifier), node.moduleSpecifier), 10 | options.hook("attributes", options.nextNode(node.attributes), node.attributes), 11 | options.hook("comment", typeof node.comment === "string" ? node.comment : options.nextNodes(node.comment), node.comment) 12 | ) as Mutable; 13 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 14 | 15 | return baseNode; 16 | } 17 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-link-code.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocLinkCode(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocLinkCode { 6 | const baseNode = options.factory.createJSDocLinkCode( 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("text", node.text, node.text) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | 12 | return baseNode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-link-plain.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocLinkPlain(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocLinkPlain { 6 | const baseNode = options.factory.createJSDocLinkPlain( 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("text", node.text, node.text) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | 12 | return baseNode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-link.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocLink(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocLink { 6 | const baseNode = options.factory.createJSDocLink( 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("text", node.text, node.text) 9 | ) as Mutable; 10 | 11 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 12 | 13 | return baseNode; 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-member-name.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocMemberName(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocMemberName { 6 | const baseNode = options.factory.createJSDocMemberName( 7 | options.hook("left", options.nextNode(node.left), node.left), 8 | options.hook("right", options.nextNode(node.right), node.right) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | 12 | return baseNode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-namepath-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocNamepathType(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocNamepathType { 6 | const baseNode = options.factory.createJSDocNamepathType(options.hook("type", options.nextNode(node.type), node.type)) as Mutable; 7 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 8 | 9 | return baseNode; 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-non-nullable-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocNonNullableType(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocNonNullableType { 6 | const baseNode = options.factory.createJSDocNonNullableType(options.hook("type", options.nextNode(node.type), node.type)) as Mutable; 7 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 8 | 9 | return baseNode; 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-nullable-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocNullableType(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocNullableType { 6 | const baseNode = options.factory.createJSDocNullableType(options.hook("type", options.nextNode(node.type), node.type)) as Mutable; 7 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 8 | 9 | return baseNode; 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-optional-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocOptionalType(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocOptionalType { 6 | const baseNode = options.factory.createJSDocOptionalType(options.hook("type", options.nextNode(node.type), node.type)) as Mutable; 7 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 8 | 9 | return baseNode; 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-overload-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocOverloadTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocOverloadTag { 6 | const baseNode = options.factory.createJSDocOverloadTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("typeExpression", options.nextNode(node.typeExpression), node.typeExpression), 9 | options.hook("comment", typeof node.comment === "string" ? node.comment : options.nextNodes(node.comment), node.comment) 10 | ) as Mutable; 11 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 12 | 13 | return baseNode; 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-parameter-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocParameterTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocParameterTag { 6 | const baseNode = options.factory.createJSDocParameterTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("name", options.nextNode(node.name), node.name), 9 | options.hook("isBracketed", node.isBracketed, node.isBracketed), 10 | options.hook("typeExpression", options.nextNode(node.typeExpression), node.typeExpression), 11 | options.hook("isNameFirst", node.isNameFirst, node.isNameFirst), 12 | options.hook("comment", node.comment, node.comment) 13 | ) as Mutable; 14 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 15 | 16 | return baseNode; 17 | } 18 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-private-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocPrivateTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocPrivateTag { 6 | const baseNode = options.factory.createJSDocPrivateTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("comment", node.comment, node.comment) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | 12 | return baseNode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-property-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocPropertyTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocPropertyTag { 6 | const baseNode = options.factory.createJSDocPropertyTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("name", options.nextNode(node.name), node.name), 9 | options.hook("isBracketed", node.isBracketed, node.isBracketed), 10 | options.hook("typeExpression", options.nextNode(node.typeExpression), node.typeExpression), 11 | options.hook("isNameFirst", node.isNameFirst, node.isNameFirst), 12 | options.hook("comment", node.comment, node.comment) 13 | ) as Mutable; 14 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 15 | 16 | return baseNode; 17 | } 18 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-protected-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocProtectedTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocProtectedTag { 6 | const baseNode = options.factory.createJSDocProtectedTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("comment", node.comment, node.comment) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | 12 | return baseNode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-public-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocPublicTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocPublicTag { 6 | const baseNode = options.factory.createJSDocPublicTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("comment", node.comment, node.comment) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | 12 | return baseNode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-readonly-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocReadonlyTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocReadonlyTag { 6 | const baseNode = options.factory.createJSDocReadonlyTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("comment", node.comment, node.comment) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | 12 | return baseNode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-return-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocReturnTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocReturnTag { 6 | const baseNode = options.factory.createJSDocReturnTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("typeExpression", options.nextNode(node.typeExpression), node.typeExpression), 9 | options.hook("comment", node.comment, node.comment) 10 | ) as Mutable; 11 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 12 | 13 | return baseNode; 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-satisfies-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocSatisfiesTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocSatisfiesTag { 6 | const baseNode = options.factory.createJSDocSatisfiesTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("typeExpression", options.nextNode(node.typeExpression), node.typeExpression), 9 | options.hook("comment", typeof node.comment === "string" ? node.comment : options.nextNodes(node.comment), node.comment) 10 | ) as Mutable; 11 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 12 | 13 | return baseNode; 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-see-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocSeeTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocSeeTag { 6 | const baseNode = options.factory.createJSDocSeeTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | // NOTE: do we want to wrap around `node.name`, which is a 9 | // `JSDocNameReference`? 10 | options.hook("name", node.name, node.name), 11 | options.hook("comment", node.comment, node.comment) 12 | ) as Mutable; 13 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 14 | 15 | return baseNode; 16 | } 17 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-signature.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 2 | import type {TS} from "./type/ts.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocSignature(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocSignature { 6 | const baseNode = options.factory.createJSDocSignature( 7 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 8 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 9 | options.hook("type", options.nextNode(node.type), node.type) 10 | ) as Mutable; 11 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 12 | 13 | return baseNode; 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-template-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {ensureNodeArray} from "./util/ensure-node-array.js"; 4 | import type {Mutable} from "helpertypes"; 5 | 6 | export function cloneJsDocTemplateTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocTemplateTag { 7 | const baseNode = options.factory.createJSDocTemplateTag( 8 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 9 | options.hook("constraint", options.nextNode(node.constraint), node.constraint), 10 | ensureNodeArray(options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), options.factory), 11 | options.hook("comment", node.comment, node.comment) 12 | ) as Mutable; 13 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 14 | 15 | return baseNode; 16 | } 17 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-this-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocThisTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocThisTag { 6 | const baseNode = options.factory.createJSDocThisTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("typeExpression", options.nextNode(node.typeExpression), node.typeExpression), 9 | options.hook("comment", node.comment, node.comment) 10 | ) as Mutable; 11 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 12 | 13 | return baseNode; 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-throws-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocThrowsTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocThrowsTag { 6 | const baseNode = options.factory.createJSDocThrowsTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("typeExpression", options.nextNode(node.typeExpression), node.typeExpression), 9 | options.hook("comment", typeof node.comment === "string" ? node.comment : options.nextNodes(node.comment), node.comment) 10 | ) as Mutable; 11 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 12 | 13 | return baseNode; 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-type-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocTypeExpression(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocTypeExpression { 6 | const baseNode = options.factory.createJSDocTypeExpression(options.hook("type", options.nextNode(node.type), node.type)) as Mutable; 7 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 8 | 9 | return baseNode; 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-type-literal.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocTypeLiteral(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocTypeLiteral { 6 | const baseNode = options.factory.createJSDocTypeLiteral( 7 | options.hook("jsDocPropertyTags", options.nextNodes(node.jsDocPropertyTags), node.jsDocPropertyTags), 8 | options.hook("isArrayType", node.isArrayType, node.isArrayType) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | 12 | return baseNode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-type-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocTypeTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocTypeTag { 6 | const baseNode = options.factory.createJSDocTypeTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("typeExpression", options.nextNode(node.typeExpression), node.typeExpression), 9 | options.hook("comment", node.comment, node.comment) 10 | ) as Mutable; 11 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 12 | 13 | return baseNode; 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-typedef-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocTypedefTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocTypedefTag { 6 | const baseNode = options.factory.createJSDocTypedefTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("typeExpression", options.nextNode(node.typeExpression), node.typeExpression), 9 | options.hook("fullName", options.nextNode(node.fullName), node.fullName), 10 | options.hook("comment", node.comment, node.comment) 11 | ) as Mutable; 12 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 13 | baseNode.name = options.hook("name", options.nextNode(node.name), node.name); 14 | 15 | return baseNode; 16 | } 17 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-unknown-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocUnknownTag(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocUnknownTag { 6 | const baseNode = options.factory.createJSDocUnknownTag( 7 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 8 | options.hook("comment", node.comment, node.comment) 9 | ) as Mutable; 10 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 11 | return baseNode; 12 | } 13 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-unknown-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocUnknownType(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocUnknownType { 6 | const baseNode = options.factory.createJSDocUnknownType() as Mutable; 7 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 8 | 9 | return baseNode; 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-js-doc-variadic-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneJsDocVariadicType(node: Mutable, options: CloneNodeVisitorOptions): TS.JSDocVariadicType { 6 | const baseNode = options.factory.createJSDocVariadicType(options.hook("type", options.nextNode(node.type), node.type)) as Mutable; 7 | baseNode.flags = options.hook("flags", (node.flags |= 8), (node.flags |= 8)); 8 | 9 | return baseNode; 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-attribute.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxAttribute(node: TS.JsxAttribute, options: CloneNodeVisitorOptions): TS.JsxAttribute { 5 | return options.factory.createJsxAttribute( 6 | options.hook("name", options.nextNode(node.name), node.name), 7 | options.hook("initializer", options.nextNode(node.initializer), node.initializer) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-attributes.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxAttributes(node: TS.JsxAttributes, options: CloneNodeVisitorOptions): TS.JsxAttributes { 5 | return options.factory.createJsxAttributes(options.hook("properties", options.nextNodes(node.properties), node.properties)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-closing-element.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxClosingElement(node: TS.JsxClosingElement, options: CloneNodeVisitorOptions): TS.JsxClosingElement { 5 | return options.factory.createJsxClosingElement(options.hook("tagName", options.nextNode(node.tagName), node.tagName)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-closing-fragment.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxClosingFragment(_node: TS.JsxClosingFragment, options: CloneNodeVisitorOptions): TS.JsxClosingFragment { 5 | return options.factory.createJsxJsxClosingFragment(); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-element.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxElement(node: TS.JsxElement, options: CloneNodeVisitorOptions): TS.JsxElement { 5 | return options.factory.createJsxElement( 6 | options.hook("openingElement", options.nextNode(node.openingElement), node.openingElement), 7 | options.hook("children", options.nextNodes(node.children), node.children), 8 | options.hook("closingElement", options.nextNode(node.closingElement), node.closingElement) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxExpression(node: TS.JsxExpression, options: CloneNodeVisitorOptions): TS.JsxExpression { 5 | return options.factory.createJsxExpression( 6 | options.hook("dotDotDotToken", options.nextNode(node.dotDotDotToken), node.dotDotDotToken), 7 | options.hook("expression", options.nextNode(node.expression), node.expression) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-fragment.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxFragment(node: TS.JsxFragment, options: CloneNodeVisitorOptions): TS.JsxFragment { 5 | return options.factory.createJsxFragment( 6 | options.hook("openingFragment", options.nextNode(node.openingFragment), node.openingFragment), 7 | options.hook("children", options.nextNodes(node.children), node.children), 8 | options.hook("closingFragment", options.nextNode(node.closingFragment), node.closingFragment) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-namespaced-name.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxNamespacedName(node: TS.JsxNamespacedName, options: CloneNodeVisitorOptions): TS.JsxNamespacedName { 5 | return options.factory.createJsxNamespacedName( 6 | options.hook("namespace", options.nextNode(node.namespace), node.namespace), 7 | options.hook("name", options.nextNode(node.name), node.name) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-opening-element.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxOpeningElement(node: TS.JsxOpeningElement, options: CloneNodeVisitorOptions): TS.JsxOpeningElement { 5 | return options.factory.createJsxOpeningElement( 6 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 7 | options.hook("typeArguments", options.nextNodes(node.typeArguments), node.typeArguments), 8 | options.hook("attributes", options.nextNode(node.attributes), node.attributes) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-opening-fragment.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxOpeningFragment(_node: TS.JsxOpeningFragment, options: CloneNodeVisitorOptions): TS.JsxOpeningFragment { 5 | return options.factory.createJsxOpeningFragment(); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-self-closing-element.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxSelfClosingElement(node: TS.JsxSelfClosingElement, options: CloneNodeVisitorOptions): TS.JsxSelfClosingElement { 5 | return options.factory.createJsxSelfClosingElement( 6 | options.hook("tagName", options.nextNode(node.tagName), node.tagName), 7 | options.hook("typeArguments", options.nextNodes(node.typeArguments), node.typeArguments), 8 | options.hook("attributes", options.nextNode(node.attributes), node.attributes) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-spread-attribute.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxSpreadAttribute(node: TS.JsxSpreadAttribute, options: CloneNodeVisitorOptions): TS.JsxSpreadAttribute { 5 | return options.factory.createJsxSpreadAttribute(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-jsx-text.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneJsxText(node: TS.JsxText, options: CloneNodeVisitorOptions): TS.JsxText { 5 | return options.factory.createJsxText( 6 | options.hook("text", node.text, node.text), 7 | options.hook("containsOnlyTriviaWhiteSpaces", node.containsOnlyTriviaWhiteSpaces, node.containsOnlyTriviaWhiteSpaces) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-keyword-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneKeywordTypeNode(node: TS.KeywordTypeNode, options: CloneNodeVisitorOptions): TS.KeywordTypeNode { 5 | return options.factory.createKeywordTypeNode(options.hook("kind", node.kind, node.kind)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-labeled-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneLabeledStatement(node: TS.LabeledStatement, options: CloneNodeVisitorOptions): TS.LabeledStatement { 5 | return options.factory.createLabeledStatement( 6 | options.hook("label", options.nextNode(node.label), node.label), 7 | options.hook("statement", options.nextNode(node.statement), node.statement) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-literal-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneLiteralTypeNode(node: TS.LiteralTypeNode, options: CloneNodeVisitorOptions): TS.LiteralTypeNode { 5 | return options.factory.createLiteralTypeNode(options.hook("literal", options.nextNode(node.literal), node.literal)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-mapped-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 2 | import type {TS} from "./type/ts.js"; 3 | import {ensureNodeArray} from "./util/ensure-node-array.js"; 4 | 5 | export function cloneMappedTypeNode(node: TS.MappedTypeNode, options: CloneNodeVisitorOptions): TS.MappedTypeNode { 6 | return options.factory.createMappedTypeNode( 7 | options.hook("readonlyToken", options.nextNode(node.readonlyToken), node.readonlyToken), 8 | options.hook("typeParameter", options.nextNode(node.typeParameter), node.typeParameter), 9 | options.hook("nameType", options.nextNode(node.nameType), node.nameType), 10 | options.hook("questionToken", options.nextNode(node.questionToken), node.questionToken), 11 | options.hook("type", options.nextNode(node.type), node.type), 12 | ensureNodeArray(options.hook("members", options.nextNodes(node.members), node.members), options.factory) 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/clone-meta-property.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneMetaProperty(node: TS.MetaProperty, options: CloneNodeVisitorOptions): TS.MetaProperty { 5 | return options.factory.createMetaProperty(options.hook("keywordToken", node.keywordToken, node.keywordToken), options.hook("name", options.nextNode(node.name), node.name)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-method-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {getModifierLikes} from "./util/get-modifier-likes.js"; 4 | 5 | export function cloneMethodDeclaration(node: TS.MethodDeclaration, options: CloneNodeVisitorOptions): TS.MethodDeclaration { 6 | const modifierLikes = getModifierLikes(node); 7 | return options.factory.createMethodDeclaration( 8 | options.hook("modifiers", options.nextNodes(modifierLikes), modifierLikes), 9 | options.hook("asteriskToken", options.nextNode(node.asteriskToken), node.asteriskToken), 10 | options.hook("name", options.nextNode(node.name), node.name), 11 | options.hook("questionToken", options.nextNode(node.questionToken), node.questionToken), 12 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 13 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 14 | options.hook("type", options.nextNode(node.type), node.type), 15 | options.hook("body", options.nextNode(node.body), node.body) 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /src/clone-node/clone-method-signature.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneMethodSignature(node: TS.MethodSignature, options: CloneNodeVisitorOptions): TS.MethodSignature { 5 | return options.factory.createMethodSignature( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("questionToken", options.nextNode(node.questionToken), node.questionToken), 9 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 10 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 11 | options.hook("type", options.nextNode(node.type), node.type) 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-module-block.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneModuleBlock(node: TS.ModuleBlock, options: CloneNodeVisitorOptions): TS.ModuleBlock { 5 | return options.factory.createModuleBlock(options.hook("statements", options.nextNodes(node.statements), node.statements)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-module-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneModuleDeclaration(node: TS.ModuleDeclaration, options: CloneNodeVisitorOptions): TS.ModuleDeclaration { 5 | return options.factory.createModuleDeclaration( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("body", options.nextNode(node.body), node.body), 9 | options.hook("flags", node.flags, node.flags) 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/clone-named-exports.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneNamedExports(node: TS.NamedExports, options: CloneNodeVisitorOptions): TS.NamedExports { 5 | return options.factory.createNamedExports(options.hook("elements", options.nextNodes(node.elements), node.elements)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-named-imports.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneNamedImports(node: TS.NamedImports, options: CloneNodeVisitorOptions): TS.NamedImports { 5 | return options.factory.createNamedImports(options.hook("elements", options.nextNodes(node.elements), node.elements)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-named-tuple-member.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneNamedTupleMember(node: TS.NamedTupleMember, options: CloneNodeVisitorOptions): TS.NamedTupleMember { 5 | return options.factory.createNamedTupleMember( 6 | options.hook("dotDotDotToken", options.nextNode(node.dotDotDotToken), node.dotDotDotToken), 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("questionToken", options.nextNode(node.questionToken), node.questionToken), 9 | options.hook("type", options.nextNode(node.type), node.type) 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/clone-namespace-export-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneNamespaceExportDeclaration( 5 | node: TS.NamespaceExportDeclaration, 6 | options: CloneNodeVisitorOptions 7 | ): TS.NamespaceExportDeclaration { 8 | return options.factory.createNamespaceExportDeclaration(options.hook("name", options.nextNode(node.name), node.name)); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-namespace-export.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneNamespaceExport(node: TS.NamespaceExport, options: CloneNodeVisitorOptions): TS.NamespaceExport { 5 | return options.factory.createNamespaceExport(options.hook("name", options.nextNode(node.name), node.name)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-namespace-import.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneNamespaceImport(node: TS.NamespaceImport, options: CloneNodeVisitorOptions): TS.NamespaceImport { 5 | return options.factory.createNamespaceImport(options.hook("name", options.nextNode(node.name), node.name)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-new-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneNewExpression(node: TS.NewExpression, options: CloneNodeVisitorOptions): TS.NewExpression { 5 | return options.factory.createNewExpression( 6 | options.hook("expression", options.nextNode(node.expression), node.expression), 7 | options.hook("typeArguments", options.nextNodes(node.typeArguments), node.typeArguments), 8 | options.hook("arguments", options.nextNodes(node.arguments), node.arguments) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-no-substitution-template-literal.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneNoSubstitutionTemplateLiteral( 5 | node: TS.NoSubstitutionTemplateLiteral, 6 | options: CloneNodeVisitorOptions 7 | ): TS.NoSubstitutionTemplateLiteral { 8 | return options.factory.createNoSubstitutionTemplateLiteral(options.hook("text", node.text, node.text), options.hook("rawText", node.rawText, node.text)); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-node-options.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {MetaNode, Modifiersable} from "./type/meta-node.js"; 3 | 4 | export type NodeHookValue = 5 | T[Key] extends TS.NodeArray 6 | ? ElementTypeA[] | readonly ElementTypeA[] | TS.NodeArray 7 | : T[Key] extends TS.NodeArray | undefined 8 | ? ElementTypeB[] | readonly ElementTypeB[] | TS.NodeArray | undefined 9 | : T[Key]; 10 | 11 | export interface CloneNodeHookFactoryPayload { 12 | depth: number; 13 | } 14 | 15 | export type CloneNodeHookCallback = (value: NodeHookValue, oldValue: NodeHookValue) => NodeHookValue; 16 | 17 | export type CloneNodeFinalizerCallback = (newNode: T, oldNode: T, payload: CloneNodeHookFactoryPayload) => T | undefined; 18 | 19 | export type CloneNodeHook = { 20 | [Key in keyof T]?: CloneNodeHookCallback; 21 | }; 22 | 23 | export type CloneNodeHookFactory = (node: T, payload: CloneNodeHookFactoryPayload) => CloneNodeHook | undefined; 24 | 25 | export type CloneNodeHookInternal = (key: Key, newValue: NodeHookValue, oldValue: NodeHookValue) => NodeHookValue; 26 | 27 | export interface CloneNodeOptions { 28 | hook: CloneNodeHookFactory; 29 | finalize: CloneNodeFinalizerCallback; 30 | typescript: typeof TS; 31 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 32 | // @ts-ignore 33 | factory: TS.NodeFactory; 34 | setParents: boolean; 35 | setOriginalNodes: boolean; 36 | preserveSymbols: boolean; 37 | preserveComments: boolean; 38 | debug: boolean; 39 | } 40 | 41 | export interface CloneNodeInternalOptions extends Omit, "hook" | "finalize"> { 42 | hook: CloneNodeHookFactory; 43 | finalize?: CloneNodeFinalizerCallback; 44 | commentRanges: Set; 45 | depth: number; 46 | } 47 | 48 | export interface CloneNodeVisitorOptions extends Omit, "hook" | "finalize"> { 49 | hook: CloneNodeHookInternal; 50 | 51 | nextNode(node: Next): Next; 52 | nextNode(node: Next | undefined): Next | undefined; 53 | 54 | nextNodes(nodes: readonly Next[] | Next[]): Next[]; 55 | nextNodes(nodes: undefined): undefined; 56 | nextNodes(nodes: readonly Next[] | Next[] | undefined): undefined; 57 | } 58 | -------------------------------------------------------------------------------- /src/clone-node/clone-non-null-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneNonNullExpression(node: TS.NonNullExpression, options: CloneNodeVisitorOptions): TS.NonNullExpression { 5 | return options.factory.createNonNullExpression(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-not-emitted-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneNotEmittedStatement(node: TS.NotEmittedStatement, options: CloneNodeVisitorOptions): TS.NotEmittedStatement { 5 | return options.factory.createNotEmittedStatement(node); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-null-literal.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneNullLiteral(_node: TS.NullLiteral, options: CloneNodeVisitorOptions): TS.NullLiteral { 5 | return options.factory.createNull(); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-numeric-literal.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneNumericLiteral(node: TS.NumericLiteral, options: CloneNodeVisitorOptions): TS.NumericLiteral { 5 | return options.factory.createNumericLiteral(options.hook("text", node.text, node.text)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-object-binding-pattern.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneObjectBindingPattern(node: TS.ObjectBindingPattern, options: CloneNodeVisitorOptions): TS.ObjectBindingPattern { 5 | return options.factory.createObjectBindingPattern(options.hook("elements", options.nextNodes(node.elements), node.elements)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-object-literal-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneObjectLiteralExpression(node: TS.ObjectLiteralExpression, options: CloneNodeVisitorOptions): TS.ObjectLiteralExpression { 5 | return options.factory.createObjectLiteralExpression(options.hook("properties", options.nextNodes(node.properties), node.properties)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-omitted-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneOmittedExpression(_node: TS.OmittedExpression, options: CloneNodeVisitorOptions): TS.OmittedExpression { 5 | return options.factory.createOmittedExpression(); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-optional-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneOptionalTypeNode(node: TS.OptionalTypeNode, options: CloneNodeVisitorOptions): TS.OptionalTypeNode { 5 | return options.factory.createOptionalTypeNode(options.hook("type", options.nextNode(node.type), node.type)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-parameter-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {getModifierLikes} from "./util/get-modifier-likes.js"; 4 | 5 | export function cloneParameterDeclaration(node: TS.ParameterDeclaration, options: CloneNodeVisitorOptions): TS.ParameterDeclaration { 6 | const modifierLikes = getModifierLikes(node); 7 | return options.factory.createParameterDeclaration( 8 | options.hook("modifiers", options.nextNodes(modifierLikes), modifierLikes), 9 | options.hook("dotDotDotToken", options.nextNode(node.dotDotDotToken), node.dotDotDotToken), 10 | options.hook("name", options.nextNode(node.name), node.name), 11 | options.hook("questionToken", options.nextNode(node.questionToken), node.questionToken), 12 | options.hook("type", options.nextNode(node.type), node.type), 13 | options.hook("initializer", options.nextNode(node.initializer), node.initializer) 14 | ); 15 | } 16 | -------------------------------------------------------------------------------- /src/clone-node/clone-parenthesized-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneParenthesizedExpression(node: TS.ParenthesizedExpression, options: CloneNodeVisitorOptions): TS.ParenthesizedExpression { 5 | return options.factory.createParenthesizedExpression(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-parenthesized-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneParenthesizedTypeNode(node: TS.ParenthesizedTypeNode, options: CloneNodeVisitorOptions): TS.ParenthesizedTypeNode { 5 | return options.factory.createParenthesizedType(options.hook("type", options.nextNode(node.type), node.type)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-partially-omitted-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function clonePartiallyEmittedExpression( 5 | node: TS.PartiallyEmittedExpression, 6 | options: CloneNodeVisitorOptions 7 | ): TS.PartiallyEmittedExpression { 8 | return options.factory.createPartiallyEmittedExpression(options.hook("expression", options.nextNode(node.expression), node.expression)); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-postfix-unary-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function clonePostfixUnaryExpression(node: TS.PostfixUnaryExpression, options: CloneNodeVisitorOptions): TS.PostfixUnaryExpression { 5 | return options.factory.createPostfixUnaryExpression( 6 | options.hook("operand", options.nextNode(node.operand), node.operand), 7 | options.hook("operator", node.operator, node.operator) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-prefix-unary-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function clonePrefixUnaryExpression(node: TS.PrefixUnaryExpression, options: CloneNodeVisitorOptions): TS.PrefixUnaryExpression { 5 | return options.factory.createPrefixUnaryExpression(options.hook("operator", node.operator, node.operator), options.hook("operand", options.nextNode(node.operand), node.operand)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-private-identifier.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function clonePrivateIdentifier(node: TS.PrivateIdentifier, options: CloneNodeVisitorOptions): TS.PrivateIdentifier { 5 | return options.factory.createPrivateIdentifier(options.hook("text", node.text, node.text)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-property-access-chain.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function clonePropertyAccessChain(node: TS.PropertyAccessChain, options: CloneNodeVisitorOptions): TS.PropertyAccessChain { 5 | return options.factory.createPropertyAccessChain( 6 | options.hook("expression", options.nextNode(node.expression), node.expression), 7 | options.hook("questionDotToken", options.nextNode(node.questionDotToken), node.questionDotToken), 8 | options.hook("name", options.nextNode(node.name), node.name) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-property-access-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function clonePropertyAccessExpression(node: TS.PropertyAccessExpression, options: CloneNodeVisitorOptions): TS.PropertyAccessExpression { 5 | return options.factory.createPropertyAccessExpression( 6 | options.hook("expression", options.nextNode(node.expression), node.expression), 7 | options.hook("name", options.nextNode(node.name), node.name) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-property-assignment.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function clonePropertyAssignment(node: TS.PropertyAssignment, options: CloneNodeVisitorOptions): TS.PropertyAssignment { 6 | const clonedPropertyAssignment = options.factory.createPropertyAssignment( 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("initializer", options.nextNode(node.initializer), node.initializer) 9 | ); 10 | 11 | // createPropertyAssignment may wrap the initializer expression in parentheses. We want to make sure that we're producing identical clones here, 12 | // so if the new PropertyAssignment has a ParenthesizedExpression that weren't there before, remove it. 13 | if (!options.typescript.isParenthesizedExpression(node.initializer) && options.typescript.isParenthesizedExpression(clonedPropertyAssignment.initializer)) { 14 | (clonedPropertyAssignment as Mutable).initializer = clonedPropertyAssignment.initializer.expression; 15 | } 16 | 17 | return clonedPropertyAssignment; 18 | } 19 | -------------------------------------------------------------------------------- /src/clone-node/clone-property-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {getModifierLikes} from "./util/get-modifier-likes.js"; 4 | 5 | export function clonePropertyDeclaration(node: TS.PropertyDeclaration, options: CloneNodeVisitorOptions): TS.PropertyDeclaration { 6 | const modifierLikes = getModifierLikes(node); 7 | return options.factory.createPropertyDeclaration( 8 | options.hook("modifiers", options.nextNodes(modifierLikes), modifierLikes), 9 | options.hook("name", options.nextNode(node.name), node.name), 10 | node.questionToken != null 11 | ? options.hook("questionToken", options.nextNode(node.questionToken), node.questionToken) 12 | : options.hook("exclamationToken", options.nextNode(node.exclamationToken), node.exclamationToken), 13 | options.hook("type", options.nextNode(node.type), node.type), 14 | options.hook("initializer", options.nextNode(node.initializer), node.initializer) 15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /src/clone-node/clone-property-signature.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function clonePropertySignature(node: TS.PropertySignature, options: CloneNodeVisitorOptions): TS.PropertySignature { 5 | return options.factory.createPropertySignature( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("questionToken", options.nextNode(node.questionToken), node.questionToken), 9 | options.hook("type", options.nextNode(node.type), node.type) 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/clone-qualified-name.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneQualifiedName(node: TS.QualifiedName, options: CloneNodeVisitorOptions): TS.QualifiedName { 5 | return options.factory.createQualifiedName(options.hook("left", options.nextNode(node.left), node.left), options.hook("right", options.nextNode(node.right), node.right)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-regular-expression-literal.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneRegularExpressionLiteral(node: TS.RegularExpressionLiteral, options: CloneNodeVisitorOptions): TS.RegularExpressionLiteral { 5 | return options.factory.createRegularExpressionLiteral(options.hook("text", node.text, node.text)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-rest-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneRestTypeNode(node: TS.RestTypeNode, options: CloneNodeVisitorOptions): TS.RestTypeNode { 5 | return options.factory.createRestTypeNode(options.hook("type", options.nextNode(node.type), node.type)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-return-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneReturnStatement(node: TS.ReturnStatement, options: CloneNodeVisitorOptions): TS.ReturnStatement { 5 | return options.factory.createReturnStatement(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-satisfies-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneSatisfiesExpression(node: TS.SatisfiesExpression, options: CloneNodeVisitorOptions): TS.SatisfiesExpression { 5 | return options.factory.createSatisfiesExpression( 6 | options.hook("expression", options.nextNode(node.expression), node.expression), 7 | options.hook("type", options.nextNode(node.type), node.type) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-semicolon-class-element.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneSemicolonClassElement(_node: TS.SemicolonClassElement, options: CloneNodeVisitorOptions): TS.SemicolonClassElement { 5 | return options.factory.createSemicolonClassElement(); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-set-accessor-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import {getModifierLikes} from "./util/get-modifier-likes.js"; 4 | 5 | export function cloneSetAccessorDeclaration(node: TS.SetAccessorDeclaration, options: CloneNodeVisitorOptions): TS.SetAccessorDeclaration { 6 | const modifierLikes = getModifierLikes(node); 7 | return options.factory.createSetAccessorDeclaration( 8 | options.hook("modifiers", options.nextNodes(modifierLikes), modifierLikes), 9 | options.hook("name", options.nextNode(node.name), node.name), 10 | options.hook("parameters", options.nextNodes(node.parameters), node.parameters), 11 | options.hook("body", options.nextNode(node.body), node.body) 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/clone-shorthand-property-assignment.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneShorthandPropertyAssignment( 5 | node: TS.ShorthandPropertyAssignment, 6 | options: CloneNodeVisitorOptions 7 | ): TS.ShorthandPropertyAssignment { 8 | return options.factory.createShorthandPropertyAssignment( 9 | options.hook("name", options.nextNode(node.name), node.name), 10 | options.hook("objectAssignmentInitializer", options.nextNode(node.objectAssignmentInitializer), node.objectAssignmentInitializer) 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /src/clone-node/clone-source-file.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneSourceFile(node: TS.SourceFile, options: CloneNodeVisitorOptions): TS.SourceFile { 6 | // Support TypeScript 3.x which uses updateSourceFileNode, whereas TypeScript 4.x uses updateSourceFile 7 | const updatedSourceFile = options.factory.updateSourceFile( 8 | node, 9 | options.hook("statements", options.nextNodes(node.statements), node.statements), 10 | node.isDeclarationFile, 11 | node.referencedFiles, 12 | node.typeReferenceDirectives, 13 | node.hasNoDefaultLib, 14 | node.libReferenceDirectives 15 | ); 16 | 17 | (updatedSourceFile as Mutable).pos = -1; 18 | (updatedSourceFile as Mutable).end = -1; 19 | return updatedSourceFile; 20 | } 21 | -------------------------------------------------------------------------------- /src/clone-node/clone-spread-assignment.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneSpreadAssignment(node: TS.SpreadAssignment, options: CloneNodeVisitorOptions): TS.SpreadAssignment { 5 | return options.factory.createSpreadAssignment(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-spread-element.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneSpreadElement(node: TS.SpreadElement, options: CloneNodeVisitorOptions): TS.SpreadElement { 5 | return options.factory.createSpreadElement(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-string-literal.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneStringLiteral(node: TS.StringLiteral, options: CloneNodeVisitorOptions): TS.StringLiteral { 5 | return options.factory.createStringLiteral(options.hook("text", node.text, node.text)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-super-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneSuperExpression(_node: TS.SuperExpression, options: CloneNodeVisitorOptions): TS.SuperExpression { 5 | return options.factory.createSuper(); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-switch-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneSwitchStatement(node: TS.SwitchStatement, options: CloneNodeVisitorOptions): TS.SwitchStatement { 5 | return options.factory.createSwitchStatement( 6 | options.hook("expression", options.nextNode(node.expression), node.expression), 7 | options.hook("caseBlock", options.nextNode(node.caseBlock), node.caseBlock) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-tagged-template-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTaggedTemplateExpression(node: TS.TaggedTemplateExpression, options: CloneNodeVisitorOptions): TS.TaggedTemplateExpression { 5 | return options.factory.createTaggedTemplateExpression( 6 | options.hook("tag", options.nextNode(node.tag), node.tag), 7 | options.hook("typeArguments", options.nextNodes(node.typeArguments), node.typeArguments), 8 | options.hook("template", options.nextNode(node.template), node.template) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-template-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTemplateExpression(node: TS.TemplateExpression, options: CloneNodeVisitorOptions): TS.TemplateExpression { 5 | return options.factory.createTemplateExpression( 6 | options.hook("head", options.nextNode(node.head), node.head), 7 | options.hook("templateSpans", options.nextNodes(node.templateSpans), node.templateSpans) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-template-head.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTemplateHead(node: TS.TemplateHead, options: CloneNodeVisitorOptions): TS.TemplateHead { 5 | return options.factory.createTemplateHead(options.hook("text", node.text, node.text), options.hook("rawText", node.rawText, node.rawText)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-template-literal-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTemplateLiteralTypeNode(node: TS.TemplateLiteralTypeNode, options: CloneNodeVisitorOptions): TS.TemplateLiteralTypeNode { 5 | return options.factory.createTemplateLiteralType( 6 | options.hook("head", options.nextNode(node.head), node.head), 7 | options.hook("templateSpans", options.nextNodes(node.templateSpans), node.templateSpans) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-template-literal-type-span.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTemplateLiteralTypeSpan(node: TS.TemplateLiteralTypeSpan, options: CloneNodeVisitorOptions): TS.TemplateLiteralTypeSpan { 5 | return options.factory.createTemplateLiteralTypeSpan( 6 | options.hook("type", options.nextNode(node.type), node.type), 7 | options.hook("literal", options.nextNode(node.literal), node.literal) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-template-middle.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTemplateMiddle(node: TS.TemplateMiddle, options: CloneNodeVisitorOptions): TS.TemplateMiddle { 5 | return options.factory.createTemplateMiddle(options.hook("text", node.text, node.text), options.hook("rawText", node.rawText, node.rawText)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-template-span.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTemplateSpan(node: TS.TemplateSpan, options: CloneNodeVisitorOptions): TS.TemplateSpan { 5 | return options.factory.createTemplateSpan( 6 | options.hook("expression", options.nextNode(node.expression), node.expression), 7 | options.hook("literal", options.nextNode(node.literal), node.literal) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-template-tail.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTemplateTail(node: TS.TemplateTail, options: CloneNodeVisitorOptions): TS.TemplateTail { 5 | return options.factory.createTemplateTail(options.hook("text", node.text, node.text), options.hook("rawText", node.rawText, node.rawText)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-this-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneThisExpression(_node: TS.ThisExpression, options: CloneNodeVisitorOptions): TS.ThisExpression { 5 | return options.factory.createThis(); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-this-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneThisTypeNode(_node: TS.ThisTypeNode, options: CloneNodeVisitorOptions): TS.ThisTypeNode { 5 | return options.factory.createThisTypeNode(); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-throw-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneThrowStatement(node: TS.ThrowStatement, options: CloneNodeVisitorOptions): TS.ThrowStatement { 5 | return options.factory.createThrowStatement(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-token.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeVisitorOptions, NodeHookValue} from "./clone-node-options.js"; 2 | import type {TS} from "./type/ts.js"; 3 | 4 | export function cloneToken(node: TS.Token, options: CloneNodeVisitorOptions>): TS.Token { 5 | return options.factory.createToken( 6 | options.hook("kind", node.kind as NodeHookValue, "kind">, node.kind as NodeHookValue, "kind">) as never 7 | ) as unknown as TS.Token; 8 | } 9 | -------------------------------------------------------------------------------- /src/clone-node/clone-try-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTryStatement(node: TS.TryStatement, options: CloneNodeVisitorOptions): TS.TryStatement { 5 | return options.factory.createTryStatement( 6 | options.hook("tryBlock", options.nextNode(node.tryBlock), node.tryBlock), 7 | options.hook("catchClause", options.nextNode(node.catchClause), node.catchClause), 8 | options.hook("finallyBlock", options.nextNode(node.finallyBlock), node.finallyBlock) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-tuple-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTupleTypeNode(node: TS.TupleTypeNode, options: CloneNodeVisitorOptions): TS.TupleTypeNode { 5 | if ("elementTypes" in node) { 6 | const castNode = node as TS.TupleTypeNode & {elementTypes: TS.NodeArray}; 7 | return options.factory.createTupleTypeNode(options.hook("elements", options.nextNodes(castNode.elementTypes), castNode.elementTypes)); 8 | } else { 9 | return options.factory.createTupleTypeNode(options.hook("elements", options.nextNodes(node.elements), node.elements)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/clone-type-alias-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTypeAliasDeclaration(node: TS.TypeAliasDeclaration, options: CloneNodeVisitorOptions): TS.TypeAliasDeclaration { 5 | return options.factory.createTypeAliasDeclaration( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("typeParameters", options.nextNodes(node.typeParameters), node.typeParameters), 9 | options.hook("type", options.nextNode(node.type), node.type) 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/clone-type-assertion.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTypeAssertion(node: TS.TypeAssertion, options: CloneNodeVisitorOptions): TS.TypeAssertion { 5 | return options.factory.createTypeAssertion( 6 | options.hook("type", options.nextNode(node.type), node.type), 7 | options.hook("expression", options.nextNode(node.expression), node.expression) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-type-literal-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTypeLiteralNode(node: TS.TypeLiteralNode, options: CloneNodeVisitorOptions): TS.TypeLiteralNode { 5 | return options.factory.createTypeLiteralNode(options.hook("members", options.nextNodes(node.members), node.members)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-type-of-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTypeOfExpression(node: TS.TypeOfExpression, options: CloneNodeVisitorOptions): TS.TypeOfExpression { 5 | return options.factory.createTypeOfExpression(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-type-operator-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTypeOperatorNode(node: TS.TypeOperatorNode, options: CloneNodeVisitorOptions): TS.TypeOperatorNode { 5 | return options.factory.createTypeOperatorNode(options.hook("operator", node.operator, node.operator), options.hook("type", options.nextNode(node.type), node.type)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-type-parameter-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 2 | import type {TS} from "./type/ts.js"; 3 | 4 | export function cloneTypeParameterDeclaration(node: TS.TypeParameterDeclaration, options: CloneNodeVisitorOptions): TS.TypeParameterDeclaration { 5 | return options.factory.createTypeParameterDeclaration( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("constraint", options.nextNode(node.constraint), node.constraint), 9 | options.hook("default", options.nextNode(node.default), node.default) 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/clone-type-predicate-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTypePredicateNode(node: TS.TypePredicateNode, options: CloneNodeVisitorOptions): TS.TypePredicateNode { 5 | return options.factory.createTypePredicateNode( 6 | options.hook("assertsModifier", options.nextNode(node.assertsModifier), node.assertsModifier), 7 | options.hook("parameterName", options.nextNode(node.parameterName), node.parameterName), 8 | options.hook("type", options.nextNode(node.type), node.type) 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/clone-type-query-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTypeQueryNode(node: TS.TypeQueryNode, options: CloneNodeVisitorOptions): TS.TypeQueryNode { 5 | return options.factory.createTypeQueryNode(options.hook("exprName", options.nextNode(node.exprName), node.exprName)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-type-reference-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneTypeReferenceNode(node: TS.TypeReferenceNode, options: CloneNodeVisitorOptions): TS.TypeReferenceNode { 5 | return options.factory.createTypeReferenceNode( 6 | options.hook("typeName", options.nextNode(node.typeName), node.typeName), 7 | options.hook("typeArguments", options.nextNodes(node.typeArguments), node.typeArguments) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-union-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneUnionTypeNode(node: TS.UnionTypeNode, options: CloneNodeVisitorOptions): TS.UnionTypeNode { 5 | return options.factory.createUnionTypeNode(options.hook("types", options.nextNodes(node.types), node.types)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-variable-declaration-list.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 2 | import type {TS} from "./type/ts.js"; 3 | 4 | export function cloneVariableDeclarationList(node: TS.VariableDeclarationList, options: CloneNodeVisitorOptions): TS.VariableDeclarationList { 5 | return options.factory.createVariableDeclarationList( 6 | options.hook("declarations", options.nextNodes(node.declarations), node.declarations), 7 | options.hook("flags", node.flags, node.flags) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-variable-declaration.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | import type {Mutable} from "helpertypes"; 4 | 5 | export function cloneVariableDeclaration(node: TS.VariableDeclaration, options: CloneNodeVisitorOptions): TS.VariableDeclaration { 6 | const clonedVariableDeclaration = options.factory.createVariableDeclaration( 7 | options.hook("name", options.nextNode(node.name), node.name), 8 | options.hook("exclamationToken", options.nextNode(node.exclamationToken), node.exclamationToken), 9 | options.hook("type", options.nextNode(node.type), node.type), 10 | options.hook("initializer", options.nextNode(node.initializer), node.initializer) 11 | ); 12 | 13 | // createVariableDeclaration may wrap the initializer expression in parentheses. We want to make sure that we're producing identical clones here, 14 | // so if the new VariableDeclaration has a ParenthesizedExpression that weren't there before, remove it. 15 | if ( 16 | node.initializer != null && 17 | clonedVariableDeclaration.initializer != null && 18 | !options.typescript.isParenthesizedExpression(node.initializer) && 19 | options.typescript.isParenthesizedExpression(clonedVariableDeclaration.initializer) 20 | ) { 21 | (clonedVariableDeclaration as Mutable).initializer = clonedVariableDeclaration.initializer.expression; 22 | } 23 | 24 | return clonedVariableDeclaration; 25 | } 26 | -------------------------------------------------------------------------------- /src/clone-node/clone-variable-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneVariableStatement(node: TS.VariableStatement, options: CloneNodeVisitorOptions): TS.VariableStatement { 5 | return options.factory.createVariableStatement( 6 | options.hook("modifiers", options.nextNodes(node.modifiers), node.modifiers), 7 | options.hook("declarationList", options.nextNode(node.declarationList), node.declarationList) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-void-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneVoidExpression(node: TS.VoidExpression, options: CloneNodeVisitorOptions): TS.VoidExpression { 5 | return options.factory.createVoidExpression(options.hook("expression", options.nextNode(node.expression), node.expression)); 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/clone-while-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneWhileStatement(node: TS.WhileStatement, options: CloneNodeVisitorOptions): TS.WhileStatement { 5 | return options.factory.createWhileStatement( 6 | options.hook("expression", options.nextNode(node.expression), node.expression), 7 | options.hook("statement", options.nextNode(node.statement), node.statement) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-with-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneWithStatement(node: TS.WithStatement, options: CloneNodeVisitorOptions): TS.WithStatement { 5 | return options.factory.createWithStatement( 6 | options.hook("expression", options.nextNode(node.expression), node.expression), 7 | options.hook("statement", options.nextNode(node.statement), node.statement) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/clone-yield-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./type/ts.js"; 2 | import type {CloneNodeVisitorOptions} from "./clone-node-options.js"; 3 | 4 | export function cloneYieldExpression(node: TS.YieldExpression, options: CloneNodeVisitorOptions): TS.YieldExpression { 5 | return options.factory.createYieldExpression( 6 | options.hook("asteriskToken", options.nextNode(node.asteriskToken), node.asteriskToken)!, 7 | options.hook("expression", options.nextNode(node.expression), node.expression)! 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/type/meta-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./ts.js"; 2 | 3 | export interface Modifiersable { 4 | modifiers?: TS.NodeArray; 5 | } 6 | 7 | export type MetaNode = TS.Node & 8 | Modifiersable & { 9 | jsDoc?: TS.JSDoc[]; 10 | _original?: MetaNode; 11 | original?: MetaNode; 12 | _symbol?: TS.Symbol; 13 | symbol?: TS.Symbol; 14 | _parent?: MetaNode; 15 | localSymbol?: TS.Symbol; 16 | emitNode?: {leadingComments?: TS.SynthesizedComment[]; trailingComments?: TS.SynthesizedComment[]}; 17 | }; 18 | -------------------------------------------------------------------------------- /src/clone-node/type/set-parent-nodes-options.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "./ts.js"; 2 | 3 | export type ParentPropertyName = "parent" | "_parent"; 4 | 5 | export interface SetParentNodesOptions { 6 | propertyName: ParentPropertyName; 7 | deep: boolean; 8 | typescript: typeof TS; 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/type/ts.ts: -------------------------------------------------------------------------------- 1 | import type * as TS from "typescript"; 2 | export type {TS}; 3 | -------------------------------------------------------------------------------- /src/clone-node/util/ensure-node-array.ts: -------------------------------------------------------------------------------- 1 | import type {MetaNode} from "../type/meta-node.js"; 2 | import type {TS} from "../type/ts.js"; 3 | import {isNodeArray} from "./is-node-array.js"; 4 | 5 | export function ensureNodeArray(item: T[] | readonly T[] | TS.NodeArray, factory: TS.NodeFactory): TS.NodeArray; 6 | export function ensureNodeArray(item: T[] | readonly T[] | TS.NodeArray | undefined, factory: TS.NodeFactory): TS.NodeArray | undefined; 7 | export function ensureNodeArray(item: T[] | readonly T[] | TS.NodeArray | undefined, factory: TS.NodeFactory): TS.NodeArray | undefined { 8 | if (item == null || isNodeArray(item)) return item; 9 | return factory.createNodeArray(item); 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/util/get-modifier-likes.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | 3 | export function getModifierLikes(node: TS.Node): readonly TS.ModifierLike[] | undefined { 4 | const modifiers = ("modifiers" in node && Array.isArray(node.modifiers) ? node.modifiers : []) as TS.ModifierLike[] | undefined; 5 | 6 | if ("decorators" in node && Array.isArray(node.decorators)) { 7 | return [...(node.decorators as TS.Decorator[]), ...(modifiers as TS.Modifier[])]; 8 | } else { 9 | return modifiers; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/clone-node/util/get-original-node.ts: -------------------------------------------------------------------------------- 1 | import type {MetaNode} from "../type/meta-node.js"; 2 | import type {CloneNodeInternalOptions} from "../clone-node-options.js"; 3 | 4 | export function getOriginalNode(node: T, options: CloneNodeInternalOptions): T { 5 | if (node._original != null) { 6 | return getOriginalNode(node._original as T, options); 7 | } 8 | 9 | return (options.typescript.getOriginalNode(node) as T | undefined) ?? node; 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/util/is-boolean-literal.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is either the boolean Literal 'true' or 'false' 6 | */ 7 | export function isBooleanLiteral(node: MetaNode, typescript: typeof TS): node is TS.BooleanLiteral { 8 | switch (node.kind) { 9 | case typescript.SyntaxKind.TrueKeyword: 10 | case typescript.SyntaxKind.FalseKeyword: 11 | return true; 12 | default: 13 | return false; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/clone-node/util/is-comma-list-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a CommaListExpression 6 | */ 7 | export function isCommaListExpression(node: MetaNode, typescript: typeof TS): node is TS.CommaListExpression { 8 | // TypeScript 4.x 9 | if ("isCommaListExpression" in typescript) { 10 | return typescript.isCommaListExpression(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.CommaListExpression; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-import-type-assertion-container.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is an ImportTypeAssertionContainer 6 | */ 7 | export function isImportTypeAssertionContainer(node: MetaNode, typescript: typeof TS): node is TS.ImportTypeAssertionContainer { 8 | return ( 9 | // eslint-disable-next-line @typescript-eslint/naming-convention 10 | (typescript.SyntaxKind as {ImportTypeAssertionContainer?: number}).ImportTypeAssertionContainer != null && node.kind === typescript.SyntaxKind.ImportTypeAssertionContainer 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-all-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocAllType 6 | */ 7 | export function isJsDocAllType(node: MetaNode, typescript: typeof TS): node is TS.JSDocAllType { 8 | // TypeScript 4.x 9 | if ("isJSDocAllType" in typescript) { 10 | return typescript.isJSDocAllType(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocAllType; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-augments-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocAugmentsTag 6 | */ 7 | export function isJsDocAugmentsTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocAugmentsTag { 8 | // TypeScript 4.x 9 | if ("isJSDocAugmentsTag" in typescript) { 10 | return typescript.isJSDocAugmentsTag(node); 11 | } 12 | 13 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocAugmentsTag; 14 | } 15 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-author-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocAuthorTag 6 | */ 7 | export function isJsDocAuthorTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocAuthorTag { 8 | // TypeScript 4.x 9 | if ("isJSDocAuthorTag" in typescript) { 10 | return typescript.isJSDocAuthorTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocAuthorTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-callback-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocCallbackTag 6 | */ 7 | export function isJsDocCallbackTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocCallbackTag { 8 | // TypeScript 4.x 9 | if ("isJSDocCallbackTag" in typescript) { 10 | return typescript.isJSDocCallbackTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocCallbackTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-class-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocClassTag 6 | */ 7 | export function isJsDocClassTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocClassTag { 8 | // TypeScript 4.x 9 | if ("isJSDocClassTag" in typescript) { 10 | return typescript.isJSDocClassTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocClassTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-comment.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocComment 6 | */ 7 | export function isJsDocComment(node: MetaNode, typescript: typeof TS): node is TS.JSDoc { 8 | // TypeScript 4.x 9 | if ("isJSDoc" in typescript) { 10 | return typescript.isJSDoc(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocComment; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-deprecated-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocDeprecatedTag 6 | */ 7 | export function isJsDocDeprecatedTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocDeprecatedTag { 8 | // TypeScript 4.x 9 | if ("JSDocDeprecatedTag" in typescript) { 10 | return typescript.isJSDocDeprecatedTag(node); 11 | } 12 | return node.kind === typescript.SyntaxKind.JSDocDeprecatedTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-enum-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocEnumTag 6 | */ 7 | export function isJsDocEnumTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocEnumTag { 8 | // TypeScript 4.x 9 | if ("isJSDocEnumTag" in typescript) { 10 | return typescript.isJSDocEnumTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocEnumTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-function-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocFunctionType 6 | */ 7 | export function isJsDocFunctionType(node: MetaNode, typescript: typeof TS): node is TS.JSDocFunctionType { 8 | // TypeScript 4.x 9 | if ("isJSDocFunctionType" in typescript) { 10 | return typescript.isJSDocFunctionType(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocFunctionType; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-import-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocImportTag 6 | */ 7 | export function isJsDocImportTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocImportTag { 8 | // TypeScript 5.x 9 | if ("isJSDocImportTag" in typescript) { 10 | return typescript.isJSDocImportTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocImportTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-link-code.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocLinkCode 6 | */ 7 | export function isJsDocLinkCode(node: MetaNode, typescript: typeof TS): node is TS.JSDocLinkCode { 8 | // TypeScript 4.x 9 | if ("isJSDocLinkCode" in typescript) { 10 | return typescript.isJSDocLinkCode(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocLinkCode; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-link-plain.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocLinkPlain 6 | */ 7 | export function isJsDocLinkPlain(node: MetaNode, typescript: typeof TS): node is TS.JSDocLinkPlain { 8 | // TypeScript 4.x 9 | if ("isJSDocLinkPlain" in typescript) { 10 | return typescript.isJSDocLinkPlain(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocLinkPlain; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-link.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocLink 6 | */ 7 | export function isJsDocLink(node: MetaNode, typescript: typeof TS): node is TS.JSDocLink { 8 | // TypeScript 4.x 9 | if ("isJSDocLink" in typescript) { 10 | return typescript.isJSDocLink(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocLink; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-member-name.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocMemberName 6 | */ 7 | export function isJsDocMemberName(node: MetaNode, typescript: typeof TS): node is TS.JSDocMemberName { 8 | // TypeScript 4.x 9 | if ("isJSDocMemberName" in typescript) { 10 | return typescript.isJSDocMemberName(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocMemberName; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-namepath-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocNamepathType 6 | */ 7 | export function isJsDocNamepathType(node: MetaNode, typescript: typeof TS): node is TS.JSDocNamepathType { 8 | // TypeScript 4.x 9 | if ("isJSDocNamepathType" in typescript) { 10 | return typescript.isJSDocNamepathType(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocNamepathType; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-non-nullable-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocNonNullableType 6 | */ 7 | export function isJsDocNonNullableType(node: MetaNode, typescript: typeof TS): node is TS.JSDocNonNullableType { 8 | // TypeScript 4.x 9 | if ("isJSDocNonNullableType" in typescript) { 10 | return typescript.isJSDocNonNullableType(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocNonNullableType; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-nullable-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocNullableType 6 | */ 7 | export function isJsDocNullableType(node: MetaNode, typescript: typeof TS): node is TS.JSDocNullableType { 8 | // TypeScript 4.x 9 | if ("isJSDocNullableType" in typescript) { 10 | return typescript.isJSDocNullableType(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocNullableType; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-optional-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocOptionalType 6 | */ 7 | export function isJsDocOptionalType(node: MetaNode, typescript: typeof TS): node is TS.JSDocOptionalType { 8 | // TypeScript 4.x 9 | if ("isJSDocOptionalType" in typescript) { 10 | return typescript.isJSDocOptionalType(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocOptionalType; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-overload-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocOverloadTag 6 | */ 7 | export function isJsDocOverloadTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocOverloadTag { 8 | // TypeScript 5.x 9 | if ("isJSDocOverloadTag" in typescript) { 10 | return typescript.isJSDocOverloadTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocOverloadTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-parameter-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocParameterTag 6 | */ 7 | export function isJsDocParameterTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocParameterTag { 8 | // TypeScript 4.x 9 | if ("isJSDocParameterTag" in typescript) { 10 | return typescript.isJSDocParameterTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocParameterTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-private-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocPrivateTag 6 | */ 7 | export function isJsDocPrivateTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocPrivateTag { 8 | // TypeScript 4.x 9 | if ("isJSDocPrivateTag" in typescript) { 10 | return typescript.isJSDocPrivateTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocPrivateTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-property-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocPropertyTag 6 | */ 7 | export function isJsDocPropertyTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocPropertyTag { 8 | // TypeScript 4.x 9 | if ("isJSDocPropertyTag" in typescript) { 10 | return typescript.isJSDocPropertyTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocPropertyTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-protected-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocProtectedTag 6 | */ 7 | export function isJsDocProtectedTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocProtectedTag { 8 | // TypeScript 4.x 9 | if ("isJSDocProtectedTag" in typescript) { 10 | return typescript.isJSDocProtectedTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocProtectedTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-public-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocPublicTag 6 | */ 7 | export function isJsDocPublicTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocPublicTag { 8 | // TypeScript 4.x 9 | if ("isJSDocPublicTag" in typescript) { 10 | return typescript.isJSDocPublicTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocPublicTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-readonly-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocReadonlyTag 6 | */ 7 | export function isJsDocReadonlyTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocReadonlyTag { 8 | // TypeScript 4.x 9 | if ("isJSDocReadonlyTag" in typescript) { 10 | return typescript.isJSDocReadonlyTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocReadonlyTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-return-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocReturnTag 6 | */ 7 | export function isJsDocReturnTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocReturnTag { 8 | // TypeScript 4.x 9 | if ("isJSDocReturnTag" in typescript) { 10 | return typescript.isJSDocReturnTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocReturnTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-satisfies-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocSatisfiesTag 6 | */ 7 | export function isJsDocSatisfiesTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocSatisfiesTag { 8 | // TypeScript 5.x 9 | if ("isJSDocSatisfiesTag" in typescript) { 10 | return typescript.isJSDocSatisfiesTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocSatisfiesTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-see-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocSeeTag 6 | */ 7 | export function isJsDocSeeTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocSeeTag { 8 | // TypeScript 4.x 9 | if ("isJSDocSeeTag" in typescript) { 10 | return typescript.isJSDocSeeTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocSeeTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-signature.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocSignature 6 | */ 7 | export function isJsDocSignature(node: MetaNode, typescript: typeof TS): node is TS.JSDocSignature { 8 | // TypeScript 4.x 9 | if ("isJSDocSignature" in typescript) { 10 | return typescript.isJSDocSignature(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocSignature; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-template-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocTemplateTag 6 | */ 7 | export function isJsDocTemplateTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocTemplateTag { 8 | // TypeScript 4.x 9 | if ("isJSDocTemplateTag" in typescript) { 10 | return typescript.isJSDocTemplateTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocTemplateTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-this-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocThisTag 6 | */ 7 | export function isJsDocThisTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocThisTag { 8 | // TypeScript 4.x 9 | if ("isJSDocThisTag" in typescript) { 10 | return typescript.isJSDocThisTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocThisTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-throws-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocThrowsTag 6 | */ 7 | export function isJsDocThrowsTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocThrowsTag { 8 | // TypeScript 5.x 9 | if ("isJSDocThrowsTag" in typescript) { 10 | return typescript.isJSDocThrowsTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocThrowsTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-type-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocTypeExpression 6 | */ 7 | export function isJsDocTypeExpression(node: MetaNode, typescript: typeof TS): node is TS.JSDocTypeExpression { 8 | // TypeScript 4.x 9 | if ("isJSDocTypeExpression" in typescript) { 10 | return typescript.isJSDocTypeExpression(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocTypeExpression; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-type-literal.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocTypeLiteral 6 | */ 7 | export function isJsDocTypeLiteral(node: MetaNode, typescript: typeof TS): node is TS.JSDocTypeLiteral { 8 | // TypeScript 4.x 9 | if ("isJSDocTypeLiteral" in typescript) { 10 | return typescript.isJSDocTypeLiteral(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocTypeLiteral; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-type-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocTypeTag 6 | */ 7 | export function isJsDocTypeTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocTypeTag { 8 | // TypeScript 4.x 9 | if ("isJSDocTypeTag" in typescript) { 10 | return typescript.isJSDocTypeTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocTypeTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-typedef-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocTypedefTag 6 | */ 7 | export function isJsDocTypedefTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocTypedefTag { 8 | // TypeScript 4.x 9 | if ("isJSDocTypedefTag" in typescript) { 10 | return typescript.isJSDocTypedefTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocTypedefTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-unknown-tag.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocUnknownTag 6 | */ 7 | export function isJsDocUnknownTag(node: MetaNode, typescript: typeof TS): node is TS.JSDocUnknownTag { 8 | // TypeScript 4.x 9 | if ("isJSDocUnknownTag" in typescript) { 10 | return typescript.isJSDocUnknownTag(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocTag; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-unknown-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocUnknownType 6 | */ 7 | export function isJsDocUnknownType(node: MetaNode, typescript: typeof TS): node is TS.JSDocUnknownType { 8 | // TypeScript 4.x 9 | if ("isJSDocUnknownType" in typescript) { 10 | return typescript.isJSDocUnknownType(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocUnknownType; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-js-doc-variadic-type.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JSDocVariadicType 6 | */ 7 | export function isJsDocVariadicType(node: MetaNode, typescript: typeof TS): node is TS.JSDocVariadicType { 8 | // TypeScript 4.x 9 | if ("isJSDocVariadicType" in typescript) { 10 | return typescript.isJSDocVariadicType(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JSDocVariadicType; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-jsx-namespaced-name.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a JsxNamespacedName 6 | */ 7 | export function isJsxNamespacedName(node: MetaNode, typescript: typeof TS): node is TS.JsxNamespacedName { 8 | // TypeScript >=5.1 9 | if ("isJsxNamespacedName" in typescript) { 10 | return typescript.isJsxNamespacedName(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.JsxNamespacedName; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-keyword-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a KeywordTypeNode 6 | */ 7 | export function isKeywordTypeNode(node: MetaNode, typescript: typeof TS): node is TS.KeywordTypeNode { 8 | switch (node.kind) { 9 | case typescript.SyntaxKind.AnyKeyword: 10 | case typescript.SyntaxKind.UnknownKeyword: 11 | case typescript.SyntaxKind.BigIntKeyword: 12 | case typescript.SyntaxKind.ObjectKeyword: 13 | case typescript.SyntaxKind.BooleanKeyword: 14 | case typescript.SyntaxKind.StringKeyword: 15 | case typescript.SyntaxKind.SymbolKeyword: 16 | case typescript.SyntaxKind.VoidKeyword: 17 | case typescript.SyntaxKind.UndefinedKeyword: 18 | case typescript.SyntaxKind.NullKeyword: 19 | case typescript.SyntaxKind.NeverKeyword: 20 | return true; 21 | } 22 | return false; 23 | } 24 | -------------------------------------------------------------------------------- /src/clone-node/util/is-named-tuple-member.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a NamedTupleMember 6 | */ 7 | export function isNamedTupleMember(node: MetaNode, typescript: typeof TS): node is TS.NamedTupleMember { 8 | // eslint-disable-next-line @typescript-eslint/naming-convention 9 | return (typescript.SyntaxKind as {NamedTupleMember?: number}).NamedTupleMember != null && node.kind === typescript.SyntaxKind.NamedTupleMember; 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/util/is-node-array.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | export function isNodeArray(item: unknown): item is TS.NodeArray { 5 | return item != null && Array.isArray(item) && "pos" in item; 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/util/is-not-emitted-statement.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a NotEmittedStatement 6 | */ 7 | export function isNotEmittedStatement(node: MetaNode, typescript: typeof TS): node is TS.NotEmittedStatement { 8 | // TypeScript 4.x 9 | if ("isNotEmittedStatement" in typescript) { 10 | return typescript.isNotEmittedStatement(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.NotEmittedStatement; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-null-literal.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is the literal 'null' 6 | */ 7 | export function isNullLiteral(node: MetaNode, typescript: typeof TS): node is TS.NullLiteral { 8 | return node.kind === typescript.SyntaxKind.NullKeyword; 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/util/is-optional-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is an OptionalTypeNode 6 | */ 7 | export function isOptionalTypeNode(node: MetaNode, typescript: typeof TS): node is TS.OptionalTypeNode { 8 | // TypeScript 4.x 9 | if ("isOptionalTypeNode" in typescript) { 10 | return typescript.isOptionalTypeNode(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.OptionalType; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-partially-emitted-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a PartiallyEmittedExpression 6 | */ 7 | export function isPartiallyEmittedExpression(node: MetaNode, typescript: typeof TS): node is TS.PartiallyEmittedExpression { 8 | // TypeScript 4.x 9 | if ("isPartiallyEmittedExpression" in typescript) { 10 | return typescript.isPartiallyEmittedExpression(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.PartiallyEmittedExpression; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-rest-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a RestTypeNode 6 | */ 7 | export function isRestTypeNode(node: MetaNode, typescript: typeof TS): node is TS.RestTypeNode { 8 | // TypeScript 4.x 9 | if ("isRestTypeNode" in typescript) { 10 | return typescript.isRestTypeNode(node); 11 | } 12 | return node.kind === (typescript as typeof TS).SyntaxKind.RestType; 13 | } 14 | -------------------------------------------------------------------------------- /src/clone-node/util/is-super-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | export function isSuperExpression(node: MetaNode, typescript: typeof TS): node is TS.SuperExpression { 5 | return node.kind === typescript.SyntaxKind.SuperKeyword; 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/util/is-template-literal-type-node.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a TemplateLiteralTypeNode 6 | */ 7 | export function isTemplateLiteralTypeNode(node: MetaNode, typescript: typeof TS): node is TS.TemplateLiteralTypeNode { 8 | // eslint-disable-next-line @typescript-eslint/naming-convention 9 | return (typescript.SyntaxKind as {TemplateLiteralType?: number}).TemplateLiteralType != null && node.kind === typescript.SyntaxKind.TemplateLiteralType; 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/util/is-template-literal-type-span.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a TemplateLiteralTypeSpan 6 | */ 7 | export function isTemplateLiteralTypeSpan(node: MetaNode, typescript: typeof TS): node is TS.TemplateLiteralTypeSpan { 8 | // eslint-disable-next-line @typescript-eslint/naming-convention 9 | return (typescript.SyntaxKind as {TemplateLiteralTypeSpan?: number}).TemplateLiteralTypeSpan != null && node.kind === typescript.SyntaxKind.TemplateLiteralTypeSpan; 10 | } 11 | -------------------------------------------------------------------------------- /src/clone-node/util/is-this-expression.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../type/ts.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | /** 5 | * Returns true if the given Node is a ThisExpression 6 | */ 7 | export function isThisExpression(node: MetaNode, typescript: typeof TS): node is TS.ThisExpression { 8 | return node.kind === typescript.SyntaxKind.ThisKeyword; 9 | } 10 | -------------------------------------------------------------------------------- /src/clone-node/util/next-options.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeInternalOptions} from "../clone-node-options.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | export function nextOptions(options: CloneNodeInternalOptions): CloneNodeInternalOptions { 5 | return {...options, depth: options.depth + 1}; 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/util/payload.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeHookFactoryPayload, CloneNodeInternalOptions} from "../clone-node-options.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | 4 | export function payload({depth}: CloneNodeInternalOptions): CloneNodeHookFactoryPayload { 5 | return {depth}; 6 | } 7 | -------------------------------------------------------------------------------- /src/clone-node/util/preserve-comments.ts: -------------------------------------------------------------------------------- 1 | import type {MetaNode} from "../type/meta-node.js"; 2 | import type {TS} from "../type/ts.js"; 3 | import type {CloneNodeInternalOptions} from "../clone-node-options.js"; 4 | import {getOriginalNode} from "./get-original-node.js"; 5 | 6 | function formatCommentRange({pos, end}: TS.CommentRange): string { 7 | return `${pos}:${end}`; 8 | } 9 | 10 | export interface TSComment { 11 | pos: number; 12 | end: number; 13 | text: string; 14 | isLeading: boolean; 15 | kind: TS.SyntaxKind.SingleLineCommentTrivia | TS.SyntaxKind.MultiLineCommentTrivia; 16 | hasTrailingNewLine: boolean; 17 | } 18 | 19 | export interface PreserveCommentsOptions extends CloneNodeInternalOptions {} 20 | 21 | function getCommentRanges(node: T, options: PreserveCommentsOptions): TSComment[] { 22 | const comments: TSComment[] = []; 23 | const originalNode = getOriginalNode(node, options); 24 | 25 | const sourceFile = originalNode.getSourceFile() as TS.SourceFile | undefined; 26 | 27 | if (sourceFile == null || originalNode.pos === -1 || originalNode.end === -1) return []; 28 | 29 | const sourceFileText = sourceFile.getFullText(); 30 | const pos = originalNode.getFullStart(); 31 | const end = originalNode.getEnd(); 32 | const leadingCommentRanges = options.typescript.getLeadingCommentRanges(sourceFileText, pos) ?? []; 33 | const trailingCommentRanges = options.typescript.getTrailingCommentRanges(sourceFileText, end) ?? []; 34 | 35 | if (leadingCommentRanges.length < 1) { 36 | // There may be one anyway such as will be the case when looking at the StringLiteral "foo" inside the following 37 | // source text: /** @type {string} */ "foo" 38 | const fullTextTrimmed = originalNode.getFullText().trim(); 39 | 40 | // If the text includes one or more comments, mark them as leading comment ranges 41 | if (fullTextTrimmed.startsWith("//") || fullTextTrimmed.startsWith("/*")) { 42 | leadingCommentRanges.push(...(options.typescript.getTrailingCommentRanges(sourceFileText, pos) ?? [])); 43 | } 44 | } 45 | 46 | const commentRanges = [ 47 | ...leadingCommentRanges.map(range => ({...range, hasTrailingNewLine: Boolean(range.hasTrailingNewLine), isLeading: true})), 48 | ...trailingCommentRanges.map(range => ({...range, hasTrailingNewLine: Boolean(range.hasTrailingNewLine), isLeading: false})) 49 | ]; 50 | 51 | for (const commentRange of commentRanges) { 52 | if (options.commentRanges.has(formatCommentRange(commentRange))) continue; 53 | options.commentRanges.add(formatCommentRange(commentRange)); 54 | let text = sourceFile.text.substring(commentRange.pos, commentRange.end); 55 | 56 | if (!text.startsWith("//") && !text.startsWith("/*")) continue; 57 | const isUsingLineCarriages = text.includes("\r\n"); 58 | const isJsDoc = text.startsWith("/**"); 59 | 60 | text = text 61 | .split(/\r?\n/) 62 | .map(line => line.trim()) 63 | .map(line => (!isJsDoc || line.startsWith("/**") ? line : ` ${line}`)) 64 | .join(isUsingLineCarriages ? `\r\n` : `\n`); 65 | 66 | if (text.startsWith("/**")) { 67 | // 'addSyntheticLeadingComment' will place the leading '/*' and the trailing '*/', so these two parts must be stripped 68 | // from the text before passing it to TypeScript 69 | text = text.slice(2, text.length - 2); 70 | } else if (text.startsWith("/*")) { 71 | // 'addSyntheticLeadingComment' will place the leading '/*' and the trailing '*/', so these two parts must be stripped 72 | // from the text before passing it to TypeScript 73 | text = text.slice(2, text.length - 2); 74 | } else { 75 | // 'addSyntheticLeadingComment' will place the leading '//', so this part must be stripped 76 | // from the text before passing it to TypeScript 77 | text = text.slice(2); 78 | } 79 | 80 | comments.push({ 81 | ...commentRange, 82 | text 83 | }); 84 | } 85 | return comments; 86 | } 87 | 88 | export function preserveAllComments(node: T, options: PreserveCommentsOptions): void { 89 | if (!options.preserveComments) return; 90 | preserveCommentsForOriginalNode(node, options); 91 | options.typescript.forEachChild(node, child => { 92 | preserveAllComments(child, options); 93 | }); 94 | } 95 | 96 | function preserveCommentsForOriginalNode(node: T, options: PreserveCommentsOptions): void { 97 | if (options.typescript.isSourceFile(node)) return; 98 | const originalNode = getOriginalNode(node, options); 99 | if (node !== originalNode) preserveComments(node, originalNode, options); 100 | } 101 | 102 | export function preserveComments(node: T, oldNode: T, options: PreserveCommentsOptions): T { 103 | if (!options.preserveComments) return node; 104 | 105 | if (node.pos > -1 && node.end >= -1) { 106 | return node; 107 | } 108 | 109 | if (node.jsDoc == null && oldNode.jsDoc != null) { 110 | node.jsDoc = oldNode.jsDoc; 111 | } 112 | 113 | const comments = getCommentRanges(oldNode, options); 114 | 115 | if (comments.length > 0) { 116 | options.typescript.setSyntheticLeadingComments(node, undefined); 117 | options.typescript.setSyntheticTrailingComments(node, undefined); 118 | } 119 | 120 | for (const {isLeading, text, hasTrailingNewLine, kind} of comments) { 121 | if (isLeading) { 122 | options.typescript.addSyntheticLeadingComment(node, kind, text, hasTrailingNewLine); 123 | } else { 124 | options.typescript.addSyntheticTrailingComment(node, kind, text, hasTrailingNewLine); 125 | } 126 | } 127 | return node; 128 | } 129 | -------------------------------------------------------------------------------- /src/clone-node/util/set-parents.ts: -------------------------------------------------------------------------------- 1 | import type {MetaNode} from "../type/meta-node.js"; 2 | import type {TS} from "../type/ts.js"; 3 | import type {SetParentNodesOptions} from "../type/set-parent-nodes-options.js"; 4 | import type {Mutable} from "helpertypes"; 5 | 6 | function fixupParentReferences(rootNode: MetaNode, {deep, propertyName, typescript}: SetParentNodesOptions): void { 7 | let parent = rootNode; 8 | typescript.forEachChild(rootNode, visitNode); 9 | 10 | function visitNode(n: MetaNode) { 11 | if (n[propertyName] !== parent) { 12 | (n as Mutable)[propertyName] = parent; 13 | const saveParent = parent; 14 | parent = n; 15 | if (deep) { 16 | typescript.forEachChild(n, visitNode); 17 | } 18 | if (n.jsDoc != null) { 19 | for (const jsDocComment of n.jsDoc as MetaNode[]) { 20 | (jsDocComment as Mutable)[propertyName] = n as TS.HasJSDoc; 21 | parent = jsDocComment; 22 | typescript.forEachChild(jsDocComment, visitNode); 23 | } 24 | } 25 | parent = saveParent; 26 | } 27 | } 28 | } 29 | 30 | export function setParents(node: T, options: SetParentNodesOptions): T { 31 | fixupParentReferences(node, options); 32 | return node; 33 | } 34 | -------------------------------------------------------------------------------- /src/clone-node/util/to-internal-options.ts: -------------------------------------------------------------------------------- 1 | import type {CloneNodeFinalizerCallback, CloneNodeHookFactory, CloneNodeInternalOptions, CloneNodeOptions} from "../clone-node-options.js"; 2 | import type {MetaNode} from "../type/meta-node.js"; 3 | import {ensureNodeFactory} from "compatfactory"; 4 | import ts from "typescript"; 5 | import type {TS} from "../type/ts.js"; 6 | 7 | export function toInternalOptions(options: Partial>): CloneNodeInternalOptions { 8 | const typescript = options.typescript ?? (ts as typeof TS); 9 | return { 10 | ...options, 11 | typescript, 12 | factory: ensureNodeFactory(options.factory ?? typescript), 13 | setParents: options.setParents ?? false, 14 | setOriginalNodes: options.setOriginalNodes ?? false, 15 | preserveSymbols: options.preserveSymbols ?? false, 16 | preserveComments: options.preserveComments ?? true, 17 | commentRanges: new Set(), 18 | debug: options.debug ?? false, 19 | depth: 0, 20 | hook: (options.hook as CloneNodeHookFactory | undefined) ?? (() => ({})), 21 | finalize: (options.finalize as CloneNodeFinalizerCallback | undefined) ?? (() => undefined) 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /src/clone-node/util/to-set-parent-nodes-options.ts: -------------------------------------------------------------------------------- 1 | import type {SetParentNodesOptions} from "../type/set-parent-nodes-options.js"; 2 | import ts from "typescript"; 3 | import type {TS} from "../type/ts.js"; 4 | 5 | export function toSetParentNodesOptions(options: Partial): SetParentNodesOptions { 6 | return { 7 | typescript: options.typescript ?? (ts as typeof TS), 8 | propertyName: options.propertyName ?? "parent", 9 | deep: options.deep ?? true 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export {cloneNode, preserveNode, setParentNodes} from "./clone-node/clone-node.js"; 2 | export type {CloneNodeOptions, CloneNodeHook} from "./clone-node/clone-node-options.js"; 3 | -------------------------------------------------------------------------------- /test/util/clone-as-text.ts: -------------------------------------------------------------------------------- 1 | import {print} from "./print.js"; 2 | import {parse} from "./parse.js"; 3 | import {cloneNode} from "../../src/clone-node/clone-node.js"; 4 | import type {CloneNodeOptions} from "../../src/clone-node/clone-node-options.js"; 5 | import type {TS} from "../../src/clone-node/type/ts.js"; 6 | import type {MetaNode} from "../../src/clone-node/type/meta-node.js"; 7 | 8 | type SelectNodeCallback = (sourceFile: TS.SourceFile) => T; 9 | 10 | export interface CloneAsTextOptions extends Partial> { 11 | selectNode?: SelectNodeCallback; 12 | typescript: typeof TS; 13 | } 14 | 15 | export function cloneAsText(text: string, {selectNode = sourceFile => sourceFile as unknown as T, ...options}: CloneAsTextOptions): string { 16 | const parseResult = parse(text, options.typescript); 17 | 18 | const selectedNode = selectNode(parseResult) as T; 19 | 20 | if (Boolean(options.debug)) { 21 | console.log("BEFORE:"); 22 | printNodeTree(selectedNode, options.typescript); 23 | console.log(); 24 | } 25 | 26 | const clonedNode = cloneNode(selectedNode, options); 27 | 28 | if (Boolean(options.debug)) { 29 | console.log("AFTER:"); 30 | printNodeTree(clonedNode, options.typescript); 31 | console.log(); 32 | } 33 | 34 | return print(clonedNode, options.typescript, parseResult); 35 | } 36 | 37 | function printNodeTree(node: TS.Node, typescript: typeof TS, nest?: number) { 38 | if (nest == null) nest = 0; 39 | let space = ""; 40 | for (let i = 0; i < nest; i++) space += " "; 41 | console.log( 42 | space, 43 | (typescript as Partial).isPropertyAccessChain?.(node) 44 | ? "PropertyAccessChain" 45 | : (typescript as Partial).isImportTypeNode?.(node) 46 | ? "ImportTypeNode" 47 | : (typescript as Partial).isTypePredicateNode?.(node) 48 | ? "TypePredicateNode" 49 | : typescript.SyntaxKind[node.kind] 50 | ); 51 | node.forEachChild(child => printNodeTree(child, typescript, nest + 1)); 52 | } 53 | -------------------------------------------------------------------------------- /test/util/format-code.ts: -------------------------------------------------------------------------------- 1 | import prettier from "@prettier/sync"; 2 | import {formatWhitespace} from "./format-whitespace.js"; 3 | 4 | interface FormatOptions { 5 | parser: "typescript" | "json"; 6 | onlyWhitespace: boolean; 7 | } 8 | 9 | export function formatCode(code: string, {parser = "typescript", onlyWhitespace = false}: Partial = {}): string { 10 | if (onlyWhitespace) { 11 | return formatWhitespace(code); 12 | } 13 | try { 14 | return prettier.format(code, {parser, endOfLine: "lf"}); 15 | } catch { 16 | return formatWhitespace(code); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/util/format-whitespace.ts: -------------------------------------------------------------------------------- 1 | const NON_WHITESPACE_CHARACTER_REGEXP = /\S/; 2 | const NEWLINE_CHARACTERS = "\n"; 3 | const TAB_CHARACTER = " "; 4 | const TAB_SIZE = 2; 5 | const TAB_CHARACTERS = TAB_CHARACTER.repeat(TAB_SIZE); 6 | 7 | export function formatWhitespace(code: string): string { 8 | // Normalize whitespace to start with 9 | const normalizedWhitespace = code.replace(/\r?\n/g, NEWLINE_CHARACTERS).replace(/\t/g, TAB_CHARACTERS); 10 | 11 | // Split into lines. 12 | const [head, ...tail] = normalizedWhitespace.split(NEWLINE_CHARACTERS); 13 | if (head == null || tail.length === 0) { 14 | // If there's only one line, just trim the input 15 | return head?.trim() ?? ""; 16 | } 17 | 18 | let indentation: number | undefined; 19 | 20 | return [head, ...tail] 21 | .map(line => { 22 | const currentIndentation = line.match(NON_WHITESPACE_CHARACTER_REGEXP)?.index ?? 0; 23 | const trimmed = line.trim(); 24 | const isEmpty = trimmed.length < 1; 25 | if (isEmpty) return trimmed; 26 | 27 | if (indentation == null) { 28 | indentation = currentIndentation; 29 | return line.slice(currentIndentation); 30 | } 31 | 32 | const indentationDiff = currentIndentation - indentation; 33 | const constrainedIndentationDiff = Math.max(0, Math.min(TAB_SIZE, indentationDiff)); 34 | const sliceIndex = currentIndentation - constrainedIndentationDiff; 35 | 36 | return line.slice(sliceIndex); 37 | }) 38 | .join(NEWLINE_CHARACTERS); 39 | } 40 | -------------------------------------------------------------------------------- /test/util/parse.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../../src/clone-node/type/ts.js"; 2 | 3 | /** 4 | * Parses the given text into a SourceFile 5 | */ 6 | export function parse(text: string, typescript: typeof TS): TS.SourceFile { 7 | return typescript.createSourceFile(`sourcefile.ts`, text, typescript.ScriptTarget.ESNext, true, typescript.ScriptKind.TS); 8 | } 9 | -------------------------------------------------------------------------------- /test/util/print.ts: -------------------------------------------------------------------------------- 1 | import type {TS} from "../../src/clone-node/type/ts.js"; 2 | import type {MetaNode} from "../../src/clone-node/type/meta-node.js"; 3 | 4 | /** 5 | * Prints the given SourceFile 6 | */ 7 | export function print(node: MetaNode, typescript: typeof TS, sourceFile: TS.SourceFile): string { 8 | if (typescript.isSourceFile(node)) return typescript.createPrinter().printFile(node); 9 | return typescript.createPrinter({newLine: typescript.NewLineKind.LineFeed}).printNode(typescript.EmitHint.Unspecified, node, node.getSourceFile() ?? sourceFile); 10 | } 11 | -------------------------------------------------------------------------------- /test/util/test-runner.ts: -------------------------------------------------------------------------------- 1 | import path from "crosspath"; 2 | import fs from "fs"; 3 | import semver from "semver"; 4 | import testModule, {type TestContext} from "node:test"; 5 | import type * as TS from "typescript"; 6 | import {ensureNodeFactory} from "compatfactory"; 7 | 8 | function getNearestPackageJson(from = import.meta.url): Record | undefined { 9 | // There may be a file protocol in from of the path 10 | const normalizedFrom = path.urlToFilename(from); 11 | const currentDir = path.dirname(normalizedFrom); 12 | 13 | const pkgPath = path.join(currentDir, "package.json"); 14 | if (fs.existsSync(pkgPath)) { 15 | return JSON.parse(fs.readFileSync(pkgPath, "utf-8")) as Record; 16 | } else if (currentDir !== normalizedFrom) { 17 | return getNearestPackageJson(currentDir); 18 | } else { 19 | return undefined; 20 | } 21 | } 22 | 23 | const pkg = getNearestPackageJson(); 24 | // ava macros 25 | export interface ExecutionContextOptions { 26 | typescript: typeof TS; 27 | typescriptModuleSpecifier: string; 28 | typescriptVersion: string; 29 | factory: TS.NodeFactory; 30 | } 31 | 32 | export type ExtendedImplementation = (t: TestContext, options: ExecutionContextOptions) => void | Promise; 33 | 34 | const {devDependencies} = pkg as {devDependencies: Record}; 35 | 36 | // Set of all TypeScript versions parsed from package.json 37 | const availableTsVersions = new Set(); 38 | const TS_OPTIONS_RECORDS = new Map(); 39 | 40 | const tsRangeRegex = /(npm:typescript@)?[\^~]*(.+)$/; 41 | const filter = process.env.TS_VERSION; 42 | 43 | for (const [specifier, range] of Object.entries(devDependencies)) { 44 | const match = range.match(tsRangeRegex); 45 | if (match !== null) { 46 | const [, context, version] = match; 47 | if (version != null && (context === "npm:typescript@" || specifier === "typescript")) { 48 | availableTsVersions.add(version); 49 | if (filter === undefined || (filter.toUpperCase() === "CURRENT" && specifier === "typescript") || semver.satisfies(version, filter, {includePrerelease: true})) { 50 | const typescript = ((await import(specifier)) as {default: typeof TS}).default; 51 | TS_OPTIONS_RECORDS.set(version, { 52 | typescript, 53 | typescriptModuleSpecifier: specifier, 54 | typescriptVersion: version, 55 | factory: ensureNodeFactory(typescript) 56 | }); 57 | } 58 | } 59 | } 60 | } 61 | 62 | if (availableTsVersions.size === 0) { 63 | throw new Error(`The TS_VERSION environment variable matches none of the available TypeScript versions. 64 | Filter: ${process.env.TS_VERSION} 65 | Available TypeScript versions: ${[...availableTsVersions].join(", ")}`); 66 | } 67 | 68 | interface TestRunOptions { 69 | only: boolean; 70 | } 71 | 72 | export function test(title: string, tsVersionGlob: string | undefined, impl: ExtendedImplementation, runOptions?: Partial): void { 73 | const allOptions = 74 | tsVersionGlob == null || tsVersionGlob === "*" 75 | ? TS_OPTIONS_RECORDS.values() 76 | : [...TS_OPTIONS_RECORDS.entries()].filter(([version]) => semver.satisfies(version, tsVersionGlob, {includePrerelease: true})).map(([, options]) => options); 77 | 78 | for (const currentOptions of allOptions) { 79 | const fullTitle = `${title} (TypeScript v${currentOptions.typescriptVersion})`; 80 | 81 | if (Boolean(runOptions?.only)) { 82 | testModule(fullTitle, {only: true}, async t => impl(t, currentOptions)); 83 | } else { 84 | testModule(fullTitle, async t => impl(t, currentOptions)); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/@wessberg/ts-config/tsconfig.json", 3 | "include": ["src/**/*.*", "test/**/*.*", "sandhog.config.js"], 4 | "exclude": ["dist/*.*"], 5 | "compilerOptions": { 6 | "allowJs": true 7 | } 8 | } 9 | --------------------------------------------------------------------------------