Skip to content

[Bug]: Pure-annotated IIFE returning an array is inlined #9437

@filipsobol

Description

@filipsobol

Reproduction link or steps

Rolldown REPL: https://repl.rolldown.rs/#eNptjr0KwkAQhF9lOAsTkYhtRAvFXgQrT0IwGzlI9iTZUyHcu3vG38Jqf2e+6VSp0k4ZLuiWSPvoWaXfeayOYaTb2TaCo+VW4Ni1VCwxx2SEQZZtdtt1lmE0QYQoxnyBvWYtU80HxFE80xxcSKXSOPJj1diqKuyVk+BWmtMP9M/liTd1j+9QUGmYVv0ZHmVjawzfsmGg8itpeMxd1dePIOo0A4bPTlI8LZOaJE/6lWYfh6Q+JLwEZJULtaL8HVkfYKg=

Rollup REPL: https://rollupjs.org/repl/?version=4.60.4&shareable=eyJleGFtcGxlIjpudWxsLCJtb2R1bGVzIjpbeyJjb2RlIjoiZXhwb3J0IGNvbnN0IHVudXNlZEJ5Q29uc3VtZXIgPSAvKiAjX19QVVJFX18gKi8gKCAoKSA9PiBbXG5cdDFcbl0gKSgpO1xuIiwiaXNFbnRyeSI6dHJ1ZSwibmFtZSI6Im1haW4uanMifV0sIm9wdGlvbnMiOnt9fQ==

What is expected?

Rolldown should preserve the pure-annotated IIFE around the array initializer:

const SOME_DATA = /* #__PURE__ */ ( () => [
  1,
  2,
  3
] )();

Rollup preserves this format, so compared to Rollup this looks like a regression.

What is actually happening?

Rolldown inlines the pure-annotated IIFE and emits the array directly:

const SOME_DATA = [
  1,
  2,
  3
];

This removes the call boundary that was intentionally added by the source code.

System Info

Rolldown: `v1.0.0`

Any additional comments?

We intentionally wrap some arrays in a pure-annotated IIFE because some downstream bundlers struggle with tree-shaking arrays. The IIFE form helps those bundlers recognize that the initializer can be dropped when the export is unused.

Since Rollup preserves the original IIFE form and Rolldown rewrites it to a direct array initializer, this creates a migration issue when replacing Rollup with Rolldown.

Metadata

Metadata

Assignees

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions