From ccafe8225f16b7d80a618b2ced234310a12ef646 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Tue, 25 Nov 2025 12:14:36 +0900 Subject: [PATCH] fix: avoid bundler static analysis for `getCurrentInstance` --- packages/vue-i18n-core/src/utils.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/vue-i18n-core/src/utils.ts b/packages/vue-i18n-core/src/utils.ts index 7aa01cc4d..52ebada4f 100644 --- a/packages/vue-i18n-core/src/utils.ts +++ b/packages/vue-i18n-core/src/utils.ts @@ -223,6 +223,13 @@ export function getCurrentInstance(): | GenericComponentInstance | ComponentInternalInstance | null { - // @ts-ignore -- NOTE(kazupon): for Vue 3.6 - return Vue.currentInstance || Vue.getCurrentInstance() + if ('currentInstance' in Vue) { + // NOTE(kazupon): avoid bundler static analysis + const name = 'current' + 'Instance' + return (Vue as any)[name] as GenericComponentInstance | null + } else { + return Vue.getCurrentInstance() + } } + +/* eslint-enable @typescript-eslint/no-explicit-any */