{"id":23436444,"url":"https://github.com/effect-ts/babel-plugin","last_synced_at":"2025-04-09T17:49:56.627Z","repository":{"id":65626265,"uuid":"554799671","full_name":"Effect-TS/babel-plugin","owner":"Effect-TS","description":"A babel plugin purpose-built for the Effect ecosystem","archived":false,"fork":false,"pushed_at":"2023-03-03T12:18:46.000Z","size":133,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-22T11:43:52.427Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://effect-ts.github.io/babel-plugin","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Effect-TS.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["mikearnaldi"]}},"created_at":"2022-10-20T12:18:56.000Z","updated_at":"2024-08-04T19:47:22.000Z","dependencies_parsed_at":"2023-02-16T23:15:53.761Z","dependency_job_id":null,"html_url":"https://github.com/Effect-TS/babel-plugin","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Effect-TS%2Fbabel-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Effect-TS%2Fbabel-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Effect-TS%2Fbabel-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Effect-TS%2Fbabel-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Effect-TS","download_url":"https://codeload.github.com/Effect-TS/babel-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248082656,"owners_count":21044949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-23T13:19:22.384Z","updated_at":"2025-04-09T17:49:56.412Z","avatar_url":"https://github.com/Effect-TS.png","language":"TypeScript","funding_links":["https://github.com/sponsors/mikearnaldi"],"categories":[],"sub_categories":[],"readme":"# @effect/babel-plugin \u003c!-- omit in toc --\u003e\n\n- [Why?](#why)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Via `.babelrc` (Recommended)](#via-babelrc-recommended)\n  - [Via CLI](#via-cli)\n  - [Via Node API](#via-node-api)\n- [Transformers](#transformers)\n  - [Rewrite Pipe](#rewrite-pipe)\n  - [Rewrite Identity](#rewrite-identity)\n\n## Why?\n\nThis Babel plugin helps to improve the performance of functional code written with the `@fp-ts/*` and `@effect/*` ecosystem of libraries.\n\nThere are two transformers contained within this plugin:\n- `rewritePipe`\n- `rewriteIdentity`\n\n## Installation\n\n```sh\nnpm install -D @effect/babel-plugin\n```\n\nor\n\n```sh\nyarn add -D @effect/babel-plugin\n```\n\nor\n\n```sh\npnpm install -D @effect/babel-plugin\n```\n\n## Usage\n\n### Via `.babelrc` (Recommended)\n\n**.babelrc**\n\n```json\n{\n  \"plugins\": [\"@effect/babel-plugin\"]\n}\n```\n\n### Via CLI\n\n```sh\nbabel --plugins @effect/babel-plugin script.js\n```\n\n### Via Node API\n\n```javascript\nrequire(\"babel-core\").transform(\"pipe(a, f(() =\u003e b))\", {\n  plugins: [\"@effect/babel-plugin\"],\n})\n```\n\nThe following configuration options can also be passed to `@effect/babel-plugin`:\n\n```ts\n/**\n * The configuration options for `@effect/babel-plugin`.\n */\nexport interface PluginConfig {\n  /**\n   * Rewrites calls to `pipe` to directly call the piped functions.\n   *\n   * By default, the plugin will only rewrite calls to `pipe` imported from\n   * `@fp-ts/core/Function`. However, the `targetImports` configuration option\n   * can be used to allow the plugin to rewrite calls to `pipe` imported from\n   * custom paths.\n   */\n  readonly rewritePipe?: false | {\n    targetImports: ReadonlyArray\u003cstring\u003e\n  }\n  /**\n   * Rewrites calls to `identity` to remove them entirely.\n   *\n   * By default, the plugin will only rewrite calls to `identity` imported from\n   * `@fp-ts/core/Function`. However, the `targetImports` configuration option\n   * can be used to allow the plugin to rewrite calls to `identity` imported\n   * from custom paths.\n   */\n  readonly rewriteIdentity?: false | {\n    targetImports: ReadonlyArray\u003cstring\u003e\n  }\n}\n```\n\n## Transformers\n\n### Rewrite Pipe\n\nThe objective of this Babel transformer is to improve the performance of pipeable APIs by re-writing calls to `pipe` at compile time to directly call the piped methods.\n\nConcretely, this results in the following code example:\n\n```ts\npipe(a, f(() =\u003e b), g(() =\u003e c))\n```\n\nbeing transformed into direct calls to the previously piped functions:\n\n```ts\ng(() =\u003e c)(f(() =\u003e b)(a))\n```\n\nCalls to `pipe` are considered `CallExpression`s in the Babel AST.  To ensure that all calls to pipe are re-written correctly, the following cases are handled:\n\n  1. When `pipe` is imported as a variable from a module and referenced as an `Identifier` in the AST\n  2. When `pipe` is imported as a namespace from a module and referenced as part of a `MemberExpression`\n\n### Rewrite Identity\n\nThe objective of this Babel transformer is to improve the performance of\npipeable APIs by re-writing calls to `identity` at compile time to remove\nthem entirely\n\nConcretely, this results in the following code example:\n\n```ts\nidentity(a)\n```\n\nbeing transformed to remove calls to `identity`:\n\n```ts\na;\n```\n\nCalls to `identity` will also be removed when part of a `pipe` call:\n\n```ts\npipe(a, identity, f(() =\u003e b))\n```\n\nwill be transformed to:\n\n```ts\nf(() =\u003e b)(a);\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feffect-ts%2Fbabel-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feffect-ts%2Fbabel-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feffect-ts%2Fbabel-plugin/lists"}