binja 0.7.2 → 0.8.1
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/README.md +65 -1
- package/dist/cli.js +14 -14
- package/dist/engines/handlebars/index.d.ts +30 -0
- package/dist/engines/handlebars/lexer.d.ts +61 -0
- package/dist/engines/handlebars/parser.d.ts +37 -0
- package/dist/engines/index.d.ts +54 -0
- package/dist/engines/liquid/index.d.ts +30 -0
- package/dist/engines/liquid/lexer.d.ts +69 -0
- package/dist/engines/liquid/parser.d.ts +47 -0
- package/dist/engines/twig/index.d.ts +35 -0
- package/dist/engines/twig/lexer.d.ts +16 -0
- package/dist/engines/twig/parser.d.ts +20 -0
- package/dist/index.js +61 -61
- package/dist/lexer/tokens.d.ts +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Liquid Lexer
|
|
3
|
+
* Tokenizes Liquid template syntax: {{ output }}, {% tags %}
|
|
4
|
+
* Shopify-compatible implementation
|
|
5
|
+
*/
|
|
6
|
+
export declare enum LiquidTokenType {
|
|
7
|
+
TEXT = "TEXT",
|
|
8
|
+
VAR_START = "VAR_START",// {{
|
|
9
|
+
VAR_END = "VAR_END",// }}
|
|
10
|
+
TAG_START = "TAG_START",// {%
|
|
11
|
+
TAG_END = "TAG_END",// %}
|
|
12
|
+
ID = "ID",
|
|
13
|
+
STRING = "STRING",
|
|
14
|
+
NUMBER = "NUMBER",
|
|
15
|
+
DOT = "DOT",
|
|
16
|
+
PIPE = "PIPE",
|
|
17
|
+
COLON = "COLON",
|
|
18
|
+
COMMA = "COMMA",
|
|
19
|
+
LBRACKET = "LBRACKET",
|
|
20
|
+
RBRACKET = "RBRACKET",
|
|
21
|
+
RANGE = "RANGE",// ..
|
|
22
|
+
EQUALS = "EQUALS",// =
|
|
23
|
+
EQ = "EQ",// ==
|
|
24
|
+
NE = "NE",// != or <>
|
|
25
|
+
LT = "LT",
|
|
26
|
+
LE = "LE",
|
|
27
|
+
GT = "GT",
|
|
28
|
+
GE = "GE",
|
|
29
|
+
CONTAINS = "CONTAINS",
|
|
30
|
+
AND = "AND",
|
|
31
|
+
OR = "OR",
|
|
32
|
+
EOF = "EOF"
|
|
33
|
+
}
|
|
34
|
+
export interface LiquidToken {
|
|
35
|
+
type: LiquidTokenType;
|
|
36
|
+
value: string;
|
|
37
|
+
line: number;
|
|
38
|
+
column: number;
|
|
39
|
+
}
|
|
40
|
+
export declare class LiquidLexer {
|
|
41
|
+
private source;
|
|
42
|
+
private pos;
|
|
43
|
+
private line;
|
|
44
|
+
private column;
|
|
45
|
+
private tokens;
|
|
46
|
+
constructor(source: string);
|
|
47
|
+
tokenize(): LiquidToken[];
|
|
48
|
+
private scanToken;
|
|
49
|
+
private checkRawTag;
|
|
50
|
+
private scanRawBlock;
|
|
51
|
+
private scanText;
|
|
52
|
+
private scanExpression;
|
|
53
|
+
private scanExpressionToken;
|
|
54
|
+
private scanString;
|
|
55
|
+
private scanNumber;
|
|
56
|
+
private scanIdentifier;
|
|
57
|
+
private isAtEnd;
|
|
58
|
+
private peek;
|
|
59
|
+
private peekNext;
|
|
60
|
+
private advance;
|
|
61
|
+
private check;
|
|
62
|
+
private match;
|
|
63
|
+
private skipWhitespace;
|
|
64
|
+
private isDigit;
|
|
65
|
+
private isAlpha;
|
|
66
|
+
private isAlphaNumeric;
|
|
67
|
+
private addToken;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=lexer.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Liquid Parser
|
|
3
|
+
* Converts Liquid tokens to a common AST format
|
|
4
|
+
* Shopify-compatible implementation
|
|
5
|
+
*/
|
|
6
|
+
import { LiquidToken } from './lexer';
|
|
7
|
+
import type { TemplateNode } from '../../parser/nodes';
|
|
8
|
+
export declare class LiquidParser {
|
|
9
|
+
private tokens;
|
|
10
|
+
private current;
|
|
11
|
+
private source;
|
|
12
|
+
constructor(tokens: LiquidToken[], source?: string);
|
|
13
|
+
parse(): TemplateNode;
|
|
14
|
+
private parseNodes;
|
|
15
|
+
private parseNode;
|
|
16
|
+
private parseText;
|
|
17
|
+
private parseOutput;
|
|
18
|
+
private parseTag;
|
|
19
|
+
private parseIfTag;
|
|
20
|
+
private parseUnlessTag;
|
|
21
|
+
private parseCaseTag;
|
|
22
|
+
private parseForTag;
|
|
23
|
+
private parseForIterable;
|
|
24
|
+
private parseAssignTag;
|
|
25
|
+
private parseCaptureTag;
|
|
26
|
+
private parseIncrementTag;
|
|
27
|
+
private parseIncludeTag;
|
|
28
|
+
private parseCommentTag;
|
|
29
|
+
private parseRawTag;
|
|
30
|
+
private parseCondition;
|
|
31
|
+
private parseOr;
|
|
32
|
+
private parseAnd;
|
|
33
|
+
private parseComparison;
|
|
34
|
+
private parseExpression;
|
|
35
|
+
private parseExpressionAtom;
|
|
36
|
+
private parsePath;
|
|
37
|
+
private checkTag;
|
|
38
|
+
private consumeTag;
|
|
39
|
+
private checkKeyword;
|
|
40
|
+
private expectKeyword;
|
|
41
|
+
private isAtEnd;
|
|
42
|
+
private peek;
|
|
43
|
+
private advance;
|
|
44
|
+
private check;
|
|
45
|
+
private expect;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twig Engine
|
|
3
|
+
* PHP/Symfony compatible template engine
|
|
4
|
+
*
|
|
5
|
+
* Twig is nearly identical to Jinja2 with a few syntax differences:
|
|
6
|
+
* - Ternary: cond ? x : y (instead of x if cond else y)
|
|
7
|
+
* - Null coalesce: x ?? y
|
|
8
|
+
* - Some filter name differences (e -> escape, raw -> safe)
|
|
9
|
+
*/
|
|
10
|
+
import type { TemplateNode } from '../../parser/nodes';
|
|
11
|
+
export { TwigLexer } from './lexer';
|
|
12
|
+
export { TwigParser, TWIG_FILTER_MAP } from './parser';
|
|
13
|
+
/**
|
|
14
|
+
* Parse a Twig template string into an AST
|
|
15
|
+
*/
|
|
16
|
+
export declare function parse(source: string): TemplateNode;
|
|
17
|
+
/**
|
|
18
|
+
* Compile a Twig template to a render function
|
|
19
|
+
*/
|
|
20
|
+
export declare function compile(source: string): (context: Record<string, any>) => Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Render a Twig template with the given context
|
|
23
|
+
*/
|
|
24
|
+
export declare function render(source: string, context?: Record<string, any>): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Engine descriptor for MultiEngine
|
|
27
|
+
*/
|
|
28
|
+
export declare const engine: {
|
|
29
|
+
name: string;
|
|
30
|
+
extensions: string[];
|
|
31
|
+
parse: typeof parse;
|
|
32
|
+
compile: typeof compile;
|
|
33
|
+
render: typeof render;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twig Lexer
|
|
3
|
+
* Tokenizes Twig template syntax (very similar to Jinja2)
|
|
4
|
+
* PHP/Symfony compatible implementation
|
|
5
|
+
*
|
|
6
|
+
* Twig is nearly identical to Jinja2, so we extend the base lexer
|
|
7
|
+
* and add Twig-specific token handling.
|
|
8
|
+
*/
|
|
9
|
+
import { Lexer, TokenType } from '../../lexer';
|
|
10
|
+
import type { Token } from '../../lexer/tokens';
|
|
11
|
+
export { TokenType };
|
|
12
|
+
export type { Token };
|
|
13
|
+
export declare class TwigLexer extends Lexer {
|
|
14
|
+
constructor(source: string);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=lexer.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twig Parser
|
|
3
|
+
* Extends the Jinja2 parser with Twig-specific syntax
|
|
4
|
+
*
|
|
5
|
+
* Key differences from Jinja2:
|
|
6
|
+
* - Ternary: cond ? x : y (instead of x if cond else y)
|
|
7
|
+
* - Null coalesce: x ?? y
|
|
8
|
+
* - Some filter name differences
|
|
9
|
+
*/
|
|
10
|
+
import { Parser } from '../../parser';
|
|
11
|
+
import { Token } from '../../lexer/tokens';
|
|
12
|
+
import type { TemplateNode } from '../../parser/nodes';
|
|
13
|
+
export declare const TWIG_FILTER_MAP: Record<string, string>;
|
|
14
|
+
export declare class TwigParser extends Parser {
|
|
15
|
+
constructor(tokens: Token[], source?: string);
|
|
16
|
+
parse(): TemplateNode;
|
|
17
|
+
private transformTwigAST;
|
|
18
|
+
private transformNode;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=parser.d.ts.map
|