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

"<" in v-if directive might be treated as closing tag of elements using self-closing tags #20

Open
DawidKopys opened this issue Jul 30, 2024 · 0 comments

Comments

@DawidKopys
Copy link
Collaborator

DawidKopys commented Jul 30, 2024

Steps to reproduce:

  1. Create FooBar.vue file:
<template>
  <div>
    <img v-if="2 > 1"/>
    <p>I am a paragraph.</p>
  </div>
</template>
  1. Attempt to modify FooBar.vue with FooBar.mod.ts:
import type { TemplateMod } from '@creativestyle/kombinator'

export default function (withComponent: TemplateMod) {
  const t = withComponent('FooBar')

  const elementCode = t.templateModificator
    .findByTag('img')
    .getElementCode()

  console.log('img elementCode :', elementCode)

  t.templateModificator
    .findByTag('img')
    .insertAfter('<h1>bajojajo</h1>')

  t.saveModifiedTemplate()
}
  1. Run kombinator

Expected Result:

  1. In the terminal when kombinator was ran, developer should see below console.log’s output:
img elementCode : <img v-if="2 > 1"/>
  1. Kombinator should generate file FooBar.vue with below content:
<template>
  <div>
    <img v-if="2 > 1"/><h1>bajojajo</h1>
    <p>I am a paragraph.</p>
  </div>
</template><!-- Kombinator: FooBar.mod.ts:16:5 -->

Actual Result:

  1. In the terminal when kombinator was ran, developer sees below console.log’s output:
img elementCode : <img v-if="2 > 1"/>                                                       15:06:40
    <p>I am a paragraph.</p>
  1. Kombinator generates file FooBar.vue with below content:
<template>
<div>
    <img v-if="2 > 1"/>
    <p>I am a paragraph.</p><h1>bajojajo</h1>
  </div>
</template><!-- Kombinator: FooBar.mod.ts:16:5 -->

Technical hints:

  1. it appears that the issue is only there for elements with self closing tags, eg:
<Badge v-if="2 > 1"/>
<img v-if="2 > 1"/>
  1. it looks that elements without closing tags work fine, for example, if we tried modifying component with below markup:
<h6 v-if="2 > 1">test</h6>

… then the kombinator would handle it properly

  1. this is most likely not only a problem for v-if directives
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant