{"record":{"id":"6697c936ed19b24c","repo":"swc-project/swc","slug":"add-effects-for-class-expression","errorCode":null,"errorMessage":"add_effects for class expression","messagePattern":"add_effects for class expression","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_utils/src/lib.rs","lineNumber":2021,"sourceCode":"                    self.extract_side_effects_to(v, *e.expr);\n\n                    v\n                });\n            }\n\n            Expr::TaggedTpl(TaggedTpl { tag, tpl, .. }) => {\n                self.extract_side_effects_to(to, *tag);\n\n                tpl.exprs\n                    .into_iter()\n                    .for_each(|e| self.extract_side_effects_to(to, *e));\n            }\n            Expr::Tpl(Tpl { exprs, .. }) => {\n                exprs\n                    .into_iter()\n                    .for_each(|e| self.extract_side_effects_to(to, *e));\n            }\n            Expr::Class(ClassExpr { .. }) => unimplemented!(\"add_effects for class expression\"),\n\n            Expr::JSXMember(..)\n            | Expr::JSXNamespacedName(..)\n            | Expr::JSXEmpty(..)\n            | Expr::JSXElement(..)\n            | Expr::JSXFragment(..) => to.push(Box::new(expr)),\n\n            Expr::TsTypeAssertion(TsTypeAssertion { expr, .. })\n            | Expr::TsNonNull(TsNonNullExpr { expr, .. })\n            | Expr::TsAs(TsAsExpr { expr, .. })\n            | Expr::TsConstAssertion(TsConstAssertion { expr, .. })\n            | Expr::TsInstantiation(TsInstantiation { expr, .. })\n            | Expr::TsSatisfies(TsSatisfiesExpr { expr, .. }) => {\n                self.extract_side_effects_to(to, *expr)\n            }\n            Expr::OptChain(..) => to.push(Box::new(expr)),\n\n            Expr::Invalid(..) => unreachable!(),","sourceCodeStart":2003,"sourceCodeEnd":2039,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/swc_ecma_utils/src/lib.rs#L2003-L2039","documentation":"`ExprCtx::extract_side_effects_to` in swc_ecma_utils walks an expression to keep only its side-effectful parts; it handles calls, member accesses, unary/seq/assign, tagged templates, etc., but class expressions panic because their side effects (extends clause, computed keys, decorators) are not modeled. The optimizer's expr simplifier and the minifier call it when collapsing member accesses on array literals into sequence expressions.","triggerScenarios":"Run the optimizer's simplify pass or jsc.minify compress over code where an array literal containing a class expression is reordered — e.g. `[class {}, x, y][1]` — so preceding elements must be reduced to side effects.","commonSituations":"Minifying third-party bundles; codebases that register class expressions in arrays (DI containers, metadata registries); enabling member-expression simplification on literals under jsc.minify.compress or the optimizer.","solutions":["Disable the triggering optimization: turn off jsc.minify (or the specific simplify/compress pass) for files that hit this","Refactor class expressions inside array literals into const declarations before the array","Reduce to a minimal repro and report upstream — the `Expr::Class` arm of extract_side_effects_to needs an implementation"],"exampleFix":"// before\nconst x = [class {}, 1][1];\n\n// after\nconst _c = class {};\nconst x = [_c, 1][1];","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"// Rust: detect class expressions inside array literals that may be simplified\nfn array_literal_contains_class(e: &Expr) -> bool {\n    matches!(e, Expr::Array(ArrayLit { elems, .. })\n        if elems.iter().flatten().any(|el| matches!(&*el.expr, Expr::Class(..))))\n}","tryCatchPattern":"// Rust: isolate minification of untrusted bundles\nlet out = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    minify(source, &options)\n}));\nmatch out {\n    Ok(r) => r,\n    Err(_) => { /* log the panic and fall back to minify with compress disabled for this file */ }\n}","preventionTips":["Provide a fallback path that re-runs files failing under jsc.minify with compress/simplify disabled","Avoid class expressions as direct array-literal elements in code destined for minification","Report the input upstream — each panic here is a missing Expr::Class arm in side-effect extraction"],"tags":["minifier","optimizer","class-expression","side-effects"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}