SWC Developers

SD

SWC Developers

Join the community to ask questions about SWC Developers and get answers from other members.

Join

Any examples of maintaining same plugin for babel and swc?

Hey! I'm trying to think about making an swc compatible plugin for some existing babel plugins, but unfortunately the plugins I'm trying to migrate are quite complex, and long! One of the concerns about writing a new plugin in rust has been the possibility of behaviour drift as, we can't drop the babel plugins yet for older consumers....

Emitter in SWC does not add expected space after '=>' in Arrow Functions

Hello friends, I am new to rust and SWC, I hope I am not wasting your time 🥹🙏🏻 I edited with extra space. ```javascript // This is first test we need to have console.log("We are here");...

Does SWC remove comments in the code when transforming a JS file's AST and converting it back to a c

Hello friends, I'm quite new to Rust. Recently, I used OXC in my Elixir project with NIF to modify JS files in my CLI. Unfortunately, after making changes to the JS file, all the comments above functions or within the code are removed, which is a major issue for me. Before diving into SWC, I wanted to ask if this library exhibits the same behavior. My next question is whether SWC supports converting the entire AST to JSON and vice versa, particularly from JSON back to AST. My current requirement is focused on JS files. Thanks in advance!...

Compile .node DSO on freebsd

I posted this in the wrong place, my apologies… so I tried compiling for wasm, as suggested, but the instructions from the AI really didn't work, and I'm not familiar enough with rust and swc to know really what that means... it suggested adding a section to the next config to use the swc-wasm pkg from the bindings folder, but that didn't work. I tried yarn adding the @next/swc-freebsd-x64 package, which seems to satisfy the error checking, but does not yield a built project -- probably because that hasn't been updated since 13.x, and I am trying to use next 14.2.5 (happy to upgrade to 15 if that would help)... any other thoughts? This is my current output running yarn build: yarn run v1.22.22...

Parsing error

Are there specific settings that allow me to parse the following code? ``` function test() { (arguments = x)[1] = {}; }...
No description

1:1 line number mapping

Is there a way to have line numbers in typescript be the same line numbers as javascript? For example, if there's a statement on line 17 in the TS source, SWC would put it on line 17 in the generated JS I'm using the Rust API...

how to migrate from visit_mut_with to Pass?

I'm upgrading the swc dependency for the qwik optimizer (https://github.com/QwikDev/qwik/blob/2ed63b78bd4a20b0f96b4e6fba9ae396916f2321/packages/qwik/src/optimizer/core/src/parse.rs#L266) and it looks like I need to convert ```rust program.visit_mut_with(&mut typescript::strip( Default::default(), top_level_mark,...

preset-env support

So, in short, I've bumped into the following info (was even updated somewhat recently). What I wanna know: is that a fact? Can someone point me to /*#__PURE__*/ annotation handles/config/settings/API? (specifically, I'm in need of what @babel/plugin-transform-react-pure-annotations does, since their absence/incorrectness is kind of detrimental to tree-shaking) Oh and, hello authors of the least rusty swc 😄...
No description

Plugin panics when trying to read line number from SourceMapper

I've got a plugin where part of the logic involves reading the current line number: ```rs pub struct MyVisitor { // Provided by in from TransformPluginProgramMetadata...

how can I mark a context?

I'm trying to mark a call expression for checking if I visited it later, but this doesn't print that it worked: ```rs impl VisitMut for CleanMarker { fn visit_mut_module_item(&mut self, node: &mut ast::ModuleItem) { if let ast::ModuleItem::Stmt(ast::Stmt::Expr(expr)) = node {...

wasm build uses old swc libraries?

I'm a Rust newbie, maybe I'm doing something wrong. I have everything building natively with the latest swc. However, when I try to build for wasm, it's giving errors that indicate it's still using the old API? ```...

How can I rewrite this code for the moved SyntaxContext?

I'm upgrading the Qwik optimizer and this code no longer works because expr.span no longer has the SyntaxContext. However, the only other property is expr.expr which is a Box<Expr>. How can I get at the syntax context to add the mark? Or is this the wrong approach and should I be doing one of https://swc.rs/docs/plugin/ecmascript/cheatsheet#deleting-node ? I'm not sure how to apply that though, since it marks by making the name invalid and then removes, but here I need to retain what's marked. ...

what happened with swc_ecmascript::visit::visit_expr?

I can't find the PR nor commit that removed it, nor any discussions. It's no longer exported and I don't know what to replace it with. My code is ```rust impl Visit for IdentCollector { noop_visit_type!();...

How to debug in Rust

When I'm stepping through the code, the AST is binary data. I end up having to put a lot of dbg! statements. Is there a better way to see what the current state is?...

How to replace typescript::strip_with_jsx

In 1.3.89 typescript got overhauled and that removed typescript::strip_with_jsx. What should I do instead now?...

How to test a visitor that uses visit_mut_script?

Let's say you have a visitor, something like this ```rust struct Visitor; impl VisitMut for Visitor {...

How to compile using your own custom plugin?

I created this discussion (https://github.com/swc-project/swc/discussions/7385) but thought I'd make a post here too to try get a response faster. I don't understand how I'm supposed to apply custom transformations to a given JavaScript file. I'm using the swc compile command (from cargo install swc_cli), but the transformations aren't applied on the produced output. Even using a config like this with a plugin like https://github.com/williamtetlow/swc-plugin-console-prefix doesn't apply the transformations: ```json {...