core icon indicating copy to clipboard operation
core copied to clipboard

feat(compiler-sfc): [BREAKING] default `<script>` lang option for parser

Open hydrati opened this issue 3 years ago • 7 comments
trafficstars

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

hydrati avatar Nov 18 '22 18:11 hydrati

thanks @sxzz @enkot

hydrati avatar Nov 18 '22 23:11 hydrati

Deploy Preview for vuejs-coverage failed.

Name Link
Latest commit eaa323cb10f74548e2021119d51dfa8df70eb78a
Latest deploy log https://app.netlify.com/sites/vuejs-coverage/deploys/63ad7e41e8aee2000b18bc08

netlify[bot] avatar Nov 19 '22 00:11 netlify[bot]

With PR #7398, Should I change the defaultScriptLang option default value into "js"? @sxzz

hydrati avatar Dec 29 '22 06:12 hydrati

@hydrati Sure

sxzz avatar Dec 29 '22 06:12 sxzz

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.

LinusBorg avatar Jan 01 '23 10:01 LinusBorg

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.

hydrati avatar Jan 01 '23 11:01 hydrati

Would be amazing to have this also for the <style> tag, e.g. default to <style lang="postcss" scoped>.

toniengelhardt avatar Mar 09 '23 00:03 toniengelhardt