Skip to content

Code generated for empty <script setup> does not define __name #338

Open
@passionate-bram

Description

@passionate-bram

Related plugins

Describe the bug

When you create a component with reactivity the component will have a field __name that basically boils down to filename.match(/([^/\\]+)\.\w+$/ (relevant source from vuejs/vue).

But I noticed that if the <script setup> is empty or missing then the __name field is absent.
However, the other meta fields __file are always present.

Understanding this is entirely internal behaviour, the inconsistency is annoying and leaves a gap that could otherwise still be useful to developers (specifically devtools and other meta tools).

As immediate remedy the __name field could be set whereever __file is provided already.

Reproduction

https://stackblitz.com/edit/vitejs-vite-6zx8jk?file=src%2FApp.vue

Steps to reproduce

  1. Have a component with an empty <script setup> section, and no <script> section.
  2. Print out the __name and __file fields of the component.
  3. Notice that __file is provided, but __name is not.

System Info

System:
    OS: macOS 14.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 534.39 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
    pnpm: 8.10.2 - /opt/homebrew/bin/pnpm
  Browsers:
    Brave Browser: 120.1.61.109
    Safari: 17.2.1
  npmPackages:
    @vitejs/plugin-vue: ^4.5.0 => 4.5.0 
    vite: ^5.0.0 => 5.0.2

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions