w00t
w00t
SDSWC Developers
Created by w00t on 11/28/2024 in #questions
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
program.visit_mut_with(&mut typescript::strip(
Default::default(),
top_level_mark,
))
program.visit_mut_with(&mut typescript::strip(
Default::default(),
top_level_mark,
))
to
program.apply(&mut typescript::strip(Default::default(), top_level_mark));
program.apply(&mut typescript::strip(Default::default(), top_level_mark));
but then further down I get use of moved value for program Furthermore, we use simplifier on Module but that latter doesn't have apply
segment_module =
segment_module.fold_with(&mut simplify::simplifier(
unresolved_mark,
simplify::Config {
dce: simplify::dce::Config {
preserve_imports_with_side_effects: false,
..Default::default()
},
..Default::default()
},
));
segment_module =
segment_module.fold_with(&mut simplify::simplifier(
unresolved_mark,
simplify::Config {
dce: simplify::dce::Config {
preserve_imports_with_side_effects: false,
..Default::default()
},
..Default::default()
},
));
Any help or pointers would be greatly appreciated.
4 replies
SDSWC Developers
Created by w00t on 8/1/2024 in #questions
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:
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 {
match &*expr.expr {
ast::Expr::Call(e) => {
e.ctxt.apply_mark(self.mark);
println!("mark call expression {:?}", e.ctxt);
println!("has mark {:?}", e.ctxt.has_mark(self.mark));
}
_ => {}
}
}
}
}
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 {
match &*expr.expr {
ast::Expr::Call(e) => {
e.ctxt.apply_mark(self.mark);
println!("mark call expression {:?}", e.ctxt);
println!("has mark {:?}", e.ctxt.has_mark(self.mark));
}
_ => {}
}
}
}
}
how can I make this work?
6 replies
SDSWC Developers
Created by w00t on 7/20/2024 in #questions
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?
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
Compiling qwik-core v0.2.0 (/home/wmertens/Projects/qwik/packages/qwik/src/optimizer/core)
error[E0432]: unresolved imports `swc_ecmascript::parser::EsSyntax`, `swc_ecmascript::parser::TsSyntax`
--> /home/wmertens/Projects/qwik/packages/qwik/src/optimizer/core/src/parse.rs:34:30
|
34 | use swc_ecmascript::parser::{EsSyntax, PResult, Parser, StringInput, Syntax, TsSyntax};
| ^^^^^^^^ no `EsSyntax` in the root ^^^^^^^^ no `TsSyntax` in the root
|
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
Compiling qwik-core v0.2.0 (/home/wmertens/Projects/qwik/packages/qwik/src/optimizer/core)
error[E0432]: unresolved imports `swc_ecmascript::parser::EsSyntax`, `swc_ecmascript::parser::TsSyntax`
--> /home/wmertens/Projects/qwik/packages/qwik/src/optimizer/core/src/parse.rs:34:30
|
34 | use swc_ecmascript::parser::{EsSyntax, PResult, Parser, StringInput, Syntax, TsSyntax};
| ^^^^^^^^ no `EsSyntax` in the root ^^^^^^^^ no `TsSyntax` in the root
|
6 replies
SDSWC Developers
Created by w00t on 7/19/2024 in #questions
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. I don't quite understand how it works, but it removes statements that aren't used. The full code is at https://github.com/QwikDev/qwik/blob/b0802ca6dc448a82454dfba6b46f7392e0401c05/packages/qwik/src/optimizer/core/src/clean_side_effects.rs
pub struct CleanMarker {
pub mark: Mark,
}

impl Treeshaker {
pub fn new() -> Self {
let mark = Mark::new();
Self {
marker: CleanMarker { mark },
cleaner: CleanSideEffects {
did_drop: false,
mark,
},
}
}
}

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 {
expr.span = expr.span.apply_mark(self.mark);
}
}
}

impl VisitMut for CleanSideEffects {
fn visit_mut_module(&mut self, node: &mut ast::Module) {
node.body.retain(|item| {
if item.span().has_mark(self.mark) {
return true;
}
...
pub struct CleanMarker {
pub mark: Mark,
}

impl Treeshaker {
pub fn new() -> Self {
let mark = Mark::new();
Self {
marker: CleanMarker { mark },
cleaner: CleanSideEffects {
did_drop: false,
mark,
},
}
}
}

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 {
expr.span = expr.span.apply_mark(self.mark);
}
}
}

impl VisitMut for CleanSideEffects {
fn visit_mut_module(&mut self, node: &mut ast::Module) {
node.body.retain(|item| {
if item.span().has_mark(self.mark) {
return true;
}
...
5 replies
SDSWC Developers
Created by w00t on 7/19/2024 in #questions
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
impl Visit for IdentCollector {
noop_visit_type!();

fn visit_expr(&mut self, node: &ast::Expr) {
self.expr_ctxt.push(ExprOrSkip::Expr);
visit_expr(self, node);
self.expr_ctxt.pop();
}
...
impl Visit for IdentCollector {
noop_visit_type!();

fn visit_expr(&mut self, node: &ast::Expr) {
self.expr_ctxt.push(ExprOrSkip::Expr);
visit_expr(self, node);
self.expr_ctxt.pop();
}
...
8 replies
SDSWC Developers
Created by w00t on 5/8/2024 in #questions
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?
1 replies
SDSWC Developers
Created by w00t on 3/11/2024 in #questions
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?
6 replies