Skip to main content

Crate swc_plugin_formatjs

Crate swc_plugin_formatjs 

Source
Expand description

Rust/SWC port of babel-plugin-formatjs@10.5.41.

Build targets:

  • WASI plugin (--features plugin --no-default-features --target wasm32-wasip1) for @swc/core’s wasm plugin host. Entry point: process_transform.
  • Native rlib (--features native, default) for embedders that link directly into a native @swc/core build. Entry point: formatjs.

§Hard-error policy

Per consumer requirement, this plugin MUST hard-error on any construct we can’t statically resolve, rather than silently skip extraction.

Babel’s plugin falls back on path.evaluate() for constant folding (string concatenation, const references, ternaries with literal arms). This Rust port does not implement scope-aware constant folding — supporting it properly would mean re-implementing a chunk of @babel. Until that lands, we fail loudly via [fail] so the build breaks instead of silently producing divergent output in a 90 GB monorepo.

See CLAUDE.md for the parity bar.

Structs§

Config
Mirrors the option surface of babel-plugin-formatjs@10.5.41’s Options that upstream actually uses.
FormatJsTransform

Constants§

DEFAULT_ID_INTERPOLATION_PATTERN

Functions§

formatjs
formatjs_pass
Convenience wrapper that returns the transform as impl Pass, ready to drop into swc::Compiler::process_js_with_custom_pass without the caller having to import swc_core::ecma::visit::visit_mut_pass themselves.