janja 0.0.0 → 1.1.0

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.d.ts CHANGED
@@ -71,14 +71,14 @@ interface Mapping {
71
71
  source: Range;
72
72
  target: Range;
73
73
  }
74
- type ExpTokenType = 'AND' | 'OR' | 'NOT' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'IF' | 'ELSE' | 'SET' | 'LP' | 'RP' | 'COMMA' | 'DOT' | 'STR' | 'NUM' | 'BOOL' | 'ID';
74
+ type ExpTokenType = 'AND' | 'OR' | 'IS' | 'NOT' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'IF' | 'ELSE' | 'SET' | 'LP' | 'RP' | 'COMMA' | 'DOT' | 'ID' | 'LIT';
75
75
  interface ExpToken<T = ExpTokenType> extends Range {
76
76
  type: T;
77
77
  value: string | number | boolean | null | undefined;
78
78
  raw?: string;
79
79
  }
80
80
  type Checker = (token: ExpToken) => 'BACK' | 'BREAK' | undefined;
81
- type ExpType = 'AND' | 'OR' | 'NOT' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'IF' | 'SET' | 'SEQ' | 'STR' | 'NUM' | 'BOOL' | 'ID';
81
+ type ExpType = 'AND' | 'OR' | 'IS' | 'NOT' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'IF' | 'SET' | 'SEQ' | 'ID' | 'LIT';
82
82
  interface BaseExp extends Range {
83
83
  type: ExpType;
84
84
  }
@@ -88,24 +88,16 @@ interface IdExp extends BaseExp {
88
88
  path?: IdExp[];
89
89
  args?: Exp[];
90
90
  }
91
- interface StrExp extends BaseExp {
92
- type: 'STR';
93
- value: string;
94
- }
95
- interface NumExp extends BaseExp {
96
- type: 'NUM';
97
- value: number;
98
- }
99
- interface BoolExp extends BaseExp {
100
- type: 'BOOL';
101
- value: boolean;
91
+ interface LitExp extends BaseExp {
92
+ type: 'LIT';
93
+ value: string | number | boolean | null | undefined;
102
94
  }
103
95
  interface NotExp extends BaseExp {
104
96
  type: 'NOT';
105
97
  argument: Exp;
106
98
  }
107
99
  interface BinaryExp extends BaseExp {
108
- type: 'AND' | 'OR' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'SET';
100
+ type: 'AND' | 'OR' | 'IS' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'SET';
109
101
  left: Exp;
110
102
  right: Exp;
111
103
  }
@@ -124,19 +116,19 @@ interface SeqExp extends BaseExp {
124
116
  type: 'SEQ';
125
117
  elements: Exp[];
126
118
  }
127
- type Exp = IdExp | StrExp | NumExp | BoolExp | NotExp | BinaryExp | IfExp | PipeExp | SeqExp;
119
+ type Exp = IdExp | LitExp | NotExp | BinaryExp | IfExp | PipeExp | SeqExp;
128
120
  interface Globals {
129
121
  translations?: Record<string, string>;
130
122
  [key: string]: any;
131
123
  }
132
124
  type Filters = Record<string, (value: any, ...args: any[]) => any>;
133
125
  type Script = (globals: Globals, filters: Filters, escape: (v: unknown) => unknown) => Promise<string>;
134
- interface TagToken extends Range {
126
+ interface Tag extends Range {
135
127
  name: string;
136
128
  value?: Exp | null;
137
129
  raw: string;
138
- previous: TagToken | null;
139
- next: TagToken | null;
130
+ previous: Tag | null;
131
+ next: Tag | null;
140
132
  stripBefore?: boolean;
141
133
  stripAfter?: boolean;
142
134
  }
@@ -148,7 +140,7 @@ interface TagCompiler {
148
140
  * - Return `void` to continue compiling.
149
141
  */
150
142
  compile: (arg: {
151
- token: TagToken;
143
+ tag: Tag;
152
144
  ctx: Context;
153
145
  out: OutScript;
154
146
  }) => MaybePromise<Range | void | false>;
@@ -181,13 +173,12 @@ declare class ExpCompiler {
181
173
  private compileExp;
182
174
  private compileNot;
183
175
  private compileId;
184
- private compileStr;
185
- private compileNum;
186
- private compileBool;
176
+ private compileLit;
187
177
  private compileSeq;
188
178
  private compilePipe;
189
179
  private compileOf;
190
180
  private compileSet;
181
+ private compileIs;
191
182
  private compileBinary;
192
183
  private compileTernary;
193
184
  }
@@ -224,4 +215,4 @@ declare function render(template: string, data: ObjectType, options?: Config): P
224
215
  declare function renderFile(filepath: string, data: ObjectType, options?: Config): Promise<string>;
225
216
 
226
217
  export { Engine, ExpCompiler, ExpParser, compiler, parser, render, renderFile };
227
- export type { BaseExp, BinaryExp, BoolExp, CacheValue, Checker, Config, Exp, ExpToken, ExpTokenType, ExpType, Filters, Globals, IdExp, IfExp, Mapping, MaybePromise, NotExp, NumExp, ObjectType, PipeExp, Range, Script, SeqExp, StrExp, TagCompiler, TagToken };
218
+ export type { BaseExp, BinaryExp, CacheValue, Checker, Config, Exp, ExpToken, ExpTokenType, ExpType, Filters, Globals, IdExp, IfExp, LitExp, Mapping, MaybePromise, NotExp, ObjectType, PipeExp, Range, Script, SeqExp, Tag, TagCompiler };