vsn 0.1.26 → 0.1.27

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 (191) hide show
  1. package/dist/AST.js +2197 -0
  2. package/dist/AST.js.map +1 -0
  3. package/dist/Attribute.d.ts +1 -1
  4. package/dist/Attribute.js +187 -0
  5. package/dist/Attribute.js.map +1 -0
  6. package/dist/Bencmark.js +179 -0
  7. package/dist/Bencmark.js.map +1 -0
  8. package/dist/Configuration.d.ts +1 -1
  9. package/dist/Configuration.js +64 -0
  10. package/dist/Configuration.js.map +1 -0
  11. package/dist/Controller.d.ts +1 -1
  12. package/dist/Controller.js +54 -0
  13. package/dist/Controller.js.map +1 -0
  14. package/dist/DOM/DOMObject.d.ts +1 -1
  15. package/dist/DOM/DOMObject.js +47 -0
  16. package/dist/DOM/DOMObject.js.map +1 -0
  17. package/dist/DOM/WrappedDocument.js +34 -0
  18. package/dist/DOM/WrappedDocument.js.map +1 -0
  19. package/dist/DOM/WrappedWindow.js +45 -0
  20. package/dist/DOM/WrappedWindow.js.map +1 -0
  21. package/dist/DOM.d.ts +1 -1
  22. package/dist/DOM.js +547 -0
  23. package/dist/DOM.js.map +1 -0
  24. package/dist/EventDispatcher.d.ts +26 -0
  25. package/dist/EventDispatcher.js +117 -0
  26. package/dist/EventDispatcher.js.map +1 -0
  27. package/dist/Formats.js +44 -0
  28. package/dist/Formats.js.map +1 -0
  29. package/dist/MessageList.d.ts +14 -0
  30. package/dist/MessageList.js +88 -0
  31. package/dist/MessageList.js.map +1 -0
  32. package/dist/Model/Collection.d.ts +5 -0
  33. package/dist/Model/Collection.js +37 -0
  34. package/dist/Model/Collection.js.map +1 -0
  35. package/dist/Model/DataModel.d.ts +6 -0
  36. package/dist/Model/DataModel.js +54 -0
  37. package/dist/Model/DataModel.js.map +1 -0
  38. package/dist/Model/ModelAbstract.d.ts +20 -0
  39. package/dist/Model/ModelAbstract.js +122 -0
  40. package/dist/Model/ModelAbstract.js.map +1 -0
  41. package/dist/Model/fields/BooleanField.d.ts +5 -0
  42. package/dist/Model/fields/BooleanField.js +43 -0
  43. package/dist/Model/fields/BooleanField.js.map +1 -0
  44. package/dist/Model/fields/EmailField.d.ts +5 -0
  45. package/dist/Model/fields/EmailField.js +36 -0
  46. package/dist/Model/fields/EmailField.js.map +1 -0
  47. package/dist/Model/fields/Field.d.ts +13 -0
  48. package/dist/Model/fields/Field.js +79 -0
  49. package/dist/Model/fields/Field.js.map +1 -0
  50. package/dist/Model/fields/FloatField.d.ts +5 -0
  51. package/dist/Model/fields/FloatField.js +47 -0
  52. package/dist/Model/fields/FloatField.js.map +1 -0
  53. package/dist/Model/fields/PositiveNumberField.d.ts +5 -0
  54. package/dist/Model/fields/PositiveNumberField.js +51 -0
  55. package/dist/Model/fields/PositiveNumberField.js.map +1 -0
  56. package/dist/Model/fields/StringField.d.ts +5 -0
  57. package/dist/Model/fields/StringField.js +43 -0
  58. package/dist/Model/fields/StringField.js.map +1 -0
  59. package/dist/Model.d.ts +11 -0
  60. package/dist/Model.js +72 -0
  61. package/dist/Model.js.map +1 -0
  62. package/dist/Query.js +66 -0
  63. package/dist/Query.js.map +1 -0
  64. package/dist/Registry.d.ts +2 -2
  65. package/dist/Registry.js +128 -0
  66. package/dist/Registry.js.map +1 -0
  67. package/dist/Scope.d.ts +7 -10
  68. package/dist/Scope.js +462 -0
  69. package/dist/Scope.js.map +1 -0
  70. package/dist/SimplePromise.d.ts +42 -0
  71. package/dist/SimplePromise.js +217 -0
  72. package/dist/SimplePromise.js.map +1 -0
  73. package/dist/Tag/List.js +85 -0
  74. package/dist/Tag/List.js.map +1 -0
  75. package/dist/Tag.js +770 -0
  76. package/dist/Tag.js.map +1 -0
  77. package/dist/Types.js +48 -0
  78. package/dist/Types.js.map +1 -0
  79. package/dist/attributes/AddClassIf.js +93 -0
  80. package/dist/attributes/AddClassIf.js.map +1 -0
  81. package/dist/attributes/Bind.js +272 -0
  82. package/dist/attributes/Bind.js.map +1 -0
  83. package/dist/attributes/ClassConstructor.js +104 -0
  84. package/dist/attributes/ClassConstructor.js.map +1 -0
  85. package/dist/attributes/ClickRemoveClass.js +114 -0
  86. package/dist/attributes/ClickRemoveClass.js.map +1 -0
  87. package/dist/attributes/ClickToggleClass.js +114 -0
  88. package/dist/attributes/ClickToggleClass.js.map +1 -0
  89. package/dist/attributes/ControllerAttribute.js +28 -0
  90. package/dist/attributes/ControllerAttribute.js.map +1 -0
  91. package/dist/attributes/DisableIf.js +94 -0
  92. package/dist/attributes/DisableIf.js.map +1 -0
  93. package/dist/attributes/Exec.js +108 -0
  94. package/dist/attributes/Exec.js.map +1 -0
  95. package/dist/attributes/Format.js +99 -0
  96. package/dist/attributes/Format.js.map +1 -0
  97. package/dist/attributes/If.js +159 -0
  98. package/dist/attributes/If.js.map +1 -0
  99. package/dist/attributes/JSONAttribute.js +118 -0
  100. package/dist/attributes/JSONAttribute.js.map +1 -0
  101. package/dist/attributes/KeyAbstract.js +117 -0
  102. package/dist/attributes/KeyAbstract.js.map +1 -0
  103. package/dist/attributes/KeyDown.js +88 -0
  104. package/dist/attributes/KeyDown.js.map +1 -0
  105. package/dist/attributes/KeyUp.js +88 -0
  106. package/dist/attributes/KeyUp.js.map +1 -0
  107. package/dist/attributes/List.js +282 -0
  108. package/dist/attributes/List.js.map +1 -0
  109. package/dist/attributes/ListItem.js +138 -0
  110. package/dist/attributes/ListItem.js.map +1 -0
  111. package/dist/attributes/ListItemModel.js +39 -0
  112. package/dist/attributes/ListItemModel.js.map +1 -0
  113. package/dist/attributes/ModelAttribute.js +29 -0
  114. package/dist/attributes/ModelAttribute.js.map +1 -0
  115. package/dist/attributes/Name.js +88 -0
  116. package/dist/attributes/Name.js.map +1 -0
  117. package/dist/attributes/On.js +135 -0
  118. package/dist/attributes/On.js.map +1 -0
  119. package/dist/attributes/Radio.js +174 -0
  120. package/dist/attributes/Radio.js.map +1 -0
  121. package/dist/attributes/Referenced.js +38 -0
  122. package/dist/attributes/Referenced.js.map +1 -0
  123. package/dist/attributes/RootAttribute.js +91 -0
  124. package/dist/attributes/RootAttribute.js.map +1 -0
  125. package/dist/attributes/ScopeAttribute.js +40 -0
  126. package/dist/attributes/ScopeAttribute.js.map +1 -0
  127. package/dist/attributes/ScopeChange.js +130 -0
  128. package/dist/attributes/ScopeChange.js.map +1 -0
  129. package/dist/attributes/SetAttribute.js +133 -0
  130. package/dist/attributes/SetAttribute.js.map +1 -0
  131. package/dist/attributes/StandardAttribute.js +186 -0
  132. package/dist/attributes/StandardAttribute.js.map +1 -0
  133. package/dist/attributes/StyleAttribute.js +183 -0
  134. package/dist/attributes/StyleAttribute.js.map +1 -0
  135. package/dist/attributes/Template.js +39 -0
  136. package/dist/attributes/Template.js.map +1 -0
  137. package/dist/attributes/TypeAttribute.js +104 -0
  138. package/dist/attributes/TypeAttribute.js.map +1 -0
  139. package/dist/attributes/_imports.js +60 -0
  140. package/dist/attributes/_imports.js.map +1 -0
  141. package/dist/helpers/DOMHelper.js +81 -0
  142. package/dist/helpers/DOMHelper.js.map +1 -0
  143. package/dist/helpers/ElementHelper.js +25 -0
  144. package/dist/helpers/ElementHelper.js.map +1 -0
  145. package/dist/helpers/VisionHelper.js +71 -0
  146. package/dist/helpers/VisionHelper.js.map +1 -0
  147. package/dist/helpers/decorators.js +38 -0
  148. package/dist/helpers/decorators.js.map +1 -0
  149. package/dist/vsn.d.ts +2 -1
  150. package/dist/vsn.js +166 -0
  151. package/dist/vsn.js.map +1 -0
  152. package/package.json +2 -6
  153. package/src/AST.ts +2 -2
  154. package/src/Attribute.ts +2 -2
  155. package/src/Configuration.ts +3 -3
  156. package/src/Controller.ts +1 -1
  157. package/src/DOM/DOMObject.ts +1 -1
  158. package/src/DOM.ts +3 -3
  159. package/src/EventDispatcher.ts +117 -0
  160. package/src/Formats.ts +2 -2
  161. package/src/MessageList.ts +81 -0
  162. package/src/Model/Collection.ts +13 -0
  163. package/src/Model/DataModel.ts +29 -0
  164. package/src/Model/ModelAbstract.ts +114 -0
  165. package/src/Model/fields/BooleanField.ts +16 -0
  166. package/src/Model/fields/EmailField.ts +12 -0
  167. package/src/Model/fields/Field.ts +65 -0
  168. package/src/Model/fields/FloatField.ts +22 -0
  169. package/src/Model/fields/PositiveNumberField.ts +24 -0
  170. package/src/Model/fields/StringField.ts +16 -0
  171. package/src/Model.ts +57 -0
  172. package/src/Registry.ts +3 -3
  173. package/src/Scope.ts +33 -89
  174. package/src/SimplePromise.ts +219 -0
  175. package/src/Tag.ts +2 -2
  176. package/src/attributes/Bind.ts +1 -1
  177. package/src/attributes/List.ts +3 -3
  178. package/src/attributes/Radio.ts +1 -1
  179. package/src/attributes/ScopeChange.ts +1 -1
  180. package/src/attributes/StandardAttribute.ts +1 -1
  181. package/src/attributes/StyleAttribute.ts +1 -1
  182. package/src/vsn.ts +3 -2
  183. package/test/AST.spec.ts +2 -1
  184. package/test/MessageList.spec.ts +101 -0
  185. package/test/Model/DataModel.spec.ts +141 -0
  186. package/test/Model.spec.ts +306 -0
  187. package/test/Scope.spec.ts +2 -2
  188. package/test/SimplePromise.spec.ts +271 -0
  189. package/test/attributes/Bind.spec.ts +5 -5
  190. package/test/attributes/ListItem.spec.ts +1 -1
  191. package/dist/vsn.min.js +0 -1
