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
GitHub
qwik/packages/qwik/src/optimizer/core/src/clean_side_effects.rs at ...
Instant-loading web apps, without effort. Contribute to QwikDev/qwik development by creating an account on GitHub.
Plugin cheatsheet – SWC
SWC is an extensible Rust-based platform for the next generation of fast developer tools. It's used by tools like Next.js, Parcel, and Deno, as well as companies like Vercel, ByteDance, Tencent, Shopify, and more.
4 Replies
I think you can make the node invalid in the
else
statement for your ast::ModuleItem::Stmt(ast::Stmt::Expr(expr))
hmm that will basically kill all import statements.
I think I figured out how it works. It gets used here:
https://github.com/QwikDev/qwik/blob/b0802ca6dc448a82454dfba6b46f7392e0401c05/packages/qwik/src/optimizer/core/src/parse.rs#L334-L361
First it marks all top-level statements in the module. Then it simplifes, which will remove all unused statements and assignments but leave possibly impure expressions.
Anything that was simplified and moved to toplevel will not have been marked, and if they are function calls/new constructions, they will be forcibly removed.
So I only need to mark top level call/new expressions, not all expressions. Hmm.
GitHub
qwik/packages/qwik/src/optimizer/core/src/parse.rs at b0802ca6dc448...
Instant-loading web apps, without effort. Contribute to QwikDev/qwik development by creating an account on GitHub.
Call / New has syntax context
yes it works now 🙂