swc-project/swc · error

JSXNamespacedName -> JSXObject

Error message

JSXNamespacedName -> JSXObject

What it means

In the JSX parser, after a tag name is parsed you may continue with `.prop` segments (`<Foo.Bar />`). When the already-parsed node is a `JSXNamespacedName` (`<ns:tag>`) and a dot follows, converting the namespaced name into the `JSXObject` of a member expression is unsupported and the parser panics with `unimplemented!`.

Source

Thrown at crates/swc_ecma_lexer/src/common/parser/jsx.rs:114

/// identifier.
fn parse_jsx_element_name<'a, P: Parser<'a>>(p: &mut P) -> PResult<JSXElementName> {
    debug_assert!(p.input().syntax().jsx());
    trace_cur!(p, parse_jsx_element_name);
    let start = p.input().cur_pos();
    let mut node = match parse_jsx_namespaced_name(p)? {
        JSXAttrName::Ident(i) => JSXElementName::Ident(i.into()),
        JSXAttrName::JSXNamespacedName(i) => JSXElementName::JSXNamespacedName(i),
        #[cfg(swc_ast_unknown)]
        _ => unreachable!(),
    };
    while p.input_mut().eat(&P::Token::DOT) {
        let prop = parse_jsx_ident(p).map(IdentName::from)?;
        let new_node = JSXElementName::JSXMemberExpr(JSXMemberExpr {
            span: p.span(start),
            obj: match node {
                JSXElementName::Ident(i) => JSXObject::Ident(i),
                JSXElementName::JSXMemberExpr(i) => JSXObject::JSXMemberExpr(Box::new(i)),
                _ => unimplemented!("JSXNamespacedName -> JSXObject"),
            },
            prop,
        });
        node = new_node;
    }
    Ok(node)
}

/// JSXEmptyExpression is unique type since it doesn't actually parse
/// anything, and so it should start at the end of last read token (left
/// brace) and finish at the beginning of the next one (right brace).
pub fn parse_jsx_empty_expr<'a>(p: &mut impl Parser<'a>) -> JSXEmptyExpr {
    debug_assert!(p.input().syntax().jsx());
    let start = p.input().cur_pos();
    JSXEmptyExpr {
        span: Span::new_with_checked(start, start),
    }
}

View on GitHub (pinned to d7d7434666)

Solutions

  1. Fix the JSX: use either `<ns:tag />` or `<Obj.tag />`, never `<ns:tag.prop />`
  2. Pre-validate generated JSX before handing it to swc
  3. Report upstream if you believe the input is spec-valid

Example fix

// before
const el = <svg:circle.cx />;

// after
const el = <circle cx={cx} />;
Defensive patterns

Strategy: validation

Validate before calling

// Reject namespaced-then-member JSX tags before parsing
const malformed = /<[A-Za-z][\w.-]*:[\w-]+\./;
if (malformed.test(jsxSource)) throw new Error('namespaced tag with member access is not valid JSX');

Prevention

When it happens

Trigger: Parse JSX containing a namespaced tag immediately followed by member access, e.g. `<svg:use.x />` — i.e. the shape `<ns:name.prop>`, which is not valid JSX to begin with.

Common situations: Malformed JSX produced by template engines or string concatenation; fuzzers; editor auto-complete inserting a dot after a namespaced tag; programmatic JSX construction.

Related errors


AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16). Data as JSON: /api/errors/0036a6a8227d7bfb. Report an issue: GitHub.