@ibyar/expressions 0.8.2-dev.20221008 → 0.8.3

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 (130) hide show
  1. package/api/abstract.d.ts +0 -3
  2. package/api/abstract.js +0 -4
  3. package/api/abstract.js.map +1 -1
  4. package/api/class/class.d.ts +85 -43
  5. package/api/class/class.js +237 -173
  6. package/api/class/class.js.map +1 -1
  7. package/api/class/decorator.d.ts +0 -2
  8. package/api/class/decorator.js +0 -3
  9. package/api/class/decorator.js.map +1 -1
  10. package/api/computing/call.d.ts +0 -2
  11. package/api/computing/call.js +0 -3
  12. package/api/computing/call.js.map +1 -1
  13. package/api/computing/debugger.d.ts +0 -2
  14. package/api/computing/debugger.js +0 -2
  15. package/api/computing/debugger.js.map +1 -1
  16. package/api/computing/new.d.ts +0 -2
  17. package/api/computing/new.js +0 -3
  18. package/api/computing/new.js.map +1 -1
  19. package/api/computing/rest.d.ts +0 -2
  20. package/api/computing/rest.js +0 -3
  21. package/api/computing/rest.js.map +1 -1
  22. package/api/computing/return.d.ts +0 -2
  23. package/api/computing/return.js +0 -3
  24. package/api/computing/return.js.map +1 -1
  25. package/api/computing/spread.d.ts +0 -2
  26. package/api/computing/spread.js +0 -3
  27. package/api/computing/spread.js.map +1 -1
  28. package/api/computing/throw.d.ts +0 -4
  29. package/api/computing/throw.js +0 -5
  30. package/api/computing/throw.js.map +1 -1
  31. package/api/computing/yield.d.ts +0 -2
  32. package/api/computing/yield.js +0 -3
  33. package/api/computing/yield.js.map +1 -1
  34. package/api/definition/array.d.ts +0 -3
  35. package/api/definition/array.js +0 -4
  36. package/api/definition/array.js.map +1 -1
  37. package/api/definition/bind.d.ts +0 -1
  38. package/api/definition/bind.js +0 -1
  39. package/api/definition/bind.js.map +1 -1
  40. package/api/definition/comment.d.ts +0 -2
  41. package/api/definition/comment.js +0 -1
  42. package/api/definition/comment.js.map +1 -1
  43. package/api/definition/function.d.ts +3 -11
  44. package/api/definition/function.js +33 -56
  45. package/api/definition/function.js.map +1 -1
  46. package/api/definition/member.d.ts +0 -1
  47. package/api/definition/member.js +1 -2
  48. package/api/definition/member.js.map +1 -1
  49. package/api/definition/object.d.ts +1 -5
  50. package/api/definition/object.js +2 -8
  51. package/api/definition/object.js.map +1 -1
  52. package/api/definition/statement.d.ts +0 -2
  53. package/api/definition/statement.js +0 -3
  54. package/api/definition/statement.js.map +1 -1
  55. package/api/definition/values.d.ts +0 -3
  56. package/api/definition/values.js +0 -5
  57. package/api/definition/values.js.map +1 -1
  58. package/api/expression.d.ts +0 -20
  59. package/api/expression.js.map +1 -1
  60. package/api/module/common.d.ts +1 -2
  61. package/api/module/common.js +3 -3
  62. package/api/module/common.js.map +1 -1
  63. package/api/module/export.d.ts +0 -5
  64. package/api/module/export.js +5 -9
  65. package/api/module/export.js.map +1 -1
  66. package/api/module/import.d.ts +2 -6
  67. package/api/module/import.js +4 -9
  68. package/api/module/import.js.map +1 -1
  69. package/api/operators/await.d.ts +0 -2
  70. package/api/operators/await.js +0 -3
  71. package/api/operators/await.js.map +1 -1
  72. package/api/operators/chaining.d.ts +0 -1
  73. package/api/operators/chaining.js +0 -1
  74. package/api/operators/chaining.js.map +1 -1
  75. package/api/operators/comma.d.ts +0 -2
  76. package/api/operators/comma.js +0 -3
  77. package/api/operators/comma.js.map +1 -1
  78. package/api/operators/grouping.d.ts +0 -2
  79. package/api/operators/grouping.js +0 -3
  80. package/api/operators/grouping.js.map +1 -1
  81. package/api/operators/pipeline.d.ts +1 -3
  82. package/api/operators/pipeline.js +0 -7
  83. package/api/operators/pipeline.js.map +1 -1
  84. package/api/operators/ternary.d.ts +0 -2
  85. package/api/operators/ternary.js +0 -5
  86. package/api/operators/ternary.js.map +1 -1
  87. package/api/operators/unary.d.ts +0 -2
  88. package/api/operators/unary.js +0 -3
  89. package/api/operators/unary.js.map +1 -1
  90. package/api/operators/update.d.ts +0 -2
  91. package/api/operators/update.js +0 -3
  92. package/api/operators/update.js.map +1 -1
  93. package/api/program.d.ts +0 -2
  94. package/api/program.js +0 -1
  95. package/api/program.js.map +1 -1
  96. package/api/statement/control/block.d.ts +0 -2
  97. package/api/statement/control/block.js +3 -8
  98. package/api/statement/control/block.js.map +1 -1
  99. package/api/statement/control/empty.d.ts +0 -2
  100. package/api/statement/control/empty.js +0 -1
  101. package/api/statement/control/empty.js.map +1 -1
  102. package/api/statement/control/if.d.ts +0 -2
  103. package/api/statement/control/if.js +0 -5
  104. package/api/statement/control/if.js.map +1 -1
  105. package/api/statement/control/switch.d.ts +0 -3
  106. package/api/statement/control/switch.js +0 -8
  107. package/api/statement/control/switch.js.map +1 -1
  108. package/api/statement/control/terminate.d.ts +0 -3
  109. package/api/statement/control/terminate.js +0 -4
  110. package/api/statement/control/terminate.js.map +1 -1
  111. package/api/statement/declarations/declares.d.ts +1 -4
  112. package/api/statement/declarations/declares.js +0 -6
  113. package/api/statement/declarations/declares.js.map +1 -1
  114. package/api/statement/iterations/for.d.ts +1 -6
  115. package/api/statement/iterations/for.js +0 -18
  116. package/api/statement/iterations/for.js.map +1 -1
  117. package/api/statement/iterations/while.d.ts +0 -3
  118. package/api/statement/iterations/while.js +0 -8
  119. package/api/statement/iterations/while.js.map +1 -1
  120. package/package.json +2 -2
  121. package/scope/scope.d.ts +6 -22
  122. package/scope/scope.js +12 -59
  123. package/scope/scope.js.map +1 -1
  124. package/scope/stack.d.ts +15 -3
  125. package/scope/stack.js +26 -9
  126. package/scope/stack.js.map +1 -1
  127. package/v8/inline.d.ts +3 -1
  128. package/v8/inline.js +29 -16
  129. package/v8/inline.js.map +1 -1
  130. package/v8/nodes.d.ts +1 -1
