Skip to content

topLevelVar does not apply to exported const/let` declarations #8506

@IWANABETHATGUY

Description

@IWANABETHATGUY

Discussed in #8505

Originally posted by victordidenko March 1, 2026
Or am I misunderstood it?

Code

export const x = 1
export function y() {
  let x = {}
  x.a = 1
  return x
}

with config

export default {
  output: {
    topLevelVar: true,
  },
}

generates

//#region index.js
const x = 1;
function y() {
	let x = {};
	x.a = 1;
	return x;
}

//#endregion
export { x, y };

(repl)

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions