vsn 0.1.24 → 0.1.28

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/demo.html +18 -7
  2. package/demo/vsn.js +1 -0
  3. package/dist/AST/ArithmeticAssignmentNode.d.ts +23 -0
  4. package/dist/AST/ArithmeticAssignmentNode.js +313 -0
  5. package/dist/AST/ArithmeticAssignmentNode.js.map +1 -0
  6. package/dist/AST/ArithmeticNode.d.ts +15 -0
  7. package/dist/AST/ArithmeticNode.js +114 -0
  8. package/dist/AST/ArithmeticNode.js.map +1 -0
  9. package/dist/AST/ArrayNode.d.ts +14 -0
  10. package/dist/AST/ArrayNode.js +114 -0
  11. package/dist/AST/ArrayNode.js.map +1 -0
  12. package/dist/AST/BlockNode.d.ts +11 -0
  13. package/dist/AST/BlockNode.js +98 -0
  14. package/dist/AST/BlockNode.js.map +1 -0
  15. package/dist/AST/BooleanLiteralNode.d.ts +5 -0
  16. package/dist/AST/BooleanLiteralNode.js +31 -0
  17. package/dist/AST/BooleanLiteralNode.js.map +1 -0
  18. package/dist/AST/ComparisonNode.d.ts +15 -0
  19. package/dist/AST/ComparisonNode.js +120 -0
  20. package/dist/AST/ComparisonNode.js.map +1 -0
  21. package/dist/AST/ConditionalNode.d.ts +13 -0
  22. package/dist/AST/ConditionalNode.js +95 -0
  23. package/dist/AST/ConditionalNode.js.map +1 -0
  24. package/dist/AST/ElementAttributeNode.d.ts +18 -0
  25. package/dist/AST/ElementAttributeNode.js +159 -0
  26. package/dist/AST/ElementAttributeNode.js.map +1 -0
  27. package/dist/AST/ElementQueryNode.d.ts +12 -0
  28. package/dist/AST/ElementQueryNode.js +111 -0
  29. package/dist/AST/ElementQueryNode.js.map +1 -0
  30. package/dist/AST/ElementStyleNode.d.ts +18 -0
  31. package/dist/AST/ElementStyleNode.js +159 -0
  32. package/dist/AST/ElementStyleNode.js.map +1 -0
  33. package/dist/AST/ForStatementNode.d.ts +17 -0
  34. package/dist/AST/ForStatementNode.js +121 -0
  35. package/dist/AST/ForStatementNode.js.map +1 -0
  36. package/dist/AST/FunctionArgumentNode.d.ts +11 -0
  37. package/dist/AST/FunctionArgumentNode.js +100 -0
  38. package/dist/AST/FunctionArgumentNode.js.map +1 -0
  39. package/dist/AST/FunctionCallNode.d.ts +13 -0
  40. package/dist/AST/FunctionCallNode.js +102 -0
  41. package/dist/AST/FunctionCallNode.js.map +1 -0
  42. package/dist/AST/IfStatementNode.d.ts +14 -0
  43. package/dist/AST/IfStatementNode.js +128 -0
  44. package/dist/AST/IfStatementNode.js.map +1 -0
  45. package/dist/AST/InNode.d.ts +15 -0
  46. package/dist/AST/InNode.js +107 -0
  47. package/dist/AST/InNode.js.map +1 -0
  48. package/dist/AST/IndexNode.d.ts +16 -0
  49. package/dist/AST/IndexNode.js +126 -0
  50. package/dist/AST/IndexNode.js.map +1 -0
  51. package/dist/AST/LiteralNode.d.ts +10 -0
  52. package/dist/AST/LiteralNode.js +74 -0
  53. package/dist/AST/LiteralNode.js.map +1 -0
  54. package/dist/AST/Node.d.ts +19 -0
  55. package/dist/AST/Node.js +117 -0
  56. package/dist/AST/Node.js.map +1 -0
  57. package/dist/AST/NotNode.d.ts +12 -0
  58. package/dist/AST/NotNode.js +103 -0
  59. package/dist/AST/NotNode.js.map +1 -0
  60. package/dist/AST/NumberLiteralNode.d.ts +5 -0
  61. package/dist/AST/NumberLiteralNode.js +36 -0
  62. package/dist/AST/NumberLiteralNode.js.map +1 -0
  63. package/dist/AST/ObjectNode.d.ts +14 -0
  64. package/dist/AST/ObjectNode.js +131 -0
  65. package/dist/AST/ObjectNode.js.map +1 -0
  66. package/dist/AST/RootScopeMemberNode.d.ts +11 -0
  67. package/dist/AST/RootScopeMemberNode.js +87 -0
  68. package/dist/AST/RootScopeMemberNode.js.map +1 -0
  69. package/dist/AST/ScopeMemberNode.d.ts +12 -0
  70. package/dist/AST/ScopeMemberNode.js +128 -0
  71. package/dist/AST/ScopeMemberNode.js.map +1 -0
  72. package/dist/AST/UnitLiteralNode.d.ts +15 -0
  73. package/dist/AST/UnitLiteralNode.js +72 -0
  74. package/dist/AST/UnitLiteralNode.js.map +1 -0
  75. package/dist/AST.d.ts +9 -61
  76. package/dist/AST.js +84 -1413
  77. package/dist/AST.js.map +1 -1
  78. package/dist/Attribute.d.ts +1 -1
  79. package/dist/Attribute.js +3 -3
  80. package/dist/Attribute.js.map +1 -1
  81. package/dist/Configuration.d.ts +1 -1
  82. package/dist/Configuration.js +4 -4
  83. package/dist/Configuration.js.map +1 -1
  84. package/dist/Controller.d.ts +12 -4
  85. package/dist/Controller.js +38 -6
  86. package/dist/Controller.js.map +1 -1
  87. package/dist/DOM/DOMObject.d.ts +1 -1
  88. package/dist/DOM/DOMObject.js +2 -2
  89. package/dist/DOM/DOMObject.js.map +1 -1
  90. package/dist/DOM.d.ts +1 -1
  91. package/dist/DOM.js +4 -4
  92. package/dist/DOM.js.map +1 -1
  93. package/dist/EventDispatcher.d.ts +29 -0
  94. package/dist/EventDispatcher.js +132 -0
  95. package/dist/EventDispatcher.js.map +1 -0
  96. package/dist/Formats.js +2 -2
  97. package/dist/Formats.js.map +1 -1
  98. package/dist/MessageList.d.ts +14 -0
  99. package/dist/MessageList.js +88 -0
  100. package/dist/MessageList.js.map +1 -0
  101. package/dist/Model/Field.d.ts +8 -0
  102. package/dist/Model/Field.js +38 -0
  103. package/dist/Model/Field.js.map +1 -0
  104. package/dist/Model.d.ts +12 -0
  105. package/dist/Model.js +61 -0
  106. package/dist/Model.js.map +1 -0
  107. package/dist/Registry.d.ts +5 -2
  108. package/dist/Registry.js +17 -16
  109. package/dist/Registry.js.map +1 -1
  110. package/dist/Scope/DynamicScopeData.d.ts +6 -0
  111. package/dist/Scope/DynamicScopeData.js +54 -0
  112. package/dist/Scope/DynamicScopeData.js.map +1 -0
  113. package/dist/Scope/QueryReference.d.ts +10 -0
  114. package/dist/Scope/QueryReference.js +103 -0
  115. package/dist/Scope/QueryReference.js.map +1 -0
  116. package/dist/Scope/ScopeData.d.ts +4 -0
  117. package/dist/Scope/ScopeData.js +40 -0
  118. package/dist/Scope/ScopeData.js.map +1 -0
  119. package/dist/Scope/ScopeDataAbstract.d.ts +22 -0
  120. package/dist/Scope/ScopeDataAbstract.js +137 -0
  121. package/dist/Scope/ScopeDataAbstract.js.map +1 -0
  122. package/dist/Scope/ScopeReference.d.ts +10 -0
  123. package/dist/Scope/ScopeReference.js +73 -0
  124. package/dist/Scope/ScopeReference.js.map +1 -0
  125. package/dist/Scope/ScopedVariableType.d.ts +6 -0
  126. package/dist/Scope/ScopedVariableType.js +14 -0
  127. package/dist/Scope/ScopedVariableType.js.map +1 -0
  128. package/dist/Scope/WrappedArray.d.ts +16 -0
  129. package/dist/Scope/WrappedArray.js +121 -0
  130. package/dist/Scope/WrappedArray.js.map +1 -0
  131. package/dist/Scope/properties/Property.d.ts +18 -0
  132. package/dist/Scope/properties/Property.js +93 -0
  133. package/dist/Scope/properties/Property.js.map +1 -0
  134. package/dist/Scope.d.ts +4 -48
  135. package/dist/Scope.js +39 -324
  136. package/dist/Scope.js.map +1 -1
  137. package/dist/SimplePromise.d.ts +42 -0
  138. package/dist/SimplePromise.js +217 -0
  139. package/dist/SimplePromise.js.map +1 -0
  140. package/dist/Tag.js +11 -5
  141. package/dist/Tag.js.map +1 -1
  142. package/dist/Types.d.ts +1 -0
  143. package/dist/Types.js +8 -1
  144. package/dist/Types.js.map +1 -1
  145. package/dist/Validators.d.ts +7 -0
  146. package/dist/Validators.js +54 -0
  147. package/dist/Validators.js.map +1 -0
  148. package/dist/attributes/Bind.js +1 -1
  149. package/dist/attributes/Bind.js.map +1 -1
  150. package/dist/attributes/JSONAttribute.js.map +1 -1
  151. package/dist/attributes/List.js +7 -7
  152. package/dist/attributes/List.js.map +1 -1
  153. package/dist/attributes/On.js +4 -1
  154. package/dist/attributes/On.js.map +1 -1
  155. package/dist/attributes/Radio.js +4 -2
  156. package/dist/attributes/Radio.js.map +1 -1
  157. package/dist/attributes/ScopeChange.js +1 -1
  158. package/dist/attributes/ScopeChange.js.map +1 -1
  159. package/dist/attributes/SetAttribute.js.map +1 -1
  160. package/dist/attributes/StandardAttribute.js +1 -1
  161. package/dist/attributes/StandardAttribute.js.map +1 -1
  162. package/dist/attributes/StyleAttribute.js +1 -1
  163. package/dist/attributes/StyleAttribute.js.map +1 -1
  164. package/dist/{Vision.d.ts → vsn.d.ts} +7 -2
  165. package/dist/{Vision.js → vsn.js} +21 -12
  166. package/dist/vsn.js.map +1 -0
  167. package/package.json +9 -13
  168. package/src/AST/ArithmeticAssignmentNode.ts +236 -0
  169. package/src/AST/ArithmeticNode.ts +52 -0
  170. package/src/AST/ArrayNode.ts +39 -0
  171. package/src/AST/BlockNode.ts +25 -0
  172. package/src/AST/BooleanLiteralNode.ts +10 -0
  173. package/src/AST/ComparisonNode.ts +57 -0
  174. package/src/AST/ConditionalNode.ts +36 -0
  175. package/src/AST/ElementAttributeNode.ts +63 -0
  176. package/src/AST/ElementQueryNode.ts +25 -0
  177. package/src/AST/ElementStyleNode.ts +63 -0
  178. package/src/AST/ForStatementNode.ts +59 -0
  179. package/src/AST/FunctionArgumentNode.ts +27 -0
  180. package/src/AST/FunctionCallNode.ts +32 -0
  181. package/src/AST/IfStatementNode.ts +67 -0
  182. package/src/AST/InNode.ts +46 -0
  183. package/src/AST/IndexNode.ts +61 -0
  184. package/src/AST/LiteralNode.ts +17 -0
  185. package/src/AST/Node.ts +71 -0
  186. package/src/AST/NotNode.ts +41 -0
  187. package/src/AST/NumberLiteralNode.ts +14 -0
  188. package/src/AST/ObjectNode.ts +55 -0
  189. package/src/AST/RootScopeMemberNode.ts +25 -0
  190. package/src/AST/ScopeMemberNode.ts +53 -0
  191. package/src/AST/UnitLiteralNode.ts +51 -0
  192. package/src/AST.ts +45 -1014
  193. package/src/Attribute.ts +2 -2
  194. package/src/Configuration.ts +3 -3
  195. package/src/Controller.ts +31 -6
  196. package/src/DOM/DOMObject.ts +1 -1
  197. package/src/DOM.ts +4 -4
  198. package/src/EventDispatcher.ts +134 -0
  199. package/src/Formats.ts +2 -2
  200. package/src/MessageList.ts +81 -0
  201. package/src/Model/Field.ts +20 -0
  202. package/src/Model.ts +43 -0
  203. package/src/Registry.ts +13 -5
  204. package/src/Scope/DynamicScopeData.ts +29 -0
  205. package/src/Scope/QueryReference.ts +29 -0
  206. package/src/Scope/ScopeData.ts +21 -0
  207. package/src/Scope/ScopeDataAbstract.ts +126 -0
  208. package/src/Scope/ScopeReference.ts +30 -0
  209. package/src/Scope/ScopedVariableType.ts +7 -0
  210. package/src/Scope/WrappedArray.ts +88 -0
  211. package/src/Scope/properties/Property.ts +79 -0
  212. package/src/Scope.ts +35 -251
  213. package/src/SimplePromise.ts +219 -0
  214. package/src/Tag.ts +9 -5
  215. package/src/Types.ts +6 -1
  216. package/src/Validators.ts +45 -0
  217. package/src/attributes/Bind.ts +3 -2
  218. package/src/attributes/JSONAttribute.ts +2 -1
  219. package/src/attributes/List.ts +4 -4
  220. package/src/attributes/On.ts +2 -0
  221. package/src/attributes/Radio.ts +5 -3
  222. package/src/attributes/ScopeChange.ts +2 -2
  223. package/src/attributes/SetAttribute.ts +2 -1
  224. package/src/attributes/StandardAttribute.ts +1 -1
  225. package/src/attributes/StyleAttribute.ts +3 -2
  226. package/src/attributes/TypeAttribute.ts +1 -1
  227. package/src/{Vision.ts → vsn.ts} +12 -5
  228. package/test/AST/ArithmeticAssignmentNode.spec.ts +47 -0
  229. package/test/AST.spec.ts +3 -2
  230. package/test/Controller.spec.ts +44 -0
  231. package/test/DOM.spec.ts +1 -1
  232. package/test/MessageList.spec.ts +101 -0
  233. package/test/Model/DataModel.spec.ts +0 -0
  234. package/test/Scope/DynamicScopeData.spec.ts +141 -0
  235. package/test/Scope.spec.ts +15 -3
  236. package/test/SimplePromise.spec.ts +271 -0
  237. package/test/Tag/TagList.spec.ts +1 -1
  238. package/test/attributes/Bind.spec.ts +5 -5
  239. package/test/attributes/JSONAttribute.spec.ts +1 -1
  240. package/test/attributes/ListItem.spec.ts +1 -1
  241. package/webpack.config.js +2 -2
  242. package/demo/vision.js +0 -1
  243. package/dist/Vision.js.map +0 -1
  244. package/main.py +0 -16
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
  }
