Skip to content

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

@fisker

Description

@fisker

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood fist issue!lang:vueIssues affecting Vuelocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions