Unverified Commit f93a867d authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

Update wasm and next-custom-transforms crates to Rust edition 2024 (#90350)

The `wasm` and `next-custom-transforms` crates were still on Rust edition 2018 while the rest of the crates in this repo use edition 2024. This caused a pre-commit hook conflict:

- `cargo fmt` passes the crate's own edition (2018) to `rustfmt`, which uses **case-insensitive** import sorting
- The lint-staged pre-commit hook runs `rustfmt --edition 2024 --`, which uses **ASCII order** import sorting (uppercase before lowercase)

These two sort orders disagree on items like `{custom_before_pass, TransformOptions}` vs `{TransformOptions, custom_before_pass}`, causing an infinite flip-flop: every commit would reorder imports, and the next `cargo fmt` would reorder them back.

## Changes

- Bump `crates/wasm` and `crates/next-custom-transforms` from edition 2018 to 2024
- Add `+ use<C>` precise capturing to `server_actions()` return type to satisfy edition 2024's stricter `impl Trait` lifetime capture rules
- Add `style_edition = "2024"` to `.rustfmt.toml` as a safety net so `cargo fmt` uses 2024-style formatting regardless of individual crate editions
- Reformat all affected files with `cargo fmt`
- Apply new clippy rules
parent 757ab17e
edition = "2024" edition = "2024"
style_edition = "2024"
max_width = 100 max_width = 100
comment_width = 100 comment_width = 100
......
[package] [package]
edition = "2018" edition = "2024"
name = "next-custom-transforms" name = "next-custom-transforms"
version = "0.0.0" version = "0.0.0"
publish = false publish = false
......
...@@ -8,12 +8,12 @@ use serde::Deserialize; ...@@ -8,12 +8,12 @@ use serde::Deserialize;
use swc_core::{ use swc_core::{
atoms::Atom, atoms::Atom,
common::{ common::{
FileName, Mark, SourceFile, SourceMap, SyntaxContext,
comments::{Comments, NoopComments}, comments::{Comments, NoopComments},
pass::Optional, pass::Optional,
FileName, Mark, SourceFile, SourceMap, SyntaxContext,
}, },
ecma::{ ecma::{
ast::{fn_pass, noop_pass, EsVersion, Pass}, ast::{EsVersion, Pass, fn_pass, noop_pass},
parser::parse_file_as_module, parser::parse_file_as_module,
visit::visit_mut_pass, visit::visit_mut_pass,
}, },
...@@ -23,7 +23,7 @@ use crate::{ ...@@ -23,7 +23,7 @@ use crate::{
linter::linter, linter::linter,
transforms::{ transforms::{
cjs_finder::contains_cjs, cjs_finder::contains_cjs,
dynamic::{next_dynamic, NextDynamicMode}, dynamic::{NextDynamicMode, next_dynamic},
fonts::next_font_loaders, fonts::next_font_loaders,
lint_codemod_comments::lint_codemod_comments, lint_codemod_comments::lint_codemod_comments,
react_server_components, react_server_components,
......
use swc_core::ecma::{ use swc_core::ecma::{
ast::Pass, ast::Pass,
visit::{visit_pass, Visit}, visit::{Visit, visit_pass},
}; };
pub fn linter<V>(visitor: V) -> impl Pass pub fn linter<V>(visitor: V) -> impl Pass
......
...@@ -23,15 +23,13 @@ struct Finder { ...@@ -23,15 +23,13 @@ struct Finder {
impl Visit for Finder { impl Visit for Finder {
fn visit_callee(&mut self, node: &Callee) { fn visit_callee(&mut self, node: &Callee) {
if self.is_interested { if self.is_interested
if let Callee::Expr(e) = node { && let Callee::Expr(e) = node
if let Expr::Ident(c) = &**e { && let Expr::Ident(c) = &**e
if c.sym.starts_with("use") { && c.sym.starts_with("use")
self.found = true; {
return; self.found = true;
} return;
}
}
} }
node.visit_children_with(self); node.visit_children_with(self);
...@@ -130,7 +128,7 @@ impl Visit for Finder { ...@@ -130,7 +128,7 @@ impl Visit for Finder {
mod tests { mod tests {
use swc_core::{ use swc_core::{
common::FileName, common::FileName,
ecma::parser::{parse_file_as_program, EsSyntax}, ecma::parser::{EsSyntax, parse_file_as_program},
}; };
use testing::run_test2; use testing::run_test2;
......
...@@ -56,33 +56,22 @@ impl Visit for CjsFinder { ...@@ -56,33 +56,22 @@ impl Visit for CjsFinder {
// Note that `Object.defineProperty(module.exports, ...)` will be handled by // Note that `Object.defineProperty(module.exports, ...)` will be handled by
// `visit_member_expr`. // `visit_member_expr`.
fn visit_call_expr(&mut self, e: &CallExpr) { fn visit_call_expr(&mut self, e: &CallExpr) {
if !self.ignore_exports { if !self.ignore_exports
if let Callee::Expr(expr) = &e.callee { && let Callee::Expr(expr) = &e.callee
if let Expr::Member(member_expr) = &**expr { && let Expr::Member(member_expr) = &**expr
if let (Expr::Ident(obj), MemberProp::Ident(prop)) = && let (Expr::Ident(obj), MemberProp::Ident(prop)) =
(&*member_expr.obj, &member_expr.prop) (&*member_expr.obj, &member_expr.prop)
{ && &*obj.sym == "Object"
if &*obj.sym == "Object" && &*prop.sym == "defineProperty" { && &*prop.sym == "defineProperty"
if let Some(ExprOrSpread { expr: expr0, .. }) = e.args.first() { && let Some(ExprOrSpread { expr: expr0, .. }) = e.args.first()
if let Expr::Ident(arg0) = &**expr0 { && let Expr::Ident(arg0) = &**expr0
if &*arg0.sym == "exports" { && &*arg0.sym == "exports"
if let Some(ExprOrSpread { expr: expr1, .. }) = && let Some(ExprOrSpread { expr: expr1, .. }) = e.args.get(1)
e.args.get(1) && let Expr::Lit(Lit::Str(arg1)) = &**expr1
{ && &*arg1.value == "__esModule"
if let Expr::Lit(Lit::Str(arg1)) = &**expr1 { {
if &*arg1.value == "__esModule" { self.found = true;
self.found = true; return;
return;
}
}
}
}
}
}
}
}
}
}
} }
e.callee.visit_with(self); e.callee.visit_with(self);
...@@ -113,15 +102,15 @@ impl Visit for CjsFinder { ...@@ -113,15 +102,15 @@ impl Visit for CjsFinder {
} }
fn visit_member_expr(&mut self, e: &MemberExpr) { fn visit_member_expr(&mut self, e: &MemberExpr) {
if let Expr::Ident(obj) = &*e.obj { if let Expr::Ident(obj) = &*e.obj
if let MemberProp::Ident(prop) = &e.prop { && let MemberProp::Ident(prop) = &e.prop
// Detect `module.exports` and `exports.__esModule` {
if (!self.ignore_module && &*obj.sym == "module" && &*prop.sym == "exports") // Detect `module.exports` and `exports.__esModule`
|| (!self.ignore_exports && &*obj.sym == "exports") if (!self.ignore_module && &*obj.sym == "module" && &*prop.sym == "exports")
{ || (!self.ignore_exports && &*obj.sym == "exports")
self.found = true; {
return; self.found = true;
} return;
} }
} }
......
...@@ -2,14 +2,14 @@ use std::fmt::Write; ...@@ -2,14 +2,14 @@ use std::fmt::Write;
use swc_core::{ use swc_core::{
atoms::Atom, atoms::Atom,
common::{util::take::Take, DUMMY_SP}, common::{DUMMY_SP, util::take::Take},
ecma::{ ecma::{
ast::{ ast::{
CallExpr, Callee, ExportDefaultDecl, ExportDefaultExpr, Expr, FnDecl, FnExpr, CallExpr, Callee, ExportDefaultDecl, ExportDefaultExpr, Expr, FnDecl, FnExpr,
KeyValueProp, MemberProp, ObjectLit, Pass, PropOrSpread, VarDeclarator, KeyValueProp, MemberProp, ObjectLit, Pass, PropOrSpread, VarDeclarator,
}, },
utils::ExprFactory, utils::ExprFactory,
visit::{visit_mut_pass, VisitMut, VisitMutWith}, visit::{VisitMut, VisitMutWith, visit_mut_pass},
}, },
}; };
......
...@@ -2,7 +2,7 @@ use swc_core::{ ...@@ -2,7 +2,7 @@ use swc_core::{
common::{Span, Spanned}, common::{Span, Spanned},
ecma::{ ecma::{
ast::*, ast::*,
visit::{fold_pass, Fold}, visit::{Fold, fold_pass},
}, },
quote, quote,
}; };
...@@ -52,12 +52,11 @@ fn find_var_init_span(items: &[ModuleItem], local_name: &str) -> Option<Span> { ...@@ -52,12 +52,11 @@ fn find_var_init_span(items: &[ModuleItem], local_name: &str) -> Option<Span> {
_ => continue, _ => continue,
}; };
for d in &decl.decls { for d in &decl.decls {
if let Pat::Ident(ident) = &d.name { if let Pat::Ident(ident) = &d.name
if ident.id.sym == local_name { && ident.id.sym == local_name
if let Some(init) = &d.init { && let Some(init) = &d.init
return Some(init.span()); {
} return Some(init.span());
}
} }
} }
} }
...@@ -72,12 +71,11 @@ impl Fold for DebugInstantStack { ...@@ -72,12 +71,11 @@ impl Fold for DebugInstantStack {
ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(export_decl)) => { ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(export_decl)) => {
if let Decl::Var(var_decl) = &export_decl.decl { if let Decl::Var(var_decl) = &export_decl.decl {
for decl in &var_decl.decls { for decl in &var_decl.decls {
if let Pat::Ident(ident) = &decl.name { if let Pat::Ident(ident) = &decl.name
if ident.id.sym == "unstable_instant" { && ident.id.sym == "unstable_instant"
if let Some(init) = &decl.init { && let Some(init) = &decl.init
self.instant_export_span = Some(init.span()); {
} self.instant_export_span = Some(init.span());
}
} }
} }
} }
......
...@@ -2,7 +2,7 @@ use swc_core::{ ...@@ -2,7 +2,7 @@ use swc_core::{
common::errors::HANDLER, common::errors::HANDLER,
ecma::{ ecma::{
ast::*, ast::*,
visit::{noop_visit_type, Visit}, visit::{Visit, noop_visit_type},
}, },
}; };
pub struct FindFunctionsOutsideModuleScope<'a> { pub struct FindFunctionsOutsideModuleScope<'a> {
......
...@@ -3,7 +3,7 @@ use swc_core::{ ...@@ -3,7 +3,7 @@ use swc_core::{
common::errors::HANDLER, common::errors::HANDLER,
ecma::{ ecma::{
ast::*, ast::*,
visit::{noop_visit_type, Visit}, visit::{Visit, noop_visit_type},
}, },
}; };
......
...@@ -6,7 +6,7 @@ use swc_core::{ ...@@ -6,7 +6,7 @@ use swc_core::{
ecma::{ ecma::{
ast::{Id, ModuleItem, Pass}, ast::{Id, ModuleItem, Pass},
atoms::Atom, atoms::Atom,
visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitWith}, visit::{VisitMut, VisitWith, noop_visit_mut_type, visit_mut_pass},
}, },
}; };
......
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use swc_core::{ use swc_core::{
atoms::{atom, Atom, Wtf8Atom}, atoms::{Atom, Wtf8Atom, atom},
ecma::{ ecma::{
ast::{ ast::{
Expr, Id, ImportDecl, ImportNamedSpecifier, ImportSpecifier, MemberExpr, MemberProp, Expr, Id, ImportDecl, ImportNamedSpecifier, ImportSpecifier, MemberExpr, MemberProp,
Module, Module,
}, },
visit::{noop_visit_type, Visit, VisitWith}, visit::{Visit, VisitWith, noop_visit_type},
}, },
}; };
......
...@@ -37,10 +37,10 @@ impl VisitMut for MiddlewareDynamic { ...@@ -37,10 +37,10 @@ impl VisitMut for MiddlewareDynamic {
let callee = &call_expr.callee; let callee = &call_expr.callee;
if let Callee::Expr(callee) = callee { if let Callee::Expr(callee) = callee {
// `eval('some')`, or `Function('some')` // `eval('some')`, or `Function('some')`
if let Expr::Ident(ident) = &**callee { if let Expr::Ident(ident) = &**callee
if ident.sym == "eval" || ident.sym == "Function" { && (ident.sym == "eval" || ident.sym == "Function")
should_wrap = Some(WrappedExpr::Eval); {
} should_wrap = Some(WrappedExpr::Eval);
} }
if let Expr::Member(MemberExpr { if let Expr::Member(MemberExpr {
...@@ -70,16 +70,15 @@ impl VisitMut for MiddlewareDynamic { ...@@ -70,16 +70,15 @@ impl VisitMut for MiddlewareDynamic {
prop: MemberProp::Ident(member_prop_ident), prop: MemberProp::Ident(member_prop_ident),
.. ..
}) = &**obj }) = &**obj
&& let Expr::Ident(ident) = &**obj
{ {
if let Expr::Ident(ident) = &**obj { // `global.WebAssembly.compile('some')` &
// `global.WebAssembly.compile('some')` & // `global.WebAssembly.instantiate('some')`
// `global.WebAssembly.instantiate('some')` if ident.sym == "global" && member_prop_ident.sym == "WebAssembly" {
if ident.sym == "global" && member_prop_ident.sym == "WebAssembly" { if prop_ident.sym == "compile" {
if prop_ident.sym == "compile" { should_wrap = Some(WrappedExpr::WasmCompile);
should_wrap = Some(WrappedExpr::WasmCompile); } else if prop_ident.sym == "instantiate" {
} else if prop_ident.sym == "instantiate" { should_wrap = Some(WrappedExpr::WasmInstantiate);
should_wrap = Some(WrappedExpr::WasmInstantiate);
}
} }
} }
} }
...@@ -100,12 +99,11 @@ impl VisitMut for MiddlewareDynamic { ...@@ -100,12 +99,11 @@ impl VisitMut for MiddlewareDynamic {
} }
} }
if let Expr::New(NewExpr { callee, .. }) = &expr { if let Expr::New(NewExpr { callee, .. }) = &expr
if let Expr::Ident(ident) = &**callee { && let Expr::Ident(ident) = &**callee
if ident.sym == "Function" { && ident.sym == "Function"
*expr = quote!("__next_eval__(function() { return $orig_call });" as Expr, orig_call: Expr = expr.clone()); {
} *expr = quote!("__next_eval__(function() { return $orig_call });" as Expr, orig_call: Expr = expr.clone());
}
} }
} }
} }
...@@ -5,7 +5,7 @@ use swc_core::{ ...@@ -5,7 +5,7 @@ use swc_core::{
common::DUMMY_SP, common::DUMMY_SP,
ecma::{ ecma::{
ast::*, ast::*,
visit::{visit_mut_pass, VisitMut}, visit::{VisitMut, visit_mut_pass},
}, },
}; };
......
use std::{cell::RefCell, mem::take, rc::Rc}; use std::{cell::RefCell, mem::take, rc::Rc};
use easy_error::{bail, Error}; use easy_error::{Error, bail};
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use swc_core::{ use swc_core::{
atoms::{atom, Atom}, atoms::{Atom, atom},
common::{ common::{
DUMMY_SP,
errors::HANDLER, errors::HANDLER,
pass::{Repeat, Repeated}, pass::{Repeat, Repeated},
DUMMY_SP,
}, },
ecma::{ ecma::{
ast::*, ast::*,
visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}, visit::{VisitMut, VisitMutWith, noop_visit_mut_type, visit_mut_pass},
}, },
}; };
...@@ -131,10 +131,10 @@ impl VisitMut for Analyzer<'_> { ...@@ -131,10 +131,10 @@ impl VisitMut for Analyzer<'_> {
} }
fn visit_mut_export_named_specifier(&mut self, s: &mut ExportNamedSpecifier) { fn visit_mut_export_named_specifier(&mut self, s: &mut ExportNamedSpecifier) {
if let ModuleExportName::Ident(id) = &s.orig { if let ModuleExportName::Ident(id) = &s.orig
if !SSG_EXPORTS.contains(&&*id.sym) { && !SSG_EXPORTS.contains(&&*id.sym)
self.add_ref(id.to_id()); {
} self.add_ref(id.to_id());
} }
} }
...@@ -145,10 +145,10 @@ impl VisitMut for Analyzer<'_> { ...@@ -145,10 +145,10 @@ impl VisitMut for Analyzer<'_> {
} }
for decl in &d.decls { for decl in &d.decls {
if let Pat::Ident(id) = &decl.name { if let Pat::Ident(id) = &decl.name
if !SSG_EXPORTS.contains(&&*id.id.sym) { && !SSG_EXPORTS.contains(&&*id.id.sym)
self.add_ref(id.to_id()); {
} self.add_ref(id.to_id());
} }
} }
} }
...@@ -240,10 +240,10 @@ impl VisitMut for Analyzer<'_> { ...@@ -240,10 +240,10 @@ impl VisitMut for Analyzer<'_> {
match &e.decl { match &e.decl {
Decl::Fn(f) => { Decl::Fn(f) => {
// Drop getStaticProps. // Drop getStaticProps.
if let Ok(is_data_identifier) = self.state.is_data_identifier(&f.ident) { if let Ok(is_data_identifier) = self.state.is_data_identifier(&f.ident)
if is_data_identifier { && is_data_identifier
*s = ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); {
} *s = ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP }));
} }
} }
...@@ -468,18 +468,17 @@ impl VisitMut for NextSsg { ...@@ -468,18 +468,17 @@ impl VisitMut for NextSsg {
| ModuleDecl::ExportDefaultDecl(..) | ModuleDecl::ExportDefaultDecl(..)
| ModuleDecl::ExportDefaultExpr(..), | ModuleDecl::ExportDefaultExpr(..),
) = &item ) = &item
&& let Some(var) = var.take()
{ {
if let Some(var) = var.take() { new.push(ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl {
new.push(ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { span: DUMMY_SP,
decl: Decl::Var(Box::new(VarDecl {
span: DUMMY_SP, span: DUMMY_SP,
decl: Decl::Var(Box::new(VarDecl { kind: VarDeclKind::Var,
span: DUMMY_SP, decls: vec![var],
kind: VarDeclKind::Var, ..Default::default()
decls: vec![var], })),
..Default::default() })))
})),
})))
}
} }
new.push(item); new.push(item);
...@@ -599,12 +598,12 @@ impl VisitMut for NextSsg { ...@@ -599,12 +598,12 @@ impl VisitMut for NextSsg {
#[allow(clippy::single_match)] #[allow(clippy::single_match)]
fn visit_mut_stmt(&mut self, s: &mut Stmt) { fn visit_mut_stmt(&mut self, s: &mut Stmt) {
if let Stmt::Decl(Decl::Fn(f)) = s { if let Stmt::Decl(Decl::Fn(f)) = s
if self.should_remove(f.ident.to_id()) { && self.should_remove(f.ident.to_id())
self.mark_as_candidate(&mut f.function); {
*s = Stmt::Empty(EmptyStmt { span: DUMMY_SP }); self.mark_as_candidate(&mut f.function);
return; *s = Stmt::Empty(EmptyStmt { span: DUMMY_SP });
} return;
} }
s.visit_mut_children_with(self); s.visit_mut_children_with(self);
......
...@@ -2,12 +2,12 @@ use std::collections::HashMap; ...@@ -2,12 +2,12 @@ use std::collections::HashMap;
use serde::Deserialize; use serde::Deserialize;
use swc_core::{ use swc_core::{
atoms::{atom, Atom, Wtf8Atom}, atoms::{Atom, Wtf8Atom, atom},
common::DUMMY_SP, common::DUMMY_SP,
ecma::{ ecma::{
ast::*, ast::*,
utils::private_ident, utils::private_ident,
visit::{fold_pass, Fold}, visit::{Fold, fold_pass},
}, },
}; };
......
...@@ -10,7 +10,7 @@ use swc_core::{ ...@@ -10,7 +10,7 @@ use swc_core::{
common::DUMMY_SP, common::DUMMY_SP,
ecma::{ ecma::{
ast::*, ast::*,
visit::{fold_pass, Fold, FoldWith}, visit::{Fold, FoldWith, fold_pass},
}, },
}; };
...@@ -139,31 +139,30 @@ impl Fold for OptimizeServerReact { ...@@ -139,31 +139,30 @@ impl Fold for OptimizeServerReact {
if let Expr::Call(call) = &expr { if let Expr::Call(call) = &expr {
if let Callee::Expr(box Expr::Ident(f)) = &call.callee { if let Callee::Expr(box Expr::Ident(f)) = &call.callee {
// Mark `useEffect` as DCE'able // Mark `useEffect` as DCE'able
if let Some(use_effect_ident) = &self.use_effect_ident { if let Some(use_effect_ident) = &self.use_effect_ident
if &f.to_id() == use_effect_ident && !effect_has_side_effect_deps(call) { && &f.to_id() == use_effect_ident
// return Expr::Lit(Lit::Null(Null { span: DUMMY_SP })); && !effect_has_side_effect_deps(call)
return wrap_expr_with_env_prod_condition(call.clone()); {
} // return Expr::Lit(Lit::Null(Null { span: DUMMY_SP }));
return wrap_expr_with_env_prod_condition(call.clone());
} }
// Mark `useLayoutEffect` as DCE'able // Mark `useLayoutEffect` as DCE'able
if let Some(use_layout_effect_ident) = &self.use_layout_effect_ident { if let Some(use_layout_effect_ident) = &self.use_layout_effect_ident
if &f.to_id() == use_layout_effect_ident && !effect_has_side_effect_deps(call) { && &f.to_id() == use_layout_effect_ident
return wrap_expr_with_env_prod_condition(call.clone()); && !effect_has_side_effect_deps(call)
} {
return wrap_expr_with_env_prod_condition(call.clone());
} }
} else if let Some(react_ident) = &self.react_ident { } else if let Some(react_ident) = &self.react_ident
if let Callee::Expr(box Expr::Member(member)) = &call.callee { && let Callee::Expr(box Expr::Member(member)) = &call.callee
if let box Expr::Ident(f) = &member.obj { && let box Expr::Ident(f) = &member.obj
if &f.to_id() == react_ident { && &f.to_id() == react_ident
if let MemberProp::Ident(i) = &member.prop { && let MemberProp::Ident(i) = &member.prop
// Mark `React.useEffect` and `React.useLayoutEffect` as DCE'able {
// calls in production // Mark `React.useEffect` and `React.useLayoutEffect` as DCE'able
if i.sym == "useEffect" || i.sym == "useLayoutEffect" { // calls in production
return wrap_expr_with_env_prod_condition(call.clone()); if i.sym == "useEffect" || i.sym == "useLayoutEffect" {
} return wrap_expr_with_env_prod_condition(call.clone());
}
}
}
} }
} }
} }
...@@ -178,53 +177,48 @@ impl Fold for OptimizeServerReact { ...@@ -178,53 +177,48 @@ impl Fold for OptimizeServerReact {
return decl; return decl;
} }
if let Pat::Array(array_pat) = &decl.name { if let Pat::Array(array_pat) = &decl.name
if array_pat.elems.len() == 2 { && array_pat.elems.len() == 2
if let Some(box Expr::Call(call)) = &decl.init { && let Some(box Expr::Call(call)) = &decl.init
if let Callee::Expr(box Expr::Ident(f)) = &call.callee { && let Callee::Expr(box Expr::Ident(f)) = &call.callee
if let Some(use_state_ident) = &self.use_state_ident { && let Some(use_state_ident) = &self.use_state_ident
if &f.to_id() == use_state_ident && call.args.len() == 1 { && &f.to_id() == use_state_ident
// We do the optimization only if the arg is a literal or a && call.args.len() == 1
// type that we can {
// be sure is not a function (e.g. {} or [] lit). // We do the optimization only if the arg is a literal or a
// This is because useState allows a function as the // type that we can
// initialiser. // be sure is not a function (e.g. {} or [] lit).
match &call.args[0].expr { // This is because useState allows a function as the
box Expr::Lit(_) | box Expr::Object(_) | box Expr::Array(_) => { // initialiser.
// const [state, setState] = [x, () => {}]; match &call.args[0].expr {
return VarDeclarator { box Expr::Lit(_) | box Expr::Object(_) | box Expr::Array(_) => {
definite: false, // const [state, setState] = [x, () => {}];
name: decl.name.clone(), return VarDeclarator {
init: Some(Box::new(Expr::Array(ArrayLit { definite: false,
elems: vec![ name: decl.name.clone(),
Some(call.args[0].expr.clone().into()), init: Some(Box::new(Expr::Array(ArrayLit {
Some( elems: vec![
Expr::Arrow(ArrowExpr { Some(call.args[0].expr.clone().into()),
span: DUMMY_SP, Some(
body: Box::new(BlockStmtOrExpr::Expr( Expr::Arrow(ArrowExpr {
Box::new(Expr::Lit(Lit::Null( span: DUMMY_SP,
Null { span: DUMMY_SP }, body: Box::new(BlockStmtOrExpr::Expr(Box::new(Expr::Lit(
))), Lit::Null(Null { span: DUMMY_SP }),
)), )))),
is_async: false, is_async: false,
is_generator: false, is_generator: false,
params: vec![], params: vec![],
..Default::default() ..Default::default()
}) })
.into(), .into(),
), ),
], ],
span: DUMMY_SP, span: DUMMY_SP,
}))), }))),
span: DUMMY_SP, span: DUMMY_SP,
}; };
}
_ => {}
}
}
}
}
} }
_ => {}
} }
} }
......
use chrono::Utc; use chrono::Utc;
use swc_core::{ use swc_core::{
common::{errors::HANDLER, Span, DUMMY_SP}, common::{DUMMY_SP, Span, errors::HANDLER},
ecma::{ ecma::{
ast::*, ast::*,
visit::{fold_pass, Fold, FoldWith}, visit::{Fold, FoldWith, fold_pass},
}, },
}; };
...@@ -68,10 +68,10 @@ impl Fold for PageConfig { ...@@ -68,10 +68,10 @@ impl Fold for PageConfig {
if let Decl::Var(var_decl) = &export.decl { if let Decl::Var(var_decl) = &export.decl {
for decl in &var_decl.decls { for decl in &var_decl.decls {
let mut is_config = false; let mut is_config = false;
if let Pat::Ident(ident) = &decl.name { if let Pat::Ident(ident) = &decl.name
if ident.id.sym == CONFIG_KEY { && ident.id.sym == CONFIG_KEY
is_config = true; {
} is_config = true;
} }
if is_config { if is_config {
...@@ -120,17 +120,17 @@ impl Fold for PageConfig { ...@@ -120,17 +120,17 @@ impl Fold for PageConfig {
) -> ExportNamedSpecifier { ) -> ExportNamedSpecifier {
match &specifier.exported { match &specifier.exported {
Some(ident) => { Some(ident) => {
if let ModuleExportName::Ident(ident) = ident { if let ModuleExportName::Ident(ident) = ident
if ident.sym == CONFIG_KEY { && ident.sym == CONFIG_KEY
self.handle_error("Config cannot be re-exported.", specifier.span) {
} self.handle_error("Config cannot be re-exported.", specifier.span)
} }
} }
None => { None => {
if let ModuleExportName::Ident(ident) = &specifier.orig { if let ModuleExportName::Ident(ident) = &specifier.orig
if ident.sym == CONFIG_KEY { && ident.sym == CONFIG_KEY
self.handle_error("Config cannot be re-exported.", specifier.span) {
} self.handle_error("Config cannot be re-exported.", specifier.span)
} }
} }
} }
......
use swc_core::{ use swc_core::{
common::{comments::Comments, errors::HANDLER, util::take::Take, Span, Spanned, DUMMY_SP}, common::{DUMMY_SP, Span, Spanned, comments::Comments, errors::HANDLER, util::take::Take},
ecma::{ ecma::{
ast::{CallExpr, Callee, EmptyStmt, Expr, Module, ModuleDecl, ModuleItem, Stmt}, ast::{CallExpr, Callee, EmptyStmt, Expr, Module, ModuleDecl, ModuleItem, Stmt},
visit::{noop_visit_mut_type, VisitMut, VisitMutWith}, visit::{VisitMut, VisitMutWith, noop_visit_mut_type},
}, },
}; };
...@@ -74,11 +74,11 @@ where ...@@ -74,11 +74,11 @@ where
} }
fn visit_mut_module_item(&mut self, m: &mut ModuleItem) { fn visit_mut_module_item(&mut self, m: &mut ModuleItem) {
if let ModuleItem::ModuleDecl(ModuleDecl::Import(import)) = m { if let ModuleItem::ModuleDecl(ModuleDecl::Import(import)) = m
if import.src.value == MODULE { && import.src.value == MODULE
*m = ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); {
return; *m = ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP }));
} return;
} }
m.visit_mut_children_with(self); m.visit_mut_children_with(self);
......
...@@ -11,19 +11,19 @@ use regex::Regex; ...@@ -11,19 +11,19 @@ use regex::Regex;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use serde::Deserialize; use serde::Deserialize;
use swc_core::{ use swc_core::{
atoms::{atom, Atom, Wtf8Atom}, atoms::{Atom, Wtf8Atom, atom},
common::{ common::{
DUMMY_SP, FileName, Span, Spanned,
comments::{Comment, CommentKind, Comments}, comments::{Comment, CommentKind, Comments},
errors::HANDLER, errors::HANDLER,
util::take::Take, util::take::Take,
FileName, Span, Spanned, DUMMY_SP,
}, },
ecma::{ ecma::{
ast::*, ast::*,
utils::{prepend_stmts, quote_ident, quote_str, ExprFactory}, utils::{ExprFactory, prepend_stmts, quote_ident, quote_str},
visit::{ visit::{
noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, Visit, VisitMut, VisitMutWith, VisitWith, noop_visit_mut_type, noop_visit_type,
VisitWith, visit_mut_pass,
}, },
}, },
}; };
...@@ -162,15 +162,13 @@ impl<C: Comments> ReactServerComponents<C> { ...@@ -162,15 +162,13 @@ impl<C: Comments> ReactServerComponents<C> {
/// removes specific directive from the AST. /// removes specific directive from the AST.
fn remove_top_level_directive(&mut self, module: &mut Module) { fn remove_top_level_directive(&mut self, module: &mut Module) {
module.body.retain(|item| { module.body.retain(|item| {
if let ModuleItem::Stmt(stmt) = item { if let ModuleItem::Stmt(stmt) = item
if let Some(expr_stmt) = stmt.as_expr() { && let Some(expr_stmt) = stmt.as_expr()
if let Expr::Lit(Lit::Str(Str { value, .. })) = &*expr_stmt.expr { && let Expr::Lit(Lit::Str(Str { value, .. })) = &*expr_stmt.expr
if &**value == "use client" { && &**value == "use client"
// Remove the directive. {
return false; // Remove the directive.
} return false;
}
}
} }
true true
}); });
...@@ -454,14 +452,14 @@ fn collect_module_info( ...@@ -454,14 +452,14 @@ fn collect_module_info(
// an exception because they are not valid directives. // an exception because they are not valid directives.
Expr::Paren(ParenExpr { expr, .. }) => { Expr::Paren(ParenExpr { expr, .. }) => {
finished_directives = true; finished_directives = true;
if let Expr::Lit(Lit::Str(Str { value, .. })) = &**expr { if let Expr::Lit(Lit::Str(Str { value, .. })) = &**expr
if &**value == "use client" { && &**value == "use client"
report_error( {
app_dir, report_error(
filepath, app_dir,
RSCErrorKind::NextRscErrClientDirective(expr_stmt.span), filepath,
); RSCErrorKind::NextRscErrClientDirective(expr_stmt.span),
} );
} }
} }
_ => { _ => {
...@@ -825,24 +823,22 @@ impl ReactServerComponentValidator { ...@@ -825,24 +823,22 @@ impl ReactServerComponentValidator {
let is_error_file = RE.is_match(&self.filepath); let is_error_file = RE.is_match(&self.filepath);
if is_error_file { if is_error_file
if let Some(app_dir) = &self.app_dir { && let Some(app_dir) = &self.app_dir
if let Some(app_dir) = app_dir.to_str() { && let Some(app_dir) = app_dir.to_str()
if self.filepath.starts_with(app_dir) { && self.filepath.starts_with(app_dir)
let span = if let Some(first_item) = module.body.first() { {
first_item.span() let span = if let Some(first_item) = module.body.first() {
} else { first_item.span()
module.span } else {
}; module.span
};
report_error( report_error(
&self.app_dir, &self.app_dir,
&self.filepath, &self.filepath,
RSCErrorKind::NextRscErrErrorFileServerComponent(span), RSCErrorKind::NextRscErrErrorFileServerComponent(span),
); );
}
}
}
} }
} }
......
...@@ -3,9 +3,9 @@ use swc_core::{ ...@@ -3,9 +3,9 @@ use swc_core::{
common::Mark, common::Mark,
ecma::{ ecma::{
ast::*, ast::*,
atoms::{atom, Atom}, atoms::{Atom, atom},
transforms::optimization::simplify::dce::{dce, Config as DCEConfig}, transforms::optimization::simplify::dce::{Config as DCEConfig, dce},
visit::{fold_pass, Fold, FoldWith, VisitMutWith}, visit::{Fold, FoldWith, VisitMutWith, fold_pass},
}, },
}; };
...@@ -63,10 +63,10 @@ impl Fold for ExportShaker { ...@@ -63,10 +63,10 @@ impl Fold for ExportShaker {
.decls .decls
.iter() .iter()
.filter_map(|var_decl| { .filter_map(|var_decl| {
if let Pat::Ident(BindingIdent { id, .. }) = &var_decl.name { if let Pat::Ident(BindingIdent { id, .. }) = &var_decl.name
if self.ignore.contains(&id.sym) { && self.ignore.contains(&id.sym)
return Some(var_decl.to_owned()); {
} return Some(var_decl.to_owned());
} }
None None
}) })
...@@ -87,15 +87,15 @@ impl Fold for ExportShaker { ...@@ -87,15 +87,15 @@ impl Fold for ExportShaker {
.filter_map(|spec| { .filter_map(|spec| {
if let ExportSpecifier::Named(named_spec) = spec { if let ExportSpecifier::Named(named_spec) = spec {
if let Some(ident) = &named_spec.exported { if let Some(ident) = &named_spec.exported {
if let ModuleExportName::Ident(ident) = ident { if let ModuleExportName::Ident(ident) = ident
if self.ignore.contains(&ident.sym) { && self.ignore.contains(&ident.sym)
return Some(ExportSpecifier::Named(named_spec)); {
}
}
} else if let ModuleExportName::Ident(ident) = &named_spec.orig {
if self.ignore.contains(&ident.sym) {
return Some(ExportSpecifier::Named(named_spec)); return Some(ExportSpecifier::Named(named_spec));
} }
} else if let ModuleExportName::Ident(ident) = &named_spec.orig
&& self.ignore.contains(&ident.sym)
{
return Some(ExportSpecifier::Named(named_spec));
} }
} }
None None
......
...@@ -9,13 +9,13 @@ use rustc_hash::{FxHashMap, FxHashSet}; ...@@ -9,13 +9,13 @@ use rustc_hash::{FxHashMap, FxHashSet};
use swc_core::{ use swc_core::{
atoms::Atom, atoms::Atom,
common::{ common::{
DUMMY_SP,
errors::HANDLER, errors::HANDLER,
pass::{Repeat, Repeated}, pass::{Repeat, Repeated},
DUMMY_SP,
}, },
ecma::{ ecma::{
ast::*, ast::*,
visit::{fold_pass, noop_fold_type, noop_visit_type, Fold, FoldWith, Visit, VisitWith}, visit::{Fold, FoldWith, Visit, VisitWith, fold_pass, noop_fold_type, noop_visit_type},
}, },
}; };
...@@ -347,10 +347,10 @@ impl Visit for Analyzer<'_> { ...@@ -347,10 +347,10 @@ impl Visit for Analyzer<'_> {
self.state self.state
.encounter_export(exported_ident, local_ident, export_type); .encounter_export(exported_ident, local_ident, export_type);
if let Some(local_ident) = local_ident { if let Some(local_ident) = local_ident
if self.state.should_retain_export_type(export_type) { && self.state.should_retain_export_type(export_type)
self.add_ref(local_ident.to_id()); {
} self.add_ref(local_ident.to_id());
} }
} }
} }
...@@ -793,13 +793,13 @@ impl Fold for NextSsg { ...@@ -793,13 +793,13 @@ impl Fold for NextSsg {
} }
ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(e)) => match &e.decl { ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(e)) => match &e.decl {
Decl::Fn(f) => { Decl::Fn(f) => {
if let Some(export_type) = self.state.export_type(&f.ident.to_id()) { if let Some(export_type) = self.state.export_type(&f.ident.to_id())
if self.state.dropping_export(export_type) { && self.state.dropping_export(export_type)
tracing::trace!( {
"Dropping an export specifier because it's an SSR/SSG function" tracing::trace!(
); "Dropping an export specifier because it's an SSR/SSG function"
return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); );
} return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP }));
} }
} }
...@@ -950,20 +950,19 @@ impl Fold for NextSsg { ...@@ -950,20 +950,19 @@ impl Fold for NextSsg {
} }
} }
Pat::Expr(expr) => { Pat::Expr(expr) => {
if let Expr::Member(member_expr) = &**expr { if let Expr::Member(member_expr) = &**expr
if let Some(id) = find_member_root_id(member_expr) { && let Some(id) = find_member_root_id(member_expr)
if self.should_remove(&id) { && self.should_remove(&id)
self.state.should_run_again = true; {
tracing::trace!( self.state.should_run_again = true;
"Dropping member expression object `{}{:?}` because it should \ tracing::trace!(
be removed", "Dropping member expression object `{}{:?}` because it should be \
id.0, removed",
id.1 id.0,
); id.1
);
return Pat::Invalid(Invalid { span: DUMMY_SP });
} return Pat::Invalid(Invalid { span: DUMMY_SP });
}
} }
} }
_ => {} _ => {}
...@@ -976,32 +975,31 @@ impl Fold for NextSsg { ...@@ -976,32 +975,31 @@ impl Fold for NextSsg {
fn fold_simple_assign_target(&mut self, mut n: SimpleAssignTarget) -> SimpleAssignTarget { fn fold_simple_assign_target(&mut self, mut n: SimpleAssignTarget) -> SimpleAssignTarget {
n = n.fold_children_with(self); n = n.fold_children_with(self);
if let SimpleAssignTarget::Ident(name) = &n { if let SimpleAssignTarget::Ident(name) = &n
if self.should_remove(&name.id.to_id()) { && self.should_remove(&name.id.to_id())
self.state.should_run_again = true; {
tracing::trace!( self.state.should_run_again = true;
"Dropping var `{}{:?}` because it should be removed", tracing::trace!(
name.id.sym, "Dropping var `{}{:?}` because it should be removed",
name.id.ctxt name.id.sym,
); name.id.ctxt
);
return SimpleAssignTarget::Invalid(Invalid { span: DUMMY_SP });
} return SimpleAssignTarget::Invalid(Invalid { span: DUMMY_SP });
} }
if let SimpleAssignTarget::Member(member_expr) = &n { if let SimpleAssignTarget::Member(member_expr) = &n
if let Some(id) = find_member_root_id(member_expr) { && let Some(id) = find_member_root_id(member_expr)
if self.should_remove(&id) { && self.should_remove(&id)
self.state.should_run_again = true; {
tracing::trace!( self.state.should_run_again = true;
"Dropping member expression object `{}{:?}` because it should be removed", tracing::trace!(
id.0, "Dropping member expression object `{}{:?}` because it should be removed",
id.1 id.0,
); id.1
);
return SimpleAssignTarget::Invalid(Invalid { span: DUMMY_SP });
} return SimpleAssignTarget::Invalid(Invalid { span: DUMMY_SP });
}
} }
n n
......
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use swc_core::{ use swc_core::{
common::{ common::{
BytePos, DUMMY_SP, Mark, Span, Spanned, SyntaxContext,
comments::{Comment, CommentKind, Comments}, comments::{Comment, CommentKind, Comments},
source_map::PURE_SP, source_map::PURE_SP,
util::take::Take, util::take::Take,
BytePos, Mark, Span, Spanned, SyntaxContext, DUMMY_SP,
}, },
ecma::{ ecma::{
ast::*, ast::*,
utils::{prepend_stmt, private_ident, quote_ident, quote_str}, utils::{prepend_stmt, private_ident, quote_ident, quote_str},
visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}, visit::{VisitMut, VisitMutWith, noop_visit_mut_type, visit_mut_pass},
}, },
quote, quote,
}; };
...@@ -129,14 +129,12 @@ impl<C: Comments> VisitMut for ImportReplacer<C> { ...@@ -129,14 +129,12 @@ impl<C: Comments> VisitMut for ImportReplacer<C> {
// //
// Only extract names when `await` is present — without await, the // Only extract names when `await` is present — without await, the
// destructuring targets the Promise, not the module namespace. // destructuring targets the Promise, not the module namespace.
if let Some(init) = &decl.init { if let Some(init) = &decl.init
if let Some(import_span) = find_awaited_import_call_span(init) { && let Some(import_span) = find_awaited_import_call_span(init)
if let Pat::Object(obj_pat) = &decl.name { && let Pat::Object(obj_pat) = &decl.name
if let Some(names) = extract_export_names_from_pat(obj_pat) { && let Some(names) = extract_export_names_from_pat(obj_pat)
self.import_export_names.insert(import_span.lo, names); {
} self.import_export_names.insert(import_span.lo, names);
}
}
} }
decl.visit_mut_children_with(self); decl.visit_mut_children_with(self);
...@@ -158,24 +156,24 @@ impl<C: Comments> VisitMut for ImportReplacer<C> { ...@@ -158,24 +156,24 @@ impl<C: Comments> VisitMut for ImportReplacer<C> {
self.has_dynamic_import = true; self.has_dynamic_import = true;
// Add /* webpackExports: [...] */ comment if we detected destructuring // Add /* webpackExports: [...] */ comment if we detected destructuring
if let Some(names) = self.import_export_names.remove(&call_expr.span.lo) { if let Some(names) = self.import_export_names.remove(&call_expr.span.lo)
if let Some(first_arg) = call_expr.args.first() { && let Some(first_arg) = call_expr.args.first()
let comment_text = if names.is_empty() { {
" webpackExports: [] ".to_string() let comment_text = if names.is_empty() {
} else { " webpackExports: [] ".to_string()
let names_json: Vec<String> = } else {
names.iter().map(|n| format!("\"{}\"", n)).collect(); let names_json: Vec<String> =
format!(" webpackExports: [{}] ", names_json.join(", ")) names.iter().map(|n| format!("\"{}\"", n)).collect();
}; format!(" webpackExports: [{}] ", names_json.join(", "))
self.comments.add_leading( };
first_arg.span_lo(), self.comments.add_leading(
Comment { first_arg.span_lo(),
span: DUMMY_SP, Comment {
kind: CommentKind::Block, span: DUMMY_SP,
text: comment_text.into(), kind: CommentKind::Block,
}, text: comment_text.into(),
); },
} );
} }
let replacement_expr = quote!( let replacement_expr = quote!(
......
...@@ -2,11 +2,11 @@ use std::sync::Arc; ...@@ -2,11 +2,11 @@ use std::sync::Arc;
use swc_core::{ use swc_core::{
atoms::{Atom, Wtf8Atom}, atoms::{Atom, Wtf8Atom},
common::{errors::HANDLER, SourceMap, Span}, common::{SourceMap, Span, errors::HANDLER},
ecma::{ ecma::{
ast::{ ast::{
op, BinExpr, CallExpr, Callee, CondExpr, Expr, IdentName, IfStmt, ImportDecl, Lit, BinExpr, CallExpr, Callee, CondExpr, Expr, IdentName, IfStmt, ImportDecl, Lit,
MemberExpr, MemberProp, NamedExport, UnaryExpr, MemberExpr, MemberProp, NamedExport, UnaryExpr, op,
}, },
utils::{ExprCtx, ExprExt}, utils::{ExprCtx, ExprExt},
visit::{Visit, VisitWith}, visit::{Visit, VisitWith},
...@@ -272,19 +272,17 @@ Learn more: https://nextjs.org/docs/api-reference/edge-runtime", ...@@ -272,19 +272,17 @@ Learn more: https://nextjs.org/docs/api-reference/edge-runtime",
self.guarded_symbols.push(ident.sym.clone()); self.guarded_symbols.push(ident.sym.clone());
} }
Expr::Member(member) => { Expr::Member(member) => {
if member.prop.is_ident_with("NEXT_RUNTIME") { if member.prop.is_ident_with("NEXT_RUNTIME")
if let Expr::Member(obj_member) = &*member.obj { && let Expr::Member(obj_member) = &*member.obj
if obj_member.obj.is_global_ref_to(self.ctx, "process") && obj_member.obj.is_global_ref_to(self.ctx, "process")
&& obj_member.prop.is_ident_with("env") && obj_member.prop.is_ident_with("env")
{ {
self.guarded_runtime = true; self.guarded_runtime = true;
}
}
} }
if member.obj.is_global_ref_to(self.ctx, "process") { if member.obj.is_global_ref_to(self.ctx, "process")
if let MemberProp::Ident(prop) = &member.prop { && let MemberProp::Ident(prop) = &member.prop
self.guarded_process_props.push(prop.sym.clone()); {
} self.guarded_process_props.push(prop.sym.clone());
} }
} }
Expr::Bin(BinExpr { Expr::Bin(BinExpr {
...@@ -330,10 +328,10 @@ where ...@@ -330,10 +328,10 @@ where
fn visit_call_expr(&mut self, n: &CallExpr) { fn visit_call_expr(&mut self, n: &CallExpr) {
n.visit_children_with(self); n.visit_children_with(self);
if let Callee::Import(_) = &n.callee { if let Callee::Import(_) = &n.callee
if let Some(Expr::Lit(Lit::Str(s))) = n.args.first().map(|e| &*e.expr) { && let Some(Expr::Lit(Lit::Str(s))) = n.args.first().map(|e| &*e.expr)
self.warn_if_nodejs_module(n.span, &s.value); {
} self.warn_if_nodejs_module(n.span, &s.value);
} }
} }
...@@ -371,18 +369,18 @@ where ...@@ -371,18 +369,18 @@ where
} }
fn visit_expr(&mut self, n: &Expr) { fn visit_expr(&mut self, n: &Expr) {
if let Expr::Ident(ident) = n { if let Expr::Ident(ident) = n
if ident.ctxt == self.ctx.unresolved_ctxt { && ident.ctxt == self.ctx.unresolved_ctxt
if ident.sym == "eval" { {
self.emit_dynamic_not_allowed_error(ident.span); if ident.sym == "eval" {
return; self.emit_dynamic_not_allowed_error(ident.span);
} return;
}
for api in EDGE_UNSUPPORTED_NODE_APIS { for api in EDGE_UNSUPPORTED_NODE_APIS {
if self.is_in_middleware_layer() && ident.sym == *api { if self.is_in_middleware_layer() && ident.sym == *api {
self.emit_unsupported_api_error(ident.span, api); self.emit_unsupported_api_error(ident.span, api);
return; return;
}
} }
} }
} }
...@@ -406,11 +404,11 @@ where ...@@ -406,11 +404,11 @@ where
} }
fn visit_member_expr(&mut self, n: &MemberExpr) { fn visit_member_expr(&mut self, n: &MemberExpr) {
if n.obj.is_global_ref_to(self.ctx, "process") { if n.obj.is_global_ref_to(self.ctx, "process")
if let MemberProp::Ident(prop) = &n.prop { && let MemberProp::Ident(prop) = &n.prop
self.warn_for_unsupported_process_api(n.span, prop); {
return; self.warn_for_unsupported_process_api(n.span, prop);
} return;
} }
n.visit_children_with(self); n.visit_children_with(self);
......
...@@ -2,12 +2,12 @@ use std::{iter::FromIterator, path::PathBuf}; ...@@ -2,12 +2,12 @@ use std::{iter::FromIterator, path::PathBuf};
use next_custom_transforms::transforms::{ use next_custom_transforms::transforms::{
disallow_re_export_all_in_page::disallow_re_export_all_in_page, disallow_re_export_all_in_page::disallow_re_export_all_in_page,
dynamic::{next_dynamic, NextDynamicMode}, dynamic::{NextDynamicMode, next_dynamic},
fonts::{next_font_loaders, Config as FontLoaderConfig}, fonts::{Config as FontLoaderConfig, next_font_loaders},
next_ssg::next_ssg, next_ssg::next_ssg,
react_server_components::server_components, react_server_components::server_components,
server_actions::{self, server_actions, ServerActionsMode}, server_actions::{self, ServerActionsMode, server_actions},
strip_page_exports::{next_transform_strip_page_exports, ExportFilter}, strip_page_exports::{ExportFilter, next_transform_strip_page_exports},
}; };
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use swc_core::{ use swc_core::{
...@@ -17,7 +17,7 @@ use swc_core::{ ...@@ -17,7 +17,7 @@ use swc_core::{
parser::{EsSyntax, Syntax}, parser::{EsSyntax, Syntax},
transforms::{ transforms::{
base::resolver, base::resolver,
testing::{test_fixture, FixtureTestConfig}, testing::{FixtureTestConfig, test_fixture},
}, },
}, },
}; };
......
...@@ -9,17 +9,17 @@ use next_custom_transforms::transforms::{ ...@@ -9,17 +9,17 @@ use next_custom_transforms::transforms::{
cjs_optimizer::cjs_optimizer, cjs_optimizer::cjs_optimizer,
debug_fn_name::debug_fn_name, debug_fn_name::debug_fn_name,
debug_instant_stack::debug_instant_stack, debug_instant_stack::debug_instant_stack,
dynamic::{next_dynamic, NextDynamicMode}, dynamic::{NextDynamicMode, next_dynamic},
fonts::{next_font_loaders, Config as FontLoaderConfig}, fonts::{Config as FontLoaderConfig, next_font_loaders},
named_import_transform::named_import_transform, named_import_transform::named_import_transform,
next_ssg::next_ssg, next_ssg::next_ssg,
optimize_barrel::optimize_barrel, optimize_barrel::optimize_barrel,
optimize_server_react::{self, optimize_server_react}, optimize_server_react::{self, optimize_server_react},
pure::pure_magic, pure::pure_magic,
react_server_components::server_components, react_server_components::server_components,
server_actions::{self, server_actions, ServerActionsMode}, server_actions::{self, ServerActionsMode, server_actions},
shake_exports::{shake_exports, Config as ShakeExportsConfig}, shake_exports::{Config as ShakeExportsConfig, shake_exports},
strip_page_exports::{next_transform_strip_page_exports, ExportFilter}, strip_page_exports::{ExportFilter, next_transform_strip_page_exports},
track_dynamic_imports::track_dynamic_imports, track_dynamic_imports::track_dynamic_imports,
warn_for_edge_runtime::warn_for_edge_runtime, warn_for_edge_runtime::warn_for_edge_runtime,
}; };
...@@ -27,20 +27,20 @@ use rustc_hash::FxHashSet; ...@@ -27,20 +27,20 @@ use rustc_hash::FxHashSet;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use swc_core::{ use swc_core::{
atoms::atom, atoms::atom,
common::{comments::SingleThreadedComments, FileName, Mark, SyntaxContext}, common::{FileName, Mark, SyntaxContext, comments::SingleThreadedComments},
ecma::{ ecma::{
ast::Pass, ast::Pass,
parser::{EsSyntax, Syntax, TsSyntax}, parser::{EsSyntax, Syntax, TsSyntax},
transforms::{ transforms::{
base::resolver, base::resolver,
react::jsx, react::jsx,
testing::{test_fixture, FixtureTestConfig}, testing::{FixtureTestConfig, test_fixture},
}, },
utils::ExprCtx, utils::ExprCtx,
visit::{visit_mut_pass, visit_pass, Visit}, visit::{Visit, visit_mut_pass, visit_pass},
}, },
}; };
use swc_relay::{relay, RelayLanguageConfig}; use swc_relay::{RelayLanguageConfig, relay};
use testing::fixture; use testing::fixture;
fn syntax() -> Syntax { fn syntax() -> Syntax {
......
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use next_custom_transforms::chain_transforms::{custom_before_pass, TransformOptions}; use next_custom_transforms::chain_transforms::{TransformOptions, custom_before_pass};
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use swc_core::{ use swc_core::{
base::Compiler, base::Compiler,
common::{comments::SingleThreadedComments, Mark}, common::{Mark, comments::SingleThreadedComments},
ecma::{ ecma::{
ast::noop_pass, ast::noop_pass,
parser::{Syntax, TsSyntax}, parser::{Syntax, TsSyntax},
......
...@@ -5,8 +5,8 @@ use once_cell::sync::Lazy; ...@@ -5,8 +5,8 @@ use once_cell::sync::Lazy;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use swc_core::{ use swc_core::{
atoms::Atom, atoms::Atom,
base::{try_with_handler, Compiler}, base::{Compiler, try_with_handler},
common::{comments::SingleThreadedComments, FileName, FilePathMapping, SourceMap, GLOBALS}, common::{FileName, FilePathMapping, GLOBALS, SourceMap, comments::SingleThreadedComments},
ecma::ast::noop_pass, ecma::ast::noop_pass,
}; };
......
[package] [package]
edition = "2018" edition = "2024"
name = "wasm" name = "wasm"
publish = false publish = false
version = "0.0.0" version = "0.0.0"
......
...@@ -2,17 +2,18 @@ use std::{fmt::Debug, sync::Arc}; ...@@ -2,17 +2,18 @@ use std::{fmt::Debug, sync::Arc};
use anyhow::Context; use anyhow::Context;
use js_sys::JsString; use js_sys::JsString;
use next_custom_transforms::chain_transforms::{custom_before_pass, TransformOptions}; use next_custom_transforms::chain_transforms::{TransformOptions, custom_before_pass};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use swc_core::{ use swc_core::{
base::{ base::{
Compiler,
config::{JsMinifyOptions, ParseOptions}, config::{JsMinifyOptions, ParseOptions},
try_with_handler, Compiler, try_with_handler,
}, },
common::{ common::{
FileName, FilePathMapping, GLOBALS, Mark, SourceMap,
comments::{Comments, SingleThreadedComments}, comments::{Comments, SingleThreadedComments},
errors::ColorConfig, errors::ColorConfig,
FileName, FilePathMapping, Mark, SourceMap, GLOBALS,
}, },
ecma::ast::noop_pass, ecma::ast::noop_pass,
}; };
......
use js_sys::JsString; use js_sys::JsString;
use mdxjs::{compile, Options}; use mdxjs::{Options, compile};
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::future_to_promise; use wasm_bindgen_futures::future_to_promise;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment