//rolldown-private-field-bugbyproductdevbook

rolldown-private-field-bug

Minimal reproduction for rolldown/rolldown#7843 - private field helper variable shadowing

0
0
0
JavaScript

Rolldown Private Field Helper Variable Shadowing Bug

Issue

https://github.com/rolldown/rolldown/issues/7843

Reproduction

pnpm install
pnpm build
pnpm preview
# Open http://localhost:4173 in browser
# Check console for error: "TypeError: n is not a function"

Description

When Vite 8 (with rolldown) bundles @electric-sql/pglite, the minifier assigns the same variable name n to both:

  1. A global guard function for private field access
  2. A function parameter in the helper

This causes variable shadowing and runtime error.

Evidence

In dist/assets/index-*.js:

// Guard function - checks if object has private field
n=(e,t,n)=>t.has(e)||a(`Cannot `+n)

// Helper - parameter 'n' shadows global 'n'!
x$3=(e,t,n,r)=>(n(e,t,`write to private field`),r?r.call(e,n):t.set(e,n),n)
//        ↑ this 'n' shadows the guard function above

When x$3 calls n(e,t,...), it’s calling the parameter (a value) instead of the guard function.

Expected

Different variable names should be used:

_guard=(e,t,msg)=>t.has(e)||a(`Cannot `+msg)
x$3=(e,t,val,setter)=>(_guard(e,t,`write...`),...)

Environment

  • Vite: 8.0.0-beta.7
  • pglite: 0.3.14
  • Node: 24.x
[beta]v0.14.0