Skip to content

[Vue][Bug] Long v-if condition break the code after reformat #5561

@maguszoldik

Description

@maguszoldik

Prettier 1.15.2
Vue 2.5.17
Playground link

# Options (if any):
--parser vue

Input:
A v-if is used on a template element which is also declared as a slot.

<template>
  <div>
    <template 
      slot="row_expander"
      slot-scope="{row}"
      v-if="longCondition1 && anotherLongCondition === 'my awesome result' && anotherWhichBreakTheLineLength">
      <something />
      <something/>
    </template>
  </div>
</template>

Output:

<template>
  <div>
    <template
      slot="row_expander"
      slot-scope="{
        row
      }"
      v-if="
        longCondition1 &&
          anotherLongCondition === 'my awesome result' &&
          anotherWhichBreakTheLineLength
      "
    >
      <something /> <something />
    </template>
  </div>
</template>

In this particular case (usage on template element which is a slot renderer), the resulting code will break.

Expected behavior:
The code must be encapsulated in parenthesis to properly work. (And indentation may be better imho.)

<template>
  <div>
    <template
      slot="row_expander"
      slot-scope="{
        row
      }"
      v-if="(
        longCondition1 &&
        anotherLongCondition === 'my awesome result' &&
        anotherWhichBreakTheLineLength
     ) "
    >
      <something /> <something />
    </template>
  </div>
</template>

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:vueIssues affecting Vuelocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!scope:externalThis is not an issue with Prettier, it’s an issue with external software, like an editor integration

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions