Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Commit 7eeb29f

Browse files
committed
🐛 bug(mixin): fix cannot create VueI18n instance error for minify production
1 parent 8f04abc commit 7eeb29f

2 files changed

Lines changed: 4 additions & 25 deletions

File tree

src/mixin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22

33
import VueI18n from './index'
4-
import { typeName, isPlainObject, warn } from './util'
4+
import { isPlainObject, warn } from './util'
55

66
export default {
77
computed: {
@@ -45,11 +45,11 @@ export default {
4545
beforeCreate () {
4646
const options: any = this.$options
4747
if (options.i18n) {
48-
if (typeName(options.i18n) === 'VueI18n') {
48+
if (options.i18n instanceof VueI18n) {
4949
this.$i18n = options.i18n
5050
} else if (isPlainObject(options.i18n)) {
5151
// component local i18n
52-
if (this.$root && this.$root.$i18n && typeName(this.$root.$i18n) === 'VueI18n') {
52+
if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
5353
options.i18n.root = this.$root.$i18n
5454
}
5555
this.$i18n = new VueI18n(options.i18n)
@@ -61,7 +61,7 @@ export default {
6161
warn(`Cannot be interpreted 'i18n' option.`)
6262
}
6363
}
64-
} else if (this.$root && this.$root.$i18n && typeName(this.$root.$i18n) === 'VueI18n') {
64+
} else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
6565
// root i18n
6666
this.$i18n = this.$root.$i18n
6767
}

src/util.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,6 @@ export function isPlainObject (obj: any): boolean {
4242
return toString.call(obj) === OBJECT_STRING
4343
}
4444

45-
function funcName (f: Function): string {
46-
if (f.name) { return f.name }
47-
const match = /^\s*function\s*([^\(]*)/im.exec(f.toString())
48-
return match ? match[1] : ''
49-
}
50-
51-
function ctorName (obj: any): string {
52-
const str = toString.call(obj).slice(8, -1)
53-
if ((str === 'Object' || str === 'Error') && obj.constructor) {
54-
return funcName(obj.constructor)
55-
}
56-
return str
57-
}
58-
59-
export function typeName (val: mixed): string {
60-
if (val === null) { return 'null' }
61-
const type: string = typeof val
62-
if (type === 'object') { return ctorName(val) }
63-
return type
64-
}
65-
6645
export function isNull (val: mixed): boolean {
6746
return val === null || val === undefined
6847
}

0 commit comments

Comments
 (0)