vsn 0.1.14 → 0.1.15
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/AST.d.ts +2 -2
- package/dist/AST.js +1995 -0
- package/dist/AST.js.map +1 -0
- package/dist/Attribute.js +187 -0
- package/dist/Attribute.js.map +1 -0
- package/dist/Bencmark.js +179 -0
- package/dist/Bencmark.js.map +1 -0
- package/dist/Configuration.js +64 -0
- package/dist/Configuration.js.map +1 -0
- package/dist/Controller.js +39 -0
- package/dist/Controller.js.map +1 -0
- package/dist/DOM/DOMObject.js +45 -0
- package/dist/DOM/DOMObject.js.map +1 -0
- package/dist/DOM/WrappedDocument.js +34 -0
- package/dist/DOM/WrappedDocument.js.map +1 -0
- package/dist/DOM/WrappedWindow.js +45 -0
- package/dist/DOM/WrappedWindow.js.map +1 -0
- package/dist/DOM.js +547 -0
- package/dist/DOM.js.map +1 -0
- package/dist/Formats.js +44 -0
- package/dist/Formats.js.map +1 -0
- package/dist/Query.js +66 -0
- package/dist/Query.js.map +1 -0
- package/dist/Registry.js +138 -0
- package/dist/Registry.js.map +1 -0
- package/dist/Scope.js +499 -0
- package/dist/Scope.js.map +1 -0
- package/dist/Tag/List.js +85 -0
- package/dist/Tag/List.js.map +1 -0
- package/dist/Tag.js +715 -0
- package/dist/Tag.js.map +1 -0
- package/dist/Types.js +48 -0
- package/dist/Types.js.map +1 -0
- package/dist/Vision.d.ts +1 -1
- package/dist/Vision.js +155 -0
- package/dist/Vision.js.map +1 -0
- package/dist/attributes/AddClassIf.js +93 -0
- package/dist/attributes/AddClassIf.js.map +1 -0
- package/dist/attributes/Bind.js +272 -0
- package/dist/attributes/Bind.js.map +1 -0
- package/dist/attributes/ClassConstructor.js +104 -0
- package/dist/attributes/ClassConstructor.js.map +1 -0
- package/dist/attributes/ClickRemoveClass.js +102 -0
- package/dist/attributes/ClickRemoveClass.js.map +1 -0
- package/dist/attributes/ClickToggleClass.js +102 -0
- package/dist/attributes/ClickToggleClass.js.map +1 -0
- package/dist/attributes/ControllerAttribute.js +28 -0
- package/dist/attributes/ControllerAttribute.js.map +1 -0
- package/dist/attributes/DisableIf.js +94 -0
- package/dist/attributes/DisableIf.js.map +1 -0
- package/dist/attributes/Exec.js +102 -0
- package/dist/attributes/Exec.js.map +1 -0
- package/dist/attributes/Format.js +96 -0
- package/dist/attributes/Format.js.map +1 -0
- package/dist/attributes/If.js +147 -0
- package/dist/attributes/If.js.map +1 -0
- package/dist/attributes/JSONAttribute.js +115 -0
- package/dist/attributes/JSONAttribute.js.map +1 -0
- package/dist/attributes/KeyAbstract.js +110 -0
- package/dist/attributes/KeyAbstract.js.map +1 -0
- package/dist/attributes/KeyDown.js +82 -0
- package/dist/attributes/KeyDown.js.map +1 -0
- package/dist/attributes/KeyUp.js +82 -0
- package/dist/attributes/KeyUp.js.map +1 -0
- package/dist/attributes/List.js +273 -0
- package/dist/attributes/List.js.map +1 -0
- package/dist/attributes/ListItem.js +135 -0
- package/dist/attributes/ListItem.js.map +1 -0
- package/dist/attributes/ListItemModel.js +39 -0
- package/dist/attributes/ListItemModel.js.map +1 -0
- package/dist/attributes/ModelAttribute.js +29 -0
- package/dist/attributes/ModelAttribute.js.map +1 -0
- package/dist/attributes/Name.js +88 -0
- package/dist/attributes/Name.js.map +1 -0
- package/dist/attributes/On.js +123 -0
- package/dist/attributes/On.js.map +1 -0
- package/dist/attributes/Radio.js +127 -0
- package/dist/attributes/Radio.js.map +1 -0
- package/dist/attributes/Referenced.js +38 -0
- package/dist/attributes/Referenced.js.map +1 -0
- package/dist/attributes/RootAttribute.js +85 -0
- package/dist/attributes/RootAttribute.js.map +1 -0
- package/dist/attributes/ScopeAttribute.js +40 -0
- package/dist/attributes/ScopeAttribute.js.map +1 -0
- package/dist/attributes/ScopeChange.js +124 -0
- package/dist/attributes/ScopeChange.js.map +1 -0
- package/dist/attributes/SetAttribute.js +130 -0
- package/dist/attributes/SetAttribute.js.map +1 -0
- package/dist/attributes/StandardAttribute.js +168 -0
- package/dist/attributes/StandardAttribute.js.map +1 -0
- package/dist/attributes/Template.js +39 -0
- package/dist/attributes/Template.js.map +1 -0
- package/dist/attributes/TypeAttribute.js +101 -0
- package/dist/attributes/TypeAttribute.js.map +1 -0
- package/dist/attributes/_imports.d.ts +27 -27
- package/dist/attributes/_imports.js +58 -0
- package/dist/attributes/_imports.js.map +1 -0
- package/dist/helpers/DOMHelper.js +81 -0
- package/dist/helpers/DOMHelper.js.map +1 -0
- package/dist/helpers/ElementHelper.js +25 -0
- package/dist/helpers/ElementHelper.js.map +1 -0
- package/dist/helpers/VisionHelper.js +71 -0
- package/dist/helpers/VisionHelper.js.map +1 -0
- package/dist/helpers/decorators.js +38 -0
- package/dist/helpers/decorators.js.map +1 -0
- package/package.json +1 -1
- package/src/Vision.ts +3 -3
- package/src/attributes/_imports.ts +27 -27
- package/dist/vision.min.js +0 -1
package/dist/AST.js
ADDED
|
@@ -0,0 +1,1995 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
54
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
55
|
+
to[j] = from[i];
|
|
56
|
+
return to;
|
|
57
|
+
};
|
|
58
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.Tree = exports.AttributableNodes = exports.BlockNode = exports.Node = exports.TokenType = exports.BlockType = void 0;
|
|
60
|
+
var Scope_1 = require("./Scope");
|
|
61
|
+
var DOMObject_1 = require("./DOM/DOMObject");
|
|
62
|
+
var List_1 = require("./Tag/List");
|
|
63
|
+
function lower(str) {
|
|
64
|
+
return str ? str.toLowerCase() : null;
|
|
65
|
+
}
|
|
66
|
+
var BlockType;
|
|
67
|
+
(function (BlockType) {
|
|
68
|
+
BlockType[BlockType["BRACE"] = 0] = "BRACE";
|
|
69
|
+
BlockType[BlockType["BRACKET"] = 1] = "BRACKET";
|
|
70
|
+
BlockType[BlockType["PAREN"] = 2] = "PAREN";
|
|
71
|
+
BlockType[BlockType["STATEMENT"] = 3] = "STATEMENT";
|
|
72
|
+
})(BlockType = exports.BlockType || (exports.BlockType = {}));
|
|
73
|
+
var TokenType;
|
|
74
|
+
(function (TokenType) {
|
|
75
|
+
TokenType[TokenType["WHITESPACE"] = 0] = "WHITESPACE";
|
|
76
|
+
TokenType[TokenType["TYPE_INT"] = 1] = "TYPE_INT";
|
|
77
|
+
TokenType[TokenType["TYPE_UINT"] = 2] = "TYPE_UINT";
|
|
78
|
+
TokenType[TokenType["TYPE_FLOAT"] = 3] = "TYPE_FLOAT";
|
|
79
|
+
TokenType[TokenType["TYPE_STRING"] = 4] = "TYPE_STRING";
|
|
80
|
+
TokenType[TokenType["RETURN"] = 5] = "RETURN";
|
|
81
|
+
TokenType[TokenType["NOT"] = 6] = "NOT";
|
|
82
|
+
TokenType[TokenType["OF"] = 7] = "OF";
|
|
83
|
+
TokenType[TokenType["IN"] = 8] = "IN";
|
|
84
|
+
TokenType[TokenType["FOR"] = 9] = "FOR";
|
|
85
|
+
TokenType[TokenType["IF"] = 10] = "IF";
|
|
86
|
+
TokenType[TokenType["ELSE_IF"] = 11] = "ELSE_IF";
|
|
87
|
+
TokenType[TokenType["ELSE"] = 12] = "ELSE";
|
|
88
|
+
TokenType[TokenType["NAME"] = 13] = "NAME";
|
|
89
|
+
TokenType[TokenType["L_BRACE"] = 14] = "L_BRACE";
|
|
90
|
+
TokenType[TokenType["R_BRACE"] = 15] = "R_BRACE";
|
|
91
|
+
TokenType[TokenType["L_BRACKET"] = 16] = "L_BRACKET";
|
|
92
|
+
TokenType[TokenType["R_BRACKET"] = 17] = "R_BRACKET";
|
|
93
|
+
TokenType[TokenType["L_PAREN"] = 18] = "L_PAREN";
|
|
94
|
+
TokenType[TokenType["R_PAREN"] = 19] = "R_PAREN";
|
|
95
|
+
TokenType[TokenType["TILDE"] = 20] = "TILDE";
|
|
96
|
+
TokenType[TokenType["PERIOD"] = 21] = "PERIOD";
|
|
97
|
+
TokenType[TokenType["COMMA"] = 22] = "COMMA";
|
|
98
|
+
TokenType[TokenType["COLON"] = 23] = "COLON";
|
|
99
|
+
TokenType[TokenType["SEMI_COLON"] = 24] = "SEMI_COLON";
|
|
100
|
+
TokenType[TokenType["STRING_LITERAL"] = 25] = "STRING_LITERAL";
|
|
101
|
+
TokenType[TokenType["NUMBER_LITERAL"] = 26] = "NUMBER_LITERAL";
|
|
102
|
+
TokenType[TokenType["BOOLEAN_LITERAL"] = 27] = "BOOLEAN_LITERAL";
|
|
103
|
+
TokenType[TokenType["NULL_LITERAL"] = 28] = "NULL_LITERAL";
|
|
104
|
+
TokenType[TokenType["STRICT_EQUALS"] = 29] = "STRICT_EQUALS";
|
|
105
|
+
TokenType[TokenType["STRICT_NOT_EQUALS"] = 30] = "STRICT_NOT_EQUALS";
|
|
106
|
+
TokenType[TokenType["EQUALS"] = 31] = "EQUALS";
|
|
107
|
+
TokenType[TokenType["NOT_EQUALS"] = 32] = "NOT_EQUALS";
|
|
108
|
+
TokenType[TokenType["GREATER_THAN_EQUAL"] = 33] = "GREATER_THAN_EQUAL";
|
|
109
|
+
TokenType[TokenType["LESS_THAN_EQUAL"] = 34] = "LESS_THAN_EQUAL";
|
|
110
|
+
TokenType[TokenType["GREATER_THAN"] = 35] = "GREATER_THAN";
|
|
111
|
+
TokenType[TokenType["LESS_THAN"] = 36] = "LESS_THAN";
|
|
112
|
+
TokenType[TokenType["ASSIGN"] = 37] = "ASSIGN";
|
|
113
|
+
TokenType[TokenType["AND"] = 38] = "AND";
|
|
114
|
+
TokenType[TokenType["OR"] = 39] = "OR";
|
|
115
|
+
TokenType[TokenType["ADD"] = 40] = "ADD";
|
|
116
|
+
TokenType[TokenType["SUBTRACT"] = 41] = "SUBTRACT";
|
|
117
|
+
TokenType[TokenType["MULTIPLY"] = 42] = "MULTIPLY";
|
|
118
|
+
TokenType[TokenType["DIVIDE"] = 43] = "DIVIDE";
|
|
119
|
+
TokenType[TokenType["ADD_ASSIGN"] = 44] = "ADD_ASSIGN";
|
|
120
|
+
TokenType[TokenType["SUBTRACT_ASSIGN"] = 45] = "SUBTRACT_ASSIGN";
|
|
121
|
+
TokenType[TokenType["MULTIPLY_ASSIGN"] = 46] = "MULTIPLY_ASSIGN";
|
|
122
|
+
TokenType[TokenType["DIVIDE_ASSIGN"] = 47] = "DIVIDE_ASSIGN";
|
|
123
|
+
TokenType[TokenType["EXCLAMATION_POINT"] = 48] = "EXCLAMATION_POINT";
|
|
124
|
+
TokenType[TokenType["ELEMENT_REFERENCE"] = 49] = "ELEMENT_REFERENCE";
|
|
125
|
+
TokenType[TokenType["ELEMENT_ATTRIBUTE"] = 50] = "ELEMENT_ATTRIBUTE";
|
|
126
|
+
TokenType[TokenType["ELEMENT_QUERY"] = 51] = "ELEMENT_QUERY";
|
|
127
|
+
})(TokenType = exports.TokenType || (exports.TokenType = {}));
|
|
128
|
+
var TOKEN_PATTERNS = [
|
|
129
|
+
{
|
|
130
|
+
type: TokenType.WHITESPACE,
|
|
131
|
+
pattern: /^[\s\n\r]+/
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
type: TokenType.TYPE_INT,
|
|
135
|
+
pattern: /^int+/
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
type: TokenType.TYPE_UINT,
|
|
139
|
+
pattern: /^uint+/
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
type: TokenType.TYPE_FLOAT,
|
|
143
|
+
pattern: /^float+/
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
type: TokenType.TYPE_STRING,
|
|
147
|
+
pattern: /^string+/
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
type: TokenType.BOOLEAN_LITERAL,
|
|
151
|
+
pattern: /^(true|false)/
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
type: TokenType.NULL_LITERAL,
|
|
155
|
+
pattern: /^null/
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
type: TokenType.RETURN,
|
|
159
|
+
pattern: /^return\s/
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
type: TokenType.NOT,
|
|
163
|
+
pattern: /^not\s/
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
type: TokenType.OF,
|
|
167
|
+
pattern: /^of\s/
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
type: TokenType.IN,
|
|
171
|
+
pattern: /^in\s/
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
type: TokenType.FOR,
|
|
175
|
+
pattern: /^for\s/
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
type: TokenType.IF,
|
|
179
|
+
pattern: /^if\s/
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
type: TokenType.ELSE_IF,
|
|
183
|
+
pattern: /^else if\s/
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
type: TokenType.ELSE,
|
|
187
|
+
pattern: /^else\s/
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
type: TokenType.ELEMENT_ATTRIBUTE,
|
|
191
|
+
pattern: /^\.?@[_a-zA-Z0-9]*/
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
type: TokenType.ELEMENT_REFERENCE,
|
|
195
|
+
pattern: /^#[-_a-zA-Z0-9]*/
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
type: TokenType.ELEMENT_QUERY,
|
|
199
|
+
pattern: /^\?\(([#.\[\]:,=\-_a-zA-Z0-9*\s]*[\]_a-zA-Z0-9*])\)/
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
type: TokenType.NAME,
|
|
203
|
+
pattern: /^[$_a-zA-Z][_a-zA-Z0-9]*/
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
type: TokenType.NUMBER_LITERAL,
|
|
207
|
+
pattern: /^-?\d+(?:\.\d+)?(?:e[+\-]?\d+)?/i
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
type: TokenType.L_BRACE,
|
|
211
|
+
pattern: /^{/
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
type: TokenType.R_BRACE,
|
|
215
|
+
pattern: /^}/
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
type: TokenType.L_BRACKET,
|
|
219
|
+
pattern: /^\[/
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
type: TokenType.R_BRACKET,
|
|
223
|
+
pattern: /^]/
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
type: TokenType.L_PAREN,
|
|
227
|
+
pattern: /^\(/
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
type: TokenType.R_PAREN,
|
|
231
|
+
pattern: /^\)/
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
type: TokenType.TILDE,
|
|
235
|
+
pattern: /^~/
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
type: TokenType.PERIOD,
|
|
239
|
+
pattern: /^\./
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
type: TokenType.COMMA,
|
|
243
|
+
pattern: /^,/
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
type: TokenType.EQUALS,
|
|
247
|
+
pattern: /^==/
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
type: TokenType.NOT_EQUALS,
|
|
251
|
+
pattern: /^!=/
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
type: TokenType.GREATER_THAN,
|
|
255
|
+
pattern: /^>/
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
type: TokenType.LESS_THAN,
|
|
259
|
+
pattern: /^</
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
type: TokenType.GREATER_THAN_EQUAL,
|
|
263
|
+
pattern: /^>=/
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
type: TokenType.LESS_THAN_EQUAL,
|
|
267
|
+
pattern: /^<=/
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
type: TokenType.COLON,
|
|
271
|
+
pattern: /^:/
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
type: TokenType.SEMI_COLON,
|
|
275
|
+
pattern: /^;/
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
type: TokenType.STRING_LITERAL,
|
|
279
|
+
pattern: /^"([^"]*)"/
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
type: TokenType.STRING_LITERAL,
|
|
283
|
+
pattern: /^'([^']*)'/ // Try to make this work: /^(?<!\\)(?:\\\\)*"([^(?<!\\)(?:\\\\)*"]*)(?<!\\)(?:\\\\)*"/
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
type: TokenType.AND,
|
|
287
|
+
pattern: /^&&/
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
type: TokenType.OR,
|
|
291
|
+
pattern: /^\|\|/
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
type: TokenType.ADD_ASSIGN,
|
|
295
|
+
pattern: /^\+=/
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
type: TokenType.SUBTRACT_ASSIGN,
|
|
299
|
+
pattern: /^-=/
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
type: TokenType.MULTIPLY_ASSIGN,
|
|
303
|
+
pattern: /^\*=/
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
type: TokenType.DIVIDE_ASSIGN,
|
|
307
|
+
pattern: /^\/=/
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
type: TokenType.ADD,
|
|
311
|
+
pattern: /^\+/
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
type: TokenType.SUBTRACT,
|
|
315
|
+
pattern: /^-/
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
type: TokenType.MULTIPLY,
|
|
319
|
+
pattern: /^\*/
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
type: TokenType.DIVIDE,
|
|
323
|
+
pattern: /^\//
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
type: TokenType.ASSIGN,
|
|
327
|
+
pattern: /^=/
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
type: TokenType.EXCLAMATION_POINT,
|
|
331
|
+
pattern: /^!/
|
|
332
|
+
}
|
|
333
|
+
];
|
|
334
|
+
var Node = /** @class */ (function () {
|
|
335
|
+
function Node() {
|
|
336
|
+
this.requiresPrep = false;
|
|
337
|
+
this.nodeCache = {};
|
|
338
|
+
}
|
|
339
|
+
Node.prototype.isPreparationRequired = function () {
|
|
340
|
+
if (this.requiresPrep)
|
|
341
|
+
return true;
|
|
342
|
+
if (this._isPreparationRequired !== undefined)
|
|
343
|
+
return this._isPreparationRequired;
|
|
344
|
+
for (var _i = 0, _a = this.getChildNodes(); _i < _a.length; _i++) {
|
|
345
|
+
var node = _a[_i];
|
|
346
|
+
if (node.isPreparationRequired()) {
|
|
347
|
+
this._isPreparationRequired = true;
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return false;
|
|
352
|
+
};
|
|
353
|
+
Node.prototype.prepare = function (scope, dom, tag) {
|
|
354
|
+
if (tag === void 0) { tag = null; }
|
|
355
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
356
|
+
var _i, _a, node;
|
|
357
|
+
return __generator(this, function (_b) {
|
|
358
|
+
switch (_b.label) {
|
|
359
|
+
case 0:
|
|
360
|
+
_i = 0, _a = this.getChildNodes();
|
|
361
|
+
_b.label = 1;
|
|
362
|
+
case 1:
|
|
363
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
364
|
+
node = _a[_i];
|
|
365
|
+
return [4 /*yield*/, node.prepare(scope, dom, tag)];
|
|
366
|
+
case 2:
|
|
367
|
+
_b.sent();
|
|
368
|
+
_b.label = 3;
|
|
369
|
+
case 3:
|
|
370
|
+
_i++;
|
|
371
|
+
return [3 /*break*/, 1];
|
|
372
|
+
case 4: return [2 /*return*/];
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
};
|
|
377
|
+
Node.prototype._getChildNodes = function () {
|
|
378
|
+
return [];
|
|
379
|
+
};
|
|
380
|
+
Node.prototype.getChildNodes = function () {
|
|
381
|
+
if (this.childNodes === undefined) {
|
|
382
|
+
this.childNodes = this._getChildNodes();
|
|
383
|
+
}
|
|
384
|
+
return this.childNodes;
|
|
385
|
+
};
|
|
386
|
+
Node.prototype.findChildrenByType = function (t) {
|
|
387
|
+
return this.findChildrenByTypes([t]);
|
|
388
|
+
};
|
|
389
|
+
Node.prototype.findChildrenByTypes = function (types, cacheKey) {
|
|
390
|
+
if (cacheKey === void 0) { cacheKey = null; }
|
|
391
|
+
if (cacheKey !== null && this.nodeCache[cacheKey])
|
|
392
|
+
return this.nodeCache[cacheKey];
|
|
393
|
+
var nodes = [];
|
|
394
|
+
for (var _i = 0, _a = this.getChildNodes(); _i < _a.length; _i++) {
|
|
395
|
+
var child = _a[_i];
|
|
396
|
+
for (var _b = 0, types_1 = types; _b < types_1.length; _b++) {
|
|
397
|
+
var t = types_1[_b];
|
|
398
|
+
if (child instanceof t)
|
|
399
|
+
nodes.push(child);
|
|
400
|
+
var childNodes = child.findChildrenByType(t);
|
|
401
|
+
nodes.push.apply(nodes, childNodes);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (cacheKey !== null)
|
|
405
|
+
this.nodeCache[cacheKey] = nodes;
|
|
406
|
+
return nodes;
|
|
407
|
+
};
|
|
408
|
+
return Node;
|
|
409
|
+
}());
|
|
410
|
+
exports.Node = Node;
|
|
411
|
+
var BlockNode = /** @class */ (function (_super) {
|
|
412
|
+
__extends(BlockNode, _super);
|
|
413
|
+
function BlockNode(statements) {
|
|
414
|
+
var _this = _super.call(this) || this;
|
|
415
|
+
_this.statements = statements;
|
|
416
|
+
return _this;
|
|
417
|
+
}
|
|
418
|
+
BlockNode.prototype._getChildNodes = function () {
|
|
419
|
+
return __spreadArray([], this.statements);
|
|
420
|
+
};
|
|
421
|
+
BlockNode.prototype.evaluate = function (scope, dom, tag) {
|
|
422
|
+
if (tag === void 0) { tag = null; }
|
|
423
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
424
|
+
var returnValue, i;
|
|
425
|
+
return __generator(this, function (_a) {
|
|
426
|
+
switch (_a.label) {
|
|
427
|
+
case 0:
|
|
428
|
+
returnValue = null;
|
|
429
|
+
i = 0;
|
|
430
|
+
_a.label = 1;
|
|
431
|
+
case 1:
|
|
432
|
+
if (!(i < this.statements.length)) return [3 /*break*/, 4];
|
|
433
|
+
return [4 /*yield*/, this.statements[i].evaluate(scope, dom, tag)];
|
|
434
|
+
case 2:
|
|
435
|
+
returnValue = _a.sent();
|
|
436
|
+
_a.label = 3;
|
|
437
|
+
case 3:
|
|
438
|
+
i++;
|
|
439
|
+
return [3 /*break*/, 1];
|
|
440
|
+
case 4: return [2 /*return*/, returnValue];
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
};
|
|
445
|
+
return BlockNode;
|
|
446
|
+
}(Node));
|
|
447
|
+
exports.BlockNode = BlockNode;
|
|
448
|
+
var ComparisonNode = /** @class */ (function (_super) {
|
|
449
|
+
__extends(ComparisonNode, _super);
|
|
450
|
+
function ComparisonNode(left, right, type) {
|
|
451
|
+
var _this = _super.call(this) || this;
|
|
452
|
+
_this.left = left;
|
|
453
|
+
_this.right = right;
|
|
454
|
+
_this.type = type;
|
|
455
|
+
return _this;
|
|
456
|
+
}
|
|
457
|
+
ComparisonNode.prototype._getChildNodes = function () {
|
|
458
|
+
return [
|
|
459
|
+
this.left,
|
|
460
|
+
this.right
|
|
461
|
+
];
|
|
462
|
+
};
|
|
463
|
+
ComparisonNode.prototype.evaluate = function (scope, dom, tag) {
|
|
464
|
+
if (tag === void 0) { tag = null; }
|
|
465
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
466
|
+
var left, right;
|
|
467
|
+
return __generator(this, function (_a) {
|
|
468
|
+
switch (_a.label) {
|
|
469
|
+
case 0: return [4 /*yield*/, this.left.evaluate(scope, dom, tag)];
|
|
470
|
+
case 1:
|
|
471
|
+
left = _a.sent();
|
|
472
|
+
return [4 /*yield*/, this.right.evaluate(scope, dom, tag)];
|
|
473
|
+
case 2:
|
|
474
|
+
right = _a.sent();
|
|
475
|
+
switch (this.type) {
|
|
476
|
+
case TokenType.EQUALS:
|
|
477
|
+
return [2 /*return*/, left === right];
|
|
478
|
+
case TokenType.NOT_EQUALS:
|
|
479
|
+
return [2 /*return*/, left !== right];
|
|
480
|
+
case TokenType.GREATER_THAN:
|
|
481
|
+
return [2 /*return*/, left > right];
|
|
482
|
+
case TokenType.LESS_THAN:
|
|
483
|
+
return [2 /*return*/, left < right];
|
|
484
|
+
case TokenType.GREATER_THAN_EQUAL:
|
|
485
|
+
return [2 /*return*/, left >= right];
|
|
486
|
+
case TokenType.LESS_THAN_EQUAL:
|
|
487
|
+
return [2 /*return*/, left <= right];
|
|
488
|
+
}
|
|
489
|
+
return [2 /*return*/];
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
};
|
|
494
|
+
ComparisonNode.match = function (tokens) {
|
|
495
|
+
return [
|
|
496
|
+
TokenType.EQUALS,
|
|
497
|
+
TokenType.NOT_EQUALS,
|
|
498
|
+
TokenType.GREATER_THAN,
|
|
499
|
+
TokenType.LESS_THAN,
|
|
500
|
+
TokenType.GREATER_THAN_EQUAL,
|
|
501
|
+
TokenType.LESS_THAN_EQUAL
|
|
502
|
+
].indexOf(tokens[0].type) > -1;
|
|
503
|
+
};
|
|
504
|
+
ComparisonNode.parse = function (lastNode, token, tokens) {
|
|
505
|
+
tokens.splice(0, 1); // Remove comparison operator
|
|
506
|
+
return new ComparisonNode(lastNode, Tree.processTokens(Tree.getNextStatementTokens(tokens)), token.type);
|
|
507
|
+
};
|
|
508
|
+
return ComparisonNode;
|
|
509
|
+
}(Node));
|
|
510
|
+
var ConditionalNode = /** @class */ (function (_super) {
|
|
511
|
+
__extends(ConditionalNode, _super);
|
|
512
|
+
function ConditionalNode(condition, block) {
|
|
513
|
+
var _this = _super.call(this) || this;
|
|
514
|
+
_this.condition = condition;
|
|
515
|
+
_this.block = block;
|
|
516
|
+
return _this;
|
|
517
|
+
}
|
|
518
|
+
ConditionalNode.prototype._getChildNodes = function () {
|
|
519
|
+
return [
|
|
520
|
+
this.condition,
|
|
521
|
+
this.block
|
|
522
|
+
];
|
|
523
|
+
};
|
|
524
|
+
ConditionalNode.prototype.evaluate = function (scope, dom, tag) {
|
|
525
|
+
if (tag === void 0) { tag = null; }
|
|
526
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
527
|
+
var condition;
|
|
528
|
+
return __generator(this, function (_a) {
|
|
529
|
+
switch (_a.label) {
|
|
530
|
+
case 0: return [4 /*yield*/, this.condition.evaluate(scope, dom, tag)];
|
|
531
|
+
case 1:
|
|
532
|
+
condition = _a.sent();
|
|
533
|
+
if (!condition) return [3 /*break*/, 3];
|
|
534
|
+
return [4 /*yield*/, this.block.evaluate(scope, dom, tag)];
|
|
535
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
536
|
+
case 3: return [2 /*return*/, null];
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
};
|
|
541
|
+
return ConditionalNode;
|
|
542
|
+
}(Node));
|
|
543
|
+
var IfStatementNode = /** @class */ (function (_super) {
|
|
544
|
+
__extends(IfStatementNode, _super);
|
|
545
|
+
function IfStatementNode(nodes) {
|
|
546
|
+
var _this = _super.call(this) || this;
|
|
547
|
+
_this.nodes = nodes;
|
|
548
|
+
return _this;
|
|
549
|
+
}
|
|
550
|
+
IfStatementNode.prototype._getChildNodes = function () {
|
|
551
|
+
return __spreadArray([], this.nodes);
|
|
552
|
+
};
|
|
553
|
+
IfStatementNode.prototype.evaluate = function (scope, dom, tag) {
|
|
554
|
+
if (tag === void 0) { tag = null; }
|
|
555
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
556
|
+
var _i, _a, condition, uno;
|
|
557
|
+
return __generator(this, function (_b) {
|
|
558
|
+
switch (_b.label) {
|
|
559
|
+
case 0:
|
|
560
|
+
_i = 0, _a = this.nodes;
|
|
561
|
+
_b.label = 1;
|
|
562
|
+
case 1:
|
|
563
|
+
if (!(_i < _a.length)) return [3 /*break*/, 5];
|
|
564
|
+
condition = _a[_i];
|
|
565
|
+
return [4 /*yield*/, condition.condition.evaluate(scope, dom, tag)];
|
|
566
|
+
case 2:
|
|
567
|
+
uno = _b.sent();
|
|
568
|
+
if (!uno) return [3 /*break*/, 4];
|
|
569
|
+
return [4 /*yield*/, condition.block.evaluate(scope, dom, tag)];
|
|
570
|
+
case 3: return [2 /*return*/, _b.sent()];
|
|
571
|
+
case 4:
|
|
572
|
+
_i++;
|
|
573
|
+
return [3 /*break*/, 1];
|
|
574
|
+
case 5: return [2 /*return*/];
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
};
|
|
579
|
+
IfStatementNode.parseConditional = function (tokens) {
|
|
580
|
+
if ([
|
|
581
|
+
TokenType.IF,
|
|
582
|
+
TokenType.ELSE_IF
|
|
583
|
+
].indexOf(tokens[0].type) === -1) {
|
|
584
|
+
throw SyntaxError('Invalid Syntax');
|
|
585
|
+
}
|
|
586
|
+
tokens.splice(0, 1); // consume if and else if
|
|
587
|
+
return new ConditionalNode(Tree.processTokens(Tree.getBlockTokens(tokens, null)[0]), Tree.processTokens(Tree.getBlockTokens(tokens, null)[0]));
|
|
588
|
+
};
|
|
589
|
+
IfStatementNode.parse = function (lastNode, token, tokens) {
|
|
590
|
+
if (tokens[1].type !== TokenType.L_PAREN) {
|
|
591
|
+
throw SyntaxError('If statement needs to be followed by a condition encased in parenthesis.');
|
|
592
|
+
}
|
|
593
|
+
var nodes = [];
|
|
594
|
+
nodes.push(IfStatementNode.parseConditional(tokens));
|
|
595
|
+
while (tokens.length > 0 && TokenType.ELSE_IF === tokens[0].type) {
|
|
596
|
+
nodes.push(IfStatementNode.parseConditional(tokens));
|
|
597
|
+
}
|
|
598
|
+
if (tokens.length > 0 && TokenType.ELSE === tokens[0].type) {
|
|
599
|
+
tokens.splice(0, 1); // Consume else
|
|
600
|
+
nodes.push(new ConditionalNode(new LiteralNode(true), Tree.processTokens(Tree.getBlockTokens(tokens, null)[0])));
|
|
601
|
+
}
|
|
602
|
+
return new IfStatementNode(nodes);
|
|
603
|
+
};
|
|
604
|
+
return IfStatementNode;
|
|
605
|
+
}(Node));
|
|
606
|
+
var ForStatementNode = /** @class */ (function (_super) {
|
|
607
|
+
__extends(ForStatementNode, _super);
|
|
608
|
+
function ForStatementNode(variable, list, block) {
|
|
609
|
+
var _this = _super.call(this) || this;
|
|
610
|
+
_this.variable = variable;
|
|
611
|
+
_this.list = list;
|
|
612
|
+
_this.block = block;
|
|
613
|
+
return _this;
|
|
614
|
+
}
|
|
615
|
+
ForStatementNode.prototype._getChildNodes = function () {
|
|
616
|
+
return [
|
|
617
|
+
this.variable,
|
|
618
|
+
this.list,
|
|
619
|
+
this.block
|
|
620
|
+
];
|
|
621
|
+
};
|
|
622
|
+
ForStatementNode.prototype.evaluate = function (scope, dom, tag) {
|
|
623
|
+
if (tag === void 0) { tag = null; }
|
|
624
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
625
|
+
var variable, list, i;
|
|
626
|
+
return __generator(this, function (_a) {
|
|
627
|
+
switch (_a.label) {
|
|
628
|
+
case 0: return [4 /*yield*/, this.variable.evaluate(scope, dom, tag)];
|
|
629
|
+
case 1:
|
|
630
|
+
variable = _a.sent();
|
|
631
|
+
return [4 /*yield*/, this.list.evaluate(scope, dom, tag)];
|
|
632
|
+
case 2:
|
|
633
|
+
list = _a.sent();
|
|
634
|
+
i = 0;
|
|
635
|
+
_a.label = 3;
|
|
636
|
+
case 3:
|
|
637
|
+
if (!(i < list.length)) return [3 /*break*/, 6];
|
|
638
|
+
scope.set(variable, list[i]);
|
|
639
|
+
return [4 /*yield*/, this.block.evaluate(scope, dom, tag)];
|
|
640
|
+
case 4:
|
|
641
|
+
_a.sent();
|
|
642
|
+
_a.label = 5;
|
|
643
|
+
case 5:
|
|
644
|
+
i++;
|
|
645
|
+
return [3 /*break*/, 3];
|
|
646
|
+
case 6: return [2 /*return*/, null];
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
};
|
|
651
|
+
ForStatementNode.parse = function (lastNode, token, tokens) {
|
|
652
|
+
if (tokens[1].type !== TokenType.L_PAREN) {
|
|
653
|
+
throw SyntaxError('Syntax error: Missing (');
|
|
654
|
+
}
|
|
655
|
+
if (tokens[3].type !== TokenType.OF) {
|
|
656
|
+
throw SyntaxError('Syntax error: Missing of');
|
|
657
|
+
}
|
|
658
|
+
tokens.splice(0, 1); // consume for
|
|
659
|
+
var loopDef = Tree.getNextStatementTokens(tokens);
|
|
660
|
+
var variableName = loopDef.splice(0, 1)[0];
|
|
661
|
+
loopDef.splice(0, 1); // consume of
|
|
662
|
+
var list = Tree.processTokens(loopDef);
|
|
663
|
+
var block = Tree.processTokens(Tree.getBlockTokens(tokens, null)[0]);
|
|
664
|
+
return new ForStatementNode(new LiteralNode(variableName.value), list, block);
|
|
665
|
+
};
|
|
666
|
+
return ForStatementNode;
|
|
667
|
+
}(Node));
|
|
668
|
+
var NotNode = /** @class */ (function (_super) {
|
|
669
|
+
__extends(NotNode, _super);
|
|
670
|
+
function NotNode(toFlip) {
|
|
671
|
+
var _this = _super.call(this) || this;
|
|
672
|
+
_this.toFlip = toFlip;
|
|
673
|
+
return _this;
|
|
674
|
+
}
|
|
675
|
+
NotNode.prototype.evaluate = function (scope, dom, tag) {
|
|
676
|
+
if (tag === void 0) { tag = null; }
|
|
677
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
678
|
+
var flipping;
|
|
679
|
+
return __generator(this, function (_a) {
|
|
680
|
+
switch (_a.label) {
|
|
681
|
+
case 0: return [4 /*yield*/, this.toFlip.evaluate(scope, dom, tag)];
|
|
682
|
+
case 1:
|
|
683
|
+
flipping = _a.sent();
|
|
684
|
+
return [2 /*return*/, !flipping];
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
});
|
|
688
|
+
};
|
|
689
|
+
NotNode.prototype._getChildNodes = function () {
|
|
690
|
+
return [
|
|
691
|
+
this.toFlip
|
|
692
|
+
];
|
|
693
|
+
};
|
|
694
|
+
NotNode.parse = function (lastNode, token, tokens) {
|
|
695
|
+
tokens.splice(0, 1); // Remove not operator
|
|
696
|
+
var containedTokens;
|
|
697
|
+
if (tokens[0].type === TokenType.L_PAREN) {
|
|
698
|
+
containedTokens = Tree.getNextStatementTokens(tokens);
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
containedTokens = Tree.consumeTypes(tokens, [
|
|
702
|
+
TokenType.BOOLEAN_LITERAL,
|
|
703
|
+
TokenType.NUMBER_LITERAL,
|
|
704
|
+
TokenType.STRING_LITERAL,
|
|
705
|
+
TokenType.NAME,
|
|
706
|
+
TokenType.PERIOD
|
|
707
|
+
]);
|
|
708
|
+
}
|
|
709
|
+
return new NotNode(Tree.processTokens(containedTokens));
|
|
710
|
+
};
|
|
711
|
+
return NotNode;
|
|
712
|
+
}(Node));
|
|
713
|
+
var InNode = /** @class */ (function (_super) {
|
|
714
|
+
__extends(InNode, _super);
|
|
715
|
+
function InNode(left, right, flip) {
|
|
716
|
+
if (flip === void 0) { flip = false; }
|
|
717
|
+
var _this = _super.call(this) || this;
|
|
718
|
+
_this.left = left;
|
|
719
|
+
_this.right = right;
|
|
720
|
+
_this.flip = flip;
|
|
721
|
+
return _this;
|
|
722
|
+
}
|
|
723
|
+
InNode.prototype.evaluate = function (scope, dom, tag) {
|
|
724
|
+
if (tag === void 0) { tag = null; }
|
|
725
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
726
|
+
var toCheck, array, inArray;
|
|
727
|
+
return __generator(this, function (_a) {
|
|
728
|
+
switch (_a.label) {
|
|
729
|
+
case 0: return [4 /*yield*/, this.left.evaluate(scope, dom, tag)];
|
|
730
|
+
case 1:
|
|
731
|
+
toCheck = _a.sent();
|
|
732
|
+
return [4 /*yield*/, this.right.evaluate(scope, dom, tag)];
|
|
733
|
+
case 2:
|
|
734
|
+
array = _a.sent();
|
|
735
|
+
inArray = array.indexOf(toCheck) > -1;
|
|
736
|
+
if (this.flip)
|
|
737
|
+
inArray = !inArray;
|
|
738
|
+
return [2 /*return*/, inArray];
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
};
|
|
743
|
+
InNode.prototype._getChildNodes = function () {
|
|
744
|
+
return [
|
|
745
|
+
this.left,
|
|
746
|
+
this.right
|
|
747
|
+
];
|
|
748
|
+
};
|
|
749
|
+
InNode.match = function (tokens) {
|
|
750
|
+
return tokens[0].type === TokenType.IN || (tokens[0].type === TokenType.NOT && tokens[1].type === TokenType.IN);
|
|
751
|
+
};
|
|
752
|
+
InNode.parse = function (lastNode, token, tokens) {
|
|
753
|
+
var flip = tokens[0].type === TokenType.NOT;
|
|
754
|
+
if (flip)
|
|
755
|
+
tokens.splice(0, 1); // consume not
|
|
756
|
+
tokens.splice(0, 1); // consume in
|
|
757
|
+
var containedTokens = Tree.getNextStatementTokens(tokens, false, false, true);
|
|
758
|
+
return new InNode(lastNode, Tree.processTokens(containedTokens), flip);
|
|
759
|
+
};
|
|
760
|
+
return InNode;
|
|
761
|
+
}(Node));
|
|
762
|
+
var LiteralNode = /** @class */ (function (_super) {
|
|
763
|
+
__extends(LiteralNode, _super);
|
|
764
|
+
function LiteralNode(value) {
|
|
765
|
+
var _this = _super.call(this) || this;
|
|
766
|
+
_this.value = value;
|
|
767
|
+
return _this;
|
|
768
|
+
}
|
|
769
|
+
LiteralNode.prototype.evaluate = function (scope, dom, tag) {
|
|
770
|
+
if (tag === void 0) { tag = null; }
|
|
771
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
772
|
+
return __generator(this, function (_a) {
|
|
773
|
+
return [2 /*return*/, this.value];
|
|
774
|
+
});
|
|
775
|
+
});
|
|
776
|
+
};
|
|
777
|
+
return LiteralNode;
|
|
778
|
+
}(Node));
|
|
779
|
+
var BooleanLiteralNode = /** @class */ (function (_super) {
|
|
780
|
+
__extends(BooleanLiteralNode, _super);
|
|
781
|
+
function BooleanLiteralNode(value) {
|
|
782
|
+
var _this = _super.call(this, value) || this;
|
|
783
|
+
_this.value = value;
|
|
784
|
+
_this.value = value === 'true';
|
|
785
|
+
return _this;
|
|
786
|
+
}
|
|
787
|
+
return BooleanLiteralNode;
|
|
788
|
+
}(LiteralNode));
|
|
789
|
+
var NumberLiteralNode = /** @class */ (function (_super) {
|
|
790
|
+
__extends(NumberLiteralNode, _super);
|
|
791
|
+
function NumberLiteralNode(value) {
|
|
792
|
+
var _this = _super.call(this, value) || this;
|
|
793
|
+
_this.value = value;
|
|
794
|
+
if (_this.value.indexOf('.') > -1) {
|
|
795
|
+
_this.value = parseFloat(_this.value);
|
|
796
|
+
}
|
|
797
|
+
else {
|
|
798
|
+
_this.value = parseInt(_this.value);
|
|
799
|
+
}
|
|
800
|
+
return _this;
|
|
801
|
+
}
|
|
802
|
+
return NumberLiteralNode;
|
|
803
|
+
}(LiteralNode));
|
|
804
|
+
var FunctionCallNode = /** @class */ (function (_super) {
|
|
805
|
+
__extends(FunctionCallNode, _super);
|
|
806
|
+
function FunctionCallNode(fnc, args) {
|
|
807
|
+
var _this = _super.call(this) || this;
|
|
808
|
+
_this.fnc = fnc;
|
|
809
|
+
_this.args = args;
|
|
810
|
+
return _this;
|
|
811
|
+
}
|
|
812
|
+
FunctionCallNode.prototype._getChildNodes = function () {
|
|
813
|
+
return [
|
|
814
|
+
this.fnc,
|
|
815
|
+
this.args
|
|
816
|
+
];
|
|
817
|
+
};
|
|
818
|
+
FunctionCallNode.prototype.evaluate = function (scope, dom, tag) {
|
|
819
|
+
if (tag === void 0) { tag = null; }
|
|
820
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
821
|
+
var functionScope, values;
|
|
822
|
+
var _a;
|
|
823
|
+
return __generator(this, function (_b) {
|
|
824
|
+
switch (_b.label) {
|
|
825
|
+
case 0:
|
|
826
|
+
functionScope = scope;
|
|
827
|
+
if (!(this.fnc instanceof ScopeMemberNode)) return [3 /*break*/, 2];
|
|
828
|
+
return [4 /*yield*/, this.fnc.scope.evaluate(scope, dom, tag)];
|
|
829
|
+
case 1:
|
|
830
|
+
functionScope = _b.sent();
|
|
831
|
+
_b.label = 2;
|
|
832
|
+
case 2: return [4 /*yield*/, this.args.evaluate(scope, dom, tag)];
|
|
833
|
+
case 3:
|
|
834
|
+
values = _b.sent();
|
|
835
|
+
return [4 /*yield*/, this.fnc.evaluate(scope, dom, tag)];
|
|
836
|
+
case 4: return [2 /*return*/, (_a = (_b.sent())).call.apply(_a, __spreadArray([functionScope.wrapped || functionScope], values))];
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
});
|
|
840
|
+
};
|
|
841
|
+
return FunctionCallNode;
|
|
842
|
+
}(Node));
|
|
843
|
+
var FunctionArgumentNode = /** @class */ (function (_super) {
|
|
844
|
+
__extends(FunctionArgumentNode, _super);
|
|
845
|
+
function FunctionArgumentNode(args) {
|
|
846
|
+
var _this = _super.call(this) || this;
|
|
847
|
+
_this.args = args;
|
|
848
|
+
return _this;
|
|
849
|
+
}
|
|
850
|
+
FunctionArgumentNode.prototype._getChildNodes = function () {
|
|
851
|
+
return __spreadArray([], this.args);
|
|
852
|
+
};
|
|
853
|
+
FunctionArgumentNode.prototype.evaluate = function (scope, dom, tag) {
|
|
854
|
+
if (tag === void 0) { tag = null; }
|
|
855
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
856
|
+
var values, _i, _a, arg, _b, _c;
|
|
857
|
+
return __generator(this, function (_d) {
|
|
858
|
+
switch (_d.label) {
|
|
859
|
+
case 0:
|
|
860
|
+
values = [];
|
|
861
|
+
_i = 0, _a = this.args;
|
|
862
|
+
_d.label = 1;
|
|
863
|
+
case 1:
|
|
864
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
865
|
+
arg = _a[_i];
|
|
866
|
+
_c = (_b = values).push;
|
|
867
|
+
return [4 /*yield*/, arg.evaluate(scope, dom, tag)];
|
|
868
|
+
case 2:
|
|
869
|
+
_c.apply(_b, [_d.sent()]);
|
|
870
|
+
_d.label = 3;
|
|
871
|
+
case 3:
|
|
872
|
+
_i++;
|
|
873
|
+
return [3 /*break*/, 1];
|
|
874
|
+
case 4: return [2 /*return*/, values];
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
});
|
|
878
|
+
};
|
|
879
|
+
return FunctionArgumentNode;
|
|
880
|
+
}(Node));
|
|
881
|
+
var ScopeMemberNode = /** @class */ (function (_super) {
|
|
882
|
+
__extends(ScopeMemberNode, _super);
|
|
883
|
+
function ScopeMemberNode(scope, name) {
|
|
884
|
+
var _this = _super.call(this) || this;
|
|
885
|
+
_this.scope = scope;
|
|
886
|
+
_this.name = name;
|
|
887
|
+
return _this;
|
|
888
|
+
}
|
|
889
|
+
ScopeMemberNode.prototype._getChildNodes = function () {
|
|
890
|
+
return [
|
|
891
|
+
this.scope,
|
|
892
|
+
this.name
|
|
893
|
+
];
|
|
894
|
+
};
|
|
895
|
+
ScopeMemberNode.prototype.evaluate = function (scope, dom, tag) {
|
|
896
|
+
if (tag === void 0) { tag = null; }
|
|
897
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
898
|
+
var scopes, values, evalScope, _i, scopes_1, parent_1, _a, _b, name_1, value;
|
|
899
|
+
return __generator(this, function (_c) {
|
|
900
|
+
switch (_c.label) {
|
|
901
|
+
case 0:
|
|
902
|
+
scopes = [];
|
|
903
|
+
values = [];
|
|
904
|
+
if (!(this.scope instanceof ElementQueryNode)) return [3 /*break*/, 2];
|
|
905
|
+
return [4 /*yield*/, this.scope.evaluate(scope, dom, tag)];
|
|
906
|
+
case 1:
|
|
907
|
+
scopes = _c.sent();
|
|
908
|
+
return [3 /*break*/, 4];
|
|
909
|
+
case 2: return [4 /*yield*/, this.scope.evaluate(scope, dom, tag)];
|
|
910
|
+
case 3:
|
|
911
|
+
evalScope = _c.sent();
|
|
912
|
+
if (evalScope instanceof List_1.TagList) {
|
|
913
|
+
scopes = evalScope;
|
|
914
|
+
}
|
|
915
|
+
else {
|
|
916
|
+
scopes.push(evalScope);
|
|
917
|
+
}
|
|
918
|
+
_c.label = 4;
|
|
919
|
+
case 4:
|
|
920
|
+
_i = 0, scopes_1 = scopes;
|
|
921
|
+
_c.label = 5;
|
|
922
|
+
case 5:
|
|
923
|
+
if (!(_i < scopes_1.length)) return [3 /*break*/, 10];
|
|
924
|
+
parent_1 = scopes_1[_i];
|
|
925
|
+
if (parent_1 instanceof DOMObject_1.DOMObject)
|
|
926
|
+
parent_1 = parent_1.scope;
|
|
927
|
+
if (!!parent_1) return [3 /*break*/, 7];
|
|
928
|
+
_a = Error;
|
|
929
|
+
_b = "Cannot access \"";
|
|
930
|
+
return [4 /*yield*/, this.name.evaluate(scope, dom, tag)];
|
|
931
|
+
case 6: throw _a.apply(void 0, [_b + (_c.sent()) + "\" of undefined."]);
|
|
932
|
+
case 7: return [4 /*yield*/, this.name.evaluate(scope, dom, tag)];
|
|
933
|
+
case 8:
|
|
934
|
+
name_1 = _c.sent();
|
|
935
|
+
value = parent_1.get(name_1, false);
|
|
936
|
+
values.push(value instanceof Scope_1.Scope && value.wrapped || value);
|
|
937
|
+
_c.label = 9;
|
|
938
|
+
case 9:
|
|
939
|
+
_i++;
|
|
940
|
+
return [3 /*break*/, 5];
|
|
941
|
+
case 10: return [2 /*return*/, values.length === 1 ? values[0] : values];
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
});
|
|
945
|
+
};
|
|
946
|
+
return ScopeMemberNode;
|
|
947
|
+
}(Node));
|
|
948
|
+
var RootScopeMemberNode = /** @class */ (function (_super) {
|
|
949
|
+
__extends(RootScopeMemberNode, _super);
|
|
950
|
+
function RootScopeMemberNode(name) {
|
|
951
|
+
var _this = _super.call(this) || this;
|
|
952
|
+
_this.name = name;
|
|
953
|
+
return _this;
|
|
954
|
+
}
|
|
955
|
+
RootScopeMemberNode.prototype._getChildNodes = function () {
|
|
956
|
+
return [
|
|
957
|
+
this.name
|
|
958
|
+
];
|
|
959
|
+
};
|
|
960
|
+
RootScopeMemberNode.prototype.evaluate = function (scope, dom, tag) {
|
|
961
|
+
if (tag === void 0) { tag = null; }
|
|
962
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
963
|
+
var value, _a, _b;
|
|
964
|
+
return __generator(this, function (_c) {
|
|
965
|
+
switch (_c.label) {
|
|
966
|
+
case 0:
|
|
967
|
+
_b = (_a = scope).get;
|
|
968
|
+
return [4 /*yield*/, this.name.evaluate(scope, dom, tag)];
|
|
969
|
+
case 1:
|
|
970
|
+
value = _b.apply(_a, [_c.sent()]);
|
|
971
|
+
return [2 /*return*/, value instanceof Scope_1.Scope && value.wrapped || value];
|
|
972
|
+
}
|
|
973
|
+
});
|
|
974
|
+
});
|
|
975
|
+
};
|
|
976
|
+
return RootScopeMemberNode;
|
|
977
|
+
}(Node));
|
|
978
|
+
var ArithmeticNode = /** @class */ (function (_super) {
|
|
979
|
+
__extends(ArithmeticNode, _super);
|
|
980
|
+
function ArithmeticNode(left, right, type) {
|
|
981
|
+
var _this = _super.call(this) || this;
|
|
982
|
+
_this.left = left;
|
|
983
|
+
_this.right = right;
|
|
984
|
+
_this.type = type;
|
|
985
|
+
return _this;
|
|
986
|
+
}
|
|
987
|
+
ArithmeticNode.prototype._getChildNodes = function () {
|
|
988
|
+
return [
|
|
989
|
+
this.left,
|
|
990
|
+
this.right
|
|
991
|
+
];
|
|
992
|
+
};
|
|
993
|
+
ArithmeticNode.prototype.evaluate = function (scope, dom, tag) {
|
|
994
|
+
if (tag === void 0) { tag = null; }
|
|
995
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
996
|
+
var left, right;
|
|
997
|
+
return __generator(this, function (_a) {
|
|
998
|
+
switch (_a.label) {
|
|
999
|
+
case 0: return [4 /*yield*/, this.left.evaluate(scope, dom, tag)];
|
|
1000
|
+
case 1:
|
|
1001
|
+
left = _a.sent();
|
|
1002
|
+
return [4 /*yield*/, this.right.evaluate(scope, dom, tag)];
|
|
1003
|
+
case 2:
|
|
1004
|
+
right = _a.sent();
|
|
1005
|
+
switch (this.type) {
|
|
1006
|
+
case TokenType.ADD:
|
|
1007
|
+
return [2 /*return*/, left + right];
|
|
1008
|
+
case TokenType.SUBTRACT:
|
|
1009
|
+
return [2 /*return*/, left - right];
|
|
1010
|
+
case TokenType.MULTIPLY:
|
|
1011
|
+
return [2 /*return*/, left * right];
|
|
1012
|
+
case TokenType.DIVIDE:
|
|
1013
|
+
return [2 /*return*/, left / right];
|
|
1014
|
+
}
|
|
1015
|
+
return [2 /*return*/];
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
});
|
|
1019
|
+
};
|
|
1020
|
+
ArithmeticNode.match = function (tokens) {
|
|
1021
|
+
return [
|
|
1022
|
+
TokenType.ADD,
|
|
1023
|
+
TokenType.SUBTRACT,
|
|
1024
|
+
TokenType.MULTIPLY,
|
|
1025
|
+
TokenType.DIVIDE
|
|
1026
|
+
].indexOf(tokens[0].type) > -1;
|
|
1027
|
+
};
|
|
1028
|
+
ArithmeticNode.parse = function (lastNode, token, tokens) {
|
|
1029
|
+
tokens.splice(0, 1); // Remove arithmetic operator
|
|
1030
|
+
return new ArithmeticNode(lastNode, Tree.processTokens(Tree.getNextStatementTokens(tokens)), token.type);
|
|
1031
|
+
};
|
|
1032
|
+
return ArithmeticNode;
|
|
1033
|
+
}(Node));
|
|
1034
|
+
var ArithmeticAssignmentNode = /** @class */ (function (_super) {
|
|
1035
|
+
__extends(ArithmeticAssignmentNode, _super);
|
|
1036
|
+
function ArithmeticAssignmentNode(left, right, type) {
|
|
1037
|
+
var _this = _super.call(this) || this;
|
|
1038
|
+
_this.left = left;
|
|
1039
|
+
_this.right = right;
|
|
1040
|
+
_this.type = type;
|
|
1041
|
+
return _this;
|
|
1042
|
+
}
|
|
1043
|
+
ArithmeticAssignmentNode.prototype._getChildNodes = function () {
|
|
1044
|
+
return [
|
|
1045
|
+
this.left,
|
|
1046
|
+
this.right
|
|
1047
|
+
];
|
|
1048
|
+
};
|
|
1049
|
+
ArithmeticAssignmentNode.prototype.evaluate = function (scope, dom, tag) {
|
|
1050
|
+
if (tag === void 0) { tag = null; }
|
|
1051
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1052
|
+
var scopes, name, inner, values, _i, scopes_2, localScope, left, right;
|
|
1053
|
+
return __generator(this, function (_a) {
|
|
1054
|
+
switch (_a.label) {
|
|
1055
|
+
case 0:
|
|
1056
|
+
scopes = [];
|
|
1057
|
+
return [4 /*yield*/, this.left.name.evaluate(scope, dom, tag)];
|
|
1058
|
+
case 1:
|
|
1059
|
+
name = _a.sent();
|
|
1060
|
+
if (!(this.left instanceof ScopeMemberNode)) return [3 /*break*/, 3];
|
|
1061
|
+
return [4 /*yield*/, this.left.scope.evaluate(scope, dom, tag)];
|
|
1062
|
+
case 2:
|
|
1063
|
+
inner = _a.sent();
|
|
1064
|
+
if (this.left.scope instanceof ElementQueryNode) {
|
|
1065
|
+
scopes.push.apply(scopes, inner);
|
|
1066
|
+
}
|
|
1067
|
+
else {
|
|
1068
|
+
scopes.push(inner);
|
|
1069
|
+
}
|
|
1070
|
+
return [3 /*break*/, 6];
|
|
1071
|
+
case 3:
|
|
1072
|
+
if (!(this.left instanceof ElementAttributeNode && this.left.elementRef)) return [3 /*break*/, 5];
|
|
1073
|
+
return [4 /*yield*/, this.left.elementRef.evaluate(scope, dom, tag)];
|
|
1074
|
+
case 4:
|
|
1075
|
+
scopes = _a.sent();
|
|
1076
|
+
return [3 /*break*/, 6];
|
|
1077
|
+
case 5:
|
|
1078
|
+
scopes.push(scope);
|
|
1079
|
+
_a.label = 6;
|
|
1080
|
+
case 6:
|
|
1081
|
+
values = [];
|
|
1082
|
+
_i = 0, scopes_2 = scopes;
|
|
1083
|
+
_a.label = 7;
|
|
1084
|
+
case 7:
|
|
1085
|
+
if (!(_i < scopes_2.length)) return [3 /*break*/, 13];
|
|
1086
|
+
localScope = scopes_2[_i];
|
|
1087
|
+
if (!(localScope instanceof DOMObject_1.DOMObject)) return [3 /*break*/, 9];
|
|
1088
|
+
return [4 /*yield*/, this.handleDOMObject(name, dom, localScope, tag)];
|
|
1089
|
+
case 8:
|
|
1090
|
+
_a.sent();
|
|
1091
|
+
return [3 /*break*/, 12];
|
|
1092
|
+
case 9:
|
|
1093
|
+
if (localScope['$wrapped'] && localScope['$scope'])
|
|
1094
|
+
localScope = localScope['$scope'];
|
|
1095
|
+
return [4 /*yield*/, this.left.evaluate(localScope, dom, tag)];
|
|
1096
|
+
case 10:
|
|
1097
|
+
left = _a.sent();
|
|
1098
|
+
return [4 /*yield*/, this.right.evaluate(localScope, dom, tag)];
|
|
1099
|
+
case 11:
|
|
1100
|
+
right = _a.sent();
|
|
1101
|
+
if (left instanceof Array) {
|
|
1102
|
+
left = this.handleArray(name, left, right, localScope);
|
|
1103
|
+
}
|
|
1104
|
+
else if (Number.isFinite(left)) {
|
|
1105
|
+
left = this.handleNumber(name, left, right, localScope);
|
|
1106
|
+
}
|
|
1107
|
+
else {
|
|
1108
|
+
left = this.handleString(name, left, right, localScope);
|
|
1109
|
+
}
|
|
1110
|
+
values.push(left);
|
|
1111
|
+
_a.label = 12;
|
|
1112
|
+
case 12:
|
|
1113
|
+
_i++;
|
|
1114
|
+
return [3 /*break*/, 7];
|
|
1115
|
+
case 13: return [2 /*return*/, values.length > 1 ? values : values[0]];
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
});
|
|
1119
|
+
};
|
|
1120
|
+
ArithmeticAssignmentNode.prototype.handleNumber = function (key, left, right, scope) {
|
|
1121
|
+
if (right !== null && !Number.isFinite(right))
|
|
1122
|
+
right = parseFloat("" + right);
|
|
1123
|
+
left = left;
|
|
1124
|
+
right = right;
|
|
1125
|
+
switch (this.type) {
|
|
1126
|
+
case TokenType.ASSIGN:
|
|
1127
|
+
left = right;
|
|
1128
|
+
break;
|
|
1129
|
+
case TokenType.ADD_ASSIGN:
|
|
1130
|
+
left += right;
|
|
1131
|
+
break;
|
|
1132
|
+
case TokenType.SUBTRACT_ASSIGN:
|
|
1133
|
+
left -= right;
|
|
1134
|
+
break;
|
|
1135
|
+
case TokenType.MULTIPLY_ASSIGN:
|
|
1136
|
+
left *= right;
|
|
1137
|
+
break;
|
|
1138
|
+
case TokenType.DIVIDE_ASSIGN:
|
|
1139
|
+
left /= right;
|
|
1140
|
+
break;
|
|
1141
|
+
}
|
|
1142
|
+
scope.set(key, left);
|
|
1143
|
+
return left;
|
|
1144
|
+
};
|
|
1145
|
+
ArithmeticAssignmentNode.prototype.handleString = function (key, left, right, scope) {
|
|
1146
|
+
switch (this.type) {
|
|
1147
|
+
case TokenType.ASSIGN:
|
|
1148
|
+
left = right;
|
|
1149
|
+
break;
|
|
1150
|
+
case TokenType.ADD_ASSIGN:
|
|
1151
|
+
left = "" + left + right;
|
|
1152
|
+
break;
|
|
1153
|
+
case TokenType.SUBTRACT_ASSIGN:
|
|
1154
|
+
left.replace(right, '');
|
|
1155
|
+
break;
|
|
1156
|
+
case TokenType.MULTIPLY_ASSIGN:
|
|
1157
|
+
left *= right;
|
|
1158
|
+
break;
|
|
1159
|
+
case TokenType.DIVIDE_ASSIGN:
|
|
1160
|
+
left /= right;
|
|
1161
|
+
break;
|
|
1162
|
+
}
|
|
1163
|
+
scope.set(key, left);
|
|
1164
|
+
return left;
|
|
1165
|
+
};
|
|
1166
|
+
ArithmeticAssignmentNode.prototype.handleDOMObject = function (key, dom, domObject, tag) {
|
|
1167
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1168
|
+
var left, right;
|
|
1169
|
+
return __generator(this, function (_a) {
|
|
1170
|
+
switch (_a.label) {
|
|
1171
|
+
case 0:
|
|
1172
|
+
left = domObject.scope.get(key);
|
|
1173
|
+
return [4 /*yield*/, this.right.evaluate(domObject.scope, dom, tag)];
|
|
1174
|
+
case 1:
|
|
1175
|
+
right = _a.sent();
|
|
1176
|
+
if (left instanceof Array)
|
|
1177
|
+
return [2 /*return*/, this.handleArray(key, left, right, domObject.scope)];
|
|
1178
|
+
return [2 /*return*/, this.handleString(key, left, right, domObject.scope)];
|
|
1179
|
+
}
|
|
1180
|
+
});
|
|
1181
|
+
});
|
|
1182
|
+
};
|
|
1183
|
+
ArithmeticAssignmentNode.prototype.handleArray = function (key, left, right, scope) {
|
|
1184
|
+
if (!(right instanceof Array))
|
|
1185
|
+
right = [right];
|
|
1186
|
+
switch (this.type) {
|
|
1187
|
+
case TokenType.ASSIGN:
|
|
1188
|
+
left.splice(0, left.length);
|
|
1189
|
+
left.push.apply(left, right);
|
|
1190
|
+
break;
|
|
1191
|
+
case TokenType.ADD_ASSIGN:
|
|
1192
|
+
left.push.apply(left, right);
|
|
1193
|
+
break;
|
|
1194
|
+
case TokenType.SUBTRACT_ASSIGN:
|
|
1195
|
+
for (var i = left.length - 1; i >= 0; i--) {
|
|
1196
|
+
if (right.indexOf(left[i]) > -1) {
|
|
1197
|
+
left.splice(i, 1);
|
|
1198
|
+
i++;
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
break;
|
|
1202
|
+
case TokenType.TILDE:
|
|
1203
|
+
for (var _i = 0, right_1 = right; _i < right_1.length; _i++) {
|
|
1204
|
+
var toggle = right_1[_i];
|
|
1205
|
+
var index = left.indexOf(toggle);
|
|
1206
|
+
if (index > -1) {
|
|
1207
|
+
left.splice(index, 1);
|
|
1208
|
+
}
|
|
1209
|
+
else {
|
|
1210
|
+
left.push(toggle);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
break;
|
|
1214
|
+
}
|
|
1215
|
+
/*
|
|
1216
|
+
We have to trigger a change manually here. Setting the variable on the scope with an array won't trigger
|
|
1217
|
+
it since we are modifying values inside of the array instance.
|
|
1218
|
+
*/
|
|
1219
|
+
scope.trigger("change:" + key);
|
|
1220
|
+
return left;
|
|
1221
|
+
};
|
|
1222
|
+
ArithmeticAssignmentNode.match = function (tokens) {
|
|
1223
|
+
return [
|
|
1224
|
+
TokenType.ASSIGN,
|
|
1225
|
+
TokenType.ADD_ASSIGN,
|
|
1226
|
+
TokenType.SUBTRACT_ASSIGN,
|
|
1227
|
+
TokenType.MULTIPLY_ASSIGN,
|
|
1228
|
+
TokenType.DIVIDE_ASSIGN,
|
|
1229
|
+
TokenType.TILDE,
|
|
1230
|
+
].indexOf(tokens[0].type) > -1;
|
|
1231
|
+
};
|
|
1232
|
+
ArithmeticAssignmentNode.parse = function (lastNode, token, tokens) {
|
|
1233
|
+
if (!(lastNode instanceof RootScopeMemberNode) && !(lastNode instanceof ScopeMemberNode) && !(lastNode instanceof ElementAttributeNode)) {
|
|
1234
|
+
throw SyntaxError("Invalid assignment syntax near " + Tree.toCode(tokens.splice(0, 10)));
|
|
1235
|
+
}
|
|
1236
|
+
tokens.splice(0, 1); // consume =
|
|
1237
|
+
var assignmentTokens = Tree.getNextStatementTokens(tokens, false, false, true);
|
|
1238
|
+
return new ArithmeticAssignmentNode(lastNode, Tree.processTokens(assignmentTokens), token.type);
|
|
1239
|
+
};
|
|
1240
|
+
return ArithmeticAssignmentNode;
|
|
1241
|
+
}(Node));
|
|
1242
|
+
var IndexNode = /** @class */ (function (_super) {
|
|
1243
|
+
__extends(IndexNode, _super);
|
|
1244
|
+
function IndexNode(object, index, indexTwo) {
|
|
1245
|
+
if (indexTwo === void 0) { indexTwo = null; }
|
|
1246
|
+
var _this = _super.call(this) || this;
|
|
1247
|
+
_this.object = object;
|
|
1248
|
+
_this.index = index;
|
|
1249
|
+
_this.indexTwo = indexTwo;
|
|
1250
|
+
return _this;
|
|
1251
|
+
}
|
|
1252
|
+
IndexNode.prototype._getChildNodes = function () {
|
|
1253
|
+
var children = [
|
|
1254
|
+
this.object,
|
|
1255
|
+
this.index
|
|
1256
|
+
];
|
|
1257
|
+
if (this.indexTwo)
|
|
1258
|
+
children.push(this.indexTwo);
|
|
1259
|
+
return children;
|
|
1260
|
+
};
|
|
1261
|
+
IndexNode.prototype.negativeIndex = function (obj, index) {
|
|
1262
|
+
if (Number.isFinite(index) && index < 0)
|
|
1263
|
+
return obj.length + index;
|
|
1264
|
+
return index;
|
|
1265
|
+
};
|
|
1266
|
+
IndexNode.prototype.evaluate = function (scope, dom, tag) {
|
|
1267
|
+
if (tag === void 0) { tag = null; }
|
|
1268
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1269
|
+
var obj, index, _a, _b, indexTwo, _c, _d, values, i;
|
|
1270
|
+
return __generator(this, function (_e) {
|
|
1271
|
+
switch (_e.label) {
|
|
1272
|
+
case 0: return [4 /*yield*/, this.object.evaluate(scope, dom, tag)];
|
|
1273
|
+
case 1:
|
|
1274
|
+
obj = _e.sent();
|
|
1275
|
+
_a = this.negativeIndex;
|
|
1276
|
+
_b = [obj];
|
|
1277
|
+
return [4 /*yield*/, this.index.evaluate(scope, dom, tag)];
|
|
1278
|
+
case 2:
|
|
1279
|
+
index = _a.apply(this, _b.concat([_e.sent()]));
|
|
1280
|
+
if (!(Number.isFinite(index) && this.indexTwo)) return [3 /*break*/, 4];
|
|
1281
|
+
_c = this.negativeIndex;
|
|
1282
|
+
_d = [obj];
|
|
1283
|
+
return [4 /*yield*/, this.indexTwo.evaluate(scope, dom, tag)];
|
|
1284
|
+
case 3:
|
|
1285
|
+
indexTwo = _c.apply(this, _d.concat([_e.sent()]));
|
|
1286
|
+
values = [];
|
|
1287
|
+
for (i = index; i <= indexTwo; i++) {
|
|
1288
|
+
values.push(obj[i]);
|
|
1289
|
+
}
|
|
1290
|
+
return [2 /*return*/, values];
|
|
1291
|
+
case 4: return [2 /*return*/, (obj)[index]];
|
|
1292
|
+
}
|
|
1293
|
+
});
|
|
1294
|
+
});
|
|
1295
|
+
};
|
|
1296
|
+
IndexNode.match = function (tokens) {
|
|
1297
|
+
return tokens[0].type === TokenType.L_BRACKET;
|
|
1298
|
+
};
|
|
1299
|
+
IndexNode.parse = function (lastNode, token, tokens) {
|
|
1300
|
+
var valueTokens = Tree.getBlockTokens(tokens, TokenType.COLON);
|
|
1301
|
+
var values = [];
|
|
1302
|
+
for (var _i = 0, valueTokens_1 = valueTokens; _i < valueTokens_1.length; _i++) {
|
|
1303
|
+
var arg = valueTokens_1[_i];
|
|
1304
|
+
values.push(Tree.processTokens(arg));
|
|
1305
|
+
}
|
|
1306
|
+
return new IndexNode(lastNode, values[0], values.length > 1 && values[1]);
|
|
1307
|
+
};
|
|
1308
|
+
return IndexNode;
|
|
1309
|
+
}(Node));
|
|
1310
|
+
var ArrayNode = /** @class */ (function (_super) {
|
|
1311
|
+
__extends(ArrayNode, _super);
|
|
1312
|
+
function ArrayNode(values) {
|
|
1313
|
+
var _this = _super.call(this) || this;
|
|
1314
|
+
_this.values = values;
|
|
1315
|
+
return _this;
|
|
1316
|
+
}
|
|
1317
|
+
ArrayNode.prototype._getChildNodes = function () {
|
|
1318
|
+
return new (Array.bind.apply(Array, __spreadArray([void 0], this.values)))();
|
|
1319
|
+
};
|
|
1320
|
+
ArrayNode.prototype.evaluate = function (scope, dom, tag) {
|
|
1321
|
+
if (tag === void 0) { tag = null; }
|
|
1322
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1323
|
+
var arr, _i, _a, val, _b, _c;
|
|
1324
|
+
return __generator(this, function (_d) {
|
|
1325
|
+
switch (_d.label) {
|
|
1326
|
+
case 0:
|
|
1327
|
+
arr = [];
|
|
1328
|
+
_i = 0, _a = this.values;
|
|
1329
|
+
_d.label = 1;
|
|
1330
|
+
case 1:
|
|
1331
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
1332
|
+
val = _a[_i];
|
|
1333
|
+
_c = (_b = arr).push;
|
|
1334
|
+
return [4 /*yield*/, val.evaluate(scope, dom, tag)];
|
|
1335
|
+
case 2:
|
|
1336
|
+
_c.apply(_b, [_d.sent()]);
|
|
1337
|
+
_d.label = 3;
|
|
1338
|
+
case 3:
|
|
1339
|
+
_i++;
|
|
1340
|
+
return [3 /*break*/, 1];
|
|
1341
|
+
case 4: return [2 /*return*/, arr];
|
|
1342
|
+
}
|
|
1343
|
+
});
|
|
1344
|
+
});
|
|
1345
|
+
};
|
|
1346
|
+
ArrayNode.match = function (tokens) {
|
|
1347
|
+
return tokens[0].type === TokenType.L_BRACKET;
|
|
1348
|
+
};
|
|
1349
|
+
ArrayNode.parse = function (lastNode, token, tokens) {
|
|
1350
|
+
var valueTokens = Tree.getBlockTokens(tokens);
|
|
1351
|
+
var values = [];
|
|
1352
|
+
for (var _i = 0, valueTokens_2 = valueTokens; _i < valueTokens_2.length; _i++) {
|
|
1353
|
+
var arg = valueTokens_2[_i];
|
|
1354
|
+
values.push(Tree.processTokens(arg));
|
|
1355
|
+
}
|
|
1356
|
+
return new ArrayNode(values);
|
|
1357
|
+
};
|
|
1358
|
+
return ArrayNode;
|
|
1359
|
+
}(Node));
|
|
1360
|
+
var ObjectNode = /** @class */ (function (_super) {
|
|
1361
|
+
__extends(ObjectNode, _super);
|
|
1362
|
+
function ObjectNode(keys, values) {
|
|
1363
|
+
var _this = _super.call(this) || this;
|
|
1364
|
+
_this.keys = keys;
|
|
1365
|
+
_this.values = values;
|
|
1366
|
+
return _this;
|
|
1367
|
+
}
|
|
1368
|
+
ObjectNode.prototype._getChildNodes = function () {
|
|
1369
|
+
return new (Array.bind.apply(Array, __spreadArray([void 0], this.values)))();
|
|
1370
|
+
};
|
|
1371
|
+
ObjectNode.prototype.evaluate = function (scope, dom, tag) {
|
|
1372
|
+
if (tag === void 0) { tag = null; }
|
|
1373
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1374
|
+
var obj, i, key, val, _a, _b, _c;
|
|
1375
|
+
return __generator(this, function (_d) {
|
|
1376
|
+
switch (_d.label) {
|
|
1377
|
+
case 0:
|
|
1378
|
+
obj = new Scope_1.Scope();
|
|
1379
|
+
i = 0;
|
|
1380
|
+
_d.label = 1;
|
|
1381
|
+
case 1:
|
|
1382
|
+
if (!(i < this.values.length)) return [3 /*break*/, 5];
|
|
1383
|
+
key = this.keys[i];
|
|
1384
|
+
val = this.values[i];
|
|
1385
|
+
_b = (_a = obj).set;
|
|
1386
|
+
return [4 /*yield*/, key.evaluate(scope, dom, tag)];
|
|
1387
|
+
case 2:
|
|
1388
|
+
_c = [_d.sent()];
|
|
1389
|
+
return [4 /*yield*/, val.evaluate(scope, dom, tag)];
|
|
1390
|
+
case 3:
|
|
1391
|
+
_b.apply(_a, _c.concat([_d.sent()]));
|
|
1392
|
+
_d.label = 4;
|
|
1393
|
+
case 4:
|
|
1394
|
+
i++;
|
|
1395
|
+
return [3 /*break*/, 1];
|
|
1396
|
+
case 5: return [2 /*return*/, obj];
|
|
1397
|
+
}
|
|
1398
|
+
});
|
|
1399
|
+
});
|
|
1400
|
+
};
|
|
1401
|
+
ObjectNode.match = function (tokens) {
|
|
1402
|
+
return tokens[0].type === TokenType.L_BRACE;
|
|
1403
|
+
};
|
|
1404
|
+
ObjectNode.parse = function (lastNode, token, tokens) {
|
|
1405
|
+
var valueTokens = Tree.getNextStatementTokens(tokens);
|
|
1406
|
+
var keys = [];
|
|
1407
|
+
var values = [];
|
|
1408
|
+
while (valueTokens.length > 0) {
|
|
1409
|
+
var key = Tree.getTokensUntil(valueTokens, TokenType.COLON, false);
|
|
1410
|
+
if (valueTokens[0].type !== TokenType.COLON)
|
|
1411
|
+
throw Error('Invalid object literal syntax. Expecting :');
|
|
1412
|
+
valueTokens.splice(0, 1); // Consume :
|
|
1413
|
+
var val = Tree.getTokensUntil(valueTokens, TokenType.COMMA, true, false, true, {
|
|
1414
|
+
type: BlockType.STATEMENT,
|
|
1415
|
+
open: null,
|
|
1416
|
+
close: null,
|
|
1417
|
+
openCharacter: null,
|
|
1418
|
+
closeCharacter: null
|
|
1419
|
+
});
|
|
1420
|
+
keys.push(Tree.processTokens(key));
|
|
1421
|
+
values.push(Tree.processTokens(val));
|
|
1422
|
+
}
|
|
1423
|
+
return new ObjectNode(keys, values);
|
|
1424
|
+
};
|
|
1425
|
+
return ObjectNode;
|
|
1426
|
+
}(Node));
|
|
1427
|
+
var ElementQueryNode = /** @class */ (function (_super) {
|
|
1428
|
+
__extends(ElementQueryNode, _super);
|
|
1429
|
+
function ElementQueryNode(query) {
|
|
1430
|
+
var _this = _super.call(this) || this;
|
|
1431
|
+
_this.query = query;
|
|
1432
|
+
_this.requiresPrep = true;
|
|
1433
|
+
return _this;
|
|
1434
|
+
}
|
|
1435
|
+
ElementQueryNode.prototype.evaluate = function (scope, dom, tag) {
|
|
1436
|
+
if (tag === void 0) { tag = null; }
|
|
1437
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1438
|
+
var _a;
|
|
1439
|
+
return __generator(this, function (_b) {
|
|
1440
|
+
switch (_b.label) {
|
|
1441
|
+
case 0:
|
|
1442
|
+
_a = tag;
|
|
1443
|
+
if (_a) return [3 /*break*/, 2];
|
|
1444
|
+
return [4 /*yield*/, dom.getTagForScope(scope)];
|
|
1445
|
+
case 1:
|
|
1446
|
+
_a = (_b.sent());
|
|
1447
|
+
_b.label = 2;
|
|
1448
|
+
case 2:
|
|
1449
|
+
tag = _a;
|
|
1450
|
+
return [4 /*yield*/, dom.get(this.query, true, tag)];
|
|
1451
|
+
case 3: return [2 /*return*/, _b.sent()];
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
});
|
|
1455
|
+
};
|
|
1456
|
+
ElementQueryNode.prototype.prepare = function (scope, dom, tag) {
|
|
1457
|
+
if (tag === void 0) { tag = null; }
|
|
1458
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1459
|
+
var _a;
|
|
1460
|
+
return __generator(this, function (_b) {
|
|
1461
|
+
switch (_b.label) {
|
|
1462
|
+
case 0:
|
|
1463
|
+
_a = tag;
|
|
1464
|
+
if (_a) return [3 /*break*/, 2];
|
|
1465
|
+
return [4 /*yield*/, dom.getTagForScope(scope)];
|
|
1466
|
+
case 1:
|
|
1467
|
+
_a = (_b.sent());
|
|
1468
|
+
_b.label = 2;
|
|
1469
|
+
case 2:
|
|
1470
|
+
tag = _a;
|
|
1471
|
+
return [4 /*yield*/, dom.get(this.query, true, tag)];
|
|
1472
|
+
case 3:
|
|
1473
|
+
_b.sent();
|
|
1474
|
+
return [2 /*return*/];
|
|
1475
|
+
}
|
|
1476
|
+
});
|
|
1477
|
+
});
|
|
1478
|
+
};
|
|
1479
|
+
return ElementQueryNode;
|
|
1480
|
+
}(Node));
|
|
1481
|
+
var ElementAttributeNode = /** @class */ (function (_super) {
|
|
1482
|
+
__extends(ElementAttributeNode, _super);
|
|
1483
|
+
function ElementAttributeNode(elementRef, attr) {
|
|
1484
|
+
var _this = _super.call(this) || this;
|
|
1485
|
+
_this.elementRef = elementRef;
|
|
1486
|
+
_this.attr = attr;
|
|
1487
|
+
_this.requiresPrep = true;
|
|
1488
|
+
return _this;
|
|
1489
|
+
}
|
|
1490
|
+
Object.defineProperty(ElementAttributeNode.prototype, "name", {
|
|
1491
|
+
get: function () {
|
|
1492
|
+
return new LiteralNode("@" + this.attributeName);
|
|
1493
|
+
},
|
|
1494
|
+
enumerable: false,
|
|
1495
|
+
configurable: true
|
|
1496
|
+
});
|
|
1497
|
+
ElementAttributeNode.prototype._getChildNodes = function () {
|
|
1498
|
+
var nodes = [];
|
|
1499
|
+
if (this.elementRef)
|
|
1500
|
+
nodes.push(this.elementRef);
|
|
1501
|
+
return nodes;
|
|
1502
|
+
};
|
|
1503
|
+
Object.defineProperty(ElementAttributeNode.prototype, "attributeName", {
|
|
1504
|
+
get: function () {
|
|
1505
|
+
if (this.attr.startsWith('.'))
|
|
1506
|
+
return this.attr.substring(2);
|
|
1507
|
+
return this.attr.substring(1);
|
|
1508
|
+
},
|
|
1509
|
+
enumerable: false,
|
|
1510
|
+
configurable: true
|
|
1511
|
+
});
|
|
1512
|
+
ElementAttributeNode.prototype.evaluate = function (scope, dom, tag) {
|
|
1513
|
+
if (tag === void 0) { tag = null; }
|
|
1514
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1515
|
+
var tags;
|
|
1516
|
+
var _this = this;
|
|
1517
|
+
return __generator(this, function (_a) {
|
|
1518
|
+
switch (_a.label) {
|
|
1519
|
+
case 0:
|
|
1520
|
+
if (!this.elementRef) return [3 /*break*/, 2];
|
|
1521
|
+
return [4 /*yield*/, this.elementRef.evaluate(scope, dom, tag)];
|
|
1522
|
+
case 1:
|
|
1523
|
+
tags = _a.sent();
|
|
1524
|
+
return [3 /*break*/, 3];
|
|
1525
|
+
case 2:
|
|
1526
|
+
if (tag) {
|
|
1527
|
+
tags = new List_1.TagList(tag);
|
|
1528
|
+
}
|
|
1529
|
+
else {
|
|
1530
|
+
return [2 /*return*/];
|
|
1531
|
+
}
|
|
1532
|
+
_a.label = 3;
|
|
1533
|
+
case 3:
|
|
1534
|
+
if (tags.length === 1)
|
|
1535
|
+
return [2 /*return*/, tags[0].scope.get("@" + this.attributeName)];
|
|
1536
|
+
return [2 /*return*/, tags.map(function (tag) { return tag.scope.get("@" + _this.attributeName); })];
|
|
1537
|
+
}
|
|
1538
|
+
});
|
|
1539
|
+
});
|
|
1540
|
+
};
|
|
1541
|
+
ElementAttributeNode.prototype.prepare = function (scope, dom, tag) {
|
|
1542
|
+
if (tag === void 0) { tag = null; }
|
|
1543
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1544
|
+
var tags, _i, tags_1, t;
|
|
1545
|
+
return __generator(this, function (_a) {
|
|
1546
|
+
switch (_a.label) {
|
|
1547
|
+
case 0:
|
|
1548
|
+
if (!this.elementRef) return [3 /*break*/, 7];
|
|
1549
|
+
return [4 /*yield*/, this.elementRef.prepare(scope, dom, tag)];
|
|
1550
|
+
case 1:
|
|
1551
|
+
_a.sent();
|
|
1552
|
+
return [4 /*yield*/, this.elementRef.evaluate(scope, dom, tag)];
|
|
1553
|
+
case 2:
|
|
1554
|
+
tags = _a.sent();
|
|
1555
|
+
_i = 0, tags_1 = tags;
|
|
1556
|
+
_a.label = 3;
|
|
1557
|
+
case 3:
|
|
1558
|
+
if (!(_i < tags_1.length)) return [3 /*break*/, 6];
|
|
1559
|
+
t = tags_1[_i];
|
|
1560
|
+
return [4 /*yield*/, t.watchAttribute(this.attributeName)];
|
|
1561
|
+
case 4:
|
|
1562
|
+
_a.sent();
|
|
1563
|
+
_a.label = 5;
|
|
1564
|
+
case 5:
|
|
1565
|
+
_i++;
|
|
1566
|
+
return [3 /*break*/, 3];
|
|
1567
|
+
case 6: return [3 /*break*/, 9];
|
|
1568
|
+
case 7:
|
|
1569
|
+
if (!tag) return [3 /*break*/, 9];
|
|
1570
|
+
return [4 /*yield*/, tag.watchAttribute(this.attributeName)];
|
|
1571
|
+
case 8:
|
|
1572
|
+
_a.sent();
|
|
1573
|
+
_a.label = 9;
|
|
1574
|
+
case 9: return [2 /*return*/];
|
|
1575
|
+
}
|
|
1576
|
+
});
|
|
1577
|
+
});
|
|
1578
|
+
};
|
|
1579
|
+
return ElementAttributeNode;
|
|
1580
|
+
}(Node));
|
|
1581
|
+
exports.AttributableNodes = [
|
|
1582
|
+
RootScopeMemberNode,
|
|
1583
|
+
ScopeMemberNode,
|
|
1584
|
+
ElementAttributeNode
|
|
1585
|
+
];
|
|
1586
|
+
var Tree = /** @class */ (function () {
|
|
1587
|
+
function Tree(code) {
|
|
1588
|
+
this.code = code;
|
|
1589
|
+
if (Tree.cache[code]) {
|
|
1590
|
+
this.rootNode = Tree.cache[code];
|
|
1591
|
+
}
|
|
1592
|
+
else {
|
|
1593
|
+
this.parse();
|
|
1594
|
+
Tree.cache[code] = this.rootNode;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
Tree.prototype.parse = function () {
|
|
1598
|
+
var tokens = Tree.tokenize(this.code);
|
|
1599
|
+
this.rootNode = Tree.processTokens(tokens);
|
|
1600
|
+
};
|
|
1601
|
+
Tree.prototype.evaluate = function (scope, dom, tag) {
|
|
1602
|
+
if (tag === void 0) { tag = null; }
|
|
1603
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1604
|
+
return __generator(this, function (_a) {
|
|
1605
|
+
switch (_a.label) {
|
|
1606
|
+
case 0: return [4 /*yield*/, this.rootNode.evaluate(scope, dom, tag)];
|
|
1607
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1608
|
+
}
|
|
1609
|
+
});
|
|
1610
|
+
});
|
|
1611
|
+
};
|
|
1612
|
+
Tree.prototype.prepare = function (scope, dom, tag) {
|
|
1613
|
+
if (tag === void 0) { tag = null; }
|
|
1614
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1615
|
+
return __generator(this, function (_a) {
|
|
1616
|
+
switch (_a.label) {
|
|
1617
|
+
case 0:
|
|
1618
|
+
if (!this.rootNode.isPreparationRequired())
|
|
1619
|
+
return [2 /*return*/];
|
|
1620
|
+
return [4 /*yield*/, this.rootNode.prepare(scope, dom, tag)];
|
|
1621
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
});
|
|
1625
|
+
};
|
|
1626
|
+
Tree.prototype.bindToScopeChanges = function (scope, fnc, dom, tag) {
|
|
1627
|
+
if (tag === void 0) { tag = null; }
|
|
1628
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1629
|
+
var _i, _a, node, _scope, name_2;
|
|
1630
|
+
return __generator(this, function (_b) {
|
|
1631
|
+
switch (_b.label) {
|
|
1632
|
+
case 0:
|
|
1633
|
+
_i = 0, _a = this.rootNode.findChildrenByTypes([RootScopeMemberNode, ScopeMemberNode, ElementAttributeNode], 'ScopeMemberNodes');
|
|
1634
|
+
_b.label = 1;
|
|
1635
|
+
case 1:
|
|
1636
|
+
if (!(_i < _a.length)) return [3 /*break*/, 8];
|
|
1637
|
+
node = _a[_i];
|
|
1638
|
+
_scope = scope;
|
|
1639
|
+
if (!(node instanceof ScopeMemberNode)) return [3 /*break*/, 3];
|
|
1640
|
+
return [4 /*yield*/, node.scope.evaluate(scope, dom)];
|
|
1641
|
+
case 2:
|
|
1642
|
+
_scope = _b.sent();
|
|
1643
|
+
return [3 /*break*/, 5];
|
|
1644
|
+
case 3:
|
|
1645
|
+
if (!(node instanceof ElementAttributeNode && node.elementRef)) return [3 /*break*/, 5];
|
|
1646
|
+
return [4 /*yield*/, node.elementRef.evaluate(scope, dom, tag)];
|
|
1647
|
+
case 4:
|
|
1648
|
+
_scope = (_b.sent())[0].scope;
|
|
1649
|
+
_b.label = 5;
|
|
1650
|
+
case 5: return [4 /*yield*/, node.name.evaluate(scope, dom, tag)];
|
|
1651
|
+
case 6:
|
|
1652
|
+
name_2 = _b.sent();
|
|
1653
|
+
_scope.bind("change:" + name_2, fnc);
|
|
1654
|
+
_b.label = 7;
|
|
1655
|
+
case 7:
|
|
1656
|
+
_i++;
|
|
1657
|
+
return [3 /*break*/, 1];
|
|
1658
|
+
case 8: return [2 /*return*/];
|
|
1659
|
+
}
|
|
1660
|
+
});
|
|
1661
|
+
});
|
|
1662
|
+
};
|
|
1663
|
+
Tree.tokenize = function (code) {
|
|
1664
|
+
var tokens = [];
|
|
1665
|
+
if (!code || code.length === 0)
|
|
1666
|
+
return tokens;
|
|
1667
|
+
var foundToken;
|
|
1668
|
+
do {
|
|
1669
|
+
foundToken = false;
|
|
1670
|
+
for (var _i = 0, TOKEN_PATTERNS_1 = TOKEN_PATTERNS; _i < TOKEN_PATTERNS_1.length; _i++) {
|
|
1671
|
+
var tp = TOKEN_PATTERNS_1[_i];
|
|
1672
|
+
var match = tp.pattern.exec(code);
|
|
1673
|
+
if (match) {
|
|
1674
|
+
tokens.push({
|
|
1675
|
+
type: tp.type,
|
|
1676
|
+
value: match[match.length - 1]
|
|
1677
|
+
});
|
|
1678
|
+
code = code.substring(match[0].length);
|
|
1679
|
+
foundToken = true;
|
|
1680
|
+
break;
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
} while (code.length > 0 && foundToken);
|
|
1684
|
+
return tokens;
|
|
1685
|
+
};
|
|
1686
|
+
Tree.stripWhiteSpace = function (tokens) {
|
|
1687
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
1688
|
+
if (tokens[i].type === TokenType.WHITESPACE) {
|
|
1689
|
+
tokens.splice(i, 1);
|
|
1690
|
+
i--;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
return tokens;
|
|
1694
|
+
};
|
|
1695
|
+
Tree.processTokens = function (tokens) {
|
|
1696
|
+
var blockNodes = [];
|
|
1697
|
+
var node = null;
|
|
1698
|
+
var count = 0;
|
|
1699
|
+
Tree.stripWhiteSpace(tokens);
|
|
1700
|
+
while (tokens.length > 0) {
|
|
1701
|
+
count++;
|
|
1702
|
+
if (count > 1000)
|
|
1703
|
+
break; // Limit to 1000 iterations while in development
|
|
1704
|
+
if (tokens[0].type === TokenType.RETURN)
|
|
1705
|
+
tokens.splice(0, 1);
|
|
1706
|
+
var token = tokens[0];
|
|
1707
|
+
if (token.type === TokenType.NAME) {
|
|
1708
|
+
node = new RootScopeMemberNode(new LiteralNode(token.value));
|
|
1709
|
+
tokens.splice(0, 1);
|
|
1710
|
+
}
|
|
1711
|
+
else if (token.type === TokenType.IF) {
|
|
1712
|
+
node = IfStatementNode.parse(node, token, tokens);
|
|
1713
|
+
blockNodes.push(node);
|
|
1714
|
+
node = null;
|
|
1715
|
+
}
|
|
1716
|
+
else if (token.type === TokenType.FOR) {
|
|
1717
|
+
node = ForStatementNode.parse(node, token, tokens);
|
|
1718
|
+
blockNodes.push(node);
|
|
1719
|
+
node = null;
|
|
1720
|
+
}
|
|
1721
|
+
else if (token.type === TokenType.STRING_LITERAL) {
|
|
1722
|
+
node = new LiteralNode(token.value);
|
|
1723
|
+
tokens.splice(0, 1);
|
|
1724
|
+
}
|
|
1725
|
+
else if (token.type === TokenType.NUMBER_LITERAL) {
|
|
1726
|
+
node = new NumberLiteralNode(token.value);
|
|
1727
|
+
tokens.splice(0, 1);
|
|
1728
|
+
}
|
|
1729
|
+
else if (tokens[0].type === TokenType.ELEMENT_REFERENCE) {
|
|
1730
|
+
node = new ElementQueryNode(tokens[0].value);
|
|
1731
|
+
tokens.splice(0, 1);
|
|
1732
|
+
}
|
|
1733
|
+
else if (tokens[0].type === TokenType.ELEMENT_QUERY) {
|
|
1734
|
+
node = new ElementQueryNode(tokens[0].value);
|
|
1735
|
+
tokens.splice(0, 1);
|
|
1736
|
+
}
|
|
1737
|
+
else if (tokens[0].type === TokenType.L_BRACKET) {
|
|
1738
|
+
if (node) {
|
|
1739
|
+
node = IndexNode.parse(node, token, tokens);
|
|
1740
|
+
}
|
|
1741
|
+
else {
|
|
1742
|
+
node = ArrayNode.parse(node, token, tokens);
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
else if (tokens[0].type === TokenType.L_BRACE) {
|
|
1746
|
+
node = ObjectNode.parse(node, token, tokens);
|
|
1747
|
+
}
|
|
1748
|
+
else if (tokens[0].type === TokenType.ELEMENT_ATTRIBUTE) {
|
|
1749
|
+
node = new ElementAttributeNode(node, tokens[0].value);
|
|
1750
|
+
tokens.splice(0, 1);
|
|
1751
|
+
}
|
|
1752
|
+
else if (node !== null && token.type === TokenType.PERIOD && tokens[1].type === TokenType.NAME) {
|
|
1753
|
+
node = new ScopeMemberNode(node, new LiteralNode(tokens[1].value));
|
|
1754
|
+
tokens.splice(0, 2);
|
|
1755
|
+
}
|
|
1756
|
+
else if (tokens[0].type === TokenType.L_PAREN) {
|
|
1757
|
+
var funcArgs = Tree.getBlockTokens(tokens);
|
|
1758
|
+
var nodes = [];
|
|
1759
|
+
for (var _i = 0, funcArgs_1 = funcArgs; _i < funcArgs_1.length; _i++) {
|
|
1760
|
+
var arg = funcArgs_1[_i];
|
|
1761
|
+
nodes.push(Tree.processTokens(arg));
|
|
1762
|
+
}
|
|
1763
|
+
if (node) {
|
|
1764
|
+
node = new FunctionCallNode(node, // Previous node should be a NAME
|
|
1765
|
+
new FunctionArgumentNode(nodes));
|
|
1766
|
+
}
|
|
1767
|
+
else {
|
|
1768
|
+
node = new BlockNode(nodes);
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
else if (tokens[0].type === TokenType.SEMI_COLON) {
|
|
1772
|
+
if (node) {
|
|
1773
|
+
blockNodes.push(node);
|
|
1774
|
+
}
|
|
1775
|
+
node = null;
|
|
1776
|
+
tokens.splice(0, 1);
|
|
1777
|
+
}
|
|
1778
|
+
else if (InNode.match(tokens)) {
|
|
1779
|
+
node = InNode.parse(node, token, tokens);
|
|
1780
|
+
}
|
|
1781
|
+
else if (ComparisonNode.match(tokens)) {
|
|
1782
|
+
node = ComparisonNode.parse(node, token, tokens);
|
|
1783
|
+
}
|
|
1784
|
+
else if (ArithmeticNode.match(tokens)) {
|
|
1785
|
+
node = ArithmeticNode.parse(node, token, tokens);
|
|
1786
|
+
}
|
|
1787
|
+
else if (ArithmeticAssignmentNode.match(tokens)) {
|
|
1788
|
+
node = ArithmeticAssignmentNode.parse(node, token, tokens);
|
|
1789
|
+
}
|
|
1790
|
+
else if (tokens[0].type === TokenType.WHITESPACE) {
|
|
1791
|
+
tokens.splice(0, 1);
|
|
1792
|
+
}
|
|
1793
|
+
else if (tokens[0].type === TokenType.BOOLEAN_LITERAL) {
|
|
1794
|
+
node = new BooleanLiteralNode(tokens[0].value);
|
|
1795
|
+
tokens.splice(0, 1);
|
|
1796
|
+
}
|
|
1797
|
+
else if (tokens[0].type === TokenType.NULL_LITERAL) {
|
|
1798
|
+
node = new LiteralNode(null);
|
|
1799
|
+
tokens.splice(0, 1);
|
|
1800
|
+
}
|
|
1801
|
+
else if (tokens[0].type === TokenType.EXCLAMATION_POINT) {
|
|
1802
|
+
node = NotNode.parse(node, tokens[0], tokens);
|
|
1803
|
+
}
|
|
1804
|
+
else {
|
|
1805
|
+
var code = Tree.toCode(tokens, 10);
|
|
1806
|
+
throw Error("Syntax Error. Near " + code);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
if (node) {
|
|
1810
|
+
blockNodes.push(node);
|
|
1811
|
+
}
|
|
1812
|
+
return new BlockNode(blockNodes);
|
|
1813
|
+
};
|
|
1814
|
+
Tree.toCode = function (tokens, limit) {
|
|
1815
|
+
var code = '';
|
|
1816
|
+
limit = limit || tokens.length;
|
|
1817
|
+
for (var i = 0; i < limit; i++) {
|
|
1818
|
+
if (!tokens[i])
|
|
1819
|
+
break;
|
|
1820
|
+
code += tokens[i].value;
|
|
1821
|
+
}
|
|
1822
|
+
return code;
|
|
1823
|
+
};
|
|
1824
|
+
Tree.getBlockInfo = function (tokens) {
|
|
1825
|
+
var blockType;
|
|
1826
|
+
var opener = tokens[0];
|
|
1827
|
+
if (opener.type === TokenType.L_PAREN)
|
|
1828
|
+
blockType = BlockType.PAREN;
|
|
1829
|
+
else if (opener.type === TokenType.L_BRACE)
|
|
1830
|
+
blockType = BlockType.BRACE;
|
|
1831
|
+
else if (opener.type === TokenType.L_BRACKET)
|
|
1832
|
+
blockType = BlockType.BRACKET;
|
|
1833
|
+
else
|
|
1834
|
+
blockType = BlockType.STATEMENT;
|
|
1835
|
+
var open;
|
|
1836
|
+
var close;
|
|
1837
|
+
var openCharacter;
|
|
1838
|
+
var closeCharacter;
|
|
1839
|
+
switch (blockType) {
|
|
1840
|
+
case BlockType.PAREN:
|
|
1841
|
+
open = TokenType.L_PAREN;
|
|
1842
|
+
close = TokenType.R_PAREN;
|
|
1843
|
+
openCharacter = '(';
|
|
1844
|
+
closeCharacter = ')';
|
|
1845
|
+
break;
|
|
1846
|
+
case BlockType.BRACE:
|
|
1847
|
+
open = TokenType.L_BRACE;
|
|
1848
|
+
close = TokenType.R_BRACE;
|
|
1849
|
+
openCharacter = '{';
|
|
1850
|
+
closeCharacter = '}';
|
|
1851
|
+
break;
|
|
1852
|
+
case BlockType.BRACKET:
|
|
1853
|
+
open = TokenType.L_BRACKET;
|
|
1854
|
+
close = TokenType.R_BRACKET;
|
|
1855
|
+
openCharacter = '[';
|
|
1856
|
+
closeCharacter = ']';
|
|
1857
|
+
break;
|
|
1858
|
+
default:
|
|
1859
|
+
open = null;
|
|
1860
|
+
close = TokenType.SEMI_COLON;
|
|
1861
|
+
openCharacter = null;
|
|
1862
|
+
closeCharacter = ';';
|
|
1863
|
+
break;
|
|
1864
|
+
}
|
|
1865
|
+
return {
|
|
1866
|
+
type: blockType,
|
|
1867
|
+
open: open,
|
|
1868
|
+
close: close,
|
|
1869
|
+
openCharacter: openCharacter,
|
|
1870
|
+
closeCharacter: closeCharacter
|
|
1871
|
+
};
|
|
1872
|
+
};
|
|
1873
|
+
Tree.getNextStatementTokens = function (tokens, consumeClosingToken, consumeOpeningToken, includeClosingToken) {
|
|
1874
|
+
if (consumeClosingToken === void 0) { consumeClosingToken = true; }
|
|
1875
|
+
if (consumeOpeningToken === void 0) { consumeOpeningToken = true; }
|
|
1876
|
+
if (includeClosingToken === void 0) { includeClosingToken = false; }
|
|
1877
|
+
var blockInfo = Tree.getBlockInfo(tokens);
|
|
1878
|
+
// Consume opening block token
|
|
1879
|
+
if (consumeOpeningToken && tokens[0].type === blockInfo.open) {
|
|
1880
|
+
tokens.splice(0, 1);
|
|
1881
|
+
}
|
|
1882
|
+
return Tree.getTokensUntil(tokens, blockInfo.close, consumeClosingToken, includeClosingToken);
|
|
1883
|
+
};
|
|
1884
|
+
Tree.getBlockTokens = function (tokens, groupBy) {
|
|
1885
|
+
if (groupBy === void 0) { groupBy = TokenType.COMMA; }
|
|
1886
|
+
var blockInfo = Tree.getBlockInfo(tokens);
|
|
1887
|
+
var openBlocks = 0;
|
|
1888
|
+
var args = [];
|
|
1889
|
+
var arg = [];
|
|
1890
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
1891
|
+
var token = tokens[i];
|
|
1892
|
+
if (token.type === blockInfo.open) {
|
|
1893
|
+
openBlocks += 1;
|
|
1894
|
+
if (openBlocks > 1)
|
|
1895
|
+
arg.push(token);
|
|
1896
|
+
}
|
|
1897
|
+
else if (token.type === blockInfo.close) {
|
|
1898
|
+
openBlocks -= 1;
|
|
1899
|
+
if (openBlocks > 0)
|
|
1900
|
+
arg.push(token);
|
|
1901
|
+
}
|
|
1902
|
+
else if (groupBy !== null && token.type === groupBy && openBlocks == 1) {
|
|
1903
|
+
args.push(arg);
|
|
1904
|
+
arg = [];
|
|
1905
|
+
}
|
|
1906
|
+
else if (token.type !== TokenType.WHITESPACE) {
|
|
1907
|
+
arg.push(token);
|
|
1908
|
+
}
|
|
1909
|
+
// Consume token
|
|
1910
|
+
tokens.splice(0, 1);
|
|
1911
|
+
i--;
|
|
1912
|
+
if (openBlocks === 0) {
|
|
1913
|
+
if (arg.length > 0)
|
|
1914
|
+
args.push(arg);
|
|
1915
|
+
return args;
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
throw Error("Invalid Syntax, missing " + blockInfo.closeCharacter);
|
|
1919
|
+
};
|
|
1920
|
+
Tree.getTokensUntil = function (tokens, terminator, consumeTerminator, includeTerminator, validIfTerminatorNotFound, blockInfo) {
|
|
1921
|
+
if (terminator === void 0) { terminator = TokenType.SEMI_COLON; }
|
|
1922
|
+
if (consumeTerminator === void 0) { consumeTerminator = true; }
|
|
1923
|
+
if (includeTerminator === void 0) { includeTerminator = false; }
|
|
1924
|
+
if (validIfTerminatorNotFound === void 0) { validIfTerminatorNotFound = false; }
|
|
1925
|
+
if (blockInfo === void 0) { blockInfo = null; }
|
|
1926
|
+
var statementTokens = [];
|
|
1927
|
+
blockInfo = blockInfo || Tree.getBlockInfo(tokens);
|
|
1928
|
+
var openParens = 0;
|
|
1929
|
+
var openBraces = 0;
|
|
1930
|
+
var openBrackets = 0;
|
|
1931
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
1932
|
+
var token = tokens[i];
|
|
1933
|
+
if (!(token.type === blockInfo.open && i === 0)) { // Skip opener
|
|
1934
|
+
if (token.type === TokenType.L_PAREN)
|
|
1935
|
+
openParens += 1;
|
|
1936
|
+
if (token.type === TokenType.L_BRACE)
|
|
1937
|
+
openBraces += 1;
|
|
1938
|
+
if (token.type === TokenType.L_BRACKET)
|
|
1939
|
+
openBrackets += 1;
|
|
1940
|
+
}
|
|
1941
|
+
if ([
|
|
1942
|
+
terminator,
|
|
1943
|
+
TokenType.R_BRACKET,
|
|
1944
|
+
TokenType.R_BRACE,
|
|
1945
|
+
TokenType.R_PAREN
|
|
1946
|
+
].indexOf(token.type) > -1) {
|
|
1947
|
+
if (openParens > 0 && token.type === TokenType.R_PAREN) {
|
|
1948
|
+
openParens -= 1;
|
|
1949
|
+
}
|
|
1950
|
+
else if (openBraces > 0 && token.type === TokenType.R_BRACE) {
|
|
1951
|
+
openBraces -= 1;
|
|
1952
|
+
}
|
|
1953
|
+
else if (openBrackets > 0 && token.type === TokenType.R_BRACKET) {
|
|
1954
|
+
openBrackets -= 1;
|
|
1955
|
+
}
|
|
1956
|
+
else if (token.type === terminator && openParens === 0 && openBraces === 0 && openBrackets === 0) {
|
|
1957
|
+
if (includeTerminator)
|
|
1958
|
+
statementTokens.push(token);
|
|
1959
|
+
if ((includeTerminator || consumeTerminator) && token.type !== TokenType.SEMI_COLON)
|
|
1960
|
+
tokens.splice(0, 1); // Consume end of block
|
|
1961
|
+
break;
|
|
1962
|
+
}
|
|
1963
|
+
else if (token.type === terminator && (openParens > 0 || openBraces > 0 || openBrackets > 0)) {
|
|
1964
|
+
}
|
|
1965
|
+
else {
|
|
1966
|
+
if (validIfTerminatorNotFound)
|
|
1967
|
+
break;
|
|
1968
|
+
throw Error("Invalid syntax, expecting " + terminator + ".");
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
statementTokens.push(token);
|
|
1972
|
+
tokens.splice(0, 1); // Consume part of statement
|
|
1973
|
+
i--;
|
|
1974
|
+
}
|
|
1975
|
+
return statementTokens;
|
|
1976
|
+
};
|
|
1977
|
+
Tree.consumeTypes = function (tokens, types) {
|
|
1978
|
+
var matching = [];
|
|
1979
|
+
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
|
1980
|
+
var token = tokens_1[_i];
|
|
1981
|
+
if (types.indexOf(token.type) > -1) {
|
|
1982
|
+
matching.push(token);
|
|
1983
|
+
}
|
|
1984
|
+
else {
|
|
1985
|
+
break;
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
tokens.splice(0, matching.length);
|
|
1989
|
+
return matching;
|
|
1990
|
+
};
|
|
1991
|
+
Tree.cache = {};
|
|
1992
|
+
return Tree;
|
|
1993
|
+
}());
|
|
1994
|
+
exports.Tree = Tree;
|
|
1995
|
+
//# sourceMappingURL=AST.js.map
|