vsn 0.1.24 → 0.1.26

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