{"id":15504474,"url":"https://github.com/kwonoj/swc-plugin-formatjs","last_synced_at":"2025-04-23T00:46:31.706Z","repository":{"id":60246180,"uuid":"537665213","full_name":"kwonoj/swc-plugin-formatjs","owner":"kwonoj","description":null,"archived":false,"fork":false,"pushed_at":"2022-09-27T18:24:53.000Z","size":357,"stargazers_count":9,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-23T00:46:26.294Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kwonoj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-17T01:17:58.000Z","updated_at":"2024-11-07T09:07:21.000Z","dependencies_parsed_at":"2022-09-27T06:00:25.019Z","dependency_job_id":null,"html_url":"https://github.com/kwonoj/swc-plugin-formatjs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwonoj%2Fswc-plugin-formatjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwonoj%2Fswc-plugin-formatjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwonoj%2Fswc-plugin-formatjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwonoj%2Fswc-plugin-formatjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kwonoj","download_url":"https://codeload.github.com/kwonoj/swc-plugin-formatjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250348873,"owners_count":21415907,"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-10-02T09:18:15.682Z","updated_at":"2025-04-23T00:46:31.691Z","avatar_url":"https://github.com/kwonoj.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SWC-plugin-formatjs\n\n`SWC-plugin-formatjs`\n\n`swc-plugin-formatjs` is a port of `babel-plugin-formatjs` for the SWC. Transform can be performed either via SWC's wasm-based plugin, or using custom passes in rust side transform chains.\n\n## What does compatible exactly means?\n\nThis plugin attempts to mimic most of defined behavior of original plugin's test fixture. However, due to differences of plugin interfaces, as well as known limitations there are numbers of unsupported features with differences. You may able to check the list of github issues, as well as checking test fixtures.\n\nNotably, any dynamic configuration options (`overrideFn`, `onMsg`...) are not supported, and few internal behaviors relying on static evaluation won't work.\n\n**NOTE: Package can have breaking changes without major semver bump**\n\nGiven SWC's plugin interface itself is under experimental stage does not gaurantee semver-based major bump yet, this package also does not gaurantee semver compliant breaking changes yet. Please refer changelogs if you're encountering unexpected breaking behavior across versions.\n\n**Also, current implementation is largely unoptimized, and may have performance issues as initial focus was to pass existing test fixtures only.**\n\n# Usage\n\n## Using SWC's wasm-based experimental plugin\n\nFirst, install package via npm:\n\n```\nnpm install --save-dev swc-plugin-formatjs\n```\n\nThen add plugin into swc's configuration:\n\n```\ninterface PluginOptions {\n  pragma: string;\n  removeDefaultMessage: bool,\n  idInterpolationPattern?: string,\n  ast: bool,\n  extractSorceLocation: bool,\n  preserveWhitespace: bool,\n  additionalFunctionNames: Array\u003cstring\u003e,\n  additionalComponentNames: Array\u003cstring\u003e\n}\n\njsc: {\n  ...\n  experimental: {\n    plugins: [\n      [\"SWC-plugin-formatjs\", {\n        //pluginOptions\n      }]\n    ]\n  }\n}\n```\n\n## Using custom transform pass in rust\n\nThere is a single interface exposed to create a visitor for the transform, which you can pass into `before_custom_pass`.\n\n```\ncreate_formatjs_visitor\u003cC: Clone + Comments, S: SourceMapper\u003e(\n    source_map: std::sync::Arc\u003cS\u003e,\n    comments: C,\n    plugin_options: FormatJSPluginOptions,\n    filename: \u0026str,\n) -\u003e FormatJSVisitor\u003cC, S\u003e\n```\n\n# Building / Testing\n\nThis package runs slightly modified original plugin's fixture tests against SWC with its wasm plugin \u0026 custom transform both. `spec` contains set of the fixtures \u0026 unit test to run it, as well as supplimental packages to interop between instrumentation visitor to node.js runtime.\n\nFew npm scripts are supported for wrapping those setups.\n\n- `build:all`: Build all relative packages as debug build.\n- `test`: Runs unit test for wasm plugin \u0026 custom transform.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwonoj%2Fswc-plugin-formatjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkwonoj%2Fswc-plugin-formatjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwonoj%2Fswc-plugin-formatjs/lists"}