Skip to content

Invalid syntax in Vue templates after build #598

@dulnan

Description

@dulnan

I am using version 1.0.1 of @nuxt/module-builder.

Given this Vue component located in ./src/runtime/components/Foobar.vue:

<template>
  <div>
    <div>{{ $test('foobar', "Foobar 'test'") }}</div>
    <div>{{ $test('foobar', 'Foobar test') }}</div>
    <div>{{ $test('foobar', `Foobar ' " ''" test`) }}</div>
  </div>
</template>

<script lang="ts" setup>
const $test = (key: string, text: string): string => key
</script>

After running nuxt-module-build build, the output in ./dist/runtime/components/Foobar.vue looks like this:

<template>
  <div>
    <div>{{ $test(\"foobar\", \"Foobar "test"\") }}</div>
    <div>{{ $test('foobar', 'Foobar test') }}</div>
    <div>{{ $test(\"foobar\", `Foobar " \" ""\" test`) }}</div>
  </div>
</template>

<script setup>
const $test = (key, text) => key;
</script>

Here the first and the third call to $test produced invalid syntax. It looks like it tries to escape the quotes when it wouldn't be needed, especially in the third example using backticks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingupstream

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions