Skip to content

oxc-transform panics on a[b?.c!]?.["d"] 😱 when target lowers optional chaining #22246

@erictheswift

Description

@erictheswift

Versions: oxc-transform@0.127.0 (also oxc-parser@0.127.0), Node v24

  import {transformSync} from "oxc-transform";                                                                                                                                                                                          
  const src = `const x = a[b?.c!]?.["d"];`;                                                                                                                                      
  transformSync("repro.ts", src, {lang: "ts", target: ["es2018"]});

Results in

  thread '<unnamed>' panicked at crates/oxc_ast/src/ast/js.rs:1085:1:                                                                                                                                                                   
  called `Option::unwrap()` on a `None` value                                                                                                                                    

Trigger conditions (all required):

  • TS non-null assertion (!) on an expression containing ?.,
  • used as a computed (bracket) member key,
  • the surrounding expression is itself an optional chain (obj[…]?.member),
  • target lowers optional chaining (any < ES2020 / Safari < 14 / Chrome < 80, etc.).

Workarounds (each avoids the panic):

  • drop the !: a[b?.c]?.["d"]
  • non-optional outer access: a[b?.c!]["d"]
  • parenthesize inner: a[(b?.c)!]?.["d"]
  • target: "esnext" (no lowering)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-transformerArea - Transformer / Transpiler

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions