core
core copied to clipboard
feat(compiler-sfc): [BREAKING] default `<script>` lang option for parser
Add option defaultScriptLang for the parser.
If the lang attribute of the script block is empty, this option will be applied.
Example
parse(
`<script setup>console.log(0)</script>`,
{
defaultScriptLang: 'ts',
},
)
Note: This feature may break some syntax highlighters and language servers (like Volar).
Close #7173
thanks @sxzz @enkot
Deploy Preview for vuejs-coverage failed.
| Name | Link |
|---|---|
| Latest commit | eaa323cb10f74548e2021119d51dfa8df70eb78a |
| Latest deploy log | https://app.netlify.com/sites/vuejs-coverage/deploys/63ad7e41e8aee2000b18bc08 |
With PR #7398, Should I change the defaultScriptLang option default value into "js"? @sxzz
@hydrati Sure
I have my a doubts about this change - not about what it does (I think it makes sense), but when to introduce it.
It feels like a breaking change that would have to wait for Vue 4. Even if it's not to be considered a breaking change, it should only be introduced in a minor release, not a patch version.
For one, today some libraries choose to publish raw .vue files, which works particularly well if they re already written in plain JS and CSS. Those might break if the consuming app has set the default script lang to ts.
Furthermore, once we introduce this, there will quickly be pressure from users for all the tooling (Volar, eslint-plugin-vue ...) to support this, which we should prepare for in a coordinated manner.
For one, today some libraries choose to publish raw .vue files, which works particularly well if they re already written in plain JS and CSS. Those might break if the consuming app has set the default script lang to ts.
Maybe I need to add an "scope" option to keep the compatibility for those libraries.
Furthermore, once we introduce this, there will quickly be pressure from users for all the tooling (Volar, eslint-plugin-vue ...) to support this, which we should prepare for in a coordinated manner.
I know the problem, but I don't know how to deal with it.
Would be amazing to have this also for the <style> tag, e.g. default to <style lang="postcss" scoped>.