Skip to content

[Bug]: Nullish coalescing in case clause in strict mode throws ReferenceError #6328

@p51lee

Description

@p51lee

Describe the bug

input.js is expected to be terminated without error but the transpiled code throws ReferenceError.

Input code

"use strict";
switch ( 0 ) { case 0 ?? 0 : }

Config

No response

Playground link

https://play.swc.rs/?version=1.3.11&code=H4sIAAAAAAAAA1MqLU5VKC4pykwuUbLmKi7PLEnOUNBQMFDQVKhWSE4EShoo2NsDCSuFWgBB29PhLAAAAA%3D%3D&config=H4sIAAAAAAAAA0WMTQrEIAxG75K1286id5hDBCctFv9IUhgR714tlu7C915ehUMsrBUyshCPS0pU%2FMMKZAOKZZcVTNf6tKEXagYUeScdiiyd%2BZSEJjUQXHRbGSWbQmYSeRHG3T9m66GQfucYKmjJdAc%2F0N7G%2FHPynaLySe0Cj9ke9LUAAAA%3D

Expected behavior

The input code terminates without error:

$ node input.js
// terminates without error

Actual behavior

The transpiled code throws ReferenceError:

$ node output.js
output.js:3
    case (ref = 0) !== null && ref !== void 0 ? ref : 0:
              ^

ReferenceError: ref is not defined
    at Object.<anonymous> (/Users/p51lee/dev/esmeta-plrg/output.js:3:15)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.11.0

Version

1.3.11 (default SWC playground)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions