Skip to content

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

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

hydrati
Copy link

@hydrati hydrati commented Nov 18, 2022

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 hydrati changed the title feat(compiler-sfc): default lang options for <script> & <script setup> feat(compiler-sfc): default <script> lang options Nov 18, 2022
@hydrati hydrati marked this pull request as ready for review November 18, 2022 18:36
@hydrati hydrati changed the title feat(compiler-sfc): default <script> lang options feat(compiler-sfc): default <script> lang option Nov 18, 2022
@hydrati
Copy link
Author

hydrati commented Nov 18, 2022

thanks @sxzz @enkot

Copy link
Member

@sxzz sxzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@netlify
Copy link

netlify bot commented Nov 19, 2022

Deploy Preview for vuejs-coverage failed.

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

@hydrati hydrati requested review from avinean and sxzz and removed request for avinean November 19, 2022 09:46
@hydrati hydrati requested review from avinean and removed request for sxzz November 26, 2022 08:19
@hydrati hydrati changed the title feat(compiler-sfc): default <script> lang option feat(compiler-sfc): default <script> lang option for parser Dec 20, 2022
@hydrati
Copy link
Author

hydrati commented Dec 29, 2022

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

@sxzz
Copy link
Member

sxzz commented Dec 29, 2022

@hydrati Sure

@hydrati hydrati requested review from sxzz and removed request for avinean December 29, 2022 11:53
@LinusBorg
Copy link
Member

LinusBorg commented Jan 1, 2023

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.

@hydrati
Copy link
Author

hydrati commented Jan 1, 2023

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 hydrati changed the title feat(compiler-sfc): default <script> lang option for parser feat(compiler-sfc): [BREAKING] default <script> lang option for parser Jan 1, 2023
@sxzz sxzz force-pushed the feat/script-default-lang branch from eaa323c to 01f0891 Compare February 4, 2023 17:36
@toniengelhardt
Copy link

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

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

Successfully merging this pull request may close these issues.

Add option to enable Typescript by default in <script>
8 participants