Skip to content

RuntimeError (panic) in JSX parser when encountering surrogate entitie #11802

@cuyl

Description

@cuyl

Describe the bug

Got an error: RuntimeError: unreachable

Input code

"use client";

export default function Hello() {
  return (
   <div title="&#xD83E;&#xDD80;&#xDD80;&#xDD80;&55358;&56704;" >&#xD83E;&#xDD80;</div>
  );
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": true
    },
    "target": "es2024",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Link to the code that reproduces this issue

https://play.swc.rs/?version=1.15.26&code=H4sIAAAAAAAAA2XMwQrCMBCE4fs%2BxRBB2pOFGg2k7amCryHtFgIhKXFTCuK7G696%2BuYyv8pPxuQdB1GWiPc1JsHMyyN7wZLDJC4G3Nn7WNV4EZBYcgqoykQ3uw3ixHOvjod9NO3Nfh1N86%2FWrTaFy7U5W4Xh99CdSm0o2drSmz7AIZCMmgAAAA%3D%3D&config=H4sIAAAAAAAAA1WPSw7DIAxE9zkF8rqLKqq66B16CIs6ERE%2FYSIVRbl7CQHa7vCbGcbeBiFgYQkPseVnHjwGptDnTDjZiO9MgKRBlkH5CJemLnxIMaxUyH4KEDHMFEuIx%2Bt4qwHQzjFlPKFmqswoq6b0Wymd8YGY%2F42HFe2se%2F5sHGorGPdai1hPicnTucEdvqZW1j8Gxc%2BWLHfsH%2BoMFmcWAQAA

SWC Info output

No response

Expected behavior

The parser should:

  1. Support UTF-16 surrogate pairs represented as consecutive JSX entities (e.g., "&#xD83E;&#xDD80;" should decode to 🦀).
  2. Handle invalid or unpaired surrogates gracefully without panicking.
  3. Return a SyntaxError instead of panicking if a numeric entity value is invalid.

Actual behavior

No response

Version

1.15.26

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions