question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is your feature request related to a problem? Please describe. I want to switch our projects from Babel to SWC, a Rust-based JS transpiler. SWC is used by Next.js unless you opt-out from it because you rely on Babel.

Describe proposed solution SWC has a brand new plugin system, which should be able to handle the transformations needed by Lingui’s macros.

This is not yet stable / well documented, but some plugins are available here: https://github.com/swc-project/plugins (for Styled Components for example).

Those plugins are compiled to WASM, so they can be written in several languages (including AssemblyScript, a Typescript derivative compiling to WASM)

A first step would probably be to continue using Babel for extracting and use this plugin only to transform macros, but in the long term being able to use SWC for extracting could bring a much faster extract and heavily reduce dependencies needed for extraction (swc + swc-lingui and thats pretty much all).

Describe alternatives you’ve considered

  • Porting Babel macros to a SWC plugin: not sure this can easily be done, this has been discussed a bit in https://github.com/kentcdodds/babel-plugin-macros/issues/144 but this would probably be a new project. Also babel-macros is frozen as the author no longer uses it
  • Using another transpiling tool, like esbuild: there is no support for esbuild + Lingui either (and esbuild does not have a plugin support)
  • Switching away from Lingui: I really like Lingui, I would prefer not 😃
  • Keep using Babel: swc (and other modern compilers) are much faster, it would really be better to be able to switch away!

Additional context Add any other context or screenshots about the feature request here.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:77
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

29reactions
semoalcommented, Nov 15, 2022

Yes I’m already moving pieces together thanks to a similar project that implemented Macros on SWC, I’m already working on something suitable for Lingui… I’ll open-source it soon.

11reactions
thekipcommented, Dec 20, 2022

Latest updates. I’ve implemented jsx transformations with interpolations and imports replacement, so now this test passes:

  
import { Trans } from "@lingui/macro";
const t = <Trans>
  Hello <strong>World!</strong><br />
<p>
  My name is <a href="/about">{" "}
  <em>{name}</em></a>
</p>
</Trans>

// // ↓ ↓ ↓ ↓ ↓ ↓
import { Trans } from "@lingui/core";
const t = <Trans id={"Hello <0>World!</0><1/><2>My name is <3> <4>{name}</4></3></2>"} values={{
  name: name,
}} components={{
  0: <strong />,
    1: <br />,
    2: <p />,
    3: <a href="/about" />,
    4: <em />
}} />;

It was the hardest part, so rest is should be much simpler.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implementing a plugin - SWC
As plugin is written in the rust programming language and built as a .wasm file, you need to install rust toolchain and wasm...
Read more >
Plugins for swc, written in rust - GitHub
Plugins for swc, written in rust. Contribute to swc-project/plugins development by creating an account on GitHub.
Read more >
swc-plugin | Format.JS
Process string messages for translation from modules that use react-intl, specifically: Parse and verify that messages are ICU-compliant w/o any syntax issues.
Read more >
@swc/plugin-styled-components - npm
SWC plugin for styled-components. Latest version: 1.5.33, last published: 5 days ago. Start using @swc/plugin-styled-components in your ...
Read more >
swc-plugin-dev-expression - crates.io: Rust Package Registry
A port for SWC of babel-plugin-dev-expression, which expands __DEV__ and wraps invariant and warning calls.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found