@@ -1,26 +1,88 @@
1
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 { ClassScope } from '../../scope/scope.js';
4
- import { __decorate } from 'tslib';
2
+ import { __decorate, __metadata } from "tslib";
5
3
  import { AbstractExpressionNode } from '../abstract.js';
6
4
  import { Deserializer } from '../deserialize/deserialize.js';
7
5
  import { Identifier } from '../definition/values.js';
8
- import { MemberExpression } from '../definition/member.js';
9
6
  import { FunctionExpression } from '../definition/function.js';
10
7
  import { BlockStatement } from '../statement/control/block.js';
11
8
  import { CallExpression } from '../computing/call.js';
12
9
  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');
10
+ const PRIVATE_SYMBOL = Symbol('#');
11
+ ;
12
+ class ClassInitializer {
13
+ constructor() {
14
+ /**
15
+ * register class public static properties and methods
16
+ */
17
+ this.staticInitializer = {};
18
+ /**
19
+ * register class private static properties and methods
20
+ */
21
+ this.staticPrivateInitializer = {};
22
+ /**
23
+ * register static initialization block
24
+ */
25
+ this.staticInitializerBlock = [];
26
+ /**
27
+ * register super parameter resolver
28
+ */
29
+ this.superParameterResolver = (params) => params;
30
+ /**
31
+ * register in class property
32
+ */
33
+ this.instanceMethod = {};
34
+ /**
35
+ * register method in instance private space
36
+ */
37
+ this.privateInstanceMethod = {};
38
+ /**
39
+ * register property in instance itself
40
+ */
41
+ this.instanceInitializer = [];
42
+ }
43
+ addStaticInitializer(key, attributes) {
44
+ Reflect.set(this.staticInitializer, key, attributes);
45
+ }
46
+ addStaticPrivateInitializer(key, attributes) {
47
+ Reflect.set(this.staticPrivateInitializer, key, attributes);
48
+ }
49
+ addStaticInitializerBlock(block) {
50
+ this.staticInitializerBlock.push(block);
51
+ }
52
+ setConstructor(cstr) {
53
+ this.instanceConstructor = cstr;
54
+ }
55
+ setParameterResolver(resolver) {
56
+ this.superParameterResolver = resolver;
57
+ }
58
+ addInstanceMethod(key, attributes) {
59
+ Reflect.set(this.instanceMethod, key, attributes);
60
+ }
61
+ addPrivateInstanceMethod(key, attributes) {
62
+ Reflect.set(this.privateInstanceMethod, key, attributes);
63
+ }
64
+ addInstanceInitializer(initializer) {
65
+ this.instanceInitializer.push(initializer);
66
+ }
67
+ initClass(classConstructor) {
68
+ Object.defineProperties(classConstructor, this.staticInitializer);
69
+ Object.defineProperties(classConstructor[PRIVATE_SYMBOL], this.staticPrivateInitializer);
70
+ Object.defineProperties(classConstructor.prototype, this.instanceMethod);
71
+ this.staticInitializerBlock.forEach(block => block());
72
+ }
73
+ getSuperArguments(args) {
74
+ return this.superParameterResolver(args);
75
+ }
76
+ initInstance(instance) {
77
+ Object.defineProperties(instance[PRIVATE_SYMBOL], this.privateInstanceMethod);
78
+ this.instanceInitializer.forEach(initializer => {
79
+ const definition = initializer();
80
+ const target = definition.isPrivate ? instance[PRIVATE_SYMBOL] : instance;
81
+ target[definition.key] = definition.value;
82
+ });
83
+ this.instanceConstructor?.apply(instance);
84
+ }
85
+ }
24
86
  /**
25
87
  * A `super` pseudo-expression.
26
88
  */
