vsn 0.1.18 → 0.1.19

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.
Files changed (105) hide show
  1. package/dist/AST.js +1998 -0
  2. package/dist/AST.js.map +1 -0
  3. package/dist/Attribute.js +187 -0
  4. package/dist/Attribute.js.map +1 -0
  5. package/dist/Bencmark.js +179 -0
  6. package/dist/Bencmark.js.map +1 -0
  7. package/dist/Configuration.js +64 -0
  8. package/dist/Configuration.js.map +1 -0
  9. package/dist/Controller.js +39 -0
  10. package/dist/Controller.js.map +1 -0
  11. package/dist/DOM/DOMObject.js +45 -0
  12. package/dist/DOM/DOMObject.js.map +1 -0
  13. package/dist/DOM/WrappedDocument.js +34 -0
  14. package/dist/DOM/WrappedDocument.js.map +1 -0
  15. package/dist/DOM/WrappedWindow.js +45 -0
  16. package/dist/DOM/WrappedWindow.js.map +1 -0
  17. package/dist/DOM.js +547 -0
  18. package/dist/DOM.js.map +1 -0
  19. package/dist/Formats.js +44 -0
  20. package/dist/Formats.js.map +1 -0
  21. package/dist/Query.js +66 -0
  22. package/dist/Query.js.map +1 -0
  23. package/dist/Registry.js +138 -0
  24. package/dist/Registry.js.map +1 -0
  25. package/dist/Scope.js +505 -0
  26. package/dist/Scope.js.map +1 -0
  27. package/dist/Tag/List.js +85 -0
  28. package/dist/Tag/List.js.map +1 -0
  29. package/dist/Tag.js +715 -0
  30. package/dist/Tag.js.map +1 -0
  31. package/dist/Types.js +48 -0
  32. package/dist/Types.js.map +1 -0
  33. package/dist/Vision.js +161 -0
  34. package/dist/Vision.js.map +1 -0
  35. package/dist/attributes/AddClassIf.js +93 -0
  36. package/dist/attributes/AddClassIf.js.map +1 -0
  37. package/dist/attributes/Bind.js +272 -0
  38. package/dist/attributes/Bind.js.map +1 -0
  39. package/dist/attributes/ClassConstructor.js +104 -0
  40. package/dist/attributes/ClassConstructor.js.map +1 -0
  41. package/dist/attributes/ClickRemoveClass.js +102 -0
  42. package/dist/attributes/ClickRemoveClass.js.map +1 -0
  43. package/dist/attributes/ClickToggleClass.js +102 -0
  44. package/dist/attributes/ClickToggleClass.js.map +1 -0
  45. package/dist/attributes/ControllerAttribute.js +28 -0
  46. package/dist/attributes/ControllerAttribute.js.map +1 -0
  47. package/dist/attributes/DisableIf.js +94 -0
  48. package/dist/attributes/DisableIf.js.map +1 -0
  49. package/dist/attributes/Exec.js +102 -0
  50. package/dist/attributes/Exec.js.map +1 -0
  51. package/dist/attributes/Format.js +96 -0
  52. package/dist/attributes/Format.js.map +1 -0
  53. package/dist/attributes/If.js +147 -0
  54. package/dist/attributes/If.js.map +1 -0
  55. package/dist/attributes/JSONAttribute.js +115 -0
  56. package/dist/attributes/JSONAttribute.js.map +1 -0
  57. package/dist/attributes/KeyAbstract.js +110 -0
  58. package/dist/attributes/KeyAbstract.js.map +1 -0
  59. package/dist/attributes/KeyDown.js +82 -0
  60. package/dist/attributes/KeyDown.js.map +1 -0
  61. package/dist/attributes/KeyUp.js +82 -0
  62. package/dist/attributes/KeyUp.js.map +1 -0
  63. package/dist/attributes/List.js +273 -0
  64. package/dist/attributes/List.js.map +1 -0
  65. package/dist/attributes/ListItem.js +135 -0
  66. package/dist/attributes/ListItem.js.map +1 -0
  67. package/dist/attributes/ListItemModel.js +39 -0
  68. package/dist/attributes/ListItemModel.js.map +1 -0
  69. package/dist/attributes/ModelAttribute.js +29 -0
  70. package/dist/attributes/ModelAttribute.js.map +1 -0
  71. package/dist/attributes/Name.js +88 -0
  72. package/dist/attributes/Name.js.map +1 -0
  73. package/dist/attributes/On.js +123 -0
  74. package/dist/attributes/On.js.map +1 -0
  75. package/dist/attributes/Radio.js +127 -0
  76. package/dist/attributes/Radio.js.map +1 -0
  77. package/dist/attributes/Referenced.js +38 -0
  78. package/dist/attributes/Referenced.js.map +1 -0
  79. package/dist/attributes/RootAttribute.js +85 -0
  80. package/dist/attributes/RootAttribute.js.map +1 -0
  81. package/dist/attributes/ScopeAttribute.js +40 -0
  82. package/dist/attributes/ScopeAttribute.js.map +1 -0
  83. package/dist/attributes/ScopeChange.js +124 -0
  84. package/dist/attributes/ScopeChange.js.map +1 -0
  85. package/dist/attributes/SetAttribute.js +130 -0
  86. package/dist/attributes/SetAttribute.js.map +1 -0
  87. package/dist/attributes/StandardAttribute.js +168 -0
  88. package/dist/attributes/StandardAttribute.js.map +1 -0
  89. package/dist/attributes/Template.js +39 -0
  90. package/dist/attributes/Template.js.map +1 -0
  91. package/dist/attributes/TypeAttribute.js +101 -0
  92. package/dist/attributes/TypeAttribute.js.map +1 -0
  93. package/dist/attributes/_imports.js +58 -0
  94. package/dist/attributes/_imports.js.map +1 -0
  95. package/dist/helpers/DOMHelper.js +81 -0
  96. package/dist/helpers/DOMHelper.js.map +1 -0
  97. package/dist/helpers/ElementHelper.js +25 -0
  98. package/dist/helpers/ElementHelper.js.map +1 -0
  99. package/dist/helpers/VisionHelper.js +71 -0
  100. package/dist/helpers/VisionHelper.js.map +1 -0
  101. package/dist/helpers/decorators.js +38 -0
  102. package/dist/helpers/decorators.js.map +1 -0
  103. package/main.py +16 -0
  104. package/package.json +2 -2
  105. package/dist/vision.min.js +0 -1
