-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
Describe the bug
It seems that since version 1.15.4, under just some circumstances, the temporary variable used in ?? nullish coalescing doesn't get declared, leading to errors in the resulting code.
Input code
export default function DropdownNavbarItemDesktop({
items,
...props
}: Props): ReactNode {
return (
<div>
<NavbarNavLink
onClick={props.to ? undefined : (e) => e.preventDefault()}
>
{props.children ?? props.label}
</NavbarNavLink>
</div>
);
}Config
N/ALink to the code that reproduces this issue
SWC Info output
Operating System:
Platform: darwin
Arch: arm64
Machine Type: arm64
Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000
CPU: (10 cores)
Models: Apple M1 Max
Binaries:
Node: 22.18.0
npm: 10.9.3
Yarn: 4.8.1
pnpm: N/A
Relevant Packages:
@swc/core: 1.15.5
@swc/helpers: 0.5.17
@swc/types: 0.1.25
typescript: 5.7.3
SWC Config:
output: N/A
.swcrc path: N/A
Next.js info:
output: N/A
Expected behavior
// props.children ?? props.label
var _props_children;
(_props_children = props.children) !== null && _props_children !== void 0 ? _props_children : props.labelThis was working in 1.15.3.
Actual behavior
// props.children ?? props.label
(_props_children = props.children) !== null && _props_children !== void 0 ? _props_children : props.labelThe temporary variable that created for the initial LHS assignment for the ?? operator never gets declared.
This worked correctly in 1.15.3, but is broken in 1.15.4 and newer.
Version
1.15.4
Additional context
No response
Rugvip, drodil and benjdlambert