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

Vue SFC script block not using overrided parser #290

Open
1 task
neko-para opened this issue Mar 30, 2024 · 0 comments
Open
1 task

Vue SFC script block not using overrided parser #290

neko-para opened this issue Mar 30, 2024 · 0 comments

Comments

@neko-para
Copy link

Your Environment

  • Prettier version: 3.2.5
  • node version 20.11.1
  • package manager: pnpm@8
  • IDE: VSCode & CLI

Describe the bug

I'm writing typescript with explicit resource management. Current this feature is not supported (or maybe not enabled by default) by prettiers' default parser "typescript". Thus I switch to babel-ts parser which works fine with *.ts files. However, when I switch to *.vue files, error raises. After some examination, it seems that if I enable this plugin, the script block will fallback to use "typescript" parser instead of "babel-ts".

To Reproduce

  • Launch prettier ./test.vue, output
[error] ./test.vue: SyntaxError: This experimental syntax requires enabling the parser plugin: "explicitResourceManagement". (2:0)
  • Remove this plugin, relaunch previous command, output
[warn] Ignored unknown option { importOrder: ["^@/", "^\\."] }.
[warn] Ignored unknown option { importOrderSeparation: true }.
[warn] Ignored unknown option { importOrderSortSpecifiers: true }.
<script setup lang="ts">
using a = 1
</script>

<template>
  <div></div>
</template>
  • For reference, incase there's test.ts
using a = 1
  • Launch prettier ./test.ts, output
using a = 1
  • Change *.ts parser to "typescript", relaunch, output
[error] ./test.ts: SyntaxError: This experimental syntax requires enabling the parser plugin: "explicitResourceManagement". (1:0)

just like the error above.

Expected behavior

I'm not sure if it is because this plugin use "typescript" parser underly, or because the parser of script block changed to "typescript" for some reason. But the vue script block should use the overrided parser, just like if this plugin isn't activated.

Screenshots, code sample, etc

Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)

{
  "semi": false,
  "singleQuote": true,
  "trailingComma": "none",
  "arrowParens": "avoid",
  "printWidth": 100,

  "importOrder": ["^@/", "^\\."],
  "importOrderSeparation": true,
  "importOrderSortSpecifiers": true,

  "overrides": [
    {
      "files": "*.ts",
      "options": {
        "parser": "babel-ts"
      }
    }
  ],
  "plugins": ["@trivago/prettier-plugin-sort-imports"]
}

Error log

Contribute to @trivago/prettier-plugin-sort-imports

  • I'm willing to fix this bug 🥇
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant