1
1
import { format } from '@intlify/shared'
2
2
3
+ import type { BaseError } from '@intlify/shared'
3
4
import type { SourceLocation } from './location'
4
5
5
6
export type CompileDomain =
6
7
| 'tokenizer'
7
8
| 'parser'
8
9
| 'generator'
9
10
| 'transformer'
10
- | 'compiler'
11
+ | 'optimizer'
12
+ | 'minifier'
11
13
12
- export interface CompileError extends SyntaxError {
13
- code : number
14
+ export interface CompileError extends BaseError , SyntaxError {
14
15
domain ?: CompileDomain
15
16
location ?: SourceLocation
16
17
}
17
18
18
- export interface CreateCompileErrorOptions {
19
+ export interface CompileErrorOptions {
19
20
domain ?: CompileDomain
20
21
messages ?: { [ code : number ] : string }
21
22
args ?: unknown [ ]
@@ -40,10 +41,16 @@ export const CompileErrorCodes = {
40
41
UNEXPECTED_EMPTY_LINKED_KEY : 13 ,
41
42
UNEXPECTED_LEXICAL_ANALYSIS : 14 ,
42
43
44
+ // generator error codes
45
+ UNHANDLED_CODEGEN_NODE_TYPE : 15 ,
46
+
47
+ // minifier error codes
48
+ UNHANDLED_MINIFIER_NODE_TYPE : 16 ,
49
+
43
50
// Special value for higher-order compilers to pick up the last code
44
51
// to avoid collision of error codes. This should always be kept as the last
45
52
// item.
46
- __EXTEND_POINT__ : 15
53
+ __EXTEND_POINT__ : 17
47
54
} as const
48
55
49
56
export type CompileErrorCodes =
@@ -66,13 +73,17 @@ export const errorMessages: { [code: number]: string } = {
66
73
[ CompileErrorCodes . MUST_HAVE_MESSAGES_IN_PLURAL ] : `Plural must have messages` ,
67
74
[ CompileErrorCodes . UNEXPECTED_EMPTY_LINKED_MODIFIER ] : `Unexpected empty linked modifier` ,
68
75
[ CompileErrorCodes . UNEXPECTED_EMPTY_LINKED_KEY ] : `Unexpected empty linked key` ,
69
- [ CompileErrorCodes . UNEXPECTED_LEXICAL_ANALYSIS ] : `Unexpected lexical analysis in token: '{0}'`
76
+ [ CompileErrorCodes . UNEXPECTED_LEXICAL_ANALYSIS ] : `Unexpected lexical analysis in token: '{0}'` ,
77
+ // generator error messages
78
+ [ CompileErrorCodes . UNHANDLED_CODEGEN_NODE_TYPE ] : `unhandled codegen node type: '{0}'` ,
79
+ // minimizer error messages
80
+ [ CompileErrorCodes . UNHANDLED_MINIFIER_NODE_TYPE ] : `unhandled mimifier node type: '{0}'`
70
81
}
71
82
72
83
export function createCompileError < T extends number > (
73
84
code : T ,
74
85
loc : SourceLocation | null ,
75
- options : CreateCompileErrorOptions = { }
86
+ options : CompileErrorOptions = { }
76
87
) : CompileError {
77
88
const { domain, messages, args } = options
78
89
const msg = __DEV__
0 commit comments