@plitzi/sdk-shared 0.32.5 → 0.32.6
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/CHANGELOG.md +8 -0
- package/dist/dataSource/getBindingsDetails.mjs +17 -23
- package/dist/dataSource/helpers/getSourceName.d.ts +4 -0
- package/dist/dataSource/helpers/getSourceName.mjs +4 -0
- package/dist/dataSource/helpers/index.d.ts +2 -0
- package/dist/dataSource/helpers/index.mjs +2 -0
- package/dist/dataSource/hooks/useRegisterSource.mjs +20 -18
- package/dist/dataSource/index.d.ts +1 -0
- package/dist/dataSource/index.mjs +5 -4
- package/dist/dataSource/utility/twigTemplate.mjs +3 -2
- package/dist/helpers/index.mjs +7 -5
- package/dist/helpers/twigWrapper/AST.d.ts +116 -0
- package/dist/helpers/twigWrapper/Evaluator/Evaluator.d.ts +7 -0
- package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +220 -0
- package/dist/helpers/twigWrapper/Evaluator/helpers.d.ts +4 -0
- package/dist/helpers/twigWrapper/Evaluator/helpers.mjs +4 -0
- package/dist/helpers/twigWrapper/Evaluator/index.d.ts +2 -0
- package/dist/helpers/twigWrapper/Evaluator/index.mjs +2 -0
- package/dist/helpers/twigWrapper/Lexer/Lexer.d.ts +2 -0
- package/dist/helpers/twigWrapper/Lexer/Lexer.mjs +53 -0
- package/dist/helpers/twigWrapper/Lexer/index.d.ts +3 -0
- package/dist/helpers/twigWrapper/Lexer/index.mjs +3 -0
- package/dist/helpers/twigWrapper/Lexer/types.d.ts +17 -0
- package/dist/helpers/twigWrapper/Lexer/types.mjs +10 -0
- package/dist/helpers/twigWrapper/Parser/Cursor.d.ts +14 -0
- package/dist/helpers/twigWrapper/Parser/Cursor.mjs +63 -0
- package/dist/helpers/twigWrapper/Parser/ExpressionParser.d.ts +3 -0
- package/dist/helpers/twigWrapper/Parser/ExpressionParser.mjs +296 -0
- package/dist/helpers/twigWrapper/Parser/Parser.d.ts +3 -0
- package/dist/helpers/twigWrapper/Parser/Parser.mjs +237 -0
- package/dist/helpers/twigWrapper/Parser/helpers.d.ts +2 -0
- package/dist/helpers/twigWrapper/Parser/helpers.mjs +18 -0
- package/dist/helpers/twigWrapper/Parser/index.d.ts +2 -0
- package/dist/helpers/twigWrapper/Parser/index.mjs +2 -0
- package/dist/helpers/twigWrapper/Parser/types.d.ts +5 -0
- package/dist/helpers/twigWrapper/TemplateCache/TemplateCache.d.ts +17 -0
- package/dist/helpers/twigWrapper/TemplateCache/TemplateCache.mjs +64 -0
- package/dist/helpers/twigWrapper/TemplateCache/index.d.ts +1 -0
- package/dist/helpers/twigWrapper/TemplateCache/index.mjs +2 -0
- package/dist/helpers/twigWrapper/bench.bench.d.ts +1 -0
- package/dist/helpers/twigWrapper/charClass.d.ts +44 -0
- package/dist/helpers/twigWrapper/charClass.mjs +59 -0
- package/dist/helpers/twigWrapper/filters/filters.d.ts +14 -0
- package/dist/helpers/twigWrapper/filters/filters.mjs +372 -0
- package/dist/helpers/twigWrapper/filters/index.d.ts +1 -0
- package/dist/helpers/twigWrapper/filters/index.mjs +2 -0
- package/dist/helpers/twigWrapper/index.d.ts +5 -0
- package/dist/helpers/twigWrapper/index.mjs +4 -0
- package/dist/helpers/twigWrapper/processTwig/helpers.d.ts +7 -0
- package/dist/helpers/twigWrapper/processTwig/helpers.mjs +34 -0
- package/dist/helpers/twigWrapper/processTwig/index.d.ts +1 -0
- package/dist/helpers/twigWrapper/processTwig/index.mjs +2 -0
- package/dist/helpers/twigWrapper/processTwig/processTwig.d.ts +1 -0
- package/dist/helpers/twigWrapper/processTwig/processTwig.mjs +24 -0
- package/dist/helpers/twigWrapper/tokens/hasValidToken.d.ts +1 -0
- package/dist/helpers/twigWrapper/tokens/hasValidToken.mjs +9 -0
- package/dist/helpers/twigWrapper/tokens/tokenPatterns.d.ts +2 -0
- package/dist/helpers/twigWrapper/tokens/tokenPatterns.mjs +4 -0
- package/dist/hooks/useNetwork.mjs +1 -1
- package/dist/index.mjs +37 -34
- package/dist/network/graphql/builder/Mutations/Segment/SegmentAddMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/SegmentAddTemplateMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/SegmentUpdateMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentAddElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentCloneElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentMoveElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentRemoveElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentUpdateElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentUpdateElementsMutation.d.ts +2 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentUpdateElementsMutation.mjs +24 -0
- package/dist/network/graphql/builder/Mutations/Segment/style/selectors/SegmentStyleRemoveSelectorsMutation.d.ts +2 -0
- package/dist/network/graphql/builder/Mutations/Segment/style/selectors/SegmentStyleRemoveSelectorsMutation.mjs +12 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceAddElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceAddTemplateMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceCloneElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceMoveElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceRemoveElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateElementsMutation.d.ts +2 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateElementsMutation.mjs +24 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateSchemaMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/pages/SpaceAddPageMutation.mjs +9 -2
- package/dist/network/graphql/builder/Mutations/Space/pages/SpaceUpdatePageMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Style/selectors/StyleRemoveSelectorsMutation.d.ts +2 -0
- package/dist/network/graphql/builder/Mutations/Style/selectors/StyleRemoveSelectorsMutation.mjs +12 -0
- package/dist/network/graphql/builder/Mutations/index.d.ts +8 -0
- package/dist/network/graphql/builder/Mutations/index.mjs +124 -116
- package/dist/network/graphql/builder/Queries/InitQuery.mjs +2 -0
- package/dist/network/graphql/builder/Queries/Segment/SegmentQuery.mjs +1 -0
- package/dist/network/graphql/builder/Queries/Segment/SegmentsQuery.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/SegmentAddTemplateSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/space/elements/SegmentAddElementSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/space/elements/SegmentCloneElementSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/space/elements/SegmentUpdateElementSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/space/elements/SegmentUpdateElementsSubscription.d.ts +7 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/space/elements/SegmentUpdateElementsSubscription.mjs +27 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/style/selectors/SegmentStyleRemoveSelectorsSubscription.d.ts +8 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/style/selectors/SegmentStyleRemoveSelectorsSubscription.mjs +13 -0
- package/dist/network/graphql/builder/Subscriptions/Space/SpaceAddTemplateSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/SpaceUpdatedSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/elements/SpaceAddElementSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/elements/SpaceCloneElementSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/elements/SpaceUpdateElementSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/elements/SpaceUpdateElementsSubscription.d.ts +6 -0
- package/dist/network/graphql/builder/Subscriptions/Space/elements/SpaceUpdateElementsSubscription.mjs +26 -0
- package/dist/network/graphql/builder/Subscriptions/Space/pages/SpaceAddPageSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/pages/SpaceHomePageSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/pages/SpaceUpdatePageSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Style/selector/StyleRemoveSelectorsSubscription.d.ts +7 -0
- package/dist/network/graphql/builder/Subscriptions/Style/selector/StyleRemoveSelectorsSubscription.mjs +12 -0
- package/dist/network/graphql/builder/Subscriptions/index.d.ts +12 -0
- package/dist/network/graphql/builder/Subscriptions/index.mjs +94 -86
- package/dist/network/graphql/sdk/Queries/InitQuery.mjs +2 -0
- package/dist/network/graphql/sdk/Queries/Segment/SegmentQuery.mjs +1 -0
- package/dist/network/graphql/sdk/Queries/Segment/SegmentsQuery.mjs +1 -0
- package/dist/store/index.d.ts +33 -33
- package/dist/style/styleConstants.mjs +12 -8
- package/dist/types/CommonTypes.d.ts +1 -3
- package/dist/types/EventBridgeTypes.d.ts +1 -1
- package/dist/types/InteractionTypes.d.ts +2 -1
- package/dist/types/SchemaTypes.d.ts +6 -11
- package/dist/types/ServerTypes.d.ts +59 -0
- package/dist/types/StyleTypes.d.ts +1 -0
- package/package.json +176 -21
- package/dist/helpers/twigWrapper.d.ts +0 -4
- package/dist/helpers/twigWrapper.mjs +0 -33
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class Cursor {
|
|
2
|
+
protected readonly src: string;
|
|
3
|
+
protected pos: number;
|
|
4
|
+
constructor(src: string);
|
|
5
|
+
protected eof(): boolean;
|
|
6
|
+
protected peek(): number;
|
|
7
|
+
protected at(offset: number): number;
|
|
8
|
+
protected skipWs(): void;
|
|
9
|
+
protected scanName(): string;
|
|
10
|
+
protected scanStringLiteral(): string;
|
|
11
|
+
protected scanNumber(): number;
|
|
12
|
+
protected matchKeyword(kw: string): boolean;
|
|
13
|
+
protected matchBinaryOp(): string | null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Char as e, isDigit as t, isIdentPart as n, isIdentStart as r, isPathPart as i, isSpace as a } from "../charClass.mjs";
|
|
2
|
+
//#region src/helpers/twigWrapper/Parser/Cursor.ts
|
|
3
|
+
var o = class {
|
|
4
|
+
src;
|
|
5
|
+
pos = 0;
|
|
6
|
+
constructor(e) {
|
|
7
|
+
this.src = e;
|
|
8
|
+
}
|
|
9
|
+
eof() {
|
|
10
|
+
return this.pos >= this.src.length;
|
|
11
|
+
}
|
|
12
|
+
peek() {
|
|
13
|
+
return this.pos < this.src.length ? this.src.charCodeAt(this.pos) : -1;
|
|
14
|
+
}
|
|
15
|
+
at(e) {
|
|
16
|
+
let t = this.pos + e;
|
|
17
|
+
return t < this.src.length ? this.src.charCodeAt(t) : -1;
|
|
18
|
+
}
|
|
19
|
+
skipWs() {
|
|
20
|
+
for (; this.pos < this.src.length && a(this.src.charCodeAt(this.pos));) this.pos++;
|
|
21
|
+
}
|
|
22
|
+
scanName() {
|
|
23
|
+
let e = this.pos;
|
|
24
|
+
if (!this.eof() && r(this.src.charCodeAt(this.pos))) for (this.pos++; !this.eof() && i(this.src.charCodeAt(this.pos));) this.pos++;
|
|
25
|
+
return this.src.slice(e, this.pos);
|
|
26
|
+
}
|
|
27
|
+
scanStringLiteral() {
|
|
28
|
+
let t = this.src.charCodeAt(this.pos);
|
|
29
|
+
this.pos++;
|
|
30
|
+
let n = "";
|
|
31
|
+
for (; this.pos < this.src.length && this.src.charCodeAt(this.pos) !== t;) if (this.src.charCodeAt(this.pos) === e.Backslash && this.pos + 1 < this.src.length) {
|
|
32
|
+
this.pos++;
|
|
33
|
+
let r = this.src.charCodeAt(this.pos);
|
|
34
|
+
r === e.LowerN ? n += "\n" : r === e.LowerT ? n += " " : r === e.LowerR ? n += "\r" : r === e.Backslash ? n += "\\" : r === t ? n += String.fromCharCode(r) : n += String.fromCharCode(e.Backslash) + String.fromCharCode(r), this.pos++;
|
|
35
|
+
} else n += this.src[this.pos], this.pos++;
|
|
36
|
+
return this.pos < this.src.length && this.pos++, n;
|
|
37
|
+
}
|
|
38
|
+
scanNumber() {
|
|
39
|
+
let n = this.pos;
|
|
40
|
+
for (this.src.charCodeAt(this.pos) === e.Minus && this.pos++; this.pos < this.src.length && t(this.src.charCodeAt(this.pos));) this.pos++;
|
|
41
|
+
if (this.src.charCodeAt(this.pos) === e.Dot) for (this.pos++; this.pos < this.src.length && t(this.src.charCodeAt(this.pos));) this.pos++;
|
|
42
|
+
return Number(this.src.slice(n, this.pos));
|
|
43
|
+
}
|
|
44
|
+
matchKeyword(e) {
|
|
45
|
+
let t = this.pos + e.length;
|
|
46
|
+
if (t > this.src.length) return !1;
|
|
47
|
+
for (let t = 0; t < e.length; t++) if (this.src.charCodeAt(this.pos + t) !== e.charCodeAt(t)) return !1;
|
|
48
|
+
return t < this.src.length && n(this.src.charCodeAt(t)) ? !1 : (this.pos = t, this.skipWs(), !0);
|
|
49
|
+
}
|
|
50
|
+
matchBinaryOp() {
|
|
51
|
+
this.skipWs();
|
|
52
|
+
let t = this.peek();
|
|
53
|
+
if (this.at(1) === e.Equals) {
|
|
54
|
+
if (t === e.Equals) return this.pos += 2, "==";
|
|
55
|
+
if (t === e.Bang) return this.pos += 2, "!=";
|
|
56
|
+
if (t === e.Greater) return this.pos += 2, ">=";
|
|
57
|
+
if (t === e.Less) return this.pos += 2, "<=";
|
|
58
|
+
}
|
|
59
|
+
return t === e.Greater ? (this.pos++, ">") : t === e.Less ? (this.pos++, "<") : null;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
export { o as Cursor };
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { Char as e, isDigit as t } from "../charClass.mjs";
|
|
2
|
+
import { Cursor as n } from "./Cursor.mjs";
|
|
3
|
+
//#region src/helpers/twigWrapper/Parser/ExpressionParser.ts
|
|
4
|
+
var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a = class extends n {
|
|
5
|
+
parseTernary() {
|
|
6
|
+
let t = this.parseOr();
|
|
7
|
+
if (this.skipWs(), this.peek() === e.Question) {
|
|
8
|
+
this.pos++, this.skipWs();
|
|
9
|
+
let n = this.parseOr();
|
|
10
|
+
if (this.skipWs(), this.peek() === e.Colon) return this.pos++, this.skipWs(), {
|
|
11
|
+
type: "ternary",
|
|
12
|
+
condition: t,
|
|
13
|
+
trueExpr: n,
|
|
14
|
+
falseExpr: this.parseTernary()
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return t;
|
|
18
|
+
}
|
|
19
|
+
parseOr() {
|
|
20
|
+
let e = this.parseAnd();
|
|
21
|
+
for (this.skipWs(); this.matchKeyword("or");) e = {
|
|
22
|
+
type: "binary",
|
|
23
|
+
operator: "or",
|
|
24
|
+
left: e,
|
|
25
|
+
right: this.parseAnd()
|
|
26
|
+
}, this.skipWs();
|
|
27
|
+
return e;
|
|
28
|
+
}
|
|
29
|
+
parseAnd() {
|
|
30
|
+
let e = this.parseNot();
|
|
31
|
+
for (this.skipWs(); this.matchKeyword("and");) e = {
|
|
32
|
+
type: "binary",
|
|
33
|
+
operator: "and",
|
|
34
|
+
left: e,
|
|
35
|
+
right: this.parseNot()
|
|
36
|
+
}, this.skipWs();
|
|
37
|
+
return e;
|
|
38
|
+
}
|
|
39
|
+
parseNot() {
|
|
40
|
+
return this.skipWs(), this.matchKeyword("not") ? {
|
|
41
|
+
type: "unary",
|
|
42
|
+
operator: "not",
|
|
43
|
+
operand: this.parseComparison()
|
|
44
|
+
} : this.parseComparison();
|
|
45
|
+
}
|
|
46
|
+
parseComparison() {
|
|
47
|
+
let e = this.parseConcat();
|
|
48
|
+
for (this.skipWs(); !this.eof();) {
|
|
49
|
+
if (this.matchKeyword("is")) {
|
|
50
|
+
this.skipWs(), e = {
|
|
51
|
+
type: "binary",
|
|
52
|
+
operator: this.matchKeyword("not") ? "is not" : "is",
|
|
53
|
+
left: e,
|
|
54
|
+
right: this.parseConcat()
|
|
55
|
+
}, this.skipWs();
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (this.matchKeyword("not")) {
|
|
59
|
+
if (this.skipWs(), this.matchKeyword("in")) {
|
|
60
|
+
e = {
|
|
61
|
+
type: "binary",
|
|
62
|
+
operator: "not in",
|
|
63
|
+
left: e,
|
|
64
|
+
right: this.parseConcat()
|
|
65
|
+
}, this.skipWs();
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
let t = this.src.slice(this.pos - 4);
|
|
69
|
+
return this.pos = this.src.length, {
|
|
70
|
+
type: "unary",
|
|
71
|
+
operator: "not",
|
|
72
|
+
operand: r(t)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (this.matchKeyword("in")) {
|
|
76
|
+
e = {
|
|
77
|
+
type: "binary",
|
|
78
|
+
operator: "in",
|
|
79
|
+
left: e,
|
|
80
|
+
right: this.parseConcat()
|
|
81
|
+
}, this.skipWs();
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
let t = this.matchBinaryOp();
|
|
85
|
+
if (t) {
|
|
86
|
+
e = {
|
|
87
|
+
type: "binary",
|
|
88
|
+
operator: t,
|
|
89
|
+
left: e,
|
|
90
|
+
right: this.parseConcat()
|
|
91
|
+
}, this.skipWs();
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
return e;
|
|
97
|
+
}
|
|
98
|
+
parseConcat() {
|
|
99
|
+
let t = this.parseAdditive();
|
|
100
|
+
for (this.skipWs(); this.peek() === e.Tilde;) {
|
|
101
|
+
this.pos++;
|
|
102
|
+
let e = this.parseAdditive();
|
|
103
|
+
t = t.type === "concat" ? {
|
|
104
|
+
type: "concat",
|
|
105
|
+
parts: [...t.parts, e]
|
|
106
|
+
} : {
|
|
107
|
+
type: "concat",
|
|
108
|
+
parts: [t, e]
|
|
109
|
+
}, this.skipWs();
|
|
110
|
+
}
|
|
111
|
+
return t;
|
|
112
|
+
}
|
|
113
|
+
parseAdditive() {
|
|
114
|
+
let t = this.parseMultiplicative();
|
|
115
|
+
this.skipWs();
|
|
116
|
+
for (let n = this.peek(); n === e.Plus || n === e.Minus; n = this.peek()) this.pos++, t = {
|
|
117
|
+
type: "binary",
|
|
118
|
+
operator: n === e.Plus ? "+" : "-",
|
|
119
|
+
left: t,
|
|
120
|
+
right: this.parseMultiplicative()
|
|
121
|
+
}, this.skipWs();
|
|
122
|
+
return t;
|
|
123
|
+
}
|
|
124
|
+
parseMultiplicative() {
|
|
125
|
+
let t = this.parseDefault();
|
|
126
|
+
this.skipWs();
|
|
127
|
+
for (let n = this.peek(); n === e.Star || n === e.Slash || n === e.Percent; n = this.peek()) this.pos++, t = {
|
|
128
|
+
type: "binary",
|
|
129
|
+
operator: n === e.Star ? "*" : n === e.Slash ? "/" : "%",
|
|
130
|
+
left: t,
|
|
131
|
+
right: this.parseDefault()
|
|
132
|
+
}, this.skipWs();
|
|
133
|
+
return t;
|
|
134
|
+
}
|
|
135
|
+
parseDefault() {
|
|
136
|
+
if (this.skipWs(), this.peek() === e.Minus && t(this.at(1))) return this.maybeTrailingFilters({
|
|
137
|
+
type: "literal",
|
|
138
|
+
value: this.scanNumber()
|
|
139
|
+
});
|
|
140
|
+
if (this.peek() === e.Minus) return this.pos++, {
|
|
141
|
+
type: "unary",
|
|
142
|
+
operator: "-",
|
|
143
|
+
operand: this.parseDefault()
|
|
144
|
+
};
|
|
145
|
+
let n = this.parseAtom();
|
|
146
|
+
for (this.skipWs(); this.peek() === e.Question && this.at(1) === e.Question;) this.pos += 2, this.skipWs(), n = {
|
|
147
|
+
type: "default",
|
|
148
|
+
value: n,
|
|
149
|
+
defaultExpr: this.parseAtom()
|
|
150
|
+
}, this.skipWs();
|
|
151
|
+
return n;
|
|
152
|
+
}
|
|
153
|
+
parseAtom() {
|
|
154
|
+
this.skipWs();
|
|
155
|
+
let n = this.peek();
|
|
156
|
+
if (n === e.LParen) {
|
|
157
|
+
this.pos++, this.skipWs();
|
|
158
|
+
let t = this.pos, n = this.tryParseArrowParams();
|
|
159
|
+
if (n !== null) return this.maybeTrailingFilters({
|
|
160
|
+
type: "arrow",
|
|
161
|
+
params: n,
|
|
162
|
+
body: this.parseTernary()
|
|
163
|
+
});
|
|
164
|
+
this.pos = t;
|
|
165
|
+
let r = this.parseTernary();
|
|
166
|
+
return this.skipWs(), this.peek() === e.RParen && this.pos++, this.maybeTrailingFilters(r);
|
|
167
|
+
}
|
|
168
|
+
return n === e.SingleQuote || n === e.DoubleQuote ? this.maybeTrailingFilters({
|
|
169
|
+
type: "literal",
|
|
170
|
+
value: this.scanStringLiteral()
|
|
171
|
+
}) : t(n) ? this.maybeTrailingFilters({
|
|
172
|
+
type: "literal",
|
|
173
|
+
value: this.scanNumber()
|
|
174
|
+
}) : n === e.LBracket ? (this.pos++, this.maybeTrailingFilters({
|
|
175
|
+
type: "array",
|
|
176
|
+
elements: this.parseArgList(e.RBracket)
|
|
177
|
+
})) : n === e.LBrace ? (this.pos++, this.maybeTrailingFilters(this.parseObjectLiteral())) : this.parsePathOrFunctionOrArrow();
|
|
178
|
+
}
|
|
179
|
+
tryParseArrowParams() {
|
|
180
|
+
let t = this.pos, n = [];
|
|
181
|
+
for (this.skipWs(); this.peek() !== e.RParen;) {
|
|
182
|
+
let r = this.scanName();
|
|
183
|
+
if (!r) return this.pos = t, null;
|
|
184
|
+
if (n.push(r), this.skipWs(), this.peek() === e.Comma) {
|
|
185
|
+
this.pos++, this.skipWs();
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
return this.skipWs(), this.peek() === e.RParen && (this.pos++, this.skipWs(), this.peek() === e.Equals && this.at(1) === e.Greater) ? (this.pos += 2, n) : (this.pos = t, null);
|
|
191
|
+
}
|
|
192
|
+
parsePathOrFunctionOrArrow() {
|
|
193
|
+
let t = this.scanName();
|
|
194
|
+
if (!t) return this.pos++, {
|
|
195
|
+
type: "literal",
|
|
196
|
+
value: ""
|
|
197
|
+
};
|
|
198
|
+
if (t === "true" || t === "false") return this.maybeTrailingFilters({
|
|
199
|
+
type: "literal",
|
|
200
|
+
value: t === "true"
|
|
201
|
+
});
|
|
202
|
+
if (this.skipWs(), this.peek() === e.Equals && this.at(1) === e.Greater) return this.pos += 2, this.maybeTrailingFilters({
|
|
203
|
+
type: "arrow",
|
|
204
|
+
params: [t],
|
|
205
|
+
body: this.parseTernary()
|
|
206
|
+
});
|
|
207
|
+
if (this.peek() === e.LParen) {
|
|
208
|
+
this.pos++;
|
|
209
|
+
let n = this.parseArgList(e.RParen);
|
|
210
|
+
return this.maybeTrailingFilters({
|
|
211
|
+
type: "function",
|
|
212
|
+
name: t,
|
|
213
|
+
args: n
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
let n = [t];
|
|
217
|
+
for (; this.peek() === e.Dot;) {
|
|
218
|
+
this.pos++;
|
|
219
|
+
let e = this.scanName();
|
|
220
|
+
e && n.push(e);
|
|
221
|
+
}
|
|
222
|
+
return this.maybeTrailingFilters({
|
|
223
|
+
type: "path",
|
|
224
|
+
segments: n
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
maybeTrailingFilters(t) {
|
|
228
|
+
return this.skipWs(), this.peek() === e.Pipe ? {
|
|
229
|
+
type: "filter",
|
|
230
|
+
subject: t,
|
|
231
|
+
filters: this.parseTrailingFilters()
|
|
232
|
+
} : t;
|
|
233
|
+
}
|
|
234
|
+
parseObjectLiteral() {
|
|
235
|
+
let t = [];
|
|
236
|
+
for (this.skipWs(); !this.eof() && this.peek() !== e.RBrace;) {
|
|
237
|
+
let n = this.parseObjectKey();
|
|
238
|
+
this.skipWs(), this.peek() === e.Colon && this.pos++, this.skipWs(), t.push({
|
|
239
|
+
key: n,
|
|
240
|
+
value: this.parseTernary()
|
|
241
|
+
}), this.skipWs(), this.peek() === e.Comma && (this.pos++, this.skipWs());
|
|
242
|
+
}
|
|
243
|
+
return this.peek() === e.RBrace && this.pos++, {
|
|
244
|
+
type: "object",
|
|
245
|
+
entries: t
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
parseObjectKey() {
|
|
249
|
+
let n = this.peek();
|
|
250
|
+
if (n === e.SingleQuote || n === e.DoubleQuote) return {
|
|
251
|
+
type: "literal",
|
|
252
|
+
value: this.scanStringLiteral()
|
|
253
|
+
};
|
|
254
|
+
if (t(n)) return {
|
|
255
|
+
type: "literal",
|
|
256
|
+
value: this.scanNumber()
|
|
257
|
+
};
|
|
258
|
+
if (n === e.LParen) {
|
|
259
|
+
this.pos++, this.skipWs();
|
|
260
|
+
let t = this.parseTernary();
|
|
261
|
+
return this.skipWs(), this.peek() === e.RParen && this.pos++, t;
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
type: "literal",
|
|
265
|
+
value: this.scanName()
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
parseArgList(t) {
|
|
269
|
+
let n = [];
|
|
270
|
+
for (this.skipWs(); !this.eof() && this.peek() !== t;) n.push(this.parseTernary()), this.skipWs(), this.peek() === e.Comma && (this.pos++, this.skipWs());
|
|
271
|
+
return this.peek() === t && this.pos++, n;
|
|
272
|
+
}
|
|
273
|
+
parseTrailingFilters() {
|
|
274
|
+
let t = [];
|
|
275
|
+
for (; this.peek() === e.Pipe;) this.pos++, this.skipWs(), t.push(this.readFilter()), this.skipWs();
|
|
276
|
+
return t;
|
|
277
|
+
}
|
|
278
|
+
parseApplyChain() {
|
|
279
|
+
this.skipWs();
|
|
280
|
+
let t = [this.readFilter()];
|
|
281
|
+
for (this.skipWs(); this.peek() === e.Pipe;) this.pos++, this.skipWs(), t.push(this.readFilter()), this.skipWs();
|
|
282
|
+
return t;
|
|
283
|
+
}
|
|
284
|
+
readFilter() {
|
|
285
|
+
let t = this.scanName();
|
|
286
|
+
return this.skipWs(), this.peek() === e.LParen ? (this.pos++, {
|
|
287
|
+
name: t,
|
|
288
|
+
args: this.parseArgList(e.RParen)
|
|
289
|
+
}) : {
|
|
290
|
+
name: t,
|
|
291
|
+
args: []
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
//#endregion
|
|
296
|
+
export { i as parseApplyFilters, r as parseExpression };
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { isSimpleIdentifier as e, isVariableName as t } from "../charClass.mjs";
|
|
2
|
+
import { reconstructSource as n, reconstructToken as r } from "../Lexer/types.mjs";
|
|
3
|
+
import { parseApplyFilters as i, parseExpression as a } from "./ExpressionParser.mjs";
|
|
4
|
+
import { extractFirstWord as o, splitRange as s } from "./helpers.mjs";
|
|
5
|
+
//#region src/helpers/twigWrapper/Parser/Parser.ts
|
|
6
|
+
var c = (e, t = !1) => {
|
|
7
|
+
let n = new f(e, t), r = n.parseBody();
|
|
8
|
+
if (!n.error) {
|
|
9
|
+
let e = n.peek();
|
|
10
|
+
if (e && e.type === "tag") {
|
|
11
|
+
let t = o(e.content.trim());
|
|
12
|
+
l.has(t) && (n.error = `Orphan closing tag: {% ${t} %} without matching opening tag`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
nodes: r,
|
|
17
|
+
error: n.error
|
|
18
|
+
};
|
|
19
|
+
}, l = /* @__PURE__ */ new Set([
|
|
20
|
+
"endif",
|
|
21
|
+
"endfor",
|
|
22
|
+
"endset",
|
|
23
|
+
"endapply",
|
|
24
|
+
"else",
|
|
25
|
+
"elseif"
|
|
26
|
+
]), u = () => ({
|
|
27
|
+
type: "if",
|
|
28
|
+
condition: {
|
|
29
|
+
type: "literal",
|
|
30
|
+
value: !1
|
|
31
|
+
},
|
|
32
|
+
body: [],
|
|
33
|
+
elseifClauses: [],
|
|
34
|
+
elseBody: null
|
|
35
|
+
}), d = () => ({
|
|
36
|
+
type: "for",
|
|
37
|
+
valueVar: "_item",
|
|
38
|
+
keyVar: null,
|
|
39
|
+
collection: {
|
|
40
|
+
type: "literal",
|
|
41
|
+
value: ""
|
|
42
|
+
},
|
|
43
|
+
body: [],
|
|
44
|
+
elseBody: null
|
|
45
|
+
}), f = class {
|
|
46
|
+
tokens;
|
|
47
|
+
keepEmptyTokens;
|
|
48
|
+
pos = 0;
|
|
49
|
+
error = null;
|
|
50
|
+
constructor(e, t = !1) {
|
|
51
|
+
this.tokens = e, this.keepEmptyTokens = t;
|
|
52
|
+
}
|
|
53
|
+
peek() {
|
|
54
|
+
return this.tokens[this.pos];
|
|
55
|
+
}
|
|
56
|
+
advance() {
|
|
57
|
+
let e = this.tokens[this.pos];
|
|
58
|
+
return e && this.pos++, e;
|
|
59
|
+
}
|
|
60
|
+
isTag(e) {
|
|
61
|
+
let t = this.peek();
|
|
62
|
+
if (!t || t.type !== "tag") return !1;
|
|
63
|
+
let n = t.content.trim();
|
|
64
|
+
return n === e || n.startsWith(e + " ") || n.startsWith(e + " ");
|
|
65
|
+
}
|
|
66
|
+
parseBody() {
|
|
67
|
+
let e = [];
|
|
68
|
+
for (; this.pos < this.tokens.length;) {
|
|
69
|
+
let t = this.peek();
|
|
70
|
+
if (!t || t.type === "tag" && l.has(o(t.content.trim()))) break;
|
|
71
|
+
let n = this.parseNode();
|
|
72
|
+
n && e.push(n);
|
|
73
|
+
}
|
|
74
|
+
return e;
|
|
75
|
+
}
|
|
76
|
+
parseNode() {
|
|
77
|
+
let e = this.peek();
|
|
78
|
+
return e ? e.type === "text" ? (this.advance(), {
|
|
79
|
+
type: "text",
|
|
80
|
+
value: e.value
|
|
81
|
+
}) : e.type === "variable" ? this.parseVariable() : this.parseTag() : null;
|
|
82
|
+
}
|
|
83
|
+
parseVariable() {
|
|
84
|
+
let t = this.advance();
|
|
85
|
+
if (!t || t.type !== "variable") return {
|
|
86
|
+
type: "variable",
|
|
87
|
+
raw: !1,
|
|
88
|
+
expression: {
|
|
89
|
+
type: "literal",
|
|
90
|
+
value: ""
|
|
91
|
+
},
|
|
92
|
+
source: ""
|
|
93
|
+
};
|
|
94
|
+
let r = t.content.trim(), i = this.keepEmptyTokens ? n(t.content, t.raw) : "";
|
|
95
|
+
if (e(r)) return {
|
|
96
|
+
type: "variable",
|
|
97
|
+
raw: t.raw,
|
|
98
|
+
expression: {
|
|
99
|
+
type: "path",
|
|
100
|
+
segments: [r]
|
|
101
|
+
},
|
|
102
|
+
source: i
|
|
103
|
+
};
|
|
104
|
+
let o = a(r);
|
|
105
|
+
return {
|
|
106
|
+
type: "variable",
|
|
107
|
+
raw: t.raw,
|
|
108
|
+
expression: o,
|
|
109
|
+
source: i
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
parseTag() {
|
|
113
|
+
let e = this.peek();
|
|
114
|
+
if (!e || e.type !== "tag") return null;
|
|
115
|
+
switch (o(e.content.trim())) {
|
|
116
|
+
case "if": return this.parseIf();
|
|
117
|
+
case "for": return this.parseFor();
|
|
118
|
+
case "set": return this.parseSet();
|
|
119
|
+
case "apply": return this.parseApply();
|
|
120
|
+
case "break": return this.advance(), { type: "break" };
|
|
121
|
+
case "continue": return this.advance(), { type: "continue" };
|
|
122
|
+
default: return this.advance(), null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
parseIf() {
|
|
126
|
+
this.advance();
|
|
127
|
+
let e = this.tokens[this.pos - 1];
|
|
128
|
+
if (e.type !== "tag") return this.error = "Malformed {% if %} tag", u();
|
|
129
|
+
let t = e.content.trim(), n = t.indexOf(" ") === -1 ? "" : t.slice(t.indexOf(" ") + 1).trim();
|
|
130
|
+
if (!n) return this.error = "Malformed {% if %} tag: missing condition", u();
|
|
131
|
+
let r = a(n), i = this.parseBody(), s = [], c = null, l = !1;
|
|
132
|
+
for (; this.peek();) {
|
|
133
|
+
let e = this.peek();
|
|
134
|
+
if (!e || e.type !== "tag") break;
|
|
135
|
+
let t = o(e.content.trim());
|
|
136
|
+
if (t === "elseif") {
|
|
137
|
+
this.advance();
|
|
138
|
+
let t = e.content.trim(), n = a(t.slice(t.indexOf(" ") + 1).trim()), r = this.parseBody();
|
|
139
|
+
s.push({
|
|
140
|
+
condition: n,
|
|
141
|
+
body: r
|
|
142
|
+
});
|
|
143
|
+
} else if (t === "else") this.advance(), c = this.parseBody();
|
|
144
|
+
else if (t === "endif") {
|
|
145
|
+
this.advance(), l = !0;
|
|
146
|
+
break;
|
|
147
|
+
} else break;
|
|
148
|
+
}
|
|
149
|
+
return l || (this.error = "Malformed {% if %} block: missing {% endif %}"), {
|
|
150
|
+
type: "if",
|
|
151
|
+
condition: r,
|
|
152
|
+
body: i,
|
|
153
|
+
elseifClauses: s,
|
|
154
|
+
elseBody: c
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
parseFor() {
|
|
158
|
+
let e = this.pos;
|
|
159
|
+
this.advance();
|
|
160
|
+
let n = this.tokens[this.pos - 1];
|
|
161
|
+
if (n.type !== "tag") return d();
|
|
162
|
+
let r = n.content.trim(), i = r.slice(r.indexOf(" ") + 1).trim(), c = /\sin\s/.exec(i);
|
|
163
|
+
if (!c) return this.error = "Invalid {% for %} syntax: missing the `in` keyword", d();
|
|
164
|
+
let l = i.slice(0, c.index).trim(), u = i.slice(c.index + c[0].length).trim(), f = s(u), p = f ? {
|
|
165
|
+
type: "range",
|
|
166
|
+
start: a(f[0]),
|
|
167
|
+
end: a(f[1])
|
|
168
|
+
} : a(u), m = l.indexOf(","), h = m === -1 ? null : l.slice(0, m).trim(), g = m === -1 ? l : l.slice(m + 1).trim();
|
|
169
|
+
if (!t(g)) return this.error = `Invalid {% for %} variable name: "${g}"`, d();
|
|
170
|
+
if (h !== null && !t(h)) return this.error = `Invalid {% for %} key variable name: "${h}"`, d();
|
|
171
|
+
let _ = this.parseBody(), v = null;
|
|
172
|
+
if (this.peek()) {
|
|
173
|
+
let e = this.peek();
|
|
174
|
+
e && e.type === "tag" && o(e.content.trim()) === "else" && (this.advance(), v = this.parseBody());
|
|
175
|
+
}
|
|
176
|
+
let y = this.peek();
|
|
177
|
+
y && y.type === "tag" && o(y.content.trim()) === "endfor" ? this.advance() : this.error = "Malformed {% for %} block: missing {% endfor %}";
|
|
178
|
+
let b = this.keepEmptyTokens ? this.reconstructRange(e, this.pos) : void 0;
|
|
179
|
+
return {
|
|
180
|
+
type: "for",
|
|
181
|
+
valueVar: g,
|
|
182
|
+
keyVar: h,
|
|
183
|
+
collection: p,
|
|
184
|
+
body: _,
|
|
185
|
+
elseBody: v,
|
|
186
|
+
source: b
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
reconstructRange(e, t) {
|
|
190
|
+
let n = "";
|
|
191
|
+
for (let i = e; i < t; i++) n += r(this.tokens[i]);
|
|
192
|
+
return n;
|
|
193
|
+
}
|
|
194
|
+
parseSet() {
|
|
195
|
+
this.advance();
|
|
196
|
+
let e = this.tokens[this.pos - 1];
|
|
197
|
+
if (e.type !== "tag") return {
|
|
198
|
+
type: "set",
|
|
199
|
+
name: "_unknown",
|
|
200
|
+
value: {
|
|
201
|
+
type: "literal",
|
|
202
|
+
value: ""
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
let t = e.content.trim(), n = t.slice(t.indexOf(" ") + 1).trim(), r = n.indexOf("=");
|
|
206
|
+
if (r === -1) {
|
|
207
|
+
let e = n.trim(), t = this.parseBody(), r = this.peek();
|
|
208
|
+
return r && r.type === "tag" && this.advance(), {
|
|
209
|
+
type: "set",
|
|
210
|
+
name: e,
|
|
211
|
+
value: t
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
type: "set",
|
|
216
|
+
name: n.slice(0, r).trim(),
|
|
217
|
+
value: a(n.slice(r + 1).trim())
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
parseApply() {
|
|
221
|
+
this.advance();
|
|
222
|
+
let e = this.tokens[this.pos - 1];
|
|
223
|
+
if (e.type !== "tag") return {
|
|
224
|
+
type: "apply",
|
|
225
|
+
filters: [],
|
|
226
|
+
body: []
|
|
227
|
+
};
|
|
228
|
+
let t = e.content.trim(), n = i(t.slice(t.indexOf(" ") + 1).trim()), r = this.parseBody(), a = this.peek();
|
|
229
|
+
return a && a.type === "tag" && this.advance(), {
|
|
230
|
+
type: "apply",
|
|
231
|
+
filters: n,
|
|
232
|
+
body: r
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
//#endregion
|
|
237
|
+
export { c as parse };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Char as e, isSpace as t } from "../charClass.mjs";
|
|
2
|
+
//#region src/helpers/twigWrapper/Parser/helpers.ts
|
|
3
|
+
var n = (e) => {
|
|
4
|
+
let n = 0;
|
|
5
|
+
for (; n < e.length && !t(e.charCodeAt(n));) n++;
|
|
6
|
+
return e.slice(0, n);
|
|
7
|
+
}, r = (t) => {
|
|
8
|
+
let n = 0;
|
|
9
|
+
for (let r = 0; r + 1 < t.length; r++) {
|
|
10
|
+
let i = t.charCodeAt(r);
|
|
11
|
+
if (n !== 0) i === n && (n = 0);
|
|
12
|
+
else if (i === e.SingleQuote || i === e.DoubleQuote) n = i;
|
|
13
|
+
else if (i === e.Dot && t.charCodeAt(r + 1) === e.Dot) return [t.slice(0, r).trim(), t.slice(r + 2).trim()];
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { n as extractFirstWord, r as splitRange };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ASTNode } from '../AST';
|
|
2
|
+
import { Token } from '../Lexer';
|
|
3
|
+
export type CacheEntry = {
|
|
4
|
+
tokens: readonly Token[];
|
|
5
|
+
hasTags: boolean;
|
|
6
|
+
allSimpleOrDotted: boolean;
|
|
7
|
+
nodes: readonly ASTNode[] | null;
|
|
8
|
+
nodesWithSource: readonly ASTNode[] | null;
|
|
9
|
+
};
|
|
10
|
+
export type CacheStats = {
|
|
11
|
+
hits: number;
|
|
12
|
+
misses: number;
|
|
13
|
+
};
|
|
14
|
+
export declare const getCacheStats: () => CacheStats;
|
|
15
|
+
export declare const resetCacheStats: () => void;
|
|
16
|
+
export declare const resolveTokens: (template: string) => CacheEntry | null;
|
|
17
|
+
export declare const getNodes: (entry: CacheEntry, keepEmptyTokens: boolean) => readonly ASTNode[] | null;
|