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 not formatting TS expression if script[lang=ts] is second <script> #14575

Closed
fisker opened this issue Mar 24, 2023 · 0 comments · Fixed by #14587
Closed

Vue not formatting TS expression if script[lang=ts] is second <script> #14575

fisker opened this issue Mar 24, 2023 · 0 comments · Fixed by #14587
Labels
good first issue Good fist issue! lang:vue Issues affecting Vue locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program

Comments

@fisker
Copy link
Member

fisker commented Mar 24, 2023

Prettier 2.8.6
Playground link

--parser vue

Input:

<script></script>
<script setup lang="ts">
let x: string | number = 1
</script>
<template>
  {{ (x      as      number).toFixed(2) }}
</template>

Output:

<script></script>
<script setup lang="ts">
let x: string | number = 1;
</script>
<template>
  {{ (x      as      number).toFixed(2) }}
</template>

Expected behavior:

Should parse as TS. Vue playground

Problem is here

function markTsScript(ast, options) {
if (options.parser === "vue") {
const vueScriptTag = ast.children.find((child) =>
isVueScriptTag(child, options)
);
if (!vueScriptTag) {
return;
}
const { lang } = vueScriptTag.attrMap;
if (lang === "ts" || lang === "typescript") {
options.__should_parse_vue_template_with_ts = true;
}
}
}

Should check any <script> instead of only checking the first <script>

@fisker fisker added type:bug Issues identifying ugly output, or a defect in the program lang:vue Issues affecting Vue good first issue Good fist issue! labels Mar 24, 2023
seiyab added a commit to seiyab/prettier that referenced this issue Mar 25, 2023
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Nov 26, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good fist issue! lang:vue Issues affecting Vue locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant