Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
8 of 9 tasks
passionate-bram opened this issue Jan 12, 2024 · 1 comment
Open
8 of 9 tasks

Comments

@passionate-bram
Copy link

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

@edison1105
Copy link
Member

edison1105 commented Sep 23, 2024

the value of __name is generate from https://github.com/vuejs/core/blob/40193696b3564202173ac0367e4b3ae48c4ffb84/packages/compiler-sfc/src/compileScript.ts#L946
it requires a non-empty script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants