cuiqian2004
2024-08-20 4af840b0cce44ed971713281a25eba08107444ed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
 
 
import type { BaseError } from '@intlify/shared';
import type { RawSourceMap } from 'source-map-js';
 
export declare function baseCompile(source: string, options?: CompileOptions): CompilerResult;
 
export declare type CacheKeyHandler = (source: string) => string;
 
export declare interface CodeGenOptions {
    location?: boolean;
    mode?: 'normal' | 'arrow';
    breakLineCode?: '\n' | ';';
    needIndent?: boolean;
    onWarn?: CompileWarnHandler;
    onError?: CompileErrorHandler;
    sourceMap?: boolean;
    filename?: string;
}
 
declare interface CodeGenResult {
    code: string;
    ast: ResourceNode;
    map?: RawSourceMap;
}
 
export declare type CompileDomain = 'tokenizer' | 'parser' | 'generator' | 'transformer' | 'optimizer' | 'minifier';
 
export declare interface CompileError extends BaseError, SyntaxError {
    domain?: CompileDomain;
    location?: SourceLocation;
}
 
export declare const CompileErrorCodes: {
    readonly EXPECTED_TOKEN: 1;
    readonly INVALID_TOKEN_IN_PLACEHOLDER: 2;
    readonly UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER: 3;
    readonly UNKNOWN_ESCAPE_SEQUENCE: 4;
    readonly INVALID_UNICODE_ESCAPE_SEQUENCE: 5;
    readonly UNBALANCED_CLOSING_BRACE: 6;
    readonly UNTERMINATED_CLOSING_BRACE: 7;
    readonly EMPTY_PLACEHOLDER: 8;
    readonly NOT_ALLOW_NEST_PLACEHOLDER: 9;
    readonly INVALID_LINKED_FORMAT: 10;
    readonly MUST_HAVE_MESSAGES_IN_PLURAL: 11;
    readonly UNEXPECTED_EMPTY_LINKED_MODIFIER: 12;
    readonly UNEXPECTED_EMPTY_LINKED_KEY: 13;
    readonly UNEXPECTED_LEXICAL_ANALYSIS: 14;
    readonly UNHANDLED_CODEGEN_NODE_TYPE: 15;
    readonly UNHANDLED_MINIFIER_NODE_TYPE: 16;
    readonly __EXTEND_POINT__: 17;
};
 
export declare type CompileErrorCodes = (typeof CompileErrorCodes)[keyof typeof CompileErrorCodes];
 
export declare type CompileErrorHandler = (error: CompileError) => void;
 
export declare interface CompileErrorOptions {
    domain?: CompileDomain;
    messages?: {
        [code: number]: string;
    };
    args?: unknown[];
}
 
export declare type CompileOptions = {
    optimize?: boolean;
    minify?: boolean;
    jit?: boolean;
} & TransformOptions & CodeGenOptions & ParserOptions & TokenizeOptions;
 
export declare type CompilerResult = CodeGenResult;
 
export declare interface CompileWarn {
    message: string;
    code: number;
    location?: SourceLocation;
}
 
export declare const CompileWarnCodes: {
    readonly USE_MODULO_SYNTAX: 1;
    readonly __EXTEND_POINT__: 2;
};
 
export declare type CompileWarnCodes = (typeof CompileWarnCodes)[keyof typeof CompileWarnCodes];
 
export declare type CompileWarnHandler = (warn: CompileWarn) => void;
 
export declare function createCompileError<T extends number>(code: T, loc: SourceLocation | null, options?: CompileErrorOptions): CompileError;
 
export declare function createCompileWarn<T extends number>(code: T, loc: SourceLocation | null, ...args: unknown[]): CompileWarn;
 
export declare function createLocation(start: Position, end: Position, source?: string): SourceLocation;
 
export declare function createParser(options?: ParserOptions): Parser;
 
export declare function createPosition(line: number, column: number, offset: number): Position;
 
