Skip to content

topLevelVar

  • Type: boolean
  • Optional

Whether to convert top-level let and const declarations into var declarations.

Enabling this option can improve runtime performance of the generated code in certain environments by avoiding Temporal Dead Zone (TDZ) checks. Only declarations in the module's top-level scope are rewritten — declarations inside nested scopes (functions, blocks, etc.) are left as-is.

Note:

  • Top-level class X {} declarations are always emitted as var X = class {} so rolldown can hoist them alongside other top-level bindings; this transform is independent of topLevelVar.
  • Top-level function declarations are never rewritten.

Default

false

In-depth

Multiple JavaScript engines have had and continue to have performance issues with Temporal dead zone (TDZ) checks. These checks validate that a let, const, or class symbol isn't used before it's initialized.

Related issues: