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 asvar X = class {}so rolldown can hoist them alongside other top-level bindings; this transform is independent oftopLevelVar. - Top-level
functiondeclarations 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:
- V8: https://issues.chromium.org/issues/42203665
- JavaScriptCore: https://bugs.webkit.org/show_bug.cgi?id=199866 (fixed)