package/dist/AST.js ADDED
@@ -0,0 +1,1998 @@
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, evaluation;
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
+ evaluation = false;
534
+ if (condition instanceof Scope_1.WrappedArray) {
535
+ evaluation = condition.length > 0;
536
+ }
537
+ else {
538
+ evaluation = !!condition;
539
+ }
540
+ return [2 /*return*/, evaluation];
541
+ }
542
+ });
543
+ });
544
+ };
545
+ return ConditionalNode;
546
+ }(Node));
547
+ var IfStatementNode = /** @class */ (function (_super) {
548
+ __extends(IfStatementNode, _super);
549
+ function IfStatementNode(nodes) {
550
+ var _this = _super.call(this) || this;
551
+ _this.nodes = nodes;
552
+ return _this;
553
+ }
554
+ IfStatementNode.prototype._getChildNodes = function () {
555
+ return __spreadArray([], this.nodes);
556
+ };
557
+ IfStatementNode.prototype.evaluate = function (scope, dom, tag) {
558
+ if (tag === void 0) { tag = null; }
559
+ return __awaiter(this, void 0, void 0, function () {
560
+ var _i, _a, condition, uno;
561
+ return __generator(this, function (_b) {
562
+ switch (_b.label) {
563
+ case 0:
564
+ _i = 0, _a = this.nodes;
565
+ _b.label = 1;
566
+ case 1:
567
+ if (!(_i < _a.length)) return [3 /*break*/, 5];
568
+ condition = _a[_i];
569
+ return [4 /*yield*/, condition.evaluate(scope, dom, tag)];
570
+ case 2:
571
+ uno = _b.sent();
572
+ if (!uno) return [3 /*break*/, 4];
573
+ return [4 /*yield*/, condition.block.evaluate(scope, dom, tag)];
574
+ case 3: return [2 /*return*/, _b.sent()];
575
+ case 4:
576
+ _i++;
577
+ return [3 /*break*/, 1];
578
+ case 5: return [2 /*return*/];
579
+ }
580
+ });
581
+ });
582
+ };
583
+ IfStatementNode.parseConditional = function (tokens) {
584
+ if ([
585
+ TokenType.IF,
586
+ TokenType.ELSE_IF
587
+ ].indexOf(tokens[0].type) === -1) {
588
+ throw SyntaxError('Invalid Syntax');
589
+ }
590
+ tokens.splice(0, 1); // consume if and else if
591
+ return new ConditionalNode(Tree.processTokens(Tree.getBlockTokens(tokens, null)[0]), Tree.processTokens(Tree.getBlockTokens(tokens, null)[0]));
592
+ };
593
+ IfStatementNode.parse = function (lastNode, token, tokens) {
594
+ if (tokens[1].type !== TokenType.L_PAREN) {
595
+ throw SyntaxError('If statement needs to be followed by a condition encased in parenthesis.');
596
+ }
597
+ var nodes = [];
598
+ nodes.push(IfStatementNode.parseConditional(tokens));
599
+ while (tokens.length > 0 && TokenType.ELSE_IF === tokens[0].type) {
600
+ nodes.push(IfStatementNode.parseConditional(tokens));
601
+ }
602
+ if (tokens.length > 0 && TokenType.ELSE === tokens[0].type) {
603
+ tokens.splice(0, 1); // Consume else
604
+ nodes.push(new ConditionalNode(new LiteralNode(true), Tree.processTokens(Tree.getBlockTokens(tokens, null)[0])));
605
+ }
606
+ return new IfStatementNode(nodes);
607
+ };
608
+ return IfStatementNode;
609
+ }(Node));
610
+ var ForStatementNode = /** @class */ (function (_super) {
611
+ __extends(ForStatementNode, _super);
612
+ function ForStatementNode(variable, list, block) {
613
+ var _this = _super.call(this) || this;
614
+ _this.variable = variable;
615
+ _this.list = list;
616
+ _this.block = block;
617
+ return _this;
618
+ }
619
+ ForStatementNode.prototype._getChildNodes = function () {
620
+ return [
621
+ this.variable,
622
+ this.list,
623
+ this.block
624
+ ];
625
+ };
626
+ ForStatementNode.prototype.evaluate = function (scope, dom, tag) {
627
+ if (tag === void 0) { tag = null; }
628
+ return __awaiter(this, void 0, void 0, function () {
629
+ var variable, list, i;
630
+ return __generator(this, function (_a) {
631
+ switch (_a.label) {
632
+ case 0: return [4 /*yield*/, this.variable.evaluate(scope, dom, tag)];
633
+ case 1:
634
+ variable = _a.sent();
635
+ return [4 /*yield*/, this.list.evaluate(scope, dom, tag)];
636
+ case 2:
637
+ list = _a.sent();
638
+ i = 0;
639
+ _a.label = 3;
640
+ case 3:
641
+ if (!(i < list.length)) return [3 /*break*/, 6];
642
+ scope.set(variable, list[i]);
643
+ return [4 /*yield*/, this.block.evaluate(scope, dom, tag)];
644
+ case 4:
645
+ _a.sent();
646
+ _a.label = 5;
647
+ case 5:
648
+ i++;
649
+ return [3 /*break*/, 3];
650
+ case 6: return [2 /*return*/, null];
651
+ }
652
+ });
653
+ });
654
+ };
655
+ ForStatementNode.parse = function (lastNode, token, tokens) {
656
+ if (tokens[1].type !== TokenType.L_PAREN) {
657
+ throw SyntaxError('Syntax error: Missing (');
658
+ }
659
+ if (tokens[3].type !== TokenType.OF) {
660
+ throw SyntaxError('Syntax error: Missing of');
661
+ }
662
+ tokens.splice(0, 1); // consume for
663
+ var loopDef = Tree.getNextStatementTokens(tokens);
664
+ var variableName = loopDef.splice(0, 1)[0];
665
+ loopDef.splice(0, 1); // consume of
666
+ var list = Tree.processTokens(loopDef);
667
+ var block = Tree.processTokens(Tree.getBlockTokens(tokens, null)[0]);
668
+ return new ForStatementNode(new LiteralNode(variableName.value), list, block);
669
+ };
670
+ return ForStatementNode;
671
+ }(Node));
672
+ var NotNode = /** @class */ (function (_super) {
673
+ __extends(NotNode, _super);
674
+ function NotNode(toFlip) {
675
+ var _this = _super.call(this) || this;
676
+ _this.toFlip = toFlip;
677
+ return _this;
678
+ }
679
+ NotNode.prototype.evaluate = function (scope, dom, tag) {
680
+ if (tag === void 0) { tag = null; }
681
+ return __awaiter(this, void 0, void 0, function () {
682
+ var flipping;
683
+ return __generator(this, function (_a) {
684
+ switch (_a.label) {
685
+ case 0: return [4 /*yield*/, this.toFlip.evaluate(scope, dom, tag)];
686
+ case 1:
687
+ flipping = _a.sent();
688
+ return [2 /*return*/, !flipping];
689
+ }
690
+ });
691
+ });
692
+ };
693
+ NotNode.prototype._getChildNodes = function () {
694
+ return [
695
+ this.toFlip
696
+ ];
697
+ };
698
+ NotNode.parse = function (lastNode, token, tokens) {
699
+ tokens.splice(0, 1); // Remove not operator
700
+ var containedTokens;
701
+ if (tokens[0].type === TokenType.L_PAREN) {
702
+ containedTokens = Tree.getNextStatementTokens(tokens);
703
+ }
704
+ else {
705
+ containedTokens = Tree.consumeTypes(tokens, [
706
+ TokenType.BOOLEAN_LITERAL,
707
+ TokenType.NUMBER_LITERAL,
708
+ TokenType.STRING_LITERAL,
709
+ TokenType.NAME,
710
+ TokenType.PERIOD
711
+ ]);
712
+ }
713
+ return new NotNode(Tree.processTokens(containedTokens));
714
+ };
715
+ return NotNode;
716
+ }(Node));
717
+ var InNode = /** @class */ (function (_super) {
718
+ __extends(InNode, _super);
719
+ function InNode(left, right, flip) {
720
+ if (flip === void 0) { flip = false; }
721
+ var _this = _super.call(this) || this;
722
+ _this.left = left;
723
+ _this.right = right;
724
+ _this.flip = flip;
725
+ return _this;
726
+ }
727
+ InNode.prototype.evaluate = function (scope, dom, tag) {
728
+ if (tag === void 0) { tag = null; }
729
+ return __awaiter(this, void 0, void 0, function () {
730
+ var toCheck, array, inArray;
731
+ return __generator(this, function (_a) {
732
+ switch (_a.label) {
733
+ case 0: return [4 /*yield*/, this.left.evaluate(scope, dom, tag)];
734
+ case 1:
735
+ toCheck = _a.sent();
736
+ return [4 /*yield*/, this.right.evaluate(scope, dom, tag)];
737
+ case 2:
738
+ array = _a.sent();
739
+ inArray = array.indexOf(toCheck) > -1;
740
+ if (this.flip)
741
+ inArray = !inArray;
742
+ return [2 /*return*/, inArray];
743
+ }
744
+ });
745
+ });
746
+ };
747
+ InNode.prototype._getChildNodes = function () {
748
+ return [
749
+ this.left,
750
+ this.right
751
+ ];
752
+ };
753
+ InNode.match = function (tokens) {
754
+ return tokens[0].type === TokenType.IN || (tokens[0].type === TokenType.NOT && tokens[1].type === TokenType.IN);
755
+ };
756
+ InNode.parse = function (lastNode, token, tokens) {
757
+ var flip = tokens[0].type === TokenType.NOT;
758
+ if (flip)
759
+ tokens.splice(0, 1); // consume not
760
+ tokens.splice(0, 1); // consume in
761
+ var containedTokens = Tree.getNextStatementTokens(tokens, false, false, true);
762
+ return new InNode(lastNode, Tree.processTokens(containedTokens), flip);
763
+ };
764
+ return InNode;
765
+ }(Node));
766
+ var LiteralNode = /** @class */ (function (_super) {
767
+ __extends(LiteralNode, _super);
768
+ function LiteralNode(value) {
769
+ var _this = _super.call(this) || this;
770
+ _this.value = value;
771
+ return _this;
772
+ }
773
+ LiteralNode.prototype.evaluate = function (scope, dom, tag) {
774
+ if (tag === void 0) { tag = null; }
775
+ return __awaiter(this, void 0, void 0, function () {
776
+ return __generator(this, function (_a) {
777
+ return [2 /*return*/, this.value];
778
+ });
779
+ });
780
+ };
781
+ return LiteralNode;
782
+ }(Node));
783
+ var BooleanLiteralNode = /** @class */ (function (_super) {
784
+ __extends(BooleanLiteralNode, _super);
785
+ function BooleanLiteralNode(value) {
786
+ var _this = _super.call(this, value) || this;
787
+ _this.value = value;
788
+ _this.value = value === 'true';
789
+ return _this;
790
+ }
791
+ return BooleanLiteralNode;
792
+ }(LiteralNode));
793
+ var NumberLiteralNode = /** @class */ (function (_super) {
794
+ __extends(NumberLiteralNode, _super);
795
+ function NumberLiteralNode(value) {
796
+ var _this = _super.call(this, value) || this;
797
+ _this.value = value;
798
+ if (_this.value.indexOf('.') > -1) {
799
+ _this.value = parseFloat(_this.value);
800
+ }
801
+ else {
802
+ _this.value = parseInt(_this.value);
803
+ }
804
+ return _this;
805
+ }
806
+ return NumberLiteralNode;
807
+ }(LiteralNode));
808
+ var FunctionCallNode = /** @class */ (function (_super) {
809
+ __extends(FunctionCallNode, _super);
810
+ function FunctionCallNode(fnc, args) {
811
+ var _this = _super.call(this) || this;
812
+ _this.fnc = fnc;
813
+ _this.args = args;
814
+ return _this;
815
+ }
816
+ FunctionCallNode.prototype._getChildNodes = function () {
817
+ return [
818
+ this.fnc,
819
+ this.args
820
+ ];
821
+ };
822
+ FunctionCallNode.prototype.evaluate = function (scope, dom, tag) {
823
+ if (tag === void 0) { tag = null; }
824
+ return __awaiter(this, void 0, void 0, function () {
825
+ var functionScope, values;
826
+ var _a;
827
+ return __generator(this, function (_b) {
828
+ switch (_b.label) {
829
+ case 0:
830
+ functionScope = scope;
831
+ if (!(this.fnc instanceof ScopeMemberNode)) return [3 /*break*/, 2];
832
+ return [4 /*yield*/, this.fnc.scope.evaluate(scope, dom, tag)];
833
+ case 1:
834
+ functionScope = _b.sent();
835
+ _b.label = 2;
836
+ case 2: return [4 /*yield*/, this.args.evaluate(scope, dom, tag)];
837
+ case 3:
838
+ values = _b.sent();
839
+ return [4 /*yield*/, this.fnc.evaluate(scope, dom, tag)];
840
+ case 4: return [2 /*return*/, (_a = (_b.sent())).call.apply(_a, __spreadArray([functionScope.wrapped || functionScope], values))];
841
+ }
842
+ });
843
+ });
844
+ };
845
+ return FunctionCallNode;
846
+ }(Node));
847
+ var FunctionArgumentNode = /** @class */ (function (_super) {
848
+ __extends(FunctionArgumentNode, _super);
849
+ function FunctionArgumentNode(args) {
850
+ var _this = _super.call(this) || this;
851
+ _this.args = args;
852
+ return _this;
853
+ }
854
+ FunctionArgumentNode.prototype._getChildNodes = function () {
855
+ return __spreadArray([], this.args);
856
+ };
857
+ FunctionArgumentNode.prototype.evaluate = function (scope, dom, tag) {
858
+ if (tag === void 0) { tag = null; }
859
+ return __awaiter(this, void 0, void 0, function () {
860
+ var values, _i, _a, arg, _b, _c;
861
+ return __generator(this, function (_d) {
862
+ switch (_d.label) {
863
+ case 0:
864
+ values = [];
865
+ _i = 0, _a = this.args;
866
+ _d.label = 1;
867
+ case 1:
868
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
869
+ arg = _a[_i];
870
+ _c = (_b = values).push;
871
+ return [4 /*yield*/, arg.evaluate(scope, dom, tag)];
872
+ case 2:
873
+ _c.apply(_b, [_d.sent()]);
874
+ _d.label = 3;
875
+ case 3:
876
+ _i++;
877
+ return [3 /*break*/, 1];
878
+ case 4: return [2 /*return*/, values];
879
+ }
880
+ });
881
+ });
882
+ };
883
+ return FunctionArgumentNode;
884
+ }(Node));
885
+ var ScopeMemberNode = /** @class */ (function (_super) {
886
+ __extends(ScopeMemberNode, _super);
887
+ function ScopeMemberNode(scope, name) {
888
+ var _this = _super.call(this) || this;
889
+ _this.scope = scope;
890
+ _this.name = name;
891
+ return _this;
892
+ }
893
+ ScopeMemberNode.prototype._getChildNodes = function () {
894
+ return [
895
+ this.scope,
896
+ this.name
897
+ ];
898
+ };
899
+ ScopeMemberNode.prototype.evaluate = function (scope, dom, tag) {
900
+ if (tag === void 0) { tag = null; }
901
+ return __awaiter(this, void 0, void 0, function () {
902
+ var scopes, values, evalScope, _i, scopes_1, parent_1, _a, _b, name_1, value;
903
+ return __generator(this, function (_c) {
904
+ switch (_c.label) {
905
+ case 0:
906
+ scopes = [];
907
+ values = [];
908
+ if (!(this.scope instanceof ElementQueryNode)) return [3 /*break*/, 2];
909
+ return [4 /*yield*/, this.scope.evaluate(scope, dom, tag)];
910
+ case 1:
911
+ scopes = _c.sent();
912
+ return [3 /*break*/, 4];
913
+ case 2: return [4 /*yield*/, this.scope.evaluate(scope, dom, tag)];
914
+ case 3:
915
+ evalScope = _c.sent();
916
+ if (evalScope instanceof List_1.TagList) {
917
+ scopes = evalScope;
918
+ }
919
+ else {
920
+ scopes.push(evalScope);
921
+ }
922
+ _c.label = 4;
923
+ case 4:
924
+ _i = 0, scopes_1 = scopes;
925
+ _c.label = 5;
926
+ case 5:
927
+ if (!(_i < scopes_1.length)) return [3 /*break*/, 10];
928
+ parent_1 = scopes_1[_i];
929
+ if (parent_1 instanceof DOMObject_1.DOMObject)
930
+ parent_1 = parent_1.scope;
931
+ if (!!parent_1) return [3 /*break*/, 7];
932
+ _a = Error;
933
+ _b = "Cannot access \"";
934
+ return [4 /*yield*/, this.name.evaluate(scope, dom, tag)];
935
+ case 6: throw _a.apply(void 0, [_b + (_c.sent()) + "\" of undefined."]);
936
+ case 7: return [4 /*yield*/, this.name.evaluate(scope, dom, tag)];
937
+ case 8:
938
+ name_1 = _c.sent();
939
+ value = parent_1.get(name_1, false);
940
+ values.push(value instanceof Scope_1.Scope && value.wrapped || value);
941
+ _c.label = 9;
942
+ case 9:
943
+ _i++;
944
+ return [3 /*break*/, 5];
945
+ case 10: return [2 /*return*/, values.length === 1 ? values[0] : values];
946
+ }
947
+ });
948
+ });
949
+ };
950
+ return ScopeMemberNode;
951
+ }(Node));
952
+ var RootScopeMemberNode = /** @class */ (function (_super) {
953
+ __extends(RootScopeMemberNode, _super);
954
+ function RootScopeMemberNode(name) {
955
+ var _this = _super.call(this) || this;
956
+ _this.name = name;
957
+ return _this;
958
+ }
959
+ RootScopeMemberNode.prototype._getChildNodes = function () {
960
+ return [
961
+ this.name
962
+ ];
963
+ };
964
+ RootScopeMemberNode.prototype.evaluate = function (scope, dom, tag) {
965
+ if (tag === void 0) { tag = null; }
966
+ return __awaiter(this, void 0, void 0, function () {
967
+ var name, value;
968
+ return __generator(this, function (_a) {
969
+ switch (_a.label) {
970
+ case 0: return [4 /*yield*/, this.name.evaluate(scope, dom, tag)];
971
+ case 1:
972
+ name = _a.sent();
973
+ value = scope.get(name);
974
+ return [2 /*return*/, value instanceof Scope_1.Scope && value.wrapped || value];
975
+ }
976
+ });
977
+ });
978
+ };
979
+ return RootScopeMemberNode;
980
+ }(Node));
981
+ var ArithmeticNode = /** @class */ (function (_super) {
982
+ __extends(ArithmeticNode, _super);
983
+ function ArithmeticNode(left, right, type) {
984
+ var _this = _super.call(this) || this;
985
+ _this.left = left;
986
+ _this.right = right;
987
+ _this.type = type;
988
+ return _this;
989
+ }
990
+ ArithmeticNode.prototype._getChildNodes = function () {
991
+ return [
992
+ this.left,
993
+ this.right
994
+ ];
995
+ };
996
+ ArithmeticNode.prototype.evaluate = function (scope, dom, tag) {
997
+ if (tag === void 0) { tag = null; }
998
+ return __awaiter(this, void 0, void 0, function () {
999
+ var left, right;
1000
+ return __generator(this, function (_a) {
1001
+ switch (_a.label) {
1002
+ case 0: return [4 /*yield*/, this.left.evaluate(scope, dom, tag)];
1003
+ case 1:
1004
+ left = _a.sent();
1005
+ return [4 /*yield*/, this.right.evaluate(scope, dom, tag)];
1006
+ case 2:
1007
+ right = _a.sent();
1008
+ switch (this.type) {
1009
+ case TokenType.ADD:
1010
+ return [2 /*return*/, left + right];
1011
+ case TokenType.SUBTRACT:
1012
+ return [2 /*return*/, left - right];
1013
+ case TokenType.MULTIPLY:
1014
+ return [2 /*return*/, left * right];
1015
+ case TokenType.DIVIDE:
1016
+ return [2 /*return*/, left / right];
1017
+ }
1018
+ return [2 /*return*/];
1019
+ }
1020
+ });
1021
+ });
1022
+ };
1023
+ ArithmeticNode.match = function (tokens) {
1024
+ return [
1025
+ TokenType.ADD,
1026
+ TokenType.SUBTRACT,
1027
+ TokenType.MULTIPLY,
1028
+ TokenType.DIVIDE
1029
+ ].indexOf(tokens[0].type) > -1;
1030
+ };
1031
+ ArithmeticNode.parse = function (lastNode, token, tokens) {
1032
+ tokens.splice(0, 1); // Remove arithmetic operator
1033
+ return new ArithmeticNode(lastNode, Tree.processTokens(Tree.getNextStatementTokens(tokens)), token.type);
1034
+ };
1035
+ return ArithmeticNode;
1036
+ }(Node));
1037
+ var ArithmeticAssignmentNode = /** @class */ (function (_super) {
1038
+ __extends(ArithmeticAssignmentNode, _super);
1039
+ function ArithmeticAssignmentNode(left, right, type) {
1040
+ var _this = _super.call(this) || this;
1041
+ _this.left = left;
1042
+ _this.right = right;
1043
+ _this.type = type;
1044
+ return _this;
1045
+ }
1046
+ ArithmeticAssignmentNode.prototype._getChildNodes = function () {
1047
+ return [
1048
+ this.left,
1049
+ this.right
1050
+ ];
1051
+ };
1052
+ ArithmeticAssignmentNode.prototype.evaluate = function (scope, dom, tag) {
1053
+ if (tag === void 0) { tag = null; }
1054
+ return __awaiter(this, void 0, void 0, function () {
1055
+ var scopes, name, inner, values, _i, scopes_2, localScope, left, right;
1056
+ return __generator(this, function (_a) {
1057
+ switch (_a.label) {
1058
+ case 0:
1059
+ scopes = [];
1060
+ return [4 /*yield*/, this.left.name.evaluate(scope, dom, tag)];
1061
+ case 1:
1062
+ name = _a.sent();
1063
+ if (!(this.left instanceof ScopeMemberNode)) return [3 /*break*/, 3];
1064
+ return [4 /*yield*/, this.left.scope.evaluate(scope, dom, tag)];
1065
+ case 2:
1066
+ inner = _a.sent();
1067
+ if (this.left.scope instanceof ElementQueryNode) {
1068
+ scopes.push.apply(scopes, inner);
1069
+ }
1070
+ else {
1071
+ scopes.push(inner);
1072
+ }
1073
+ return [3 /*break*/, 6];
1074
+ case 3:
1075
+ if (!(this.left instanceof ElementAttributeNode && this.left.elementRef)) return [3 /*break*/, 5];
1076
+ return [4 /*yield*/, this.left.elementRef.evaluate(scope, dom, tag)];
1077
+ case 4:
1078
+ scopes = _a.sent();
1079
+ return [3 /*break*/, 6];
1080
+ case 5:
1081
+ scopes.push(scope);
1082
+ _a.label = 6;
1083
+ case 6:
1084
+ values = [];
1085
+ _i = 0, scopes_2 = scopes;
1086
+ _a.label = 7;
1087
+ case 7:
1088
+ if (!(_i < scopes_2.length)) return [3 /*break*/, 13];
1089
+ localScope = scopes_2[_i];
1090
+ if (!(localScope instanceof DOMObject_1.DOMObject)) return [3 /*break*/, 9];
1091
+ return [4 /*yield*/, this.handleDOMObject(name, dom, localScope, tag)];
1092
+ case 8:
1093
+ _a.sent();
1094
+ return [3 /*break*/, 12];
1095
+ case 9:
1096
+ if (localScope['$wrapped'] && localScope['$scope'])
1097
+ localScope = localScope['$scope'];
1098
+ return [4 /*yield*/, this.left.evaluate(localScope, dom, tag)];
1099
+ case 10:
1100
+ left = _a.sent();
1101
+ return [4 /*yield*/, this.right.evaluate(localScope, dom, tag)];
1102
+ case 11:
1103
+ right = _a.sent();
1104
+ if (left instanceof Array) {
1105
+ left = this.handleArray(name, left, right, localScope);
1106
+ }
1107
+ else if (Number.isFinite(left)) {
1108
+ left = this.handleNumber(name, left, right, localScope);
1109
+ }
1110
+ else {
1111
+ left = this.handleString(name, left, right, localScope);
1112
+ }
1113
+ values.push(left);
1114
+ _a.label = 12;
1115
+ case 12:
1116
+ _i++;
1117
+ return [3 /*break*/, 7];
1118
+ case 13: return [2 /*return*/, values.length > 1 ? values : values[0]];
1119
+ }
1120
+ });
1121
+ });
1122
+ };
1123
+ ArithmeticAssignmentNode.prototype.handleNumber = function (key, left, right, scope) {
1124
+ if (right !== null && !Number.isFinite(right))
1125
+ right = parseFloat("" + right);
1126
+ left = left;
1127
+ right = right;
1128
+ switch (this.type) {
1129
+ case TokenType.ASSIGN:
1130
+ left = right;
1131
+ break;
1132
+ case TokenType.ADD_ASSIGN:
1133
+ left += right;
1134
+ break;
1135
+ case TokenType.SUBTRACT_ASSIGN:
1136
+ left -= right;
1137
+ break;
1138
+ case TokenType.MULTIPLY_ASSIGN:
1139
+ left *= right;
1140
+ break;
1141
+ case TokenType.DIVIDE_ASSIGN:
1142
+ left /= right;
1143
+ break;
1144
+ }
1145
+ scope.set(key, left);
1146
+ return left;
1147
+ };
1148
+ ArithmeticAssignmentNode.prototype.handleString = function (key, left, right, scope) {
1149
+ switch (this.type) {
1150
+ case TokenType.ASSIGN:
1151
+ left = right;
1152
+ break;
1153
+ case TokenType.ADD_ASSIGN:
1154
+ left = "" + left + right;
1155
+ break;
1156
+ case TokenType.SUBTRACT_ASSIGN:
1157
+ left.replace(right, '');
1158
+ break;
1159
+ case TokenType.MULTIPLY_ASSIGN:
1160
+ left *= right;
1161
+ break;
1162
+ case TokenType.DIVIDE_ASSIGN:
1163
+ left /= right;
1164
+ break;
1165
+ }
1166
+ scope.set(key, left);
1167
+ return left;
1168
+ };
1169
+ ArithmeticAssignmentNode.prototype.handleDOMObject = function (key, dom, domObject, tag) {
1170
+ return __awaiter(this, void 0, void 0, function () {
1171
+ var left, right;
1172
+ return __generator(this, function (_a) {
1173
+ switch (_a.label) {
1174
+ case 0:
1175
+ left = domObject.scope.get(key);
1176
+ return [4 /*yield*/, this.right.evaluate(domObject.scope, dom, tag)];
1177
+ case 1:
1178
+ right = _a.sent();
1179
+ if (left instanceof Array)
1180
+ return [2 /*return*/, this.handleArray(key, left, right, domObject.scope)];
1181
+ return [2 /*return*/, this.handleString(key, left, right, domObject.scope)];
1182
+ }
1183
+ });
1184
+ });
1185
+ };
1186
+ ArithmeticAssignmentNode.prototype.handleArray = function (key, left, right, scope) {
1187
+ if (!(right instanceof Array))
1188
+ right = [right];
1189
+ switch (this.type) {
1190
+ case TokenType.ASSIGN:
1191
+ left.splice(0, left.length);
1192
+ left.push.apply(left, right);
1193
+ break;
1194
+ case TokenType.ADD_ASSIGN:
1195
+ left.push.apply(left, right);
1196
+ break;
1197
+ case TokenType.SUBTRACT_ASSIGN:
1198
+ for (var i = left.length - 1; i >= 0; i--) {
1199
+ if (right.indexOf(left[i]) > -1) {
1200
+ left.splice(i, 1);
1201
+ i++;
1202
+ }
1203
+ }
1204
+ break;
1205
+ case TokenType.TILDE:
1206
+ for (var _i = 0, right_1 = right; _i < right_1.length; _i++) {
1207
+ var toggle = right_1[_i];
1208
+ var index = left.indexOf(toggle);
1209
+ if (index > -1) {
1210
+ left.splice(index, 1);
1211
+ }
1212
+ else {
1213
+ left.push(toggle);
1214
+ }
1215
+ }
1216
+ break;
1217
+ }
1218
+ /*
1219
+ We have to trigger a change manually here. Setting the variable on the scope with an array won't trigger
1220
+ it since we are modifying values inside of the array instance.
1221
+ */
1222
+ scope.trigger("change:" + key);
1223
+ return left;
1224
+ };
1225
+ ArithmeticAssignmentNode.match = function (tokens) {
1226
+ return [
1227
+ TokenType.ASSIGN,
1228
+ TokenType.ADD_ASSIGN,
1229
+ TokenType.SUBTRACT_ASSIGN,
1230
+ TokenType.MULTIPLY_ASSIGN,
1231
+ TokenType.DIVIDE_ASSIGN,
1232
+ TokenType.TILDE,
1233
+ ].indexOf(tokens[0].type) > -1;
1234
+ };
1235
+ ArithmeticAssignmentNode.parse = function (lastNode, token, tokens) {
1236
+ if (!(lastNode instanceof RootScopeMemberNode) && !(lastNode instanceof ScopeMemberNode) && !(lastNode instanceof ElementAttributeNode)) {
1237
+ throw SyntaxError("Invalid assignment syntax near " + Tree.toCode(tokens.splice(0, 10)));
1238
+ }
1239
+ tokens.splice(0, 1); // consume =
1240
+ var assignmentTokens = Tree.getNextStatementTokens(tokens, false, false, true);
1241
+ return new ArithmeticAssignmentNode(lastNode, Tree.processTokens(assignmentTokens), token.type);
1242
+ };
1243
+ return ArithmeticAssignmentNode;
1244
+ }(Node));
1245
+ var IndexNode = /** @class */ (function (_super) {
1246
+ __extends(IndexNode, _super);
1247
+ function IndexNode(object, index, indexTwo) {
1248
+ if (indexTwo === void 0) { indexTwo = null; }
1249
+ var _this = _super.call(this) || this;
1250
+ _this.object = object;
1251
+ _this.index = index;
1252
+ _this.indexTwo = indexTwo;
1253
+ return _this;
1254
+ }
1255
+ IndexNode.prototype._getChildNodes = function () {
1256
+ var children = [
1257
+ this.object,
1258
+ this.index
1259
+ ];
1260
+ if (this.indexTwo)
1261
+ children.push(this.indexTwo);
1262
+ return children;
1263
+ };
1264
+ IndexNode.prototype.negativeIndex = function (obj, index) {
1265
+ if (Number.isFinite(index) && index < 0)
1266
+ return obj.length + index;
1267
+ return index;
1268
+ };
1269
+ IndexNode.prototype.evaluate = function (scope, dom, tag) {
1270
+ if (tag === void 0) { tag = null; }
1271
+ return __awaiter(this, void 0, void 0, function () {
1272
+ var obj, index, _a, _b, indexTwo, _c, _d, values, i;
1273
+ return __generator(this, function (_e) {
1274
+ switch (_e.label) {
1275
+ case 0: return [4 /*yield*/, this.object.evaluate(scope, dom, tag)];
1276
+ case 1:
1277
+ obj = _e.sent();
1278
+ _a = this.negativeIndex;
1279
+ _b = [obj];
1280
+ return [4 /*yield*/, this.index.evaluate(scope, dom, tag)];
1281
+ case 2:
1282
+ index = _a.apply(this, _b.concat([_e.sent()]));
1283
+ if (!(Number.isFinite(index) && this.indexTwo)) return [3 /*break*/, 4];
1284
+ _c = this.negativeIndex;
1285
+ _d = [obj];
1286
+ return [4 /*yield*/, this.indexTwo.evaluate(scope, dom, tag)];
1287
+ case 3:
1288
+ indexTwo = _c.apply(this, _d.concat([_e.sent()]));
1289
+ values = [];
1290
+ for (i = index; i <= indexTwo; i++) {
1291
+ values.push(obj[i]);
1292
+ }
1293
+ return [2 /*return*/, values];
1294
+ case 4: return [2 /*return*/, (obj)[index]];
1295
+ }
1296
+ });
1297
+ });
1298
+ };
1299
+ IndexNode.match = function (tokens) {
1300
+ return tokens[0].type === TokenType.L_BRACKET;
1301
+ };
1302
+ IndexNode.parse = function (lastNode, token, tokens) {
1303
+ var valueTokens = Tree.getBlockTokens(tokens, TokenType.COLON);
1304
+ var values = [];
1305
+ for (var _i = 0, valueTokens_1 = valueTokens; _i < valueTokens_1.length; _i++) {
1306
+ var arg = valueTokens_1[_i];
1307
+ values.push(Tree.processTokens(arg));
1308
+ }
1309
+ return new IndexNode(lastNode, values[0], values.length > 1 && values[1]);
1310
+ };
1311
+ return IndexNode;
1312
+ }(Node));
1313
+ var ArrayNode = /** @class */ (function (_super) {
1314
+ __extends(ArrayNode, _super);
1315
+ function ArrayNode(values) {
1316
+ var _this = _super.call(this) || this;
1317
+ _this.values = values;
1318
+ return _this;
1319
+ }
1320
+ ArrayNode.prototype._getChildNodes = function () {
1321
+ return new (Array.bind.apply(Array, __spreadArray([void 0], this.values)))();
1322
+ };
1323
+ ArrayNode.prototype.evaluate = function (scope, dom, tag) {
1324
+ if (tag === void 0) { tag = null; }
1325
+ return __awaiter(this, void 0, void 0, function () {
1326
+ var arr, _i, _a, val, _b, _c;
1327
+ return __generator(this, function (_d) {
1328
+ switch (_d.label) {
1329
+ case 0:
1330
+ arr = new Scope_1.WrappedArray();
1331
+ _i = 0, _a = this.values;
1332
+ _d.label = 1;
1333
+ case 1:
1334
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
1335
+ val = _a[_i];
1336
+ _c = (_b = arr).push;
1337
+ return [4 /*yield*/, val.evaluate(scope, dom, tag)];
1338
+ case 2:
1339
+ _c.apply(_b, [_d.sent()]);
1340
+ _d.label = 3;
1341
+ case 3:
1342
+ _i++;
1343
+ return [3 /*break*/, 1];
1344
+ case 4: return [2 /*return*/, arr];
1345
+ }
1346
+ });
1347
+ });
1348
+ };
1349
+ ArrayNode.match = function (tokens) {
1350
+ return tokens[0].type === TokenType.L_BRACKET;
1351
+ };
1352
+ ArrayNode.parse = function (lastNode, token, tokens) {
1353
+ var valueTokens = Tree.getBlockTokens(tokens);
1354
+ var values = [];
1355
+ for (var _i = 0, valueTokens_2 = valueTokens; _i < valueTokens_2.length; _i++) {
1356
+ var arg = valueTokens_2[_i];
1357
+ values.push(Tree.processTokens(arg));
1358
+ }
1359
+ return new ArrayNode(values);
1360
+ };
1361
+ return ArrayNode;
1362
+ }(Node));
1363
+ var ObjectNode = /** @class */ (function (_super) {
1364
+ __extends(ObjectNode, _super);
1365
+ function ObjectNode(keys, values) {
1366
+ var _this = _super.call(this) || this;
1367
+ _this.keys = keys;
1368
+ _this.values = values;
1369
+ return _this;
1370
+ }
1371
+ ObjectNode.prototype._getChildNodes = function () {
1372
+ return new (Array.bind.apply(Array, __spreadArray([void 0], this.values)))();
1373
+ };
1374
+ ObjectNode.prototype.evaluate = function (scope, dom, tag) {
1375
+ if (tag === void 0) { tag = null; }
1376
+ return __awaiter(this, void 0, void 0, function () {
1377
+ var obj, i, key, val, _a, _b, _c;
1378
+ return __generator(this, function (_d) {
1379
+ switch (_d.label) {
1380
+ case 0:
1381
+ obj = new Scope_1.Scope();
1382
+ i = 0;
1383
+ _d.label = 1;
1384
+ case 1:
1385
+ if (!(i < this.values.length)) return [3 /*break*/, 5];
1386
+ key = this.keys[i];
1387
+ val = this.values[i];
1388
+ _b = (_a = obj).set;
1389
+ return [4 /*yield*/, key.evaluate(scope, dom, tag)];
1390
+ case 2:
1391
+ _c = [_d.sent()];
1392
+ return [4 /*yield*/, val.evaluate(scope, dom, tag)];
1393
+ case 3:
1394
+ _b.apply(_a, _c.concat([_d.sent()]));
1395
+ _d.label = 4;
1396
+ case 4:
1397
+ i++;
1398
+ return [3 /*break*/, 1];
1399
+ case 5: return [2 /*return*/, obj];
1400
+ }
1401
+ });
1402
+ });
1403
+ };
1404
+ ObjectNode.match = function (tokens) {
1405
+ return tokens[0].type === TokenType.L_BRACE;
1406
+ };
1407
+ ObjectNode.parse = function (lastNode, token, tokens) {
1408
+ var valueTokens = Tree.getNextStatementTokens(tokens);
1409
+ var keys = [];
1410
+ var values = [];
1411
+ while (valueTokens.length > 0) {
1412
+ var key = Tree.getTokensUntil(valueTokens, TokenType.COLON, false);
1413
+ if (valueTokens[0].type !== TokenType.COLON)
1414
+ throw Error('Invalid object literal syntax. Expecting :');
1415
+ valueTokens.splice(0, 1); // Consume :
1416
+ var val = Tree.getTokensUntil(valueTokens, TokenType.COMMA, true, false, true, {
1417
+ type: BlockType.STATEMENT,
1418
+ open: null,
1419
+ close: null,
1420
+ openCharacter: null,
1421
+ closeCharacter: null
1422
+ });
1423
+ keys.push(Tree.processTokens(key));
1424
+ values.push(Tree.processTokens(val));
1425
+ }
1426
+ return new ObjectNode(keys, values);
1427
+ };
1428
+ return ObjectNode;
1429
+ }(Node));
1430
+ var ElementQueryNode = /** @class */ (function (_super) {
1431
+ __extends(ElementQueryNode, _super);
1432
+ function ElementQueryNode(query) {
1433
+ var _this = _super.call(this) || this;
1434
+ _this.query = query;
1435
+ _this.requiresPrep = true;
1436
+ return _this;
1437
+ }
1438
+ ElementQueryNode.prototype.evaluate = function (scope, dom, tag) {
1439
+ if (tag === void 0) { tag = null; }
1440
+ return __awaiter(this, void 0, void 0, function () {
1441
+ var _a;
1442
+ return __generator(this, function (_b) {
1443
+ switch (_b.label) {
1444
+ case 0:
1445
+ _a = tag;
1446
+ if (_a) return [3 /*break*/, 2];
1447
+ return [4 /*yield*/, dom.getTagForScope(scope)];
1448
+ case 1:
1449
+ _a = (_b.sent());
1450
+ _b.label = 2;
1451
+ case 2:
1452
+ tag = _a;
1453
+ return [4 /*yield*/, dom.get(this.query, true, tag)];
1454
+ case 3: return [2 /*return*/, _b.sent()];
1455
+ }
1456
+ });
1457
+ });
1458
+ };
1459
+ ElementQueryNode.prototype.prepare = function (scope, dom, tag) {
1460
+ if (tag === void 0) { tag = null; }
1461
+ return __awaiter(this, void 0, void 0, function () {
1462
+ var _a;
1463
+ return __generator(this, function (_b) {
1464
+ switch (_b.label) {
1465
+ case 0:
1466
+ _a = tag;
1467
+ if (_a) return [3 /*break*/, 2];
1468
+ return [4 /*yield*/, dom.getTagForScope(scope)];
1469
+ case 1:
1470
+ _a = (_b.sent());
1471
+ _b.label = 2;
1472
+ case 2:
1473
+ tag = _a;
1474
+ return [4 /*yield*/, dom.get(this.query, true, tag)];
1475
+ case 3:
1476
+ _b.sent();
1477
+ return [2 /*return*/];
1478
+ }
1479
+ });
1480
+ });
1481
+ };
1482
+ return ElementQueryNode;
1483
+ }(Node));
1484
+ var ElementAttributeNode = /** @class */ (function (_super) {
1485
+ __extends(ElementAttributeNode, _super);
1486
+ function ElementAttributeNode(elementRef, attr) {
1487
+ var _this = _super.call(this) || this;
1488
+ _this.elementRef = elementRef;
1489
+ _this.attr = attr;
1490
+ _this.requiresPrep = true;
1491
+ return _this;
1492
+ }
1493
+ Object.defineProperty(ElementAttributeNode.prototype, "name", {
1494
+ get: function () {
1495
+ return new LiteralNode("@" + this.attributeName);
1496
+ },
1497
+ enumerable: false,
1498
+ configurable: true
1499
+ });
1500
+ ElementAttributeNode.prototype._getChildNodes = function () {
1501
+ var nodes = [];
1502
+ if (this.elementRef)
1503
+ nodes.push(this.elementRef);
1504
+ return nodes;
1505
+ };
1506
+ Object.defineProperty(ElementAttributeNode.prototype, "attributeName", {
1507
+ get: function () {
1508
+ if (this.attr.startsWith('.'))
1509
+ return this.attr.substring(2);
1510
+ return this.attr.substring(1);
1511
+ },
1512
+ enumerable: false,
1513
+ configurable: true
1514
+ });
1515
+ ElementAttributeNode.prototype.evaluate = function (scope, dom, tag) {
1516
+ if (tag === void 0) { tag = null; }
1517
+ return __awaiter(this, void 0, void 0, function () {
1518
+ var tags;
1519
+ var _this = this;
1520
+ return __generator(this, function (_a) {
1521
+ switch (_a.label) {
1522
+ case 0:
1523
+ if (!this.elementRef) return [3 /*break*/, 2];
1524
+ return [4 /*yield*/, this.elementRef.evaluate(scope, dom, tag)];
1525
+ case 1:
1526
+ tags = _a.sent();
1527
+ return [3 /*break*/, 3];
1528
+ case 2:
1529
+ if (tag) {
1530
+ tags = new List_1.TagList(tag);
1531
+ }
1532
+ else {
1533
+ return [2 /*return*/];
1534
+ }
1535
+ _a.label = 3;
1536
+ case 3:
1537
+ if (tags.length === 1)
1538
+ return [2 /*return*/, tags[0].scope.get("@" + this.attributeName)];
1539
+ return [2 /*return*/, tags.map(function (tag) { return tag.scope.get("@" + _this.attributeName); })];
1540
+ }
1541
+ });
1542
+ });
1543
+ };
1544
+ ElementAttributeNode.prototype.prepare = function (scope, dom, tag) {
1545
+ if (tag === void 0) { tag = null; }
1546
+ return __awaiter(this, void 0, void 0, function () {
1547
+ var tags, _i, tags_1, t;
1548
+ return __generator(this, function (_a) {
1549
+ switch (_a.label) {
1550
+ case 0:
1551
+ if (!this.elementRef) return [3 /*break*/, 7];
1552
+ return [4 /*yield*/, this.elementRef.prepare(scope, dom, tag)];
1553
+ case 1:
1554
+ _a.sent();
1555
+ return [4 /*yield*/, this.elementRef.evaluate(scope, dom, tag)];
1556
+ case 2:
1557
+ tags = _a.sent();
1558
+ _i = 0, tags_1 = tags;
1559
+ _a.label = 3;
1560
+ case 3:
1561
+ if (!(_i < tags_1.length)) return [3 /*break*/, 6];
1562
+ t = tags_1[_i];
1563
+ return [4 /*yield*/, t.watchAttribute(this.attributeName)];
1564
+ case 4:
1565
+ _a.sent();
1566
+ _a.label = 5;
1567
+ case 5:
1568
+ _i++;
1569
+ return [3 /*break*/, 3];
1570
+ case 6: return [3 /*break*/, 9];
1571
+ case 7:
1572
+ if (!tag) return [3 /*break*/, 9];
1573
+ return [4 /*yield*/, tag.watchAttribute(this.attributeName)];
1574
+ case 8:
1575
+ _a.sent();
1576
+ _a.label = 9;
1577
+ case 9: return [2 /*return*/];
1578
+ }
1579
+ });
1580
+ });
1581
+ };
1582
+ return ElementAttributeNode;
1583
+ }(Node));
1584
+ exports.AttributableNodes = [
1585
+ RootScopeMemberNode,
1586
+ ScopeMemberNode,
1587
+ ElementAttributeNode
1588
+ ];
1589
+ var Tree = /** @class */ (function () {
1590
+ function Tree(code) {
1591
+ this.code = code;
1592
+ if (Tree.cache[code]) {
1593
+ this.rootNode = Tree.cache[code];
1594
+ }
1595
+ else {
1596
+ this.parse();
1597
+ Tree.cache[code] = this.rootNode;
1598
+ }
1599
+ }
1600
+ Tree.prototype.parse = function () {
1601
+ var tokens = Tree.tokenize(this.code);
1602
+ this.rootNode = Tree.processTokens(tokens);
1603
+ };
1604
+ Tree.prototype.evaluate = function (scope, dom, tag) {
1605
+ if (tag === void 0) { tag = null; }
1606
+ return __awaiter(this, void 0, void 0, function () {
1607
+ return __generator(this, function (_a) {
1608
+ switch (_a.label) {
1609
+ case 0: return [4 /*yield*/, this.rootNode.evaluate(scope, dom, tag)];
1610
+ case 1: return [2 /*return*/, _a.sent()];
1611
+ }
1612
+ });
1613
+ });
1614
+ };
1615
+ Tree.prototype.prepare = function (scope, dom, tag) {
1616
+ if (tag === void 0) { tag = null; }
1617
+ return __awaiter(this, void 0, void 0, function () {
1618
+ return __generator(this, function (_a) {
1619
+ switch (_a.label) {
1620
+ case 0:
1621
+ if (!this.rootNode.isPreparationRequired())
1622
+ return [2 /*return*/];
1623
+ return [4 /*yield*/, this.rootNode.prepare(scope, dom, tag)];
1624
+ case 1: return [2 /*return*/, _a.sent()];
1625
+ }
1626
+ });
1627
+ });
1628
+ };
1629
+ Tree.prototype.bindToScopeChanges = function (scope, fnc, dom, tag) {
1630
+ if (tag === void 0) { tag = null; }
1631
+ return __awaiter(this, void 0, void 0, function () {
1632
+ var _i, _a, node, _scope, name_2;
1633
+ return __generator(this, function (_b) {
1634
+ switch (_b.label) {
1635
+ case 0:
1636
+ _i = 0, _a = this.rootNode.findChildrenByTypes([RootScopeMemberNode, ScopeMemberNode, ElementAttributeNode], 'ScopeMemberNodes');
1637
+ _b.label = 1;
1638
+ case 1:
1639
+ if (!(_i < _a.length)) return [3 /*break*/, 8];
1640
+ node = _a[_i];
1641
+ _scope = scope;
1642
+ if (!(node instanceof ScopeMemberNode)) return [3 /*break*/, 3];
1643
+ return [4 /*yield*/, node.scope.evaluate(scope, dom)];
1644
+ case 2:
1645
+ _scope = _b.sent();
1646
+ return [3 /*break*/, 5];
1647
+ case 3:
1648
+ if (!(node instanceof ElementAttributeNode && node.elementRef)) return [3 /*break*/, 5];
1649
+ return [4 /*yield*/, node.elementRef.evaluate(scope, dom, tag)];
1650
+ case 4:
1651
+ _scope = (_b.sent())[0].scope;
1652
+ _b.label = 5;
1653
+ case 5: return [4 /*yield*/, node.name.evaluate(scope, dom, tag)];
1654
+ case 6:
1655
+ name_2 = _b.sent();
1656
+ _scope.bind("change:" + name_2, fnc);
1657
+ _b.label = 7;
1658
+ case 7:
1659
+ _i++;
1660
+ return [3 /*break*/, 1];
1661
+ case 8: return [2 /*return*/];
1662
+ }
1663
+ });
1664
+ });
1665
+ };
1666
+ Tree.tokenize = function (code) {
1667
+ var tokens = [];
1668
+ if (!code || code.length === 0)
1669
+ return tokens;
1670
+ var foundToken;
1671
+ do {
1672
+ foundToken = false;
1673
+ for (var _i = 0, TOKEN_PATTERNS_1 = TOKEN_PATTERNS; _i < TOKEN_PATTERNS_1.length; _i++) {
1674
+ var tp = TOKEN_PATTERNS_1[_i];
1675
+ var match = tp.pattern.exec(code);
1676
+ if (match) {
1677
+ tokens.push({
1678
+ type: tp.type,
1679
+ value: match[match.length - 1]
1680
+ });
1681
+ code = code.substring(match[0].length);
1682
+ foundToken = true;
1683
+ break;
1684
+ }
1685
+ }
1686
+ } while (code.length > 0 && foundToken);
1687
+ return tokens;
1688
+ };
1689
+ Tree.stripWhiteSpace = function (tokens) {
1690
+ for (var i = 0; i < tokens.length; i++) {
1691
+ if (tokens[i].type === TokenType.WHITESPACE) {
1692
+ tokens.splice(i, 1);
1693
+ i--;
1694
+ }
1695
+ }
1696
+ return tokens;
1697
+ };
1698
+ Tree.processTokens = function (tokens) {
1699
+ var blockNodes = [];
1700
+ var node = null;
1701
+ var count = 0;
1702
+ Tree.stripWhiteSpace(tokens);
1703
+ while (tokens.length > 0) {
1704
+ count++;
1705
+ if (count > 1000)
1706
+ break; // Limit to 1000 iterations while in development
1707
+ if (tokens[0].type === TokenType.RETURN)
1708
+ tokens.splice(0, 1);
1709
+ var token = tokens[0];
1710
+ if (token.type === TokenType.NAME) {
1711
+ node = new RootScopeMemberNode(new LiteralNode(token.value));
1712
+ tokens.splice(0, 1);
1713
+ }
1714
+ else if (token.type === TokenType.IF) {
1715
+ node = IfStatementNode.parse(node, token, tokens);
1716
+ blockNodes.push(node);
1717
+ node = null;
1718
+ }
1719
+ else if (token.type === TokenType.FOR) {
1720
+ node = ForStatementNode.parse(node, token, tokens);
1721
+ blockNodes.push(node);
1722
+ node = null;
1723
+ }
1724
+ else if (token.type === TokenType.STRING_LITERAL) {
1725
+ node = new LiteralNode(token.value);
1726
+ tokens.splice(0, 1);
1727
+ }
1728
+ else if (token.type === TokenType.NUMBER_LITERAL) {
1729
+ node = new NumberLiteralNode(token.value);
1730
+ tokens.splice(0, 1);
1731
+ }
1732
+ else if (tokens[0].type === TokenType.ELEMENT_REFERENCE) {
1733
+ node = new ElementQueryNode(tokens[0].value);
1734
+ tokens.splice(0, 1);
1735
+ }
1736
+ else if (tokens[0].type === TokenType.ELEMENT_QUERY) {
1737
+ node = new ElementQueryNode(tokens[0].value);
1738
+ tokens.splice(0, 1);
1739
+ }
1740
+ else if (tokens[0].type === TokenType.L_BRACKET) {
1741
+ if (node) {
1742
+ node = IndexNode.parse(node, token, tokens);
1743
+ }
1744
+ else {
1745
+ node = ArrayNode.parse(node, token, tokens);
1746
+ }
1747
+ }
1748
+ else if (tokens[0].type === TokenType.L_BRACE) {
1749
+ node = ObjectNode.parse(node, token, tokens);
1750
+ }
1751
+ else if (tokens[0].type === TokenType.ELEMENT_ATTRIBUTE) {
1752
+ node = new ElementAttributeNode(node, tokens[0].value);
1753
+ tokens.splice(0, 1);
1754
+ }
1755
+ else if (node !== null && token.type === TokenType.PERIOD && tokens[1].type === TokenType.NAME) {
1756
+ node = new ScopeMemberNode(node, new LiteralNode(tokens[1].value));
1757
+ tokens.splice(0, 2);
1758
+ }
1759
+ else if (tokens[0].type === TokenType.L_PAREN) {
1760
+ var funcArgs = Tree.getBlockTokens(tokens);
1761
+ var nodes = [];
1762
+ for (var _i = 0, funcArgs_1 = funcArgs; _i < funcArgs_1.length; _i++) {
1763
+ var arg = funcArgs_1[_i];
1764
+ nodes.push(Tree.processTokens(arg));
1765
+ }
1766
+ if (node) {
1767
+ node = new FunctionCallNode(node, // Previous node should be a NAME
1768
+ new FunctionArgumentNode(nodes));
1769
+ }
1770
+ else {
1771
+ node = new BlockNode(nodes);
1772
+ }
1773
+ }
1774
+ else if (tokens[0].type === TokenType.SEMI_COLON) {
1775
+ if (node) {
1776
+ blockNodes.push(node);
1777
+ }
1778
+ node = null;
1779
+ tokens.splice(0, 1);
1780
+ }
1781
+ else if (InNode.match(tokens)) {
1782
+ node = InNode.parse(node, token, tokens);
1783
+ }
1784
+ else if (ComparisonNode.match(tokens)) {
1785
+ node = ComparisonNode.parse(node, token, tokens);
1786
+ }
1787
+ else if (ArithmeticNode.match(tokens)) {
1788
+ node = ArithmeticNode.parse(node, token, tokens);
1789
+ }
1790
+ else if (ArithmeticAssignmentNode.match(tokens)) {
1791
+ node = ArithmeticAssignmentNode.parse(node, token, tokens);
1792
+ }
1793
+ else if (tokens[0].type === TokenType.WHITESPACE) {
1794
+ tokens.splice(0, 1);
1795
+ }
1796
+ else if (tokens[0].type === TokenType.BOOLEAN_LITERAL) {
1797
+ node = new BooleanLiteralNode(tokens[0].value);
1798
+ tokens.splice(0, 1);
1799
+ }
1800
+ else if (tokens[0].type === TokenType.NULL_LITERAL) {
1801
+ node = new LiteralNode(null);
1802
+ tokens.splice(0, 1);
1803
+ }
1804
+ else if (tokens[0].type === TokenType.EXCLAMATION_POINT) {
1805
+ node = NotNode.parse(node, tokens[0], tokens);
1806
+ }
1807
+ else {
1808
+ var code = Tree.toCode(tokens, 10);
1809
+ throw Error("Syntax Error. Near " + code);
1810
+ }
1811
+ }
1812
+ if (node) {
1813
+ blockNodes.push(node);
1814
+ }
1815
+ return new BlockNode(blockNodes);
1816
+ };
1817
+ Tree.toCode = function (tokens, limit) {
1818
+ var code = '';
1819
+ limit = limit || tokens.length;
1820
+ for (var i = 0; i < limit; i++) {
1821
+ if (!tokens[i])
1822
+ break;
1823
+ code += tokens[i].value;
1824
+ }
1825
+ return code;
1826
+ };
1827
+ Tree.getBlockInfo = function (tokens) {
1828
+ var blockType;
1829
+ var opener = tokens[0];
1830
+ if (opener.type === TokenType.L_PAREN)
1831
+ blockType = BlockType.PAREN;
1832
+ else if (opener.type === TokenType.L_BRACE)
1833
+ blockType = BlockType.BRACE;
1834
+ else if (opener.type === TokenType.L_BRACKET)
1835
+ blockType = BlockType.BRACKET;
1836
+ else
1837
+ blockType = BlockType.STATEMENT;
1838
+ var open;
1839
+ var close;
1840
+ var openCharacter;
1841
+ var closeCharacter;
1842
+ switch (blockType) {
1843
+ case BlockType.PAREN:
1844
+ open = TokenType.L_PAREN;
1845
+ close = TokenType.R_PAREN;
1846
+ openCharacter = '(';
1847
+ closeCharacter = ')';
1848
+ break;
1849
+ case BlockType.BRACE:
1850
+ open = TokenType.L_BRACE;
1851
+ close = TokenType.R_BRACE;
1852
+ openCharacter = '{';
1853
+ closeCharacter = '}';
1854
+ break;
1855
+ case BlockType.BRACKET:
1856
+ open = TokenType.L_BRACKET;
1857
+ close = TokenType.R_BRACKET;
1858
+ openCharacter = '[';
1859
+ closeCharacter = ']';
1860
+ break;
1861
+ default:
1862
+ open = null;
1863
+ close = TokenType.SEMI_COLON;
1864
+ openCharacter = null;
1865
+ closeCharacter = ';';
1866
+ break;
1867
+ }
1868
+ return {
1869
+ type: blockType,
1870
+ open: open,
1871
+ close: close,
1872
+ openCharacter: openCharacter,
1873
+ closeCharacter: closeCharacter
1874
+ };
1875
+ };
1876
+ Tree.getNextStatementTokens = function (tokens, consumeClosingToken, consumeOpeningToken, includeClosingToken) {
1877
+ if (consumeClosingToken === void 0) { consumeClosingToken = true; }
1878
+ if (consumeOpeningToken === void 0) { consumeOpeningToken = true; }
1879
+ if (includeClosingToken === void 0) { includeClosingToken = false; }
1880
+ var blockInfo = Tree.getBlockInfo(tokens);
1881
+ // Consume opening block token
1882
+ if (consumeOpeningToken && tokens[0].type === blockInfo.open) {
1883
+ tokens.splice(0, 1);
1884
+ }
1885
+ return Tree.getTokensUntil(tokens, blockInfo.close, consumeClosingToken, includeClosingToken);
1886
+ };
1887
+ Tree.getBlockTokens = function (tokens, groupBy) {
1888
+ if (groupBy === void 0) { groupBy = TokenType.COMMA; }
1889
+ var blockInfo = Tree.getBlockInfo(tokens);
1890
+ var openBlocks = 0;
1891
+ var args = [];
1892
+ var arg = [];
1893
+ for (var i = 0; i < tokens.length; i++) {
1894
+ var token = tokens[i];
1895
+ if (token.type === blockInfo.open) {
1896
+ openBlocks += 1;
1897
+ if (openBlocks > 1)
1898
+ arg.push(token);
1899
+ }
1900
+ else if (token.type === blockInfo.close) {
1901
+ openBlocks -= 1;
1902
+ if (openBlocks > 0)
1903
+ arg.push(token);
1904
+ }
1905
+ else if (groupBy !== null && token.type === groupBy && openBlocks == 1) {
1906
+ args.push(arg);
1907
+ arg = [];
1908
+ }
1909
+ else if (token.type !== TokenType.WHITESPACE) {
1910
+ arg.push(token);
1911
+ }
1912
+ // Consume token
1913
+ tokens.splice(0, 1);
1914
+ i--;
1915
+ if (openBlocks === 0) {
1916
+ if (arg.length > 0)
1917
+ args.push(arg);
1918
+ return args;
1919
+ }
1920
+ }
1921
+ throw Error("Invalid Syntax, missing " + blockInfo.closeCharacter);
1922
+ };
1923
+ Tree.getTokensUntil = function (tokens, terminator, consumeTerminator, includeTerminator, validIfTerminatorNotFound, blockInfo) {
1924
+ if (terminator === void 0) { terminator = TokenType.SEMI_COLON; }
1925
+ if (consumeTerminator === void 0) { consumeTerminator = true; }
1926
+ if (includeTerminator === void 0) { includeTerminator = false; }
1927
+ if (validIfTerminatorNotFound === void 0) { validIfTerminatorNotFound = false; }
1928
+ if (blockInfo === void 0) { blockInfo = null; }
1929
+ var statementTokens = [];
1930
+ blockInfo = blockInfo || Tree.getBlockInfo(tokens);
1931
+ var openParens = 0;
1932
+ var openBraces = 0;
1933
+ var openBrackets = 0;
1934
+ for (var i = 0; i < tokens.length; i++) {
1935
+ var token = tokens[i];
1936
+ if (!(token.type === blockInfo.open && i === 0)) { // Skip opener
1937
+ if (token.type === TokenType.L_PAREN)
1938
+ openParens += 1;
1939
+ if (token.type === TokenType.L_BRACE)
1940
+ openBraces += 1;
1941
+ if (token.type === TokenType.L_BRACKET)
1942
+ openBrackets += 1;
1943
+ }
1944
+ if ([
1945
+ terminator,
1946
+ TokenType.R_BRACKET,
1947
+ TokenType.R_BRACE,
1948
+ TokenType.R_PAREN
1949
+ ].indexOf(token.type) > -1) {
1950
+ if (openParens > 0 && token.type === TokenType.R_PAREN) {
1951
+ openParens -= 1;
1952
+ }
1953
+ else if (openBraces > 0 && token.type === TokenType.R_BRACE) {
1954
+ openBraces -= 1;
1955
+ }
1956
+ else if (openBrackets > 0 && token.type === TokenType.R_BRACKET) {
1957
+ openBrackets -= 1;
1958
+ }
1959
+ else if (token.type === terminator && openParens === 0 && openBraces === 0 && openBrackets === 0) {
1960
+ if (includeTerminator)
1961
+ statementTokens.push(token);
1962
+ if ((includeTerminator || consumeTerminator) && token.type !== TokenType.SEMI_COLON)
1963
+ tokens.splice(0, 1); // Consume end of block
1964
+ break;
1965
+ }
1966
+ else if (token.type === terminator && (openParens > 0 || openBraces > 0 || openBrackets > 0)) {
1967
+ }
1968
+ else {
1969
+ if (validIfTerminatorNotFound)
1970
+ break;
1971
+ throw Error("Invalid syntax, expecting " + terminator + ".");
1972
+ }
1973
+ }
1974
+ statementTokens.push(token);
1975
+ tokens.splice(0, 1); // Consume part of statement
1976
+ i--;
1977
+ }
1978
+ return statementTokens;
1979
+ };
1980
+ Tree.consumeTypes = function (tokens, types) {
1981
+ var matching = [];
1982
+ for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
1983
+ var token = tokens_1[_i];
1984
+ if (types.indexOf(token.type) > -1) {
1985
+ matching.push(token);
1986
+ }
1987
+ else {
1988
+ break;
1989
+ }
1990
+ }
1991
+ tokens.splice(0, matching.length);
1992
+ return matching;
1993
+ };
1994
+ Tree.cache = {};
1995
+ return Tree;
1996
+ }());
1997
+ exports.Tree = Tree;
1998
+ //# sourceMappingURL=AST.js.map