swc-project/swc · error
as_bool() for JSXText
Error message
as_bool() for JSXText
What it means
An unreachable!() arm in as_bool (swc_ecma_utils lib.rs:3028). The function statically evaluates which literals are truthy (numbers, bigints, bools, strings, null, regex...); JSXText is not a boolean-context literal — JSX text used in an expression position has no truthiness semantics that swc models, so reaching this arm means a JSXText literal was fed to as_bool, a case the evaluator deliberately refuses. The JSXText literal is the input at fault.
Source
Thrown at crates/swc_ecma_utils/src/lib.rs:3028
Expr::Unary(UnaryExpr {
op: op!("void"), ..
}) => Known(false),
Expr::Lit(ref lit) => {
return (
Pure,
Known(match *lit {
Lit::Num(Number { value: n, .. }) => is_truthy_number(n),
Lit::BigInt(ref v) => v
.value
.to_string()
.contains(|c: char| matches!(c, '1'..='9')),
Lit::Bool(b) => b.value,
Lit::Str(Str { ref value, .. }) => !value.is_empty(),
Lit::Null(..) => false,
Lit::Regex(..) => true,
Lit::JSXText(..) => unreachable!("as_bool() for JSXText"),
#[cfg(swc_ast_unknown)]
_ => return (Pure, Unknown),
}),
);
}
//TODO?
_ => Unknown,
};
if expr.may_have_side_effects(ctx) {
(MayBeImpure, val)
} else {
(Pure, val)
}
}
fn cast_to_number(expr: &Expr, ctx: ExprCtx) -> (Purity, Value<f64>) {View on GitHub (pinned to 5176682b65)
Solutions
- Check the expression kind before calling as_bool and skip JSXText-bearing expressions
- Return Known(true)/Unknown for JSXText instead of panicking if a conservative answer is acceptable
- Avoid feeding JSX-containing ASTs into boolean static-evaluation passes
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at crates/swc_ecma_utils/src/lib.rs:3028 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/e74f198fb0e68f7b.
Report an issue: GitHub.