@ibyar/expressions 0.5.4 → 0.6.0

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