Skip to content

Commit 0de1352

Browse files
committed
refactor
1 parent 3889d89 commit 0de1352

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

src/errors.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export const enum I18nErrorCodes {
2525
__EXTEND_POINT__
2626
}
2727

28-
export function createI18nError(code: I18nErrorCodes, ...args: unknown[]): I18nError {
28+
export function createI18nError(
29+
code: I18nErrorCodes,
30+
...args: unknown[]
31+
): I18nError {
2932
return createCompileError(
3033
code,
3134
null,

src/warnings.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ export const enum I18nWarnCodes {
1313

1414
export const warnMessages: { [code: number]: string } = {
1515
[I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
16-
[I18nWarnCodes.NOT_SUPPORTED_PRESERVE]: `not supportted 'preserve'.`,
17-
[I18nWarnCodes.NOT_SUPPORTED_FORMATTER]: `not supportted 'formatter'.`,
18-
[I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE]: `not supportted 'preserveDirectiveContent'.`,
19-
[I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX]: `not supportted 'getChoiceIndex'.`,
20-
[I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `component name legacy compatible: '{name}' -> 'i18n'`,
21-
[I18nWarnCodes.NOT_FOUND_PARENT_COMPOSER]: `not found parent composer. use the global composer`
16+
[I18nWarnCodes.NOT_SUPPORTED_PRESERVE]: `Not supportted 'preserve'.`,
17+
[I18nWarnCodes.NOT_SUPPORTED_FORMATTER]: `Not supportted 'formatter'.`,
18+
[I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE]: `Not supportted 'preserveDirectiveContent'.`,
19+
[I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX]: `Not supportted 'getChoiceIndex'.`,
20+
[I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `Component name legacy compatible: '{name}' -> 'i18n'`,
21+
[I18nWarnCodes.NOT_FOUND_PARENT_COMPOSER]: `Not found parent composer. use the global composer.`
2222
}
2323

2424
export function getWarnMessage(

test/diretive.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ test('object literal', async () => {
8888
const name = ref('kazupon')
8989
const t = resolveDirective('t')
9090
return () => {
91-
return withDirectives(h('p'), [[t, { path: 'hello', locale: 'ja', args: { name: name.value } }]])
91+
return withDirectives(h('p'), [
92+
[t, { path: 'hello', locale: 'ja', args: { name: name.value } }]
93+
])
9294
}
9395
}
9496
})
@@ -146,7 +148,9 @@ test('preserve modifier', async () => {
146148
const wrapper = await mount(App, i18n)
147149

148150
expect(mockWarn).toHaveBeenCalledTimes(1)
149-
expect(mockWarn.mock.calls[0][0]).toEqual(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE))
151+
expect(mockWarn.mock.calls[0][0]).toEqual(
152+
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE)
153+
)
150154
})
151155

152156
test('legacy mode', async () => {
@@ -202,7 +206,9 @@ describe('errors', () => {
202206
} catch (e) {
203207
error = e
204208
}
205-
expect(error.message).toEqual(errorMessages[I18nErrorCodes.NOT_FOUND_COMPOSER])
209+
expect(error.message).toEqual(
210+
errorMessages[I18nErrorCodes.NOT_FOUND_COMPOSER]
211+
)
206212
})
207213

208214
test(errorMessages[I18nErrorCodes.REQUIRED_VALUE], async () => {
@@ -231,7 +237,9 @@ describe('errors', () => {
231237
} catch (e) {
232238
error = e
233239
}
234-
expect(error.message).toEqual(format(errorMessages[I18nErrorCodes.REQUIRED_VALUE], 'path'))
240+
expect(error.message).toEqual(
241+
format(errorMessages[I18nErrorCodes.REQUIRED_VALUE], 'path')
242+
)
235243
})
236244

237245
test(errorMessages[I18nErrorCodes.INVALID_VALUE], async () => {

test/legacy.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { warn } from '../src/utils'
99

1010
import { createVueI18n } from '../src/legacy'
1111
import { errorMessages, I18nErrorCodes } from '../src/errors'
12+
import { getWarnMessage, I18nWarnCodes } from '../src/warnings'
1213

1314
test('locale', () => {
1415
const i18n = createVueI18n()
@@ -55,9 +56,15 @@ test('formatter', () => {
5556
}
5657
}
5758
expect(mockWarn).toHaveBeenCalledTimes(3)
58-
expect(mockWarn.mock.calls[0][0]).toEqual(`not supportted 'formatter'.`)
59-
expect(mockWarn.mock.calls[1][0]).toEqual(`not supportted 'formatter'.`)
60-
expect(mockWarn.mock.calls[2][0]).toEqual(`not supportted 'formatter'.`)
59+
expect(mockWarn.mock.calls[0][0]).toEqual(
60+
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER)
61+
)
62+
expect(mockWarn.mock.calls[1][0]).toEqual(
63+
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER)
64+
)
65+
expect(mockWarn.mock.calls[2][0]).toEqual(
66+
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER)
67+
)
6168
})
6269

6370
test('missing', () => {
@@ -452,7 +459,9 @@ test('getChoiceIndex', () => {
452459

453460
const i18n = createVueI18n({})
454461
i18n.getChoiceIndex(1, 2)
455-
expect(mockWarn.mock.calls[0][0]).toEqual(`not supportted 'getChoiceIndex'.`)
462+
expect(mockWarn.mock.calls[0][0]).toEqual(
463+
getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX)
464+
)
456465
})
457466

458467
test('warnHtmlInMessage', () => {

test/plugin.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { warn } from '../src/utils'
1313
import { createApp } from 'vue'
1414
import { I18n, I18nInternal } from '../src/i18n'
1515
import { apply } from '../src/plugin'
16+
import { getWarnMessage, I18nWarnCodes } from '../src/warnings'
1617

1718
describe('useI18nComponentName option', () => {
1819
test('default', () => {
@@ -36,7 +37,9 @@ describe('useI18nComponentName option', () => {
3637
apply(app, i18n, { useI18nComponentName: true })
3738
expect(mockWarn).toHaveBeenCalled()
3839
expect(mockWarn.mock.calls[0][0]).toEqual(
39-
`component name legacy compatible: 'i18n-t' -> 'i18n'`
40+
getWarnMessage(I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE, {
41+
name: 'i18n-t'
42+
})
4043
)
4144
})
4245
})

0 commit comments

Comments
 (0)