Skip to content

Commit eb26c18

Browse files
authored
improvement: reduce size (#584)
1 parent ce8cb07 commit eb26c18

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

packages/core-base/src/errors.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ export interface CoreError extends CompileError {
88
code: CoreErrorCodes
99
}
1010

11+
let code = CompileErrorCodes.__EXTEND_POINT__
12+
const inc = () => code++
13+
1114
export const CoreErrorCodes = {
12-
INVALID_ARGUMENT: CompileErrorCodes.__EXTEND_POINT__,
13-
INVALID_DATE_ARGUMENT: CompileErrorCodes.__EXTEND_POINT__ + 1,
14-
INVALID_ISO_DATE_ARGUMENT: CompileErrorCodes.__EXTEND_POINT__ + 2,
15-
__EXTEND_POINT__: CompileErrorCodes.__EXTEND_POINT__ + 3
15+
INVALID_ARGUMENT: code, // 15
16+
INVALID_DATE_ARGUMENT: inc(), // 16
17+
INVALID_ISO_DATE_ARGUMENT: inc(), // 17
18+
__EXTEND_POINT__: inc() // 18
1619
} as const
1720

1821
export type CoreErrorCodes = typeof CoreErrorCodes[keyof typeof CoreErrorCodes]

packages/vue-i18n/src/errors.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,27 @@ export interface I18nError extends CompileError {
88
code: I18nErrorCodes
99
}
1010

11+
let code = CompileErrorCodes.__EXTEND_POINT__
12+
const inc = () => code++
13+
1114
export const I18nErrorCodes = {
1215
// composer module errors
13-
UNEXPECTED_RETURN_TYPE: CompileErrorCodes.__EXTEND_POINT__,
16+
UNEXPECTED_RETURN_TYPE: code, // 15
1417
// legacy module errors
15-
INVALID_ARGUMENT: CompileErrorCodes.__EXTEND_POINT__ + 1,
18+
INVALID_ARGUMENT: inc(), // 16
1619
// i18n module errors
17-
MUST_BE_CALL_SETUP_TOP: CompileErrorCodes.__EXTEND_POINT__ + 2,
18-
NOT_INSLALLED: CompileErrorCodes.__EXTEND_POINT__ + 3,
19-
NOT_AVAILABLE_IN_LEGACY_MODE: CompileErrorCodes.__EXTEND_POINT__ + 4,
20+
MUST_BE_CALL_SETUP_TOP: inc(), // 17
21+
NOT_INSLALLED: inc(), // 18
22+
NOT_AVAILABLE_IN_LEGACY_MODE: inc(), // 19
2023
// directive module errors
21-
REQUIRED_VALUE: CompileErrorCodes.__EXTEND_POINT__ + 5,
22-
INVALID_VALUE: CompileErrorCodes.__EXTEND_POINT__ + 6,
24+
REQUIRED_VALUE: inc(), // 20
25+
INVALID_VALUE: inc(), // 21
2326
// vue-devtools errors
24-
CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN: CompileErrorCodes.__EXTEND_POINT__ + 7,
27+
CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN: inc(), // 22
2528
// unexpected error
26-
UNEXPECTED_ERROR: CompileErrorCodes.__EXTEND_POINT__ + 8,
29+
UNEXPECTED_ERROR: inc(), // 23
2730
// for enhancement
28-
__EXTEND_POINT__: CompileErrorCodes.__EXTEND_POINT__ + 9
31+
__EXTEND_POINT__: inc() // 24
2932
} as const
3033

3134
type I18nErrorCodes = typeof I18nErrorCodes[keyof typeof I18nErrorCodes]

packages/vue-i18n/src/warnings.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { format } from '@intlify/shared'
22
import { CoreWarnCodes } from '@intlify/core-base'
33

4+
let code = CoreWarnCodes.__EXTEND_POINT__
5+
const inc = () => code++
6+
47
export const I18nWarnCodes = {
5-
FALLBACK_TO_ROOT: CoreWarnCodes.__EXTEND_POINT__,
6-
NOT_SUPPORTED_PRESERVE: CoreWarnCodes.__EXTEND_POINT__ + 1,
7-
NOT_SUPPORTED_FORMATTER: CoreWarnCodes.__EXTEND_POINT__ + 2,
8-
NOT_SUPPORTED_PRESERVE_DIRECTIVE: CoreWarnCodes.__EXTEND_POINT__ + 3,
9-
NOT_SUPPORTED_GET_CHOICE_INDEX: CoreWarnCodes.__EXTEND_POINT__ + 4,
10-
COMPONENT_NAME_LEGACY_COMPATIBLE: CoreWarnCodes.__EXTEND_POINT__ + 5,
11-
NOT_FOUND_PARENT_SCOPE: CoreWarnCodes.__EXTEND_POINT__ + 6
8+
FALLBACK_TO_ROOT: code, // 7
9+
NOT_SUPPORTED_PRESERVE: inc(), // 8
10+
NOT_SUPPORTED_FORMATTER: inc(), // 9
11+
NOT_SUPPORTED_PRESERVE_DIRECTIVE: inc(), // 10
12+
NOT_SUPPORTED_GET_CHOICE_INDEX: inc(), // 11
13+
COMPONENT_NAME_LEGACY_COMPATIBLE: inc(), // 12
14+
NOT_FOUND_PARENT_SCOPE: inc() // 13
1215
} as const
1316

1417
type I18nWarnCodes = typeof I18nWarnCodes[keyof typeof I18nWarnCodes]

0 commit comments

Comments
 (0)