Skip to content

V-for-template-key transformer does not support key with string interpolation #117

Description

@JBustin

Describe the bug
/vue-codemod/dist/vue-transformations/v-for-template-key does not support key with string interpolation.

To Reproduce

import { applyOperation } from '@originjs/vue-codemod/dist/src/wrapVueTransformation'
import { transformAST } from '@originjs/vue-codemod/dist/vue-transformations/v-for-template-key'

const test = `<template v-for="(disclaimer, index) in block.disclaimers">
        <Disclaimer
          v-if="disclaimerValue(disclaimer)"
          :key="`disclaimer_${index}`"
          class="lv-shipping-summary__disclaimer"
        >
          <p v-safe-html="disclaimerValue(disclaimer)" />
        </Disclaimer>
      </template>`

const result = applyOperation(test,[transformAST])
console.log(result)

result is something like:

      <template v-for="(disclaimer, index) in block.disclaimers" :key="undefined">
        <Disclaimer v-if="disclaimerValue(disclaimer)" class="lv-shipping-summary__disclaimer">
          <p v-safe-html="disclaimerValue(disclaimer)" />
        </Disclaimer>
      </template>

Expected behavior

      <template v-for="(disclaimer, index) in block.disclaimers" :key="`disclaimer_${index}`">
        <Disclaimer v-if="disclaimerValue(disclaimer)" class="lv-shipping-summary__disclaimer">
          <p v-safe-html="disclaimerValue(disclaimer)" />
        </Disclaimer>
      </template>

Environment (please complete the following information):

  • OS: macOs
  • Version: Sonoma 14.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions