swc-project/swc · error

getter/setter property be compiled as CompiledProp::Accessor

Error message

getter/setter property be compiled as CompiledProp::Accessor

What it means

In the same object-literal emission path of the es2015 generator pass, getter and setter properties are expected to have been folded into CompiledProp::Accessor variants by earlier logic in the pass (it pairs getter/setter pairs onto one accessor). A raw Prop::Getter/Prop::Setter reaching this match means that earlier collection step did not classify them, so the unreachable! fires as an internal invariant of the pass.

Source

Thrown at crates/swc_ecma_compat_es2015/src/generator.rs:1329

                }
                .into(),
                Prop::KeyValue(p) => AssignExpr {
                    span: DUMMY_SP,
                    op: op!("="),
                    left: MemberExpr {
                        span: DUMMY_SP,
                        obj: temp.clone().into(),
                        prop: p.key.into(),
                    }
                    .into(),
                    right: p.value,
                }
                .into(),
                Prop::Assign(_) => {
                    unreachable!("assignment property be removed before generator pass")
                }
                Prop::Getter(_) | Prop::Setter(_) => {
                    unreachable!("getter/setter property be compiled as CompiledProp::Accessor")
                }
                Prop::Method(p) => AssignExpr {
                    span: DUMMY_SP,
                    op: op!("="),
                    left: MemberExpr {
                        span: DUMMY_SP,
                        obj: temp.clone().into(),
                        prop: p.key.into(),
                    }
                    .into(),
                    right: p.function.into(),
                }
                .into(),
                #[cfg(swc_ast_unknown)]
                _ => panic!("unable to access unknown nodes"),
            },
            CompiledProp::Accessor(getter, setter) => {
                let key = getter

View on GitHub (pinned to 5176682b65)

Solutions

  1. Update swc_core/swc_ecma_compat_es2015 — accessor handling regressions get fixed quickly when reported.
  2. Remove any custom passes that mutate ObjectLit props between the accessor-collection and emission phases; run the generator pass on unmodified parse output.
  3. Reduce the repro (generator function containing `{ get x() {...}, set x(v) {...} }`) and file an swc issue.
Defensive patterns

Strategy: validation

Validate before calling

// Prefer unmodified parse output for the generator pass; if you must mutate,
// verify accessors still pair up
fn accessor_pairs_sane(o: &ObjectLit) -> bool {
    // no duplicate raw Getter/Setter with identical keys after your mutation
    let mut keys = std::collections::HashSet::new();
    o.props.iter().all(|p| match p {
        PropOrSpread::Prop(p) => match &**p {
            Prop::Getter(g) => keys.insert(format!("{:?}", g.key)),
            Prop::Setter(s) => keys.insert(format!("{:?}", s.key)),
            _ => true,
        },
        _ => true,
    })
}

Prevention

When it happens

Trigger: An object literal inside a generator/async body whose getter/setter property was not recognized by the CompiledProp collection step — e.g. unusual computed keys, spread mixed with accessors, or an AST produced/mutated by a custom pass that desynced the two code paths.

Common situations: Third-party AST transforms mutating object literals between passes; swc version regressions in the generator pass; hand-built ASTs with accessor props.

Related errors


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/aa4513044077239e. Report an issue: GitHub.