-
Notifications
You must be signed in to change notification settings - Fork 710
Labels
Description
Reproduction link or steps
I discovered this issue while using the beta versions of Vite and Vue. here's the error example:
For comparison, here's the same example in Rollup.
Here's the example code listed below for easy reference.
const isFunction = (val) => typeof val === "function";
const extend = Object.assign;
const h = (a, b, c) => {}
// @__NO_SIDE_EFFECTS__
function defineComponent(options, extraOptions = {}) {
// 1. no problem if use a ternary conditional statement
// return isFunction(options) ? (
// /* @__PURE__ */ (() => extend({ name: options.name }, extraOptions, { setup: options }))()
// ) : options;
// 2. wrong tree sharking
if (isFunction(options)) {
return /* @__PURE__ */ (() => extend({ name: options.name }, extraOptions, { setup: options }))()
}
return options
}
const bar = defineComponent(() => h('div', null, 'hello world'))
console.log(bar) // side-effectWhat is expected?
Works just like Rollup.
What is actually happening?
The code was incorrectly removed by tree shaking.
System Info
System:
OS: macOS 15.6.1
CPU: (8) arm64 Apple M1
Memory: 274.03 MB / 16.00 GB
Shell: 4.0.0 - /opt/homebrew/bin/fish
Binaries:
Node: 22.14.0 - /Users/zhylmzr/.volta/tools/image/node/22.14.0/bin/node
Yarn: 4.5.3 - /Users/zhylmzr/.volta/tools/image/yarn/4.5.3/bin/yarn
npm: 10.9.2 - /Users/zhylmzr/.volta/tools/image/node/22.14.0/bin/npm
pnpm: 9.8.0 - /Users/zhylmzr/.volta/bin/pnpm
bun: 1.3.5 - /Users/zhylmzr/.bun/bin/bun
Watchman: 2025.11.10.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 143.0.7499.170
Safari: 18.6Any additional comments?
No response
Reactions are currently unavailable