@ibyar/expressions 0.5.2 → 0.5.62

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 (186) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -3
  3. package/api/abstract.d.ts +5 -6
  4. package/api/abstract.js +8 -3
  5. package/api/abstract.js.map +1 -1
  6. package/api/class/class.d.ts +227 -0
  7. package/api/class/class.js +662 -0
  8. package/api/class/class.js.map +1 -0
  9. package/api/class/decorator.d.ts +20 -0
  10. package/api/class/decorator.js +48 -0
  11. package/api/class/decorator.js.map +1 -0
  12. package/api/computing/call.d.ts +3 -1
  13. package/api/computing/call.js +16 -4
  14. package/api/computing/call.js.map +1 -1
  15. package/api/computing/debugger.d.ts +15 -0
  16. package/api/computing/debugger.js +35 -0
  17. package/api/computing/debugger.js.map +1 -0
  18. package/api/computing/new.d.ts +2 -1
  19. package/api/computing/new.js +4 -0
  20. package/api/computing/new.js.map +1 -1
  21. package/api/computing/rest.d.ts +6 -6
  22. package/api/computing/rest.js +5 -2
  23. package/api/computing/rest.js.map +1 -1
  24. package/api/computing/return.d.ts +6 -1
  25. package/api/computing/return.js +8 -0
  26. package/api/computing/return.js.map +1 -1
  27. package/api/computing/spread.d.ts +2 -1
  28. package/api/computing/spread.js +5 -2
  29. package/api/computing/spread.js.map +1 -1
  30. package/api/computing/throw.d.ts +6 -1
  31. package/api/computing/throw.js +7 -0
  32. package/api/computing/throw.js.map +1 -1
  33. package/api/computing/yield.d.ts +2 -1
  34. package/api/computing/yield.js +3 -0
  35. package/api/computing/yield.js.map +1 -1
  36. package/api/definition/array.d.ts +12 -12
  37. package/api/definition/array.js +31 -25
  38. package/api/definition/array.js.map +1 -1
  39. package/api/definition/bind.d.ts +8 -2
  40. package/api/definition/bind.js +7 -1
  41. package/api/definition/bind.js.map +1 -1
  42. package/api/definition/function.d.ts +40 -51
  43. package/api/definition/function.js +292 -309
  44. package/api/definition/function.js.map +1 -1
  45. package/api/definition/member.d.ts +2 -2
  46. package/api/definition/member.js +1 -1
  47. package/api/definition/member.js.map +1 -1
  48. package/api/definition/object.d.ts +15 -12
  49. package/api/definition/object.js +43 -13
  50. package/api/definition/object.js.map +1 -1
  51. package/api/definition/statement.d.ts +2 -2
  52. package/api/definition/statement.js +7 -3
  53. package/api/definition/statement.js.map +1 -1
  54. package/api/definition/values.d.ts +44 -50
  55. package/api/definition/values.js +87 -149
  56. package/api/definition/values.js.map +1 -1
  57. package/api/deserialize/deserialize.d.ts +7 -1
  58. package/api/deserialize/deserialize.js +9 -1
  59. package/api/deserialize/deserialize.js.map +1 -1
  60. package/api/deserialize/type-store.d.ts +2 -2
  61. package/api/deserialize/type-store.js.map +1 -1
  62. package/api/expression.d.ts +159 -18
  63. package/api/expression.js.map +1 -1
  64. package/api/index.d.ts +2 -0
  65. package/api/index.js +2 -0
  66. package/api/index.js.map +1 -1
  67. package/api/module/common.d.ts +29 -0
  68. package/api/module/common.js +71 -0
  69. package/api/module/common.js.map +1 -0
  70. package/api/module/export.d.ts +129 -25
  71. package/api/module/export.js +333 -58
  72. package/api/module/export.js.map +1 -1
  73. package/api/module/import.d.ts +114 -25
  74. package/api/module/import.js +279 -68
  75. package/api/module/import.js.map +1 -1
  76. package/api/operators/assignment.d.ts +2 -2
  77. package/api/operators/assignment.js +1 -1
  78. package/api/operators/assignment.js.map +1 -1
  79. package/api/operators/await.d.ts +2 -2
  80. package/api/operators/await.js +1 -1
  81. package/api/operators/await.js.map +1 -1
  82. package/api/operators/binary.d.ts +2 -2
  83. package/api/operators/binary.js +1 -1
  84. package/api/operators/binary.js.map +1 -1
  85. package/api/operators/chaining.d.ts +2 -2
  86. package/api/operators/chaining.js +1 -1
  87. package/api/operators/chaining.js.map +1 -1
  88. package/api/operators/comma.d.ts +2 -2
  89. package/api/operators/comma.js +2 -2
  90. package/api/operators/comma.js.map +1 -1
  91. package/api/operators/grouping.d.ts +9 -2
  92. package/api/operators/grouping.js +8 -1
  93. package/api/operators/grouping.js.map +1 -1
  94. package/api/operators/logical.d.ts +2 -2
  95. package/api/operators/logical.js +1 -1
  96. package/api/operators/logical.js.map +1 -1
  97. package/api/operators/pipeline.d.ts +14 -2
  98. package/api/operators/pipeline.js +13 -1
  99. package/api/operators/pipeline.js.map +1 -1
  100. package/api/operators/ternary.d.ts +2 -2
  101. package/api/operators/ternary.js +1 -1
  102. package/api/operators/ternary.js.map +1 -1
  103. package/api/operators/unary.d.ts +3 -3
  104. package/api/operators/unary.js +7 -3
  105. package/api/operators/unary.js.map +1 -1
  106. package/api/operators/update.d.ts +2 -2
  107. package/api/operators/update.js +1 -1
  108. package/api/operators/update.js.map +1 -1
  109. package/api/{app/program.d.ts → program.d.ts} +8 -9
  110. package/api/program.js +45 -0
  111. package/api/program.js.map +1 -0
  112. package/api/statement/control/block.d.ts +8 -5
  113. package/api/statement/control/block.js +26 -23
  114. package/api/statement/control/block.js.map +1 -1
  115. package/api/statement/control/empty.d.ts +8 -1
  116. package/api/statement/control/empty.js +7 -0
  117. package/api/statement/control/empty.js.map +1 -1
  118. package/api/statement/control/if.d.ts +7 -2
  119. package/api/statement/control/if.js +6 -1
  120. package/api/statement/control/if.js.map +1 -1
  121. package/api/statement/control/switch.d.ts +10 -5
  122. package/api/statement/control/switch.js +22 -9
  123. package/api/statement/control/switch.js.map +1 -1
  124. package/api/statement/control/terminate.d.ts +46 -13
  125. package/api/statement/control/terminate.js +89 -20
  126. package/api/statement/control/terminate.js.map +1 -1
  127. package/api/statement/declarations/declares.d.ts +17 -16
  128. package/api/statement/declarations/declares.js +24 -19
  129. package/api/statement/declarations/declares.js.map +1 -1
  130. package/api/statement/iterations/for.d.ts +10 -5
  131. package/api/statement/iterations/for.js +42 -23
  132. package/api/statement/iterations/for.js.map +1 -1
  133. package/api/statement/iterations/while.d.ts +9 -3
  134. package/api/statement/iterations/while.js +27 -13
  135. package/api/statement/iterations/while.js.map +1 -1
  136. package/api/utils.d.ts +5 -0
  137. package/api/utils.js +4 -0
  138. package/api/utils.js.map +1 -0
  139. package/package.json +5 -5
  140. package/scope/finalizer.d.ts +4 -0
  141. package/scope/finalizer.js +11 -0
  142. package/scope/finalizer.js.map +1 -0
  143. package/scope/proxy.d.ts +5 -3
  144. package/scope/proxy.js +26 -26
  145. package/scope/proxy.js.map +1 -1
  146. package/scope/scope.d.ts +108 -51
  147. package/scope/scope.js +72 -134
  148. package/scope/scope.js.map +1 -1
  149. package/scope/stack.d.ts +117 -26
  150. package/scope/stack.js +154 -102
  151. package/scope/stack.js.map +1 -1
  152. package/v8/enums.d.ts +204 -0
  153. package/v8/enums.js +406 -0
  154. package/v8/enums.js.map +1 -0
  155. package/v8/index.d.ts +2 -1
  156. package/v8/index.js +2 -1
  157. package/v8/index.js.map +1 -1
  158. package/v8/inline.d.ts +213 -0
  159. package/v8/inline.js +2375 -0
  160. package/v8/inline.js.map +1 -0
  161. package/v8/nodes.d.ts +8 -7
  162. package/v8/nodes.js +39 -64
  163. package/v8/nodes.js.map +1 -1
  164. package/v8/parser.d.ts +49 -151
  165. package/v8/parser.js +839 -1607
  166. package/v8/parser.js.map +1 -1
  167. package/v8/stream.d.ts +39 -3
  168. package/v8/stream.js +685 -171
  169. package/v8/stream.js.map +1 -1
  170. package/v8/token.d.ts +244 -9
  171. package/v8/token.js +315 -47
  172. package/v8/token.js.map +1 -1
  173. package/visit/visitor.d.ts +3 -0
  174. package/visit/visitor.js +4 -7
  175. package/visit/visitor.js.map +1 -1
  176. package/api/app/class.d.ts +0 -117
  177. package/api/app/class.js +0 -292
  178. package/api/app/class.js.map +0 -1
  179. package/api/app/program.js +0 -39
  180. package/api/app/program.js.map +0 -1
  181. package/api/module/module.d.ts +0 -26
  182. package/api/module/module.js +0 -63
  183. package/api/module/module.js.map +0 -1
  184. package/v8/app.d.ts +0 -0
  185. package/v8/app.js +0 -2
  186. package/v8/app.js.map +0 -1
