prettier / plugin-pug

Prettier Pug Plugin
https://prettier.github.io/plugin-pug
MIT License
196 stars 43 forks source link

Bug: Incorrect parenthesis inserts in v-for with element and index #440

Closed richardsimko closed 1 year ago

richardsimko commented 1 year ago

Info

Tool Version
Plugin v2.4.2
Prettier v2.8.8
Framework vue
Node v19.0.0
OS mac

Prettier config

{
  "pugFramework": "vue"
}

Input

<template lang="pug">
template(v-for="el, i in foo" :key="i")
  div {{ el }}
</template>

<script setup>
  import { ref } from 'vue';

  const foo = ref(['foo']);
</script>

Output or Error

Replace `el,·i·in·foo` with `(el,·i·in·foo)`

Output file:

<template lang="pug">
template(v-for="(el, i in foo)" :key="i")
  div {{ el }}
</template>

<script setup>
  import { ref } from 'vue';

  const foo = ref(['foo']);
</script>

Expected Output

<template lang="pug">
template(v-for="(el, i) in foo" :key="i")
  div {{ el }}
</template>

<script setup>
  import { ref } from 'vue';

  const foo = ref(['foo']);
</script>

Additional Context

The parenthesis ends up wrapping the whole v-for statement instead of just the two loop variables.

richardsimko commented 1 year ago

This seems to also appear in a standalone pug file:

input

.test(v-for="a, b in c")
  .inner

output

.test(v-for="(a, b in c)")
  .inner
richardsimko commented 1 year ago

Sorry, this is a duplicate of #251