rollup/rollup

Setting `moduleSideEffects: false` removes side effectful getter inside a exported function since 4.9.2

sapphi-red opened this issue · 2 comments

Rollup Version

4.12.0 (since 4.9.2)

Operating System (or Browser)

StackBlitz

Node Version (if applicable)

No response

Link To Reproduction

https://stackblitz.com/edit/rollup-repro-3brsqu?file=src%2FsupportsPassive.js,dist%2Fmain.js

Expected Behaviour

supportsPassive is not removed.

const supportsPassive = (() => {
  // simular to jQuery's test
  let supported = false;
  try {
    addEventListener(
      'test',
      () => {
        // do nothing
      },
      Object.defineProperty({}, 'passive', {
        get() {
          supported = true;
          return true;
        },
      })
    );
  } catch (e) {
    // do nothing
  }
  return supported;
})();

class TouchBackendImpl {
  addEventListener() {
    const options = supportsPassive ? { capture, passive: false } : capture;
    console.log(options);
  }
}

export { TouchBackendImpl };

Actual Behaviour

supportsPassive is removed;

class TouchBackendImpl {
  addEventListener() {
    const options = capture;
    console.log(options);
  }
}

export { TouchBackendImpl };

Additional Information

This happens with 4.9.2 and doesn't happen with 4.9.1. I guess #5322 is related.

Original issue: vitejs/vite#16065