@@ -0,0 +1,662 @@
1
+ var Super_1, MetaProperty_1, PrivateIdentifier_1, StaticBlock_1, MethodDefinition_1, PropertyDefinition_1, AccessorProperty_1, ClassBody_1, ClassDeclaration_1, ClassExpression_1;
2
+ import { __decorate as __decorate_1, __metadata } from "tslib";
3
+ import { __decorate } from 'tslib';
4
+ import { AbstractExpressionNode } from '../abstract.js';
5
+ import { Deserializer } from '../deserialize/deserialize.js';
6
+ import { Identifier } from '../definition/values.js';
7
+ import { MemberExpression } from '../definition/member.js';
8
+ import { FunctionExpression } from '../definition/function.js';
9
+ import { BlockStatement } from '../statement/control/block.js';
10
+ import { CallExpression } from '../computing/call.js';
11
+ const TEMP_CLASS_NAME = Symbol('TempClassName');
12
+ const SUPER = Symbol('Super');
13
+ const NEW_TARGET = Symbol('NewTarget');
14
+ const IMPORT_META = Symbol('ImportMeta');
15
+ const STACK = Symbol('Stack');
16
+ const GET_PARAMETERS = Symbol('GetParameters');
17
+ const GET_SUPER_PROPERTY = Symbol('GetSuperProperty');
18
+ const CALL_SUPER_Method = Symbol('CallSuperMethod');
19
+ const CONSTRUCTOR = Symbol('Constructor');
20
+ const PRIVATE_SYMBOL = Symbol('Private');
21
+ const INSTANCE_PRIVATE_SYMBOL = Symbol('InstancePrivate');
22
+ const STATIC_INITIALIZATION_BLOCK = Symbol('StaticBlock');
23
+ /**
24
+ * A `super` pseudo-expression.
25
+ */
26
+ let Super = Super_1 = class Super extends AbstractExpressionNode {
27
+ constructor() {
28
+ super();
29
+ }
30
+ static fromJSON(node) {
31
+ return Super_1.INSTANCE;
32
+ }
33
+ shareVariables(scopeList) { }
34
+ set(stack, value) {
35
+ throw new Error('Super.#set() Method not implemented.');
36
+ }
37
+ get(stack, thisContext) {
38
+ throw new Error('Super.#get() Method not implemented.');
39
+ }
40
+ dependency(computed) {
41
+ throw new Error('Super.#dependency() Method not implemented.');
42
+ }
43
+ dependencyPath(computed) {
44
+ throw new Error('Super.#dependencyPath() Method not implemented.');
45
+ }
46
+ toString() {
47
+ return `super`;
48
+ }
49
+ toJson() {
50
+ return {};
51
+ }
52
+ };
53
+ Super.INSTANCE = new Super_1();
54
+ Super = Super_1 = __decorate_1([
55
+ Deserializer('Super'),
56
+ __metadata("design:paramtypes", [])
57
+ ], Super);
58
+ export { Super };
59
+ /**
60
+ * MetaProperty node represents
61
+ * - `new.target` meta property in ES2015.
62
+ * - `import.meta` meta property in ES2030.
63
+ *
64
+ * In the future, it will represent other meta properties as well.
65
+ */
66
+ let MetaProperty = MetaProperty_1 = class MetaProperty extends MemberExpression {
67
+ constructor(meta, property) {
68
+ super(meta, property, false);
69
+ this.meta = meta;
70
+ }
71
+ static getJsonName(identifier) {
72
+ return Reflect.get(identifier, 'name');
73
+ }
74
+ static fromJSON(node, deserializer) {
75
+ if (MetaProperty_1.getJsonName(node.meta) === 'new' && MetaProperty_1.getJsonName(node.property) === 'target') {
76
+ return MetaProperty_1.NewTarget;
77
+ }
78
+ else if (MetaProperty_1.getJsonName(node.meta) === 'import' && MetaProperty_1.getJsonName(node.property) === 'meta') {
79
+ return MetaProperty_1.ImportMeta;
80
+ }
81
+ return new MetaProperty_1(deserializer(node.meta), deserializer(node.property));
82
+ }
83
+ static visit(node, visitNode) {
84
+ visitNode(node.meta);
85
+ visitNode(node.property);
86
+ }
87
+ getMeta() {
88
+ return this.meta;
89
+ }
90
+ shareVariables(scopeList) { }
91
+ get(stack, thisContext) {
92
+ if (MetaProperty_1.getJsonName(this.meta) === 'new' && MetaProperty_1.getJsonName(this.property) === 'target') {
93
+ return stack.get(NEW_TARGET);
94
+ }
95
+ else if (MetaProperty_1.getJsonName(this.meta) === 'import' && MetaProperty_1.getJsonName(this.property) === 'meta') {
96
+ const importObject = stack.getModule()?.get('import');
97
+ return importObject['meta'];
98
+ }
99
+ return super.get(stack, thisContext);
100
+ }
101
+ toString() {
102
+ return `${this.meta.toString()}.${this.property.toString()}`;
103
+ }
104
+ toJson() {
105
+ return {
106
+ meta: this.meta.toJSON(),
107
+ property: this.property.toJSON(),
108
+ };
109
+ }
110
+ };
111
+ MetaProperty.NewTarget = new MetaProperty_1(new Identifier('new'), new Identifier('target'));
112
+ MetaProperty.ImportMeta = new MetaProperty_1(new Identifier('import'), new Identifier('meta'));
113
+ MetaProperty = MetaProperty_1 = __decorate_1([
114
+ Deserializer('MetaProperty'),
115
+ __metadata("design:paramtypes", [Identifier, Identifier])
116
+ ], MetaProperty);
117
+ export { MetaProperty };
118
+ /**
119
+ * A private identifier refers to private class elements. For a private name `#a`, its name is `a`.
120
+ */
121
+ let PrivateIdentifier = PrivateIdentifier_1 = class PrivateIdentifier extends AbstractExpressionNode {
122
+ constructor(name) {
123
+ super();
124
+ this.name = name;
125
+ }
126
+ static fromJSON(node) {
127
+ return new PrivateIdentifier_1(node.name);
128
+ }
129
+ getName() {
130
+ return this.name;
131
+ }
132
+ set(stack, value) {
133
+ const privateScope = stack.findScope(PRIVATE_SYMBOL);
134
+ privateScope.getScope(PRIVATE_SYMBOL)?.set(this.name, value);
135
+ }
136
+ get(stack, thisContext) {
137
+ if (thisContext) {
138
+ return thisContext[PRIVATE_SYMBOL][this.name];
139
+ }
140
+ // return stack.get(this.name);
141
+ let privateObj = stack.get('this');
142
+ if (privateObj) {
143
+ return privateObj[PRIVATE_SYMBOL][this.name];
144
+ }
145
+ privateObj = stack.get(PRIVATE_SYMBOL);
146
+ return privateObj[this.name];
147
+ }
148
+ dependency(computed) {
149
+ return [];
150
+ }
151
+ dependencyPath(computed) {
152
+ return [];
153
+ }
154
+ shareVariables(scopeList) { }
155
+ toString() {
156
+ return `#${this.name}`;
157
+ }
158
+ toJson() {
159
+ return {
160
+ name: this.name
161
+ };
162
+ }
163
+ };
164
+ PrivateIdentifier = PrivateIdentifier_1 = __decorate_1([
165
+ Deserializer('PrivateIdentifier'),
166
+ __metadata("design:paramtypes", [String])
167
+ ], PrivateIdentifier);
168
+ export { PrivateIdentifier };
169
+ /**
170
+ * A static block static { } is a block statement serving as an additional static initializer.
171
+ */
172
+ let StaticBlock = StaticBlock_1 = class StaticBlock extends BlockStatement {
173
+ static fromJSON(node, deserializer) {
174
+ return new StaticBlock_1(deserializer(node.body));
175
+ }
176
+ constructor(body) {
177
+ super(body);
178
+ }
179
+ get(stack, classConstructor) {
180
+ const constructor = classConstructor;
181
+ constructor[STATIC_INITIALIZATION_BLOCK].push(() => super.get(stack));
182
+ }
183
+ toString() {
184
+ return `static ${super.toString()}`;
185
+ }
186
+ toJson() {
187
+ return {
188
+ body: this.body.map(node => node.toJSON())
189
+ };
190
+ }
191
+ };
192
+ StaticBlock = StaticBlock_1 = __decorate_1([
193
+ Deserializer('StaticBlock'),
194
+ __metadata("design:paramtypes", [Array])
195
+ ], StaticBlock);
196
+ export { StaticBlock };
197
+ export class AbstractDefinition extends AbstractExpressionNode {
198
+ constructor(key, decorators, computed, isStatic, value) {
199
+ super();
200
+ this.key = key;
201
+ this.decorators = decorators;
202
+ this.computed = computed;
203
+ this.value = value;
204
+ this.static = isStatic;
205
+ }
206
+ getKey() {
207
+ return this.key;
208
+ }
209
+ getValue() {
210
+ return this.value;
211
+ }
212
+ isComputed() {
213
+ return this.computed;
214
+ }
215
+ isStatic() {
216
+ return this.static;
217
+ }
218
+ getDecorators() {
219
+ return this.decorators;
220
+ }
221
+ shareVariables(scopeList) { }
222
+ set(stack, value) {
223
+ throw new Error('AbstractDefinition.#set() Method not implemented.');
224
+ }
225
+ dependency(computed) {
226
+ return [];
227
+ }
228
+ dependencyPath(computed) {
229
+ return [];
230
+ }
231
+ getTarget(classConstructor) {
232
+ return this.static
233
+ ? (this.key instanceof PrivateIdentifier ? classConstructor[PRIVATE_SYMBOL] : classConstructor)
234
+ : (this.key instanceof PrivateIdentifier ? classConstructor[INSTANCE_PRIVATE_SYMBOL] : classConstructor.prototype);
235
+ }
236
+ getKeyName(stack) {
237
+ switch (true) {
238
+ case this.computed: return this.key.get(stack);
239
+ case this.key instanceof Identifier:
240
+ case this.key instanceof PrivateIdentifier: return this.key.getName();
241
+ default: return this.key.toString();
242
+ }
243
+ }
244
+ }
245
+ /**
246
+ * - When key is a PrivateIdentifier, computed must be false and kind can not be "constructor".
247
+ */
248
+ let MethodDefinition = MethodDefinition_1 = class MethodDefinition extends AbstractDefinition {
249
+ constructor(kind, key, value, decorators, computed, isStatic) {
250
+ super(key, decorators, computed, isStatic, value);
251
+ this.kind = kind;
252
+ }
253
+ static fromJSON(node, deserializer) {
254
+ return new MethodDefinition_1(node.kind, deserializer(node.key), deserializer(node.value), node.decorators.map(deserializer), node.computed, node.static);
255
+ }
256
+ static visit(node, visitNode) {
257
+ visitNode(node.key);
258
+ visitNode(node.value);
259
+ node.decorators.forEach(visitNode);
260
+ }
261
+ getKind() {
262
+ return this.kind;
263
+ }
264
+ getValue() {
265
+ return this.value;
266
+ }
267
+ get(stack, classConstructor) {
268
+ if (this.kind === 'constructor') {
269
+ this.initConstructor(stack, classConstructor);
270
+ return;
271
+ }
272
+ const target = this.getTarget(classConstructor);
273
+ const name = this.getKeyName(stack);
274
+ const value = this.value?.get(stack);
275
+ switch (this.kind) {
276
+ case 'method':
277
+ target[name] = value;
278
+ break;
279
+ case 'set':
280
+ Object.defineProperty(target, name, {
281
+ configurable: true,
282
+ enumerable: false,
283
+ set: value,
284
+ });
285
+ break;
286
+ case 'get':
287
+ Object.defineProperty(target, name, {
288
+ configurable: true,
289
+ enumerable: false,
290
+ get: value,
291
+ });
292
+ break;
293
+ default:
294
+ break;
295
+ }
296
+ const decorators = this.decorators.map(decorator => decorator.get(stack));
297
+ decorators.length && __decorate(decorators, target, name, null);
298
+ }
299
+ initConstructor(stack, classConstructor) {
300
+ const body = this.value.getBody().getBody();
301
+ let superIndex = body
302
+ .findIndex(call => call instanceof CallExpression && Super.INSTANCE === call.getCallee());
303
+ if (superIndex === -1) {
304
+ superIndex = body.length;
305
+ }
306
+ const superCall = body[superIndex];
307
+ const blockBeforeSuper = new BlockStatement(body.slice(0, superIndex));
308
+ const blockAfterSuper = new BlockStatement(body.slice(superIndex + 1));
309
+ if (superCall) {
310
+ classConstructor[GET_PARAMETERS] = function (params) {
311
+ const scope = stack.pushBlockScope();
312
+ this.value.setParameter(stack, params);
313
+ blockBeforeSuper.get(stack);
314
+ const parameters = superCall.getCallParameters(stack);
315
+ stack.clearTo(scope);
316
+ return parameters;
317
+ };
318
+ }
319
+ classConstructor[CONSTRUCTOR] = function (params) {
320
+ const scope = this[STACK].pushBlockScope();
321
+ blockAfterSuper.get(this[STACK]);
322
+ stack.clearTo(scope);
323
+ };
324
+ }
325
+ toString() {
326
+ let str = this.decorators.map(decorator => decorator.toString()).join(' ');
327
+ if (str.length) {
328
+ str += ' ';
329
+ }
330
+ if (this.static) {
331
+ str += 'static ';
332
+ }
333
+ const methodName = this.key.toString();
334
+ switch (this.kind) {
335
+ case 'get':
336
+ str += 'get ' + methodName;
337
+ break;
338
+ case 'set':
339
+ str += 'set ' + methodName;
340
+ break;
341
+ case 'method':
342
+ if (this.value.getAsync() && this.value.getGenerator()) {
343
+ str += 'async *';
344
+ }
345
+ else if (this.value.getAsync()) {
346
+ str += 'async ';
347
+ }
348
+ else if (this.value.getGenerator()) {
349
+ str += '*';
350
+ }
351
+ str += methodName;
352
+ break;
353
+ case 'constructor':
354
+ str += 'constructor';
355
+ break;
356
+ default:
357
+ break;
358
+ }
359
+ str += this.value.paramsAndBodyToString();
360
+ return str;
361
+ }
362
+ toJson() {
363
+ return {
364
+ kind: this.kind,
365
+ key: this.key.toJSON(),
366
+ value: this.value.toJSON(),
367
+ decorators: this.decorators.map(decorator => decorator.toJSON()),
368
+ computed: this.computed,
369
+ static: this.static,
370
+ };
371
+ }
372
+ };
373
+ MethodDefinition = MethodDefinition_1 = __decorate_1([
374
+ Deserializer('MethodDefinition'),
375
+ __metadata("design:paramtypes", [String, Object, FunctionExpression, Array, Boolean, Boolean])
376
+ ], MethodDefinition);
377
+ export { MethodDefinition };
378
+ /**
379
+ * - When key is a PrivateIdentifier, computed must be false.
380
+ */
381
+ let PropertyDefinition = PropertyDefinition_1 = class PropertyDefinition extends AbstractDefinition {
382
+ static fromJSON(node, deserializer) {
383
+ return new PropertyDefinition_1(deserializer(node.key), node.decorators.map(deserializer), node.computed, node.static, node.value && deserializer(node.value));
384
+ }
385
+ static visit(node, visitNode) {
386
+ visitNode(node.key);
387
+ node.value && visitNode(node.value);
388
+ }
389
+ constructor(key, decorators, computed, isStatic, value) {
390
+ super(key, decorators, computed, isStatic, value);
391
+ }
392
+ get(stack, classConstructor) {
393
+ const target = this.getTarget(classConstructor);
394
+ const name = this.getKeyName(stack);
395
+ const value = this.value?.get(stack);
396
+ target[name] = value;
397
+ const decorators = this.decorators.map(decorator => decorator.get(stack));
398
+ decorators.length && __decorate(decorators, target, name, null);
399
+ }
400
+ toString() {
401
+ const decorators = this.decorators.map(decorator => decorator.toString()).join('\n');
402
+ const name = this.computed ? `[${this.key.toString()}]` : this.key.toString();
403
+ return `${decorators.length ? decorators + ' ' : ''}${this.static ? 'static ' : ''}${name}${this.value ? ` = ${this.value.toString()}` : ''};`;
404
+ }
405
+ toJson() {
406
+ return {
407
+ key: this.key.toJSON(),
408
+ value: this.value?.toJSON(),
409
+ decorators: this.decorators.map(decorator => decorator.toJSON()),
410
+ computed: this.computed,
411
+ static: this.static,
412
+ };
413
+ }
414
+ };
415
+ PropertyDefinition = PropertyDefinition_1 = __decorate_1([
416
+ Deserializer('PropertyDefinition'),
417
+ __metadata("design:paramtypes", [Object, Array, Boolean, Boolean, Object])
418
+ ], PropertyDefinition);
419
+ export { PropertyDefinition };
420
+ let AccessorProperty = AccessorProperty_1 = class AccessorProperty extends AbstractDefinition {
421
+ static fromJSON(node, deserializer) {
422
+ return new AccessorProperty_1(deserializer(node.key), node.decorators.map(deserializer), node.computed, node.static, node.value ? deserializer(node.value) : void 0);
423
+ }
424
+ static visit(node, visitNode) {
425
+ visitNode(node.key);
426
+ node.value && visitNode(node.value);
427
+ node.decorators.forEach(visitNode);
428
+ }
429
+ constructor(key, decorators, computed, isStatic, value) {
430
+ super(key, decorators, computed, isStatic, value);
431
+ }
432
+ get(stack, classConstructor) {
433
+ const target = this.getTarget(classConstructor);
434
+ const name = this.getKeyName(stack);
435
+ const value = this.value?.get(stack);
436
+ target[name] = value;
437
+ const ref = this.static ? classConstructor : classConstructor.prototype;
438
+ Object.defineProperty(ref, name, {
439
+ configurable: true,
440
+ enumerable: false,
441
+ set: function (setValue) {
442
+ this[PRIVATE_SYMBOL][name] = setValue;
443
+ },
444
+ });
445
+ Object.defineProperty(ref, name, {
446
+ configurable: true,
447
+ enumerable: false,
448
+ get: function () {
449
+ return this[PRIVATE_SYMBOL][name];
450
+ },
451
+ });
452
+ const decorators = this.decorators.map(decorator => decorator.get(stack));
453
+ decorators.length && __decorate(decorators, ref, name, null);
454
+ }
455
+ toString() {
456
+ const decorators = this.decorators.map(decorator => decorator.toString()).join('\n');
457
+ const name = this.computed ? `[${this.key.toString()}]` : this.key.toString();
458
+ return `${decorators.length ? decorators.concat(' ') : ''}${this.static ? 'static ' : ''}accessor ${name}${this.value ? ` = ${this.value.toString()}` : ''};`;
459
+ }
460
+ toJson() {
461
+ return {
462
+ key: this.key.toJSON(),
463
+ decorators: this.decorators.map(decorator => decorator.toJSON()),
464
+ computed: this.computed,
465
+ static: this.static,
466
+ value: this.value?.toJSON(),
467
+ };
468
+ }
469
+ };
470
+ AccessorProperty = AccessorProperty_1 = __decorate_1([
471
+ Deserializer('AccessorProperty'),
472
+ __metadata("design:paramtypes", [Object, Array, Boolean, Boolean, Object])
473
+ ], AccessorProperty);
474
+ export { AccessorProperty };
475
+ let ClassBody = ClassBody_1 = class ClassBody extends AbstractExpressionNode {
476
+ constructor(body) {
477
+ super();
478
+ this.body = body;
479
+ }
480
+ static fromJSON(node, deserializer) {
481
+ return new ClassBody_1(node.body.map(deserializer));
482
+ }
483
+ static visit(node, visitNode) {
484
+ node.body.forEach(visitNode);
485
+ }
486
+ getBody() {
487
+ return this.body;
488
+ }
489
+ shareVariables(scopeList) { }
490
+ set(stack, value) {
491
+ throw new Error('Method not implemented.');
492
+ }
493
+ get(stack, classConstructor) {
494
+ this.body.forEach(definition => definition.get(stack, classConstructor));
495
+ }
496
+ dependency(computed) {
497
+ throw new Error('Method not implemented.');
498
+ }
499
+ dependencyPath(computed) {
500
+ throw new Error('Method not implemented.');
501
+ }
502
+ toString() {
503
+ return this.body.map(definition => `\t${definition.toString()}`).join('\n');
504
+ }
505
+ toJson() {
506
+ return {
507
+ body: this.body.map(method => method.toJSON())
508
+ };
509
+ }
510
+ };
511
+ ClassBody = ClassBody_1 = __decorate_1([
512
+ Deserializer('ClassBody'),
513
+ __metadata("design:paramtypes", [Array])
514
+ ], ClassBody);
515
+ export { ClassBody };
516
+ export class Class extends AbstractExpressionNode {
517
+ constructor(body, decorators, id, superClass) {
518
+ super();
519
+ this.body = body;
520
+ this.decorators = decorators;
521
+ this.id = id;
522
+ this.superClass = superClass;
523
+ }
524
+ getBody() {
525
+ return this.body;
526
+ }
527
+ getDecorators() {
528
+ return this.decorators;
529
+ }
530
+ getId() {
531
+ return this.id;
532
+ }
533
+ getSuperClass() {
534
+ return this.superClass;
535
+ }
536
+ shareVariables(scopeList) {
537
+ this.sharedVariables = scopeList;
538
+ }
539
+ set(stack) {
540
+ throw new Error(`Class.#set() has no implementation.`);
541
+ }
542
+ get(stack) {
543
+ const className = this.id?.get(stack);
544
+ const parentClass = this.superClass?.get(stack) ?? class {
545
+ };
546
+ let classConstructor = this.createClass(stack, parentClass, className);
547
+ // build class body
548
+ this.body.get(stack, classConstructor);
549
+ // apply class decorators
550
+ const decorators = this.decorators.map(decorator => decorator.get(stack));
551
+ classConstructor = __decorate(decorators, classConstructor);
552
+ // run static initialization block
553
+ classConstructor[STATIC_INITIALIZATION_BLOCK].forEach(block => block());
554
+ Reflect.deleteProperty(classConstructor, STATIC_INITIALIZATION_BLOCK);
555
+ return classConstructor;
556
+ }
557
+ createClass(stack, parentClass, className = TEMP_CLASS_NAME) {
558
+ var _a, _b, _c, _d, _e;
559
+ const TEMP = {
560
+ [className]: (_e = class extends parentClass {
561
+ constructor(...params) {
562
+ const parameters = TEMP[className][GET_PARAMETERS](params);
563
+ super(...parameters);
564
+ this[_d] = {};
565
+ this[PRIVATE_SYMBOL] = Object.assign(this[PRIVATE_SYMBOL], TEMP[className][INSTANCE_PRIVATE_SYMBOL]);
566
+ this[STACK] = stack.copyStack();
567
+ const instanceStack = this[STACK];
568
+ instanceStack.pushBlockScope();
569
+ instanceStack.declareVariable('this', this);
570
+ instanceStack.declareVariable(NEW_TARGET, new.target);
571
+ instanceStack.declareVariable(PRIVATE_SYMBOL, this[PRIVATE_SYMBOL]);
572
+ instanceStack.declareVariable(CALL_SUPER_Method, (name) => super[name]());
573
+ instanceStack.declareVariable(GET_SUPER_PROPERTY, (name) => super[name]);
574
+ instanceStack.pushReactiveScope();
575
+ // init fields and methods values
576
+ TEMP[className][CONSTRUCTOR]();
577
+ }
578
+ static [GET_PARAMETERS](args) {
579
+ return args;
580
+ }
581
+ static [(_a = STATIC_INITIALIZATION_BLOCK, _b = PRIVATE_SYMBOL, _c = INSTANCE_PRIVATE_SYMBOL, CONSTRUCTOR)]() { }
582
+ },
583
+ _d = PRIVATE_SYMBOL,
584
+ _e[_a] = [],
585
+ _e[_b] = {},
586
+ _e[_c] = {},
587
+ _e)
588
+ };
589
+ return TEMP[className];
590
+ }
591
+ dependency(computed) {
592
+ throw new Error('Method not implemented.');
593
+ }
594
+ dependencyPath(computed) {
595
+ throw new Error('Method not implemented.');
596
+ }
597
+ toString() {
598
+ const decorators = this.decorators.map(decorator => decorator.toString()).join('\n');
599
+ let classDeclaration = 'class ';
600
+ if (this.id) {
601
+ classDeclaration += this.id.toString();
602
+ }
603
+ if (this.superClass) {
604
+ classDeclaration += ' extends ' + this.superClass.toString();
605
+ }
606
+ return `${decorators}${classDeclaration} {\n${this.body.toString()}\n}`;
607
+ }
608
+ toJson() {
609
+ return {
610
+ body: this.body.toJSON(),
611
+ decorators: this.decorators.map(decorator => decorator.toJSON()),
612
+ id: this.id?.toJSON(),
613
+ superClass: this.superClass?.toJSON(),
614
+ };
615
+ }
616
+ }
617
+ let ClassDeclaration = ClassDeclaration_1 = class ClassDeclaration extends Class {
618
+ static fromJSON(node, deserializer) {
619
+ return new ClassDeclaration_1(deserializer(node.body), deserializer(node.id), node.superClass && deserializer(node.superClass));
620
+ }
621
+ static visit(node, visitNode) {
622
+ visitNode(node.body);
623
+ node.decorators.forEach(visitNode);
624
+ visitNode(node.id);
625
+ node.superClass && visitNode(node.superClass);
626
+ }
627
+ constructor(body, decorators, id, superClass) {
628
+ super(body, decorators, id, superClass);
629
+ }
630
+ declareVariable(stack, propertyValue) {
631
+ stack.declareVariable(this.id.getName(), propertyValue);
632
+ }
633
+ getDeclarationName() {
634
+ return this.id.getDeclarationName();
635
+ }
636
+ get(stack) {
637
+ const classConstructor = super.get(stack);
638
+ this.id.declareVariable(stack, classConstructor);
639
+ return classConstructor;
640
+ }
641
+ };
642
+ ClassDeclaration = ClassDeclaration_1 = __decorate_1([
643
+ Deserializer('ClassDeclaration'),
644
+ __metadata("design:paramtypes", [ClassBody, Array, Identifier, Object])
645
+ ], ClassDeclaration);
646
+ export { ClassDeclaration };
647
+ let ClassExpression = ClassExpression_1 = class ClassExpression extends Class {
648
+ static fromJSON(node, deserializer) {
649
+ return new ClassExpression_1(deserializer(node.body), node.superClass && deserializer(node.superClass));
650
+ }
651
+ static visit(node, visitNode) {
652
+ visitNode(node.body);
653
+ node.decorators.forEach(visitNode);
654
+ node.id && visitNode(node.id);
655
+ node.superClass && visitNode(node.superClass);
656
+ }
657
+ };
658
+ ClassExpression = ClassExpression_1 = __decorate_1([
659
+ Deserializer('ClassExpression')
660
+ ], ClassExpression);
661
+ export { ClassExpression };
662
+ //# sourceMappingURL=class.js.map