@@ -125,6 +124,7 @@ var TokenType;
125
124
  TokenType[TokenType["ELEMENT_ATTRIBUTE"] = 50] = "ELEMENT_ATTRIBUTE";
126
125
  TokenType[TokenType["ELEMENT_STYLE"] = 51] = "ELEMENT_STYLE";
127
126
  TokenType[TokenType["ELEMENT_QUERY"] = 52] = "ELEMENT_QUERY";
127
+ TokenType[TokenType["UNIT"] = 53] = "UNIT";
128
128
  })(TokenType = exports.TokenType || (exports.TokenType = {}));
129
129
  var TOKEN_PATTERNS = [
130
130
  {
@@ -143,6 +143,10 @@ var TOKEN_PATTERNS = [
143
143
  type: TokenType.TYPE_FLOAT,
144
144
  pattern: /^float+/
145
145
  },
146
+ {
147
+ type: TokenType.UNIT,
148
+ pattern: /^\d+\.?\d?(?:cm|mm|in|px|pt|pc|em|ex|ch|rem|vw|vh|vmin|vmax|%)/
149
+ },
146
150
  {
147
151
  type: TokenType.TYPE_STRING,
148
152
  pattern: /^string+/
@@ -189,11 +193,11 @@ var TOKEN_PATTERNS = [
189
193
  },
190
194
  {
191
195
  type: TokenType.ELEMENT_ATTRIBUTE,
192
- pattern: /^\.?@[_a-zA-Z0-9]*/
196
+ pattern: /^\.?@[-_a-zA-Z0-9]*/
193
197
  },
194
198
  {
195
199
  type: TokenType.ELEMENT_STYLE,
196
- pattern: /^\.?\$[a-zA-Z0-9]*/
200
+ pattern: /^\.?\$[-a-zA-Z0-9]*/
197
201
  },
198
202
  {
199
203
  type: TokenType.ELEMENT_REFERENCE,
@@ -336,1360 +340,10 @@ var TOKEN_PATTERNS = [
336
340
  pattern: /^!/
337
341
  }
338
342
  ];
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
343
  exports.AttributableNodes = [
1690
- RootScopeMemberNode,
1691
- ScopeMemberNode,
1692
- ElementAttributeNode
344
+ RootScopeMemberNode_1.RootScopeMemberNode,
345
+ ScopeMemberNode_1.ScopeMemberNode,
346
+ ElementAttributeNode_1.ElementAttributeNode
1693
347
  ];
1694
348
  var Tree = /** @class */ (function () {
1695
349
  function Tree(code) {
@@ -1734,31 +388,31 @@ var Tree = /** @class */ (function () {
1734
388
  Tree.prototype.bindToScopeChanges = function (scope, fnc, dom, tag) {
1735
389
  if (tag === void 0) { tag = null; }
1736
390
  return __awaiter(this, void 0, void 0, function () {
1737
- var _i, _a, node, _scope, name_2;
391
+ var _i, _a, node, _scope, name_1;
1738
392
  return __generator(this, function (_b) {
1739
393
  switch (_b.label) {
1740
394
  case 0:
1741
- _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');
1742
396
  _b.label = 1;
1743
397
  case 1:
1744
398
  if (!(_i < _a.length)) return [3 /*break*/, 8];
1745
399
  node = _a[_i];
1746
400
  _scope = scope;
1747
- if (!(node instanceof ScopeMemberNode)) return [3 /*break*/, 3];
401
+ if (!(node instanceof ScopeMemberNode_1.ScopeMemberNode)) return [3 /*break*/, 3];
1748
402
  return [4 /*yield*/, node.scope.evaluate(scope, dom)];
1749
403
  case 2:
1750
404
  _scope = _b.sent();
1751
405
  return [3 /*break*/, 5];
1752
406
  case 3:
1753
- if (!(node instanceof ElementAttributeNode && node.elementRef)) return [3 /*break*/, 5];
407
+ if (!(node instanceof ElementAttributeNode_1.ElementAttributeNode && node.elementRef)) return [3 /*break*/, 5];
1754
408
  return [4 /*yield*/, node.elementRef.evaluate(scope, dom, tag)];
1755
409
  case 4:
1756
410
  _scope = (_b.sent())[0].scope;
1757
411
  _b.label = 5;
1758
412
  case 5: return [4 /*yield*/, node.name.evaluate(scope, dom, tag)];
1759
413
  case 6:
1760
- name_2 = _b.sent();
1761
- _scope.bind("change:" + name_2, fnc);
414
+ name_1 = _b.sent();
415
+ _scope.on("change:" + name_1, fnc);
1762
416
  _b.label = 7;
1763
417
  case 7:
1764
418
  _i++;
@@ -1813,56 +467,56 @@ var Tree = /** @class */ (function () {
1813
467
  tokens.splice(0, 1);
1814
468
  var token = tokens[0];
1815
469
  if (token.type === TokenType.NAME) {
1816
- node = new RootScopeMemberNode(new LiteralNode(token.value));
470
+ node = new RootScopeMemberNode_1.RootScopeMemberNode(new LiteralNode_1.LiteralNode(token.value));
1817
471
  tokens.splice(0, 1);
1818
472
  }
1819
473
  else if (token.type === TokenType.IF) {
1820
- node = IfStatementNode.parse(node, token, tokens);
474
+ node = IfStatementNode_1.IfStatementNode.parse(node, token, tokens);
1821
475
  blockNodes.push(node);
1822
476
  node = null;
1823
477
  }
1824
478
  else if (token.type === TokenType.FOR) {
1825
- node = ForStatementNode.parse(node, token, tokens);
479
+ node = ForStatementNode_1.ForStatementNode.parse(node, token, tokens);
1826
480
  blockNodes.push(node);
1827
481
  node = null;
1828
482
  }
1829
483
  else if (token.type === TokenType.STRING_LITERAL) {
1830
- node = new LiteralNode(token.value);
484
+ node = new LiteralNode_1.LiteralNode(token.value);
1831
485
  tokens.splice(0, 1);
1832
486
  }
1833
487
  else if (token.type === TokenType.NUMBER_LITERAL) {
1834
- node = new NumberLiteralNode(token.value);
488
+ node = new NumberLiteralNode_1.NumberLiteralNode(token.value);
1835
489
  tokens.splice(0, 1);
1836
490
  }
1837
491
  else if (tokens[0].type === TokenType.ELEMENT_REFERENCE) {
1838
- node = new ElementQueryNode(tokens[0].value);
492
+ node = new ElementQueryNode_1.ElementQueryNode(tokens[0].value);
1839
493
  tokens.splice(0, 1);
1840
494
  }
1841
495
  else if (tokens[0].type === TokenType.ELEMENT_QUERY) {
1842
- node = new ElementQueryNode(tokens[0].value);
496
+ node = new ElementQueryNode_1.ElementQueryNode(tokens[0].value);
1843
497
  tokens.splice(0, 1);
1844
498
  }
1845
499
  else if (tokens[0].type === TokenType.L_BRACKET) {
1846
500
  if (node) {
1847
- node = IndexNode.parse(node, token, tokens);
501
+ node = IndexNode_1.IndexNode.parse(node, token, tokens);
1848
502
  }
1849
503
  else {
1850
- node = ArrayNode.parse(node, token, tokens);
504
+ node = ArrayNode_1.ArrayNode.parse(node, token, tokens);
1851
505
  }
1852
506
  }
1853
507
  else if (tokens[0].type === TokenType.L_BRACE) {
1854
- node = ObjectNode.parse(node, token, tokens);
508
+ node = ObjectNode_1.ObjectNode.parse(node, token, tokens);
1855
509
  }
1856
510
  else if (tokens[0].type === TokenType.ELEMENT_ATTRIBUTE) {
1857
- node = new ElementAttributeNode(node, tokens[0].value);
511
+ node = new ElementAttributeNode_1.ElementAttributeNode(node, tokens[0].value);
1858
512
  tokens.splice(0, 1);
1859
513
  }
1860
514
  else if (tokens[0].type === TokenType.ELEMENT_STYLE) {
1861
- node = new ElementStyleNode(node, tokens[0].value);
515
+ node = new ElementStyleNode_1.ElementStyleNode(node, tokens[0].value);
1862
516
  tokens.splice(0, 1);
1863
517
  }
1864
518
  else if (node !== null && token.type === TokenType.PERIOD && tokens[1].type === TokenType.NAME) {
1865
- node = new ScopeMemberNode(node, new LiteralNode(tokens[1].value));
519
+ node = new ScopeMemberNode_1.ScopeMemberNode(node, new LiteralNode_1.LiteralNode(tokens[1].value));
1866
520
  tokens.splice(0, 2);
1867
521
  }
1868
522
  else if (tokens[0].type === TokenType.L_PAREN) {
@@ -1873,11 +527,11 @@ var Tree = /** @class */ (function () {
1873
527
  nodes.push(Tree.processTokens(arg));
1874
528
  }
1875
529
  if (node) {
1876
- node = new FunctionCallNode(node, // Previous node should be a NAME
1877
- new FunctionArgumentNode(nodes));
530
+ node = new FunctionCallNode_1.FunctionCallNode(node, // Previous node should be a NAME
531
+ new FunctionArgumentNode_1.FunctionArgumentNode(nodes));
1878
532
  }
1879
533
  else {
1880
- node = new BlockNode(nodes);
534
+ node = new BlockNode_1.BlockNode(nodes);
1881
535
  }
1882
536
  }
1883
537
  else if (tokens[0].type === TokenType.SEMI_COLON) {
@@ -1887,31 +541,35 @@ var Tree = /** @class */ (function () {
1887
541
  node = null;
1888
542
  tokens.splice(0, 1);
1889
543
  }
1890
- else if (InNode.match(tokens)) {
1891
- node = InNode.parse(node, token, tokens);
544
+ else if (InNode_1.InNode.match(tokens)) {
545
+ node = InNode_1.InNode.parse(node, token, tokens);
1892
546
  }
1893
- else if (ComparisonNode.match(tokens)) {
1894
- node = ComparisonNode.parse(node, token, tokens);
547
+ else if (ComparisonNode_1.ComparisonNode.match(tokens)) {
548
+ node = ComparisonNode_1.ComparisonNode.parse(node, token, tokens);
1895
549
  }
1896
- else if (ArithmeticNode.match(tokens)) {
1897
- node = ArithmeticNode.parse(node, token, tokens);
550
+ else if (ArithmeticNode_1.ArithmeticNode.match(tokens)) {
551
+ node = ArithmeticNode_1.ArithmeticNode.parse(node, token, tokens);
1898
552
  }
1899
- else if (ArithmeticAssignmentNode.match(tokens)) {
1900
- node = ArithmeticAssignmentNode.parse(node, token, tokens);
553
+ else if (ArithmeticAssignmentNode_1.ArithmeticAssignmentNode.match(tokens)) {
554
+ node = ArithmeticAssignmentNode_1.ArithmeticAssignmentNode.parse(node, token, tokens);
1901
555
  }
1902
556
  else if (tokens[0].type === TokenType.WHITESPACE) {
1903
557
  tokens.splice(0, 1);
1904
558
  }
559
+ else if (tokens[0].type === TokenType.UNIT) {
560
+ node = new UnitLiteralNode_1.UnitLiteralNode(tokens[0].value);
561
+ tokens.splice(0, 1);
562
+ }
1905
563
  else if (tokens[0].type === TokenType.BOOLEAN_LITERAL) {
1906
- node = new BooleanLiteralNode(tokens[0].value);
564
+ node = new BooleanLiteralNode_1.BooleanLiteralNode(tokens[0].value);
1907
565
  tokens.splice(0, 1);
1908
566
  }
1909
567
  else if (tokens[0].type === TokenType.NULL_LITERAL) {
1910
- node = new LiteralNode(null);
568
+ node = new LiteralNode_1.LiteralNode(null);
1911
569
  tokens.splice(0, 1);
1912
570
  }
1913
571
  else if (tokens[0].type === TokenType.EXCLAMATION_POINT) {
1914
- node = NotNode.parse(node, tokens[0], tokens);
572
+ node = NotNode_1.NotNode.parse(node, tokens[0], tokens);
1915
573
  }
1916
574
  else {
1917
575
  var code = Tree.toCode(tokens, 10);
@@ -1921,7 +579,7 @@ var Tree = /** @class */ (function () {
1921
579
  if (node) {
1922
580
  blockNodes.push(node);
1923
581
  }
1924
- return new BlockNode(blockNodes);
582
+ return new BlockNode_1.BlockNode(blockNodes);
1925
583
  };
1926
584
  Tree.toCode = function (tokens, limit) {
1927
585
  var code = '';
@@ -2100,6 +758,19 @@ var Tree = /** @class */ (function () {
2100
758
  tokens.splice(0, matching.length);
2101
759
  return matching;
2102
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
+ };
2103
774
  Tree.cache = {};
2104
775
  return Tree;
2105
776
  }());