vite-plugin-vue
vite-plugin-vue copied to clipboard
Code generated for empty <script setup> does not define `__name`
Related plugins
-
[X] plugin-vue
-
[ ] plugin-vue-jsx
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
- Have a component with an empty
<script setup>section, and no<script>section. - Print out the
__nameand__filefields of the component. - Notice that
__fileis provided, but__nameis 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
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
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.