Skip to content

Commit f508d17

Browse files
fix: Adapt to swc_core v77 AST changes
- `Function::body` is now `Option<FunctionBody>` instead of `Option<BlockStmt>` - `JSXText::value` is now `Wtf8Atom` instead of `Atom` Co-authored-by: Donny/강동윤 <29931815+kdy1@users.noreply.github.com>
1 parent 06db144 commit f508d17

5 files changed

Lines changed: 33 additions & 31 deletions

File tree

contrib/mut-cjs-exports/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl TransformVisitor {
199199
vec![Function {
200200
params: vec![key.clone().into()],
201201
span: DUMMY_SP,
202-
body: Some(BlockStmt {
202+
body: Some(FunctionBody {
203203
stmts: vec![
204204
// if (key === "default" || key === "__esModule") return;
205205
IfStmt {

contrib/mut-cjs-exports/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(crate) fn prop_method_setter(ident: Ident) -> Prop {
3535
let setter_param = private_ident!("v");
3636
let params = vec![setter_param.clone().into()];
3737

38-
let body = BlockStmt {
38+
let body = FunctionBody {
3939
stmts: vec![setter_param
4040
.make_assign_to(op!("="), ident.clone().into())
4141
.into_stmt()],

packages/loadable-components/src/lib.rs

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use swc_plugin_macro::plugin_transform;
2121
use swc_plugin_proxy::{PluginCommentsProxy, TransformPluginProgramMetadata};
2222
use tracing::debug;
2323

24-
use crate::util::get_import_arg;
24+
use crate::util::{expect_fn_body, get_import_arg};
2525

2626
mod util;
2727

@@ -384,7 +384,7 @@ where
384384
key: PropName::Ident(quote_ident!("chunkName")),
385385
function: Box::new(Function {
386386
params: clone_params(func),
387-
body: Some(BlockStmt {
387+
body: Some(FunctionBody {
388388
stmts: vec![Stmt::Return(ReturnStmt {
389389
span: DUMMY_SP,
390390
arg: Some(Box::new(self.replace_chunk_name(import))),
@@ -407,9 +407,8 @@ where
407407
decorators: Default::default(),
408408
pat: Pat::Ident(quote_ident!("props").into()),
409409
}],
410-
body: Some(
411-
quote!(
412-
"
410+
body: Some(expect_fn_body(quote!(
411+
"
413412
{
414413
const key=this.resolve(props)
415414
if (this.resolved[key] !== true) {
@@ -423,9 +422,7 @@ where
423422
return false
424423
}
425424
" as Stmt
426-
)
427-
.expect_block(),
428-
),
425+
))),
429426
is_generator: false,
430427
is_async: false,
431428
..Default::default()
@@ -449,9 +446,8 @@ where
449446
decorators: Default::default(),
450447
pat: Pat::Ident(quote_ident!("props").into()),
451448
}],
452-
body: Some(
453-
quote!(
454-
"
449+
body: Some(expect_fn_body(quote!(
450+
"
455451
{
456452
const key = this.resolve(props)
457453
this.resolved[key] = false
@@ -461,9 +457,7 @@ where
461457
});
462458
}
463459
" as Stmt
464-
)
465-
.expect_block(),
466-
),
460+
))),
467461
is_generator: false,
468462
is_async: false,
469463
..Default::default()
@@ -480,9 +474,8 @@ where
480474
decorators: Default::default(),
481475
pat: Pat::Ident(quote_ident!("props").into()),
482476
}],
483-
body: Some(
484-
quote!(
485-
"
477+
body: Some(expect_fn_body(quote!(
478+
"
486479
{
487480
const id = this.resolve(props)
488481
@@ -493,9 +486,7 @@ where
493486
return eval('module.require')(id)
494487
}
495488
" as Stmt
496-
)
497-
.expect_block(),
498-
),
489+
))),
499490
is_generator: false,
500491
is_async: false,
501492
..Default::default()
@@ -514,9 +505,8 @@ where
514505
key: PropName::Ident(quote_ident!("resolve")),
515506
function: Box::new(Function {
516507
params: clone_params(func),
517-
body: Some(
518-
quote!(
519-
"
508+
body: Some(expect_fn_body(quote!(
509+
"
520510
{
521511
if (require.resolveWeak) {
522512
return require.resolveWeak($id)
@@ -525,10 +515,8 @@ where
525515
return eval('require.resolve')($id)
526516
}
527517
" as Stmt,
528-
id: Expr = get_call_value(import)
529-
)
530-
.expect_block(),
531-
),
518+
id: Expr = get_call_value(import)
519+
))),
532520
is_generator: false,
533521
is_async: false,
534522
..Default::default()

packages/loadable-components/src/util.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,14 @@ use swc_core::ecma::ast::*;
33
pub(crate) fn get_import_arg(call: &CallExpr) -> &Expr {
44
&call.args[0].expr
55
}
6+
7+
/// `quote!` can only produce a `Stmt`, so quoted function bodies are parsed as
8+
/// a block statement and converted here.
9+
pub(crate) fn expect_fn_body(stmt: Stmt) -> FunctionBody {
10+
let block = stmt.expect_block();
11+
12+
FunctionBody {
13+
span: block.span,
14+
stmts: block.stmts,
15+
}
16+
}

packages/styled-jsx/transform/src/visitor.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,11 @@ fn get_style_expr(el: &JSXElement) -> Result<StyleExpr, Error> {
824824
.iter()
825825
.filter(|child| {
826826
if let JSXElementChild::JSXText(txt) = child {
827-
if txt.value.chars().all(char::is_whitespace) {
828-
return false;
827+
// A text node containing lone surrogates is never whitespace-only.
828+
if let Some(value) = txt.value.as_atom() {
829+
if value.chars().all(char::is_whitespace) {
830+
return false;
831+
}
829832
}
830833
}
831834
true

0 commit comments

Comments
 (0)