/* Excluded from this release type: defaultOnError */
 
export declare const detectHtmlTag: (source: string) => boolean;
 
export declare const ERROR_DOMAIN = "parser";
 
/* Excluded from this release type: errorMessages */
 
export declare const enum HelperNameMap {
    LIST = "list",
    NAMED = "named",
    PLURAL = "plural",
    LINKED = "linked",
    MESSAGE = "message",
    TYPE = "type",
    INTERPOLATE = "interpolate",
    NORMALIZE = "normalize",
    VALUES = "values"
}
 
export declare type Identifier = string;
 
export declare interface LinkedKeyNode extends Node_2 {
    type: NodeTypes.LinkedKey;
    value: string;
    /* Excluded from this release type: v */
}
 
export declare interface LinkedModifierNode extends Node_2 {
    type: NodeTypes.LinkedModifier;
    value: Identifier;
    /* Excluded from this release type: v */
}
 
export declare interface LinkedNode extends Node_2 {
    type: NodeTypes.Linked;
    modifier?: LinkedModifierNode;
    /* Excluded from this release type: m */
    key: LinkedKeyNode | NamedNode | ListNode | LiteralNode;
    /* Excluded from this release type: k */
}
 
export declare interface ListNode extends Node_2 {
    type: NodeTypes.List;
    index: number;
    /* Excluded from this release type: i */
}
 
export declare interface LiteralNode extends Node_2 {
    type: NodeTypes.Literal;
    value?: string;
    /* Excluded from this release type: v */
}
 
export declare const LOCATION_STUB: SourceLocation;
 
declare type MessageElementNode = TextNode | NamedNode | ListNode | LiteralNode | LinkedNode;
 
export declare interface MessageNode extends Node_2 {
    type: NodeTypes.Message;
    static?: string;
    /* Excluded from this release type: s */
    items: MessageElementNode[];
    /* Excluded from this release type: i */
}
 
export declare interface NamedNode extends Node_2 {
    type: NodeTypes.Named;
    key: Identifier;
    modulo?: boolean;
    /* Excluded from this release type: k */
}
 
declare interface Node_2 {
    type: NodeTypes;
    /* Excluded from this release type: t */
    start?: number;
    end?: number;
    loc?: SourceLocation;
}
export { Node_2 as Node }
 
export declare const enum NodeTypes {
    Resource = 0,// 0
    Plural = 1,
    Message = 2,
    Text = 3,
    Named = 4,
    List = 5,// 5
    Linked = 6,
    LinkedKey = 7,
    LinkedModifier = 8,
    Literal = 9
}
 
export declare interface Parser {
    parse(source: string): ResourceNode;
}
 
export declare interface ParserOptions {
    location?: boolean;
    onCacheKey?: (source: string) => string;
    onWarn?: CompileWarnHandler;
    onError?: CompileErrorHandler;
}
 
export declare interface PluralNode extends Node_2 {
    type: NodeTypes.Plural;
    cases: MessageNode[];
    /* Excluded from this release type: c */
}
 
export declare interface Position {
    offset: number;
    line: number;
    column: number;
}
 
export declare interface ResourceNode extends Node_2 {
    type: NodeTypes.Resource;
    body: MessageNode | PluralNode;
    /* Excluded from this release type: b */
    cacheKey?: string;
    helpers?: string[];
}
 
export declare interface SourceLocation {
    start: Position;
    end: Position;
    source?: string;
}
 
export declare interface TextNode extends Node_2 {
    type: NodeTypes.Text;
    value?: string;
    /* Excluded from this release type: v */
}
 
export declare interface TokenizeOptions {
    location?: boolean;
    onError?: CompileErrorHandler;
}
 
export declare interface TransformOptions {
    onWarn?: CompileWarnHandler;
    onError?: CompileErrorHandler;
}
 
/* Excluded from this release type: warnMessages */
 
export { }