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

Output an error when <template> nor <script> is included in SFC when parsing #6676

Closed
sapphi-red opened this issue Sep 15, 2022 · 0 comments · Fixed by #6781
Closed

Output an error when <template> nor <script> is included in SFC when parsing #6676

sapphi-red opened this issue Sep 15, 2022 · 0 comments · Fixed by #6781
Labels
✨ feature request New feature or request

Comments

@sapphi-red
Copy link
Contributor

sapphi-red commented Sep 15, 2022

What problem does this feature solve?

If you pass a string that does not include <template> or <script>, compilerSfc.parse does not output any errors.

import { parse } from '@vue/compiler-sfc';

const result = parse(`
import a from 'vue'
`);
console.log(result.errors); // []

stackblitz

According to the spec, this is a valid SFC. But this is mostly an error like passing a different value to compilerSfc.parse.

Additional context

A user was passing @vitejs/plugin-vue's output into @vitejs/plugin-vue's input. I expected compilerSfc.parse to fail the parse but in fact the input is an valid HTML, it didn't output any errors.
vitejs/vite#10133 (comment)
This could be fixed on Vite side but I thought it's better to have an error in vue compiler side.

What does the proposed API look like?

Change the spec slightly and add an error like:

SFC should have at least one <template> or <script>.

or

The SFC you passed only includes text nodes. It should include at least one element.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
✨ feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant