swc-project/swc · error

assign property in object literal is not a valid syntax

Error message

assign property in object literal is not a valid syntax

What it means

A catch-all arm in the side-effect analysis over object literal properties (swc_ecma_utils lib.rs:1955). The match covers KeyValue, Getter, Setter, Method, and Shorthand props; any unrecognized or unrepresentable prop shape (for example an assignment pattern used as a property value, which is not valid object-literal syntax in swc's Prop grammar) falls into this arm, which declares that shape invalid syntax for an object literal property. The prop node that is not one of the recognized kinds is the input at fault.

Source

Thrown at crates/swc_ecma_utils/src/lib.rs:1955

                            if let PropName::Computed(e) = key {
                                if e.expr.may_have_side_effects(self) {
                                    return true;
                                }
                            }

                            value.may_have_side_effects(self)
                        }
                        Prop::Getter(GetterProp { key, .. })
                        | Prop::Setter(SetterProp { key, .. })
                        | Prop::Method(MethodProp { key, .. }) => {
                            if let PropName::Computed(e) = key {
                                e.expr.may_have_side_effects(self)
                            } else {
                                false
                            }
                        }
                        Prop::Assign(..) => {
                            unreachable!("assign property in object literal is not a valid syntax")
                        }
                        #[cfg(swc_ast_unknown)]
                        _ => true,
                    },
                    PropOrSpread::Spread(SpreadElement { .. }) => {
                        has_spread = true;
                        true
                    }
                    #[cfg(swc_ast_unknown)]
                    _ => true,
                });

                if has_spread {
                    to.push(ObjectLit { span, props }.into())
                } else {
                    props.into_iter().for_each(|prop| match prop {
                        PropOrSpread::Prop(node) => match *node {
                            Prop::Shorthand(..) => {}

View on GitHub (pinned to 5176682b65)

Solutions

  1. Identify the Prop variant that reached the arm (log it) — it indicates an AST produced outside normal swc parsing
  2. Normalize shorthand-with-default properties into key-value form with a default-handling transform before analysis
  3. Treat the invalid prop conservatively as side-effecting (return true) instead of panicking
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/swc_ecma_utils/src/lib.rs:1955 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/636a63231afaf31a. Report an issue: GitHub.