Skip to content

Commit ccafe82

Browse files
committed
fix: avoid bundler static analysis for getCurrentInstance
1 parent d06b72c commit ccafe82

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/vue-i18n-core/src/utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ export function getCurrentInstance():
223223
| GenericComponentInstance
224224
| ComponentInternalInstance
225225
| null {
226-
// @ts-ignore -- NOTE(kazupon): for Vue 3.6
227-
return Vue.currentInstance || Vue.getCurrentInstance()
226+
if ('currentInstance' in Vue) {
227+
// NOTE(kazupon): avoid bundler static analysis
228+
const name = 'current' + 'Instance'
229+
return (Vue as any)[name] as GenericComponentInstance | null
230+
} else {
231+
return Vue.getCurrentInstance()
232+
}
228233
}
234+
235+
/* eslint-enable @typescript-eslint/no-explicit-any */

0 commit comments

Comments
 (0)