vsn 0.1.27 → 0.1.30

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