@ibyar/expressions 0.8.2-dev.20221008 → 0.8.4

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