@@ -31,12 +93,11 @@ let Super = Super_1 = class Super extends AbstractExpressionNode {
31
93
  static fromJSON(node) {
32
94
  return Super_1.INSTANCE;
33
95
  }
34
- shareVariables(scopeList) { }
35
96
  set(stack, value) {
36
97
  throw new Error('Super.#set() Method not implemented.');
37
98
  }
38
99
  get(stack, thisContext) {
39
- throw new Error('Super.#get() Method not implemented.');
100
+ return stack.get('super');
40
101
  }
41
102
  dependency(computed) {
42
103
  throw new Error('Super.#dependency() Method not implemented.');
@@ -52,7 +113,7 @@ let Super = Super_1 = class Super extends AbstractExpressionNode {
52
113
  }
53
114
  };
54
115
  Super.INSTANCE = new Super_1();
55
- Super = Super_1 = __decorate_1([
116
+ Super = Super_1 = __decorate([
56
117
  Deserializer('Super'),
57
118
  __metadata("design:paramtypes", [])
58
119
  ], Super);
@@ -64,10 +125,11 @@ export { Super };
64
125
  *
65
126
  * In the future, it will represent other meta properties as well.
66
127
  */
67
- let MetaProperty = MetaProperty_1 = class MetaProperty extends MemberExpression {
128
+ let MetaProperty = MetaProperty_1 = class MetaProperty extends AbstractExpressionNode {
68
129
  constructor(meta, property) {
69
- super(meta, property, false);
130
+ super();
70
131
  this.meta = meta;
132
+ this.property = property;
71
133
  }
72
134
  static getJsonName(identifier) {
73
135
  return Reflect.get(identifier, 'name');
@@ -88,16 +150,24 @@ let MetaProperty = MetaProperty_1 = class MetaProperty extends MemberExpression
88
150
  getMeta() {
89
151
  return this.meta;
90
152
  }
91
- shareVariables(scopeList) { }
92
- get(stack, thisContext) {
93
- if (MetaProperty_1.getJsonName(this.meta) === 'new' && MetaProperty_1.getJsonName(this.property) === 'target') {
94
- return stack.get(NEW_TARGET);
95
- }
96
- else if (MetaProperty_1.getJsonName(this.meta) === 'import' && MetaProperty_1.getJsonName(this.property) === 'meta') {
97
- const importObject = stack.getModule()?.get('import');
98
- return importObject['meta'];
153
+ getProperty() {
154
+ return this.property;
155
+ }
156
+ get(stack) {
157
+ const metaRef = this.meta.get(stack);
158
+ if (metaRef === undefined || metaRef === null) {
159
+ throw new TypeError(`Cannot read meta property '${this.property.toString()}' of ${metaRef}, reading [${this.toString()}]`);
99
160
  }
100
- return super.get(stack, thisContext);
161
+ return this.property.get(stack, metaRef);
162
+ }
163
+ set(stack, value) {
164
+ throw new Error(`MetaProperty#set() has no implementation.`);
165
+ }
166
+ dependency(computed) {
167
+ return [];
168
+ }
169
+ dependencyPath(computed) {
170
+ return [];
101
171
  }
102
172
  toString() {
103
173
  return `${this.meta.toString()}.${this.property.toString()}`;
@@ -111,7 +181,7 @@ let MetaProperty = MetaProperty_1 = class MetaProperty extends MemberExpression
111
181
  };
112
182
  MetaProperty.NewTarget = new MetaProperty_1(new Identifier('new'), new Identifier('target'));
113
183
  MetaProperty.ImportMeta = new MetaProperty_1(new Identifier('import'), new Identifier('meta'));
114
- MetaProperty = MetaProperty_1 = __decorate_1([
184
+ MetaProperty = MetaProperty_1 = __decorate([
115
185
  Deserializer('MetaProperty'),
116
186
  __metadata("design:paramtypes", [Identifier, Identifier])
117
187
  ], MetaProperty);
@@ -123,14 +193,18 @@ let PrivateIdentifier = PrivateIdentifier_1 = class PrivateIdentifier extends Id
123
193
  static fromJSON(node) {
124
194
  return new PrivateIdentifier_1(node.name);
125
195
  }
126
- get(stack) {
127
- return stack.get(this.toString());
196
+ get(stack, thisContext) {
197
+ return thisContext[PRIVATE_SYMBOL][this.name];
198
+ }
199
+ set(stack, value) {
200
+ const thisContext = stack.lastScope().getContext();
201
+ return thisContext[PRIVATE_SYMBOL][this.name] = value;
128
202
  }
129
203
  toString() {
130
204
  return `#${this.name}`;
131
205
  }
132
206
  };
133
- PrivateIdentifier = PrivateIdentifier_1 = __decorate_1([
207
+ PrivateIdentifier = PrivateIdentifier_1 = __decorate([
134
208
  Deserializer('PrivateIdentifier')
135
209
  ], PrivateIdentifier);
136
210
  export { PrivateIdentifier };
@@ -144,18 +218,8 @@ let StaticBlock = StaticBlock_1 = class StaticBlock extends BlockStatement {
144
218
  constructor(body) {
145
219
  super(body);
146
220
  }
147
- get(stack, classConstructor) {
148
- const constructor = classConstructor;
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
- });
221
+ get(stack, classInitializer) {
222
+ classInitializer?.addStaticInitializerBlock(super.get(stack));
159
223
  }
160
224
  toString() {
161
225
  return `static ${super.toString()}`;
@@ -166,7 +230,7 @@ let StaticBlock = StaticBlock_1 = class StaticBlock extends BlockStatement {
166
230
  };
167
231
  }
168
232
  };
169
- StaticBlock = StaticBlock_1 = __decorate_1([
233
+ StaticBlock = StaticBlock_1 = __decorate([
170
234
  Deserializer('StaticBlock'),
171
235
  __metadata("design:paramtypes", [Array])
172
236
  ], StaticBlock);
@@ -192,10 +256,12 @@ export class AbstractDefinition extends AbstractExpressionNode {
192
256
  isStatic() {
193
257
  return this.static;
194
258
  }
259
+ isPrivate() {
260
+ return this.key instanceof PrivateIdentifier;
261
+ }
195
262
  getDecorators() {
196
263
  return this.decorators;
197
264
  }
198
- shareVariables(scopeList) { }
199
265
  set(stack, value) {
200
266
  throw new Error('AbstractDefinition.#set() Method not implemented.');
201
267
  }
@@ -205,20 +271,15 @@ export class AbstractDefinition extends AbstractExpressionNode {
205
271
  dependencyPath(computed) {
206
272
  return [];
207
273
  }
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
274
  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();
275
+ if (this.computed) {
276
+ // private properties can't be computed
277
+ return this.key.get(stack);
278
+ }
279
+ if (this.key instanceof Identifier) {
280
+ return this.key.getName();
221
281
  }
282
+ return this.key.toString();
222
283
  }
223
284
  }
224
285
  /**
@@ -243,63 +304,73 @@ let MethodDefinition = MethodDefinition_1 = class MethodDefinition extends Abstr
243
304
  getValue() {
244
305
  return this.value;
245
306
  }
246
- get(stack, classConstructor) {
307
+ get(stack, initializer) {
247
308
  if (this.kind === 'constructor') {
248
- this.initConstructor(stack, classConstructor);
309
+ this.initConstructor(stack, initializer);
249
310
  return;
250
311
  }
251
- const target = this.getTarget(classConstructor);
252
312
  const name = this.getKeyName(stack);
253
313
  const value = this.value?.get(stack);
314
+ const attributes = this.getPropertyAttributes(value);
315
+ if (this.isStatic() && this.isPrivate()) {
316
+ initializer.addStaticPrivateInitializer(name, attributes);
317
+ }
318
+ else if (this.isStatic()) {
319
+ initializer.addStaticInitializer(name, attributes);
320
+ }
321
+ else if (this.isPrivate()) {
322
+ initializer.addPrivateInstanceMethod(name, attributes);
323
+ }
324
+ else {
325
+ initializer.addInstanceMethod(name, attributes);
326
+ }
327
+ }
328
+ getPropertyAttributes(value) {
254
329
  switch (this.kind) {
255
- case 'method':
256
- target[name] = value;
257
- break;
258
- case 'set':
259
- Object.defineProperty(target, name, {
260
- configurable: true,
261
- enumerable: false,
262
- set: value,
263
- });
264
- break;
265
- case 'get':
266
- Object.defineProperty(target, name, {
267
- configurable: true,
268
- enumerable: false,
269
- get: value,
270
- });
271
- break;
330
+ case 'set': return {
331
+ writable: true,
332
+ configurable: true,
333
+ enumerable: false,
334
+ set: value,
335
+ };
336
+ case 'get': return {
337
+ writable: true,
338
+ configurable: true,
339
+ enumerable: false,
340
+ get: value,
341
+ };
272
342
  default:
273
- break;
343
+ case 'method': return {
344
+ writable: true,
345
+ configurable: true,
346
+ enumerable: false,
347
+ value: value
348
+ };
274
349
  }
275
- const decorators = this.decorators.map(decorator => decorator.get(stack));
276
- decorators.length && __decorate(decorators, target, name, null);
277
350
  }
278
- initConstructor(stack, classConstructor) {
351
+ initConstructor(stack, initializer) {
279
352
  const body = this.value.getBody().getBody();
280
353
  let superIndex = body
281
- .findIndex(call => call instanceof CallExpression && Super.INSTANCE === call.getCallee());
282
- if (superIndex === -1) {
283
- superIndex = body.length;
284
- }
285
- const superCall = body[superIndex];
286
- const blockBeforeSuper = new BlockStatement(body.slice(0, superIndex));
354
+ .findIndex(call => call instanceof CallExpression && call.getCallee() instanceof Super);
287
355
  const blockAfterSuper = new BlockStatement(body.slice(superIndex + 1));
288
- if (superCall) {
289
- classConstructor[GET_PARAMETERS] = function (params) {
356
+ initializer.setConstructor(function (params) {
357
+ const scope = stack.pushBlockScope();
358
+ blockAfterSuper.get(stack);
359
+ stack.clearTo(scope);
360
+ });
361
+ if (superIndex >= 0) {
362
+ const blockBeforeSuper = new BlockStatement(body.slice(0, superIndex));
363
+ const superCall = body[superIndex];
364
+ const cstrExpr = this;
365
+ initializer.setParameterResolver(function (params) {
290
366
  const scope = stack.pushBlockScope();
291
- this.value.setParameter(stack, params);
367
+ cstrExpr.value.defineFunctionArguments(stack, params);
292
368
  blockBeforeSuper.get(stack);
293
369
  const parameters = superCall.getCallParameters(stack);
294
370
  stack.clearTo(scope);
295
371
  return parameters;
296
- };
372
+ });
297
373
  }
298
- classConstructor[CONSTRUCTOR] = function (params) {
299
- const scope = this[STACK].pushBlockScope();
300
- blockAfterSuper.get(this[STACK]);
301
- stack.clearTo(scope);
302
- };
303
374
  }
304
375
  toString() {
305
376
  let str = this.decorators.map(decorator => decorator.toString()).join(' ');
@@ -349,7 +420,7 @@ let MethodDefinition = MethodDefinition_1 = class MethodDefinition extends Abstr
349
420
  };
350
421
  }
351
422
  };
352
- MethodDefinition = MethodDefinition_1 = __decorate_1([
423
+ MethodDefinition = MethodDefinition_1 = __decorate([
353
424
  Deserializer('MethodDefinition'),
354
425
  __metadata("design:paramtypes", [String, Object, FunctionExpression, Array, Boolean, Boolean])
355
426
  ], MethodDefinition);
@@ -368,13 +439,20 @@ let PropertyDefinition = PropertyDefinition_1 = class PropertyDefinition extends
368
439
  constructor(key, decorators, computed, isStatic, value) {
369
440
  super(key, decorators, computed, isStatic, value);
370
441
  }
371
- get(stack, classConstructor) {
372
- const target = this.getTarget(classConstructor);
442
+ get(stack, initializer) {
373
443
  const name = this.getKeyName(stack);
444
+ if (!this.isStatic()) {
445
+ initializer.addInstanceInitializer(() => ({ isPrivate: this.isPrivate(), key: name, value: this.value?.get(stack) }));
446
+ return;
447
+ }
374
448
  const value = this.value?.get(stack);
375
- target[name] = value;
376
- const decorators = this.decorators.map(decorator => decorator.get(stack));
377
- decorators.length && __decorate(decorators, target, name, null);
449
+ const attributes = { writable: true, configurable: true, enumerable: true, value };
450
+ if (this.isPrivate()) {
451
+ initializer.addStaticPrivateInitializer(name, attributes);
452
+ }
453
+ else {
454
+ initializer.addStaticInitializer(name, attributes);
455
+ }
378
456
  }
379
457
  toString() {
380
458
  const decorators = this.decorators.map(decorator => decorator.toString()).join('\n');
@@ -391,7 +469,7 @@ let PropertyDefinition = PropertyDefinition_1 = class PropertyDefinition extends
391
469
  };
392
470
  }
393
471
  };
394
- PropertyDefinition = PropertyDefinition_1 = __decorate_1([
472
+ PropertyDefinition = PropertyDefinition_1 = __decorate([
395
473
  Deserializer('PropertyDefinition'),
396
474
  __metadata("design:paramtypes", [Object, Array, Boolean, Boolean, Object])
397
475
  ], PropertyDefinition);
@@ -408,28 +486,28 @@ let AccessorProperty = AccessorProperty_1 = class AccessorProperty extends Abstr
408
486
  constructor(key, decorators, computed, isStatic, value) {
409
487
  super(key, decorators, computed, isStatic, value);
410
488
  }
411
- get(stack, classConstructor) {
412
- const target = this.getTarget(classConstructor);
489
+ get(stack, initializer) {
413
490
  const name = this.getKeyName(stack);
414
- const value = this.value?.get(stack);
415
- target[name] = value;
416
- const ref = this.static ? classConstructor : classConstructor.prototype;
417
- Object.defineProperty(ref, name, {
491
+ const accessorAttributes = {
492
+ writable: false,
418
493
  configurable: true,
419
494
  enumerable: false,
420
- set: function (setValue) {
421
- this[PRIVATE_SYMBOL][name] = setValue;
495
+ set: function (value) {
496
+ this[PRIVATE_SYMBOL][name] = value;
422
497
  },
423
- });
424
- Object.defineProperty(ref, name, {
425
- configurable: true,
426
- enumerable: false,
427
498
  get: function () {
428
499
  return this[PRIVATE_SYMBOL][name];
429
500
  },
430
- });
431
- const decorators = this.decorators.map(decorator => decorator.get(stack));
432
- decorators.length && __decorate(decorators, ref, name, null);
501
+ };
502
+ if (!this.isStatic()) {
503
+ initializer.addInstanceInitializer(() => ({ isPrivate: true, key: name, value: this.value?.get(stack) }));
504
+ initializer.addInstanceMethod(name, accessorAttributes);
505
+ return;
506
+ }
507
+ const value = this.value?.get(stack);
508
+ const valueAttribute = { writable: true, configurable: true, enumerable: true, value };
509
+ initializer.addStaticInitializer(name, accessorAttributes);
510
+ initializer.addStaticPrivateInitializer(name, valueAttribute);
433
511
  }
434
512
  toString() {
435
513
  const decorators = this.decorators.map(decorator => decorator.toString()).join('\n');
@@ -446,7 +524,7 @@ let AccessorProperty = AccessorProperty_1 = class AccessorProperty extends Abstr
446
524
  };
447
525
  }
448
526
  };
449
- AccessorProperty = AccessorProperty_1 = __decorate_1([
527
+ AccessorProperty = AccessorProperty_1 = __decorate([
450
528
  Deserializer('AccessorProperty'),
451
529
  __metadata("design:paramtypes", [Object, Array, Boolean, Boolean, Object])
452
530
  ], AccessorProperty);
@@ -465,12 +543,11 @@ let ClassBody = ClassBody_1 = class ClassBody extends AbstractExpressionNode {
465
543
  getBody() {
466
544
  return this.body;
467
545
  }
468
- shareVariables(scopeList) { }
469
546
  set(stack, value) {
470
547
  throw new Error('Method not implemented.');
471
548
  }
472
- get(stack, classConstructor) {
473
- this.body.forEach(definition => definition.get(stack, classConstructor));
549
+ get(stack, initializer) {
550
+ this.body.forEach(definition => definition.get(stack, initializer));
474
551
  }
475
552
  dependency(computed) {
476
553
  throw new Error('Method not implemented.');
@@ -487,7 +564,7 @@ let ClassBody = ClassBody_1 = class ClassBody extends AbstractExpressionNode {
487
564
  };
488
565
  }
489
566
  };
490
- ClassBody = ClassBody_1 = __decorate_1([
567
+ ClassBody = ClassBody_1 = __decorate([
491
568
  Deserializer('ClassBody'),
492
569
  __metadata("design:paramtypes", [Array])
493
570
  ], ClassBody);
@@ -512,58 +589,45 @@ export class Class extends AbstractExpressionNode {
512
589
  getSuperClass() {
513
590
  return this.superClass;
514
591
  }
515
- shareVariables(scopeList) {
516
- this.sharedVariables = scopeList;
517
- }
518
592
  set(stack) {
519
593
  throw new Error(`Class.#set() has no implementation.`);
520
594
  }
521
595
  get(stack) {
522
- const className = this.id?.getName();
523
- const parentClass = this.superClass?.get(stack) ?? class {
596
+ // freeze stack
597
+ stack = stack.copyStack();
598
+ const className = this.id?.getName() ?? TEMP_CLASS_NAME;
599
+ const SuperClass = this.superClass?.get(stack) ?? class {
524
600
  };
525
- let classConstructor = this.createClass(stack, parentClass, className);
601
+ const initializer = new ClassInitializer();
602
+ const ClassConstructor = this.createClass(SuperClass, className, initializer);
526
603
  // build class body
527
- this.body.get(stack, classConstructor);
528
- // apply class decorators
529
- const decorators = this.decorators.map(decorator => decorator.get(stack));
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);
534
- return classConstructor;
535
- }
536
- createClass(stack, parentClass, className = TEMP_CLASS_NAME) {
537
- var _a, _b, _c, _d, _e;
538
- const ClassDeclaration = (_e = class extends parentClass {
539
- constructor(...params) {
540
- const parameters = ClassDeclaration[GET_PARAMETERS](params);
541
- super(...parameters);
542
- this[_d] = {};
543
- this[PRIVATE_SYMBOL] = Object.assign(this[PRIVATE_SYMBOL], ClassDeclaration[INSTANCE_PRIVATE_SYMBOL]);
544
- this[STACK] = stack.copyStack();
545
- const instanceStack = this[STACK];
546
- instanceStack.pushScope(ClassScope.readOnlyScopeForThis(this));
547
- instanceStack.declareVariable(NEW_TARGET, new.target);
548
- instanceStack.declareVariable(PRIVATE_SYMBOL, this[PRIVATE_SYMBOL]);
549
- instanceStack.declareVariable(CALL_SUPER_Method, (name) => super[name]());
550
- instanceStack.declareVariable(GET_SUPER_PROPERTY, (name) => super[name]);
551
- instanceStack.pushReactiveScope();
552
- // init fields and methods values
553
- ClassDeclaration[CONSTRUCTOR]();
554
- }
555
- static [GET_PARAMETERS](args) {
556
- return args;
557
- }
558
- static [(_a = STATIC_INITIALIZATION_BLOCK, _b = PRIVATE_SYMBOL, _c = INSTANCE_PRIVATE_SYMBOL, CONSTRUCTOR)]() { }
559
- },
560
- _d = PRIVATE_SYMBOL,
561
- _e[_a] = [],
562
- _e[_b] = {},
563
- _e[_c] = {},
564
- _e);
565
- Reflect.set(ClassDeclaration, 'name', className);
566
- return ClassDeclaration;
604
+ stack.pushBlockScopeFor({
605
+ 'this': ClassConstructor,
606
+ 'super': SuperClass,
607
+ });
608
+ this.body.get(stack, initializer);
609
+ initializer.initClass(ClassConstructor);
610
+ return ClassConstructor;
611
+ }
612
+ createClass(parentClass, className, initializer) {
613
+ var _a, _b, _c, _d;
614
+ const nameClassDeclaration = {
615
+ [className]: (_d = class extends parentClass {
616
+ constructor(...params) {
617
+ const parameters = initializer.getSuperArguments(params);
618
+ super(...parameters);
619
+ this[_c] = {};
620
+ initializer.initInstance(this);
621
+ }
622
+ },
623
+ _a = Symbol.toStringTag,
624
+ _b = PRIVATE_SYMBOL,
625
+ _c = PRIVATE_SYMBOL,
626
+ _d[_a] = className,
627
+ _d[_b] = {},
628
+ _d)
629
+ };
630
+ return nameClassDeclaration[className];
567
631
  }
568
632
  dependency(computed) {
569
633
  throw new Error('Method not implemented.');
@@ -616,7 +680,7 @@ let ClassDeclaration = ClassDeclaration_1 = class ClassDeclaration extends Class
616
680
  return classConstructor;
617
681
  }
618
682
  };
619
- ClassDeclaration = ClassDeclaration_1 = __decorate_1([
683
+ ClassDeclaration = ClassDeclaration_1 = __decorate([
620
684
  Deserializer('ClassDeclaration'),
621
685
  __metadata("design:paramtypes", [ClassBody, Array, Identifier, Object])
622
686
  ], ClassDeclaration);
@@ -632,7 +696,7 @@ let ClassExpression = ClassExpression_1 = class ClassExpression extends Class {
632
696
  node.superClass && visitNode(node.superClass);
633
697
  }
634
698
  };
635
- ClassExpression = ClassExpression_1 = __decorate_1([
699
+ ClassExpression = ClassExpression_1 = __decorate([
636
700
  Deserializer('ClassExpression')
637
701
  ], ClassExpression);
638
702
  export { ClassExpression };