Skip to content

Using a function imported from another file as a default value in withDefaults may prevent it from being tree-shakenΒ #12625

Closed
@wattanx

Description

@wattanx

Vue version

3.5.13

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-sr5itbdf

Steps to reproduce

  1. npm install
  2. npm run build
  3. NotTreeShaken component exists in dist/assets/index-xxx.js

What is expected?

NotTreeShaken component is not imported, so it should be tree-shaken

What is actually happening?

NotTreeShaken component exists in dist/assets/index-xxx.js

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vue: ^3.5.13 => 3.5.13

Any additional comments?

In the case of Props Destructure, it is tree-shaken.

In the case of withDefaults, props are compiled as follows:

props: {
  msg: { type: String, required: false, default: format('Hello World!!!   ') }
},

In the case of Props Destructure, it is compiled as follows:

props: {
  msg: { type: String, required: false, default: () => (format('Hello World!!!   ')) }
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions