question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ikatyangcommented, Nov 27, 2018

As a workaround, you could use <!-- prettier-ignore-attribute v-if -->:

Prettier 1.15.2 Playground link

--parser vue

Input:

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

Output:

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

0reactions
ikatyangcommented, Dec 1, 2018

Fixed in vuejs/vue#9119.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use Break, Continue, and Pass Statements when ...
You'll put the break statement within the block of code under your loop statement, usually after a conditional if statement.
Read more >
break - JavaScript - MDN Web Docs - Mozilla
The following code has a break statement that terminates the switch statement when a case is matched and the corresponding code has run....
Read more >
Why does python use 'else' after for and while loops?
Without break , return , etc., loop ends only when condition is no longer true and in such case else block will also...
Read more >
Python break statement - Tutorialspoint
If you are using nested loops, the break statement stops the execution of the innermost loop and start executing the next line of...
Read more >
Python Break and Python Continue – How to Skip to the Next ...
Inside the for loop, we have a condition that says if the letter is "i" then skip that iteration and move onto the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found