[Bug] Variable's in-template usage not detected
DamianGlowala opened this issue · comments
In the following scenario, the CurrentYear
variable doesn't get picked up.
<i18n>
{
"en": {
"copyrightNotice": "{currentYear} (...)"
}
}
</i18n>
<template>
<span>
{{ $t("copyrightNotice", { currentYear: CurrentYear }) }}
</span>
</template>
<script setup lang="ts">
import { computed, useContext } from "@nuxtjs/composition-api";
const { $moment } = useContext();
const CurrentYear = computed(() => $moment().year());
</script>
It does work though when variable is present in the following way:
<template>
<span>
{{ CurrentYear }}
</span>
</template>
Is there some background optimisation in place detecting unused variables and ignoring them? If so, unfortunately this is a case when it appears to fail.
Hey @xiaoxiangmoe, as it's been a while I wonder how the progress is going so far on this issue? Were you able to reproduce the problem? If not, I can provide a reproduction, just let me know 😃
@DamianGlowala I'm trying to rewrite parseSFC logic. It will take some time.
@DamianGlowala I can't reproduce it. Could you give me a minimal reproduction?
Definitely, I will share a reproduction as soon as I get meaningful results. I was overconfident with the above snippets - when I attempted to reproduce the problem myself in a blank project, I couldn't do that in any way. Turns out to be more tricky than I thought. Whenever I have some spare time, I will try to replicate my current project step-by-step and see which bit of code (or library) triggers the bug. Very bizarre. I am intrigued what makes it skip the variable so I will keep digging!
It turns out this library was a dependency of @nuxtjs/composition-api
(version 0.31.0), which had "unplugin-vue2-script-setup": "^0.7.3"
... I have updated to the latest version and it all works like a charm :) As trivial as it looks, it wasn't straightforward to spot at first! 😄