package/dist/AST.js ADDED
@@ -0,0 +1,2197 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
54
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
55
+ to[j] = from[i];
56
+ return to;
57
+ };
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ exports.Tree = exports.AttributableNodes = exports.BlockNode = exports.Node = exports.TokenType = exports.BlockType = void 0;
60
+ var Scope_1 = require("./Scope");
61
+ var DOMObject_1 = require("./DOM/DOMObject");
62
+ var List_1 = require("./Tag/List");
63
+ function lower(str) {
64
+ return str ? str.toLowerCase() : null;
65
+ }
66
+ var BlockType;
67
+ (function (BlockType) {
68
+ BlockType[BlockType["BRACE"] = 0] = "BRACE";
69
+ BlockType[BlockType["BRACKET"] = 1] = "BRACKET";
70
+ BlockType[BlockType["PAREN"] = 2] = "PAREN";
71
+ BlockType[BlockType["STATEMENT"] = 3] = "STATEMENT";
72
+ })(BlockType = exports.BlockType || (exports.BlockType = {}));
73
+ var TokenType;
74
+ (function (TokenType) {
75
+ TokenType[TokenType["WHITESPACE"] = 0] = "WHITESPACE";
76
+ TokenType[TokenType["TYPE_INT"] = 1] = "TYPE_INT";
77
+ TokenType[TokenType["TYPE_UINT"] = 2] = "TYPE_UINT";
78
+ TokenType[TokenType["TYPE_FLOAT"] = 3] = "TYPE_FLOAT";
79
+ TokenType[TokenType["TYPE_STRING"] = 4] = "TYPE_STRING";
80
+ TokenType[TokenType["RETURN"] = 5] = "RETURN";
81
+ TokenType[TokenType["NOT"] = 6] = "NOT";
82
+ TokenType[TokenType["OF"] = 7] = "OF";
83
+ TokenType[TokenType["IN"] = 8] = "IN";
84
+ TokenType[TokenType["FOR"] = 9] = "FOR";
85
+ TokenType[TokenType["IF"] = 10] = "IF";
86
+ TokenType[TokenType["ELSE_IF"] = 11] = "ELSE_IF";
87
+ TokenType[TokenType["ELSE"] = 12] = "ELSE";
88
+ TokenType[TokenType["NAME"] = 13] = "NAME";
89
+ TokenType[TokenType["L_BRACE"] = 14] = "L_BRACE";
90
+ TokenType[TokenType["R_BRACE"] = 15] = "R_BRACE";
91
+ TokenType[TokenType["L_BRACKET"] = 16] = "L_BRACKET";
92
+ TokenType[TokenType["R_BRACKET"] = 17] = "R_BRACKET";
93
+ TokenType[TokenType["L_PAREN"] = 18] = "L_PAREN";
94
+ TokenType[TokenType["R_PAREN"] = 19] = "R_PAREN";
95
+ TokenType[TokenType["TILDE"] = 20] = "TILDE";
96
+ TokenType[TokenType["PERIOD"] = 21] = "PERIOD";
97
+ TokenType[TokenType["COMMA"] = 22] = "COMMA";
98
+ TokenType[TokenType["COLON"] = 23] = "COLON";
99
+ TokenType[TokenType["SEMI_COLON"] = 24] = "SEMI_COLON";
100
+ TokenType[TokenType["STRING_LITERAL"] = 25] = "STRING_LITERAL";
101
+ TokenType[TokenType["NUMBER_LITERAL"] = 26] = "NUMBER_LITERAL";
102
+ TokenType[TokenType["BOOLEAN_LITERAL"] = 27] = "BOOLEAN_LITERAL";
103
+ TokenType[TokenType["NULL_LITERAL"] = 28] = "NULL_LITERAL";
104
+ TokenType[TokenType["STRICT_EQUALS"] = 29] = "STRICT_EQUALS";
105
+ TokenType[TokenType["STRICT_NOT_EQUALS"] = 30] = "STRICT_NOT_EQUALS";
106
+ TokenType[TokenType["EQUALS"] = 31] = "EQUALS";
107
+ TokenType[TokenType["NOT_EQUALS"] = 32] = "NOT_EQUALS";
108
+ TokenType[TokenType["GREATER_THAN_EQUAL"] = 33] = "GREATER_THAN_EQUAL";
109
+ TokenType[TokenType["LESS_THAN_EQUAL"] = 34] = "LESS_THAN_EQUAL";
110
+ TokenType[TokenType["GREATER_THAN"] = 35] = "GREATER_THAN";
111
+ TokenType[TokenType["LESS_THAN"] = 36] = "LESS_THAN";
112
+ TokenType[TokenType["ASSIGN"] = 37] = "ASSIGN";
113
+ TokenType[TokenType["AND"] = 38] = "AND";
114
+ TokenType[TokenType["OR"] = 39] = "OR";
115
+ TokenType[TokenType["ADD"] = 40] = "ADD";
116
+ TokenType[TokenType["SUBTRACT"] = 41] = "SUBTRACT";
117
+ TokenType[TokenType["MULTIPLY"] = 42] = "MULTIPLY";
118
+ TokenType[TokenType["DIVIDE"] = 43] = "DIVIDE";
119
+ TokenType[TokenType["ADD_ASSIGN"] = 44] = "ADD_ASSIGN";
120
+ TokenType[TokenType["SUBTRACT_ASSIGN"] = 45] = "SUBTRACT_ASSIGN";
121
+ TokenType[TokenType["MULTIPLY_ASSIGN"] = 46] = "MULTIPLY_ASSIGN";
122
+ TokenType[TokenType["DIVIDE_ASSIGN"] = 47] = "DIVIDE_ASSIGN";
123
+ TokenType[TokenType["EXCLAMATION_POINT"] = 48] = "EXCLAMATION_POINT";
124
+ TokenType[TokenType["ELEMENT_REFERENCE"] = 49] = "ELEMENT_REFERENCE";
125
+ TokenType[TokenType["ELEMENT_ATTRIBUTE"] = 50] = "ELEMENT_ATTRIBUTE";
126
+ TokenType[TokenType["ELEMENT_STYLE"] = 51] = "ELEMENT_STYLE";
127
+ TokenType[TokenType["ELEMENT_QUERY"] = 52] = "ELEMENT_QUERY";
128
+ TokenType[TokenType["UNIT"] = 53] = "UNIT";
129
+ })(TokenType = exports.TokenType || (exports.TokenType = {}));
130
+ var TOKEN_PATTERNS = [
131
+ {
132
+ type: TokenType.WHITESPACE,
133
+ pattern: /^[\s\n\r]+/
134
+ },
135
+ {
136
+ type: TokenType.TYPE_INT,
137
+ pattern: /^int+/
138
+ },
139
+ {
140
+ type: TokenType.TYPE_UINT,
141
+ pattern: /^uint+/
142
+ },
143
+ {
144
+ type: TokenType.TYPE_FLOAT,
145
+ pattern: /^float+/
146
+ },
147
+ {
148
+ type: TokenType.UNIT,
149
+ pattern: /^\d+\.?\d?(?:cm|mm|in|px|pt|pc|em|ex|ch|rem|vw|vh|vmin|vmax|%)/
150
+ },
151
+ {
152
+ type: TokenType.TYPE_STRING,
153
+ pattern: /^string+/
154
+ },
155
+ {
156
+ type: TokenType.BOOLEAN_LITERAL,
157
+ pattern: /^(true|false)/
158
+ },
159
+ {
160
+ type: TokenType.NULL_LITERAL,
161
+ pattern: /^null/
162
+ },
163
+ {
164
+ type: TokenType.RETURN,
165
+ pattern: /^return\s/
166
+ },
167
+ {
168
+ type: TokenType.NOT,
169
+ pattern: /^not\s/
170
+ },
171
+ {
172
+ type: TokenType.OF,
173
+ pattern: /^of\s/
174
+ },
175
+ {
176
+ type: TokenType.IN,
177
+ pattern: /^in\s/
178
+ },
179
+ {
180
+ type: TokenType.FOR,
181
+ pattern: /^for\s?(?=\()/
182
+ },
183
+ {
184
+ type: TokenType.IF,
185
+ pattern: /^if\s?(?=\()/
186
+ },
187
+ {
188
+ type: TokenType.ELSE_IF,
189
+ pattern: /^else if\s?(?=\()/
190
+ },
191
+ {
192
+ type: TokenType.ELSE,
193
+ pattern: /^else\s?(?=\{)/
194
+ },
195
+ {
196
+ type: TokenType.ELEMENT_ATTRIBUTE,
197
+ pattern: /^\.?@[-_a-zA-Z0-9]*/
198
+ },
199
+ {
200
+ type: TokenType.ELEMENT_STYLE,
201
+ pattern: /^\.?\$[-a-zA-Z0-9]*/
202
+ },
203
+ {
204
+ type: TokenType.ELEMENT_REFERENCE,
205
+ pattern: /^#[-_a-zA-Z0-9]*/
206
+ },
207
+ {
208
+ type: TokenType.ELEMENT_QUERY,
209
+ pattern: /^\?\(([#.\[\]:,=\-_a-zA-Z0-9*\s]*[\]_a-zA-Z0-9*])\)/
210
+ },
211
+ {
212
+ type: TokenType.NAME,
213
+ pattern: /^[_a-zA-Z][_a-zA-Z0-9]*/
214
+ },
215
+ {
216
+ type: TokenType.NUMBER_LITERAL,
217
+ pattern: /^-?\d+(?:\.\d+)?(?:e[+\-]?\d+)?/i
218
+ },
219
+ {
220
+ type: TokenType.L_BRACE,
221
+ pattern: /^{/
222
+ },
223
+ {
224
+ type: TokenType.R_BRACE,
225
+ pattern: /^}/
226
+ },
227
+ {
228
+ type: TokenType.L_BRACKET,
229
+ pattern: /^\[/
230
+ },
231
+ {
232
+ type: TokenType.R_BRACKET,
233
+ pattern: /^]/
234
+ },
235
+ {
236
+ type: TokenType.L_PAREN,
237
+ pattern: /^\(/
238
+ },
239
+ {
240
+ type: TokenType.R_PAREN,
241
+ pattern: /^\)/
242
+ },
243
+ {
244
+ type: TokenType.TILDE,
245
+ pattern: /^~/
246
+ },
247
+ {
248
+ type: TokenType.PERIOD,
249
+ pattern: /^\./
250
+ },
251
+ {
252
+ type: TokenType.COMMA,
253
+ pattern: /^,/
254
+ },
255
+ {
256
+ type: TokenType.EQUALS,
257
+ pattern: /^==/
258
+ },
259
+ {
260
+ type: TokenType.NOT_EQUALS,
261
+ pattern: /^!=/
262
+ },
263
+ {
264
+ type: TokenType.GREATER_THAN,
265
+ pattern: /^>/
266
+ },
267
+ {
268
+ type: TokenType.LESS_THAN,
269
+ pattern: /^</
270
+ },
271
+ {
272
+ type: TokenType.GREATER_THAN_EQUAL,
273
+ pattern: /^>=/
274
+ },
275
+ {
276
+ type: TokenType.LESS_THAN_EQUAL,
277
+ pattern: /^<=/
278
+ },
279
+ {
280
+ type: TokenType.COLON,
281
+ pattern: /^:/
282
+ },
283
+ {
284
+ type: TokenType.SEMI_COLON,
285
+ pattern: /^;/
286
+ },
287
+ {
288
+ type: TokenType.STRING_LITERAL,
289
+ pattern: /^"([^"]*)"/
290
+ },
291
+ {
292
+ type: TokenType.STRING_LITERAL,
293
+ pattern: /^'([^']*)'/ // Try to make this work: /^(?<!\\)(?:\\\\)*"([^(?<!\\)(?:\\\\)*"]*)(?<!\\)(?:\\\\)*"/
294
+ },
295
+ {
296
+ type: TokenType.AND,
297
+ pattern: /^&&/
298
+ },
299
+ {
300
+ type: TokenType.OR,
301
+ pattern: /^\|\|/
302
+ },
303
+ {
304
+ type: TokenType.ADD_ASSIGN,
305
+ pattern: /^\+=/
306
+ },
307
+ {
308
+ type: TokenType.SUBTRACT_ASSIGN,
309
+ pattern: /^-=/
310
+ },
311
+ {
312
+ type: TokenType.MULTIPLY_ASSIGN,
313
+ pattern: /^\*=/
314
+ },
315
+ {
316
+ type: TokenType.DIVIDE_ASSIGN,
317
+ pattern: /^\/=/
318
+ },
319
+ {
320
+ type: TokenType.ADD,
321
+ pattern: /^\+/
322
+ },
323
+ {
324
+ type: TokenType.SUBTRACT,
325
+ pattern: /^-/
326
+ },
327
+ {
328
+ type: TokenType.MULTIPLY,
329
+ pattern: /^\*/
330
+ },
331
+ {
332
+ type: TokenType.DIVIDE,
333
+ pattern: /^\//
334
+ },
335
+ {
336
+ type: TokenType.ASSIGN,
337
+ pattern: /^=/
338
+ },
339
+ {
340
+ type: TokenType.EXCLAMATION_POINT,
341
+ pattern: /^!/
342
+ }
343
+ ];
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
+ exports.AttributableNodes = [
1776
+ RootScopeMemberNode,
1777
+ ScopeMemberNode,
1778
+ ElementAttributeNode
1779
+ ];
1780
+ var Tree = /** @class */ (function () {
1781
+ function Tree(code) {
1782
+ this.code = code;
1783
+ if (Tree.cache[code]) {
1784
+ this.rootNode = Tree.cache[code];
1785
+ }
1786
+ else {
1787
+ this.parse();
1788
+ Tree.cache[code] = this.rootNode;
1789
+ }
1790
+ }
1791
+ Tree.prototype.parse = function () {
1792
+ var tokens = Tree.tokenize(this.code);
1793
+ this.rootNode = Tree.processTokens(tokens);
1794
+ };
1795
+ Tree.prototype.evaluate = function (scope, dom, tag) {
1796
+ if (tag === void 0) { tag = null; }
1797
+ return __awaiter(this, void 0, void 0, function () {
1798
+ return __generator(this, function (_a) {
1799
+ switch (_a.label) {
1800
+ case 0: return [4 /*yield*/, this.rootNode.evaluate(scope, dom, tag)];
1801
+ case 1: return [2 /*return*/, _a.sent()];
1802
+ }
1803
+ });
1804
+ });
1805
+ };
1806
+ Tree.prototype.prepare = function (scope, dom, tag) {
1807
+ if (tag === void 0) { tag = null; }
1808
+ return __awaiter(this, void 0, void 0, function () {
1809
+ return __generator(this, function (_a) {
1810
+ switch (_a.label) {
1811
+ case 0:
1812
+ if (!this.rootNode.isPreparationRequired())
1813
+ return [2 /*return*/];
1814
+ return [4 /*yield*/, this.rootNode.prepare(scope, dom, tag)];
1815
+ case 1: return [2 /*return*/, _a.sent()];
1816
+ }
1817
+ });
1818
+ });
1819
+ };
1820
+ Tree.prototype.bindToScopeChanges = function (scope, fnc, dom, tag) {
1821
+ if (tag === void 0) { tag = null; }
1822
+ return __awaiter(this, void 0, void 0, function () {
1823
+ var _i, _a, node, _scope, name_2;
1824
+ return __generator(this, function (_b) {
1825
+ switch (_b.label) {
1826
+ case 0:
1827
+ _i = 0, _a = this.rootNode.findChildrenByTypes([RootScopeMemberNode, ScopeMemberNode, ElementAttributeNode], 'ScopeMemberNodes');
1828
+ _b.label = 1;
1829
+ case 1:
1830
+ if (!(_i < _a.length)) return [3 /*break*/, 8];
1831
+ node = _a[_i];
1832
+ _scope = scope;
1833
+ if (!(node instanceof ScopeMemberNode)) return [3 /*break*/, 3];
1834
+ return [4 /*yield*/, node.scope.evaluate(scope, dom)];
1835
+ case 2:
1836
+ _scope = _b.sent();
1837
+ return [3 /*break*/, 5];
1838
+ case 3:
1839
+ if (!(node instanceof ElementAttributeNode && node.elementRef)) return [3 /*break*/, 5];
1840
+ return [4 /*yield*/, node.elementRef.evaluate(scope, dom, tag)];
1841
+ case 4:
1842
+ _scope = (_b.sent())[0].scope;
1843
+ _b.label = 5;
1844
+ case 5: return [4 /*yield*/, node.name.evaluate(scope, dom, tag)];
1845
+ case 6:
1846
+ name_2 = _b.sent();
1847
+ _scope.on("change:" + name_2, fnc);
1848
+ _b.label = 7;
1849
+ case 7:
1850
+ _i++;
1851
+ return [3 /*break*/, 1];
1852
+ case 8: return [2 /*return*/];
1853
+ }
1854
+ });
1855
+ });
1856
+ };
1857
+ Tree.tokenize = function (code) {
1858
+ var tokens = [];
1859
+ if (!code || code.length === 0)
1860
+ return tokens;
1861
+ var foundToken;
1862
+ do {
1863
+ foundToken = false;
1864
+ for (var _i = 0, TOKEN_PATTERNS_1 = TOKEN_PATTERNS; _i < TOKEN_PATTERNS_1.length; _i++) {
1865
+ var tp = TOKEN_PATTERNS_1[_i];
1866
+ var match = tp.pattern.exec(code);
1867
+ if (match) {
1868
+ tokens.push({
1869
+ type: tp.type,
1870
+ value: match[match.length - 1]
1871
+ });
1872
+ code = code.substring(match[0].length);
1873
+ foundToken = true;
1874
+ break;
1875
+ }
1876
+ }
1877
+ } while (code.length > 0 && foundToken);
1878
+ return tokens;
1879
+ };
1880
+ Tree.stripWhiteSpace = function (tokens) {
1881
+ for (var i = 0; i < tokens.length; i++) {
1882
+ if (tokens[i].type === TokenType.WHITESPACE) {
1883
+ tokens.splice(i, 1);
1884
+ i--;
1885
+ }
1886
+ }
1887
+ return tokens;
1888
+ };
1889
+ Tree.processTokens = function (tokens) {
1890
+ var blockNodes = [];
1891
+ var node = null;
1892
+ var count = 0;
1893
+ Tree.stripWhiteSpace(tokens);
1894
+ while (tokens.length > 0) {
1895
+ count++;
1896
+ if (count > 1000)
1897
+ break; // Limit to 1000 iterations while in development
1898
+ if (tokens[0].type === TokenType.RETURN)
1899
+ tokens.splice(0, 1);
1900
+ var token = tokens[0];
1901
+ if (token.type === TokenType.NAME) {
1902
+ node = new RootScopeMemberNode(new LiteralNode(token.value));
1903
+ tokens.splice(0, 1);
1904
+ }
1905
+ else if (token.type === TokenType.IF) {
1906
+ node = IfStatementNode.parse(node, token, tokens);
1907
+ blockNodes.push(node);
1908
+ node = null;
1909
+ }
1910
+ else if (token.type === TokenType.FOR) {
1911
+ node = ForStatementNode.parse(node, token, tokens);
1912
+ blockNodes.push(node);
1913
+ node = null;
1914
+ }
1915
+ else if (token.type === TokenType.STRING_LITERAL) {
1916
+ node = new LiteralNode(token.value);
1917
+ tokens.splice(0, 1);
1918
+ }
1919
+ else if (token.type === TokenType.NUMBER_LITERAL) {
1920
+ node = new NumberLiteralNode(token.value);
1921
+ tokens.splice(0, 1);
1922
+ }
1923
+ else if (tokens[0].type === TokenType.ELEMENT_REFERENCE) {
1924
+ node = new ElementQueryNode(tokens[0].value);
1925
+ tokens.splice(0, 1);
1926
+ }
1927
+ else if (tokens[0].type === TokenType.ELEMENT_QUERY) {
1928
+ node = new ElementQueryNode(tokens[0].value);
1929
+ tokens.splice(0, 1);
1930
+ }
1931
+ else if (tokens[0].type === TokenType.L_BRACKET) {
1932
+ if (node) {
1933
+ node = IndexNode.parse(node, token, tokens);
1934
+ }
1935
+ else {
1936
+ node = ArrayNode.parse(node, token, tokens);
1937
+ }
1938
+ }
1939
+ else if (tokens[0].type === TokenType.L_BRACE) {
1940
+ node = ObjectNode.parse(node, token, tokens);
1941
+ }
1942
+ else if (tokens[0].type === TokenType.ELEMENT_ATTRIBUTE) {
1943
+ node = new ElementAttributeNode(node, tokens[0].value);
1944
+ tokens.splice(0, 1);
1945
+ }
1946
+ else if (tokens[0].type === TokenType.ELEMENT_STYLE) {
1947
+ node = new ElementStyleNode(node, tokens[0].value);
1948
+ tokens.splice(0, 1);
1949
+ }
1950
+ else if (node !== null && token.type === TokenType.PERIOD && tokens[1].type === TokenType.NAME) {
1951
+ node = new ScopeMemberNode(node, new LiteralNode(tokens[1].value));
1952
+ tokens.splice(0, 2);
1953
+ }
1954
+ else if (tokens[0].type === TokenType.L_PAREN) {
1955
+ var funcArgs = Tree.getBlockTokens(tokens);
1956
+ var nodes = [];
1957
+ for (var _i = 0, funcArgs_1 = funcArgs; _i < funcArgs_1.length; _i++) {
1958
+ var arg = funcArgs_1[_i];
1959
+ nodes.push(Tree.processTokens(arg));
1960
+ }
1961
+ if (node) {
1962
+ node = new FunctionCallNode(node, // Previous node should be a NAME
1963
+ new FunctionArgumentNode(nodes));
1964
+ }
1965
+ else {
1966
+ node = new BlockNode(nodes);
1967
+ }
1968
+ }
1969
+ else if (tokens[0].type === TokenType.SEMI_COLON) {
1970
+ if (node) {
1971
+ blockNodes.push(node);
1972
+ }
1973
+ node = null;
1974
+ tokens.splice(0, 1);
1975
+ }
1976
+ else if (InNode.match(tokens)) {
1977
+ node = InNode.parse(node, token, tokens);
1978
+ }
1979
+ else if (ComparisonNode.match(tokens)) {
1980
+ node = ComparisonNode.parse(node, token, tokens);
1981
+ }
1982
+ else if (ArithmeticNode.match(tokens)) {
1983
+ node = ArithmeticNode.parse(node, token, tokens);
1984
+ }
1985
+ else if (ArithmeticAssignmentNode.match(tokens)) {
1986
+ node = ArithmeticAssignmentNode.parse(node, token, tokens);
1987
+ }
1988
+ else if (tokens[0].type === TokenType.WHITESPACE) {
1989
+ tokens.splice(0, 1);
1990
+ }
1991
+ else if (tokens[0].type === TokenType.UNIT) {
1992
+ node = new UnitLiteralNode(tokens[0].value);
1993
+ tokens.splice(0, 1);
1994
+ }
1995
+ else if (tokens[0].type === TokenType.BOOLEAN_LITERAL) {
1996
+ node = new BooleanLiteralNode(tokens[0].value);
1997
+ tokens.splice(0, 1);
1998
+ }
1999
+ else if (tokens[0].type === TokenType.NULL_LITERAL) {
2000
+ node = new LiteralNode(null);
2001
+ tokens.splice(0, 1);
2002
+ }
2003
+ else if (tokens[0].type === TokenType.EXCLAMATION_POINT) {
2004
+ node = NotNode.parse(node, tokens[0], tokens);
2005
+ }
2006
+ else {
2007
+ var code = Tree.toCode(tokens, 10);
2008
+ throw Error("Syntax Error. Near " + code);
2009
+ }
2010
+ }
2011
+ if (node) {
2012
+ blockNodes.push(node);
2013
+ }
2014
+ return new BlockNode(blockNodes);
2015
+ };
2016
+ Tree.toCode = function (tokens, limit) {
2017
+ var code = '';
2018
+ limit = limit || tokens.length;
2019
+ for (var i = 0; i < limit; i++) {
2020
+ if (!tokens[i])
2021
+ break;
2022
+ code += tokens[i].value;
2023
+ }
2024
+ return code;
2025
+ };
2026
+ Tree.getBlockInfo = function (tokens) {
2027
+ var blockType;
2028
+ var opener = tokens[0];
2029
+ if (opener.type === TokenType.L_PAREN)
2030
+ blockType = BlockType.PAREN;
2031
+ else if (opener.type === TokenType.L_BRACE)
2032
+ blockType = BlockType.BRACE;
2033
+ else if (opener.type === TokenType.L_BRACKET)
2034
+ blockType = BlockType.BRACKET;
2035
+ else
2036
+ blockType = BlockType.STATEMENT;
2037
+ var open;
2038
+ var close;
2039
+ var openCharacter;
2040
+ var closeCharacter;
2041
+ switch (blockType) {
2042
+ case BlockType.PAREN:
2043
+ open = TokenType.L_PAREN;
2044
+ close = TokenType.R_PAREN;
2045
+ openCharacter = '(';
2046
+ closeCharacter = ')';
2047
+ break;
2048
+ case BlockType.BRACE:
2049
+ open = TokenType.L_BRACE;
2050
+ close = TokenType.R_BRACE;
2051
+ openCharacter = '{';
2052
+ closeCharacter = '}';
2053
+ break;
2054
+ case BlockType.BRACKET:
2055
+ open = TokenType.L_BRACKET;
2056
+ close = TokenType.R_BRACKET;
2057
+ openCharacter = '[';
2058
+ closeCharacter = ']';
2059
+ break;
2060
+ default:
2061
+ open = null;
2062
+ close = TokenType.SEMI_COLON;
2063
+ openCharacter = null;
2064
+ closeCharacter = ';';
2065
+ break;
2066
+ }
2067
+ return {
2068
+ type: blockType,
2069
+ open: open,
2070
+ close: close,
2071
+ openCharacter: openCharacter,
2072
+ closeCharacter: closeCharacter
2073
+ };
2074
+ };
2075
+ Tree.getNextStatementTokens = function (tokens, consumeClosingToken, consumeOpeningToken, includeClosingToken) {
2076
+ if (consumeClosingToken === void 0) { consumeClosingToken = true; }
2077
+ if (consumeOpeningToken === void 0) { consumeOpeningToken = true; }
2078
+ if (includeClosingToken === void 0) { includeClosingToken = false; }
2079
+ var blockInfo = Tree.getBlockInfo(tokens);
2080
+ // Consume opening block token
2081
+ if (consumeOpeningToken && tokens[0].type === blockInfo.open) {
2082
+ tokens.splice(0, 1);
2083
+ }
2084
+ return Tree.getTokensUntil(tokens, blockInfo.close, consumeClosingToken, includeClosingToken);
2085
+ };
2086
+ Tree.getBlockTokens = function (tokens, groupBy) {
2087
+ if (groupBy === void 0) { groupBy = TokenType.COMMA; }
2088
+ var blockInfo = Tree.getBlockInfo(tokens);
2089
+ var openBlocks = 0;
2090
+ var args = [];
2091
+ var arg = [];
2092
+ for (var i = 0; i < tokens.length; i++) {
2093
+ var token = tokens[i];
2094
+ if (token.type === blockInfo.open) {
2095
+ openBlocks += 1;
2096
+ if (openBlocks > 1)
2097
+ arg.push(token);
2098
+ }
2099
+ else if (token.type === blockInfo.close) {
2100
+ openBlocks -= 1;
2101
+ if (openBlocks > 0)
2102
+ arg.push(token);
2103
+ }
2104
+ else if (groupBy !== null && token.type === groupBy && openBlocks == 1) {
2105
+ args.push(arg);
2106
+ arg = [];
2107
+ }
2108
+ else if (token.type !== TokenType.WHITESPACE) {
2109
+ arg.push(token);
2110
+ }
2111
+ // Consume token
2112
+ tokens.splice(0, 1);
2113
+ i--;
2114
+ if (openBlocks === 0) {
2115
+ if (arg.length > 0)
2116
+ args.push(arg);
2117
+ return args;
2118
+ }
2119
+ }
2120
+ throw Error("Invalid Syntax, missing " + blockInfo.closeCharacter);
2121
+ };
2122
+ Tree.getTokensUntil = function (tokens, terminator, consumeTerminator, includeTerminator, validIfTerminatorNotFound, blockInfo) {
2123
+ if (terminator === void 0) { terminator = TokenType.SEMI_COLON; }
2124
+ if (consumeTerminator === void 0) { consumeTerminator = true; }
2125
+ if (includeTerminator === void 0) { includeTerminator = false; }
2126
+ if (validIfTerminatorNotFound === void 0) { validIfTerminatorNotFound = false; }
2127
+ if (blockInfo === void 0) { blockInfo = null; }
2128
+ var statementTokens = [];
2129
+ blockInfo = blockInfo || Tree.getBlockInfo(tokens);
2130
+ var openParens = 0;
2131
+ var openBraces = 0;
2132
+ var openBrackets = 0;
2133
+ for (var i = 0; i < tokens.length; i++) {
2134
+ var token = tokens[i];
2135
+ if (!(token.type === blockInfo.open && i === 0)) { // Skip opener
2136
+ if (token.type === TokenType.L_PAREN)
2137
+ openParens += 1;
2138
+ if (token.type === TokenType.L_BRACE)
2139
+ openBraces += 1;
2140
+ if (token.type === TokenType.L_BRACKET)
2141
+ openBrackets += 1;
2142
+ }
2143
+ if ([
2144
+ terminator,
2145
+ TokenType.R_BRACKET,
2146
+ TokenType.R_BRACE,
2147
+ TokenType.R_PAREN
2148
+ ].indexOf(token.type) > -1) {
2149
+ if (openParens > 0 && token.type === TokenType.R_PAREN) {
2150
+ openParens -= 1;
2151
+ }
2152
+ else if (openBraces > 0 && token.type === TokenType.R_BRACE) {
2153
+ openBraces -= 1;
2154
+ }
2155
+ else if (openBrackets > 0 && token.type === TokenType.R_BRACKET) {
2156
+ openBrackets -= 1;
2157
+ }
2158
+ else if (token.type === terminator && openParens === 0 && openBraces === 0 && openBrackets === 0) {
2159
+ if (includeTerminator)
2160
+ statementTokens.push(token);
2161
+ if ((includeTerminator || consumeTerminator) && token.type !== TokenType.SEMI_COLON)
2162
+ tokens.splice(0, 1); // Consume end of block
2163
+ break;
2164
+ }
2165
+ else if (token.type === terminator && (openParens > 0 || openBraces > 0 || openBrackets > 0)) {
2166
+ }
2167
+ else {
2168
+ if (validIfTerminatorNotFound)
2169
+ break;
2170
+ throw Error("Invalid syntax, expecting " + terminator + ".");
2171
+ }
2172
+ }
2173
+ statementTokens.push(token);
2174
+ tokens.splice(0, 1); // Consume part of statement
2175
+ i--;
2176
+ }
2177
+ return statementTokens;
2178
+ };
2179
+ Tree.consumeTypes = function (tokens, types) {
2180
+ var matching = [];
2181
+ for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
2182
+ var token = tokens_1[_i];
2183
+ if (types.indexOf(token.type) > -1) {
2184
+ matching.push(token);
2185
+ }
2186
+ else {
2187
+ break;
2188
+ }
2189
+ }
2190
+ tokens.splice(0, matching.length);
2191
+ return matching;
2192
+ };
2193
+ Tree.cache = {};
2194
+ return Tree;
2195
+ }());
2196
+ exports.Tree = Tree;
2197
+ //# sourceMappingURL=AST.js.map