janja 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +308 -226
- package/dist/index.d.ts +12 -21
- package/dist/index.esm.js +308 -226
- package/dist/index.js +308 -226
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -73,14 +73,6 @@ declare class RootNode extends Traversal {
|
|
|
73
73
|
readonly type = "TEMPLATE";
|
|
74
74
|
constructor(body: SyntaxNode[], loc: Loc);
|
|
75
75
|
}
|
|
76
|
-
declare class UnexpectedNode extends Traversal {
|
|
77
|
-
readonly name: string;
|
|
78
|
-
readonly val: string;
|
|
79
|
-
readonly loc: Loc;
|
|
80
|
-
readonly strip: Strip;
|
|
81
|
-
readonly type = "UNEXPECTED";
|
|
82
|
-
constructor(name: string, val: string, loc: Loc, strip: Strip);
|
|
83
|
-
}
|
|
84
76
|
|
|
85
77
|
declare class BlockNode extends Traversal {
|
|
86
78
|
readonly val: IdExp;
|
|
@@ -128,13 +120,11 @@ declare class Tokenizer implements Pos {
|
|
|
128
120
|
declare class Parser extends Tokenizer {
|
|
129
121
|
private expParser;
|
|
130
122
|
protected cursor: number;
|
|
131
|
-
parse(template: string): RootNode
|
|
132
|
-
parseUntil(names?: string[]): SyntaxNode[]
|
|
133
|
-
createUnexpectedNode(token: Token): UnexpectedNode;
|
|
134
|
-
private createUnknownNode;
|
|
123
|
+
parse(template: string): Promise<RootNode>;
|
|
124
|
+
parseUntil(names?: string[]): Promise<SyntaxNode[]>;
|
|
135
125
|
parseExp({ val, loc }: DirectiveExpression): Exp;
|
|
136
126
|
peek(): Token | null;
|
|
137
|
-
advance
|
|
127
|
+
private advance;
|
|
138
128
|
match(names: string[], token?: Token | null): boolean;
|
|
139
129
|
emitExpErr({ name, loc }: DirectiveToken, required?: boolean): void;
|
|
140
130
|
}
|
|
@@ -194,9 +184,10 @@ type UnaryExpTokenType = 'NOT';
|
|
|
194
184
|
type BinaryExpTokenType = 'AND' | 'OR' | 'IS' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'ASSIGN';
|
|
195
185
|
type TernaryExpTokenType = 'IF' | 'ELSE';
|
|
196
186
|
type ExpTokenType = UnaryExpTokenType | BinaryExpTokenType | TernaryExpTokenType | 'LP' | 'RP' | 'COMMA' | 'DOT' | 'ID' | 'LIT';
|
|
187
|
+
type Primitive = string | number | boolean | null | undefined;
|
|
197
188
|
interface ExpToken<T = ExpTokenType> {
|
|
198
189
|
type: T;
|
|
199
|
-
value:
|
|
190
|
+
value: Primitive;
|
|
200
191
|
loc: Loc;
|
|
201
192
|
raw?: string;
|
|
202
193
|
}
|
|
@@ -212,7 +203,7 @@ interface ExpBase<T = ExpType> {
|
|
|
212
203
|
interface NotExp extends ExpBase<'NOT'> {
|
|
213
204
|
argument: Exp;
|
|
214
205
|
}
|
|
215
|
-
interface BinaryExp<T extends BinaryExpType =
|
|
206
|
+
interface BinaryExp<T extends BinaryExpType = any> extends ExpBase<T> {
|
|
216
207
|
left: Exp;
|
|
217
208
|
right: Exp;
|
|
218
209
|
}
|
|
@@ -226,7 +217,7 @@ interface IdExp extends ExpBase<'ID'> {
|
|
|
226
217
|
path?: IdExp[];
|
|
227
218
|
args?: Exp[];
|
|
228
219
|
}
|
|
229
|
-
interface LitExp<T =
|
|
220
|
+
interface LitExp<T = Primitive> extends ExpBase<'LIT'> {
|
|
230
221
|
value: T;
|
|
231
222
|
}
|
|
232
223
|
interface SeqExp extends ExpBase<'SEQ'> {
|
|
@@ -262,10 +253,10 @@ interface Plugin {
|
|
|
262
253
|
parsers?: ParserMap;
|
|
263
254
|
compilers?: CompilerMap;
|
|
264
255
|
}
|
|
265
|
-
type ParserFn<T extends SyntaxNode =
|
|
266
|
-
type ParserMap = Record<string, ParserFn>;
|
|
267
|
-
type CompilerFn<T extends SyntaxNode =
|
|
268
|
-
type CompilerMap =
|
|
256
|
+
type ParserFn<T extends Token = any, U extends SyntaxNode = any> = (token: T, parser: Parser) => AsyncGenerator<U | 'NEXT' | void>;
|
|
257
|
+
type ParserMap = Record<string, 'unexpected' | ParserFn>;
|
|
258
|
+
type CompilerFn<T extends SyntaxNode = any> = (node: T, compiler: Compiler) => MaybePromise<void>;
|
|
259
|
+
type CompilerMap = Record<string, CompilerFn>;
|
|
269
260
|
interface BaseOptions {
|
|
270
261
|
debug?: (error: Error) => any;
|
|
271
262
|
filters?: Filters;
|
|
@@ -302,4 +293,4 @@ declare function render(template: string, data: ObjectType, options?: RendererOp
|
|
|
302
293
|
declare function renderFile(filepath: string, data: ObjectType, options?: RendererOptions): Promise<string>;
|
|
303
294
|
|
|
304
295
|
export { Renderer, TokenType, render, renderFile };
|
|
305
|
-
export type { BaseOptions, BinaryExp, BinaryExpTokenType, BinaryExpType, Checker, CommentToken, CompilerFn, CompilerMap, CompilerOptions, DirectiveExpression, DirectiveToken, Exp, ExpBase, ExpToken, ExpTokenType, ExpType, Filters, IdExp, IfExp, LitExp, Loc, Mapping, MaybePromise, NodeCompiler, NotExp, ObjectType, OutputToken, ParserFn, ParserMap, ParserOptions, Plugin, Pos, RendererOptions, Script, SeqExp, Strip, Tag, TernaryExpTokenType, TernaryExpType, TextToken, Token, TokenBase, UnaryExpTokenType, UnaryExpType };
|
|
296
|
+
export type { BaseOptions, BinaryExp, BinaryExpTokenType, BinaryExpType, Checker, CommentToken, CompilerFn, CompilerMap, CompilerOptions, DirectiveExpression, DirectiveToken, Exp, ExpBase, ExpToken, ExpTokenType, ExpType, Filters, IdExp, IfExp, LitExp, Loc, Mapping, MaybePromise, NodeCompiler, NotExp, ObjectType, OutputToken, ParserFn, ParserMap, ParserOptions, Plugin, Pos, Primitive, RendererOptions, Script, SeqExp, Strip, Tag, TernaryExpTokenType, TernaryExpType, TextToken, Token, TokenBase, UnaryExpTokenType, UnaryExpType };
|