@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.
- package/api/abstract.d.ts +0 -3
- package/api/abstract.js +0 -4
- package/api/abstract.js.map +1 -1
- package/api/class/class.d.ts +85 -43
- package/api/class/class.js +237 -173
- package/api/class/class.js.map +1 -1
- package/api/class/decorator.d.ts +0 -2
- package/api/class/decorator.js +0 -3
- package/api/class/decorator.js.map +1 -1
- package/api/computing/call.d.ts +0 -2
- package/api/computing/call.js +0 -3
- package/api/computing/call.js.map +1 -1
- package/api/computing/debugger.d.ts +0 -2
- package/api/computing/debugger.js +0 -2
- package/api/computing/debugger.js.map +1 -1
- package/api/computing/new.d.ts +0 -2
- package/api/computing/new.js +0 -3
- package/api/computing/new.js.map +1 -1
- package/api/computing/rest.d.ts +0 -2
- package/api/computing/rest.js +0 -3
- package/api/computing/rest.js.map +1 -1
- package/api/computing/return.d.ts +0 -2
- package/api/computing/return.js +0 -3
- package/api/computing/return.js.map +1 -1
- package/api/computing/spread.d.ts +0 -2
- package/api/computing/spread.js +0 -3
- package/api/computing/spread.js.map +1 -1
- package/api/computing/throw.d.ts +0 -4
- package/api/computing/throw.js +0 -5
- package/api/computing/throw.js.map +1 -1
- package/api/computing/yield.d.ts +0 -2
- package/api/computing/yield.js +0 -3
- package/api/computing/yield.js.map +1 -1
- package/api/definition/array.d.ts +0 -3
- package/api/definition/array.js +0 -4
- package/api/definition/array.js.map +1 -1
- package/api/definition/bind.d.ts +0 -1
- package/api/definition/bind.js +0 -1
- package/api/definition/bind.js.map +1 -1
- package/api/definition/comment.d.ts +0 -2
- package/api/definition/comment.js +0 -1
- package/api/definition/comment.js.map +1 -1
- package/api/definition/function.d.ts +3 -11
- package/api/definition/function.js +33 -56
- package/api/definition/function.js.map +1 -1
- package/api/definition/member.d.ts +0 -1
- package/api/definition/member.js +1 -2
- package/api/definition/member.js.map +1 -1
- package/api/definition/object.d.ts +1 -5
- package/api/definition/object.js +2 -8
- package/api/definition/object.js.map +1 -1
- package/api/definition/statement.d.ts +0 -2
- package/api/definition/statement.js +0 -3
- package/api/definition/statement.js.map +1 -1
- package/api/definition/values.d.ts +0 -3
- package/api/definition/values.js +0 -5
- package/api/definition/values.js.map +1 -1
- package/api/expression.d.ts +0 -20
- package/api/expression.js.map +1 -1
- package/api/module/common.d.ts +1 -2
- package/api/module/common.js +3 -3
- package/api/module/common.js.map +1 -1
- package/api/module/export.d.ts +0 -5
- package/api/module/export.js +5 -9
- package/api/module/export.js.map +1 -1
- package/api/module/import.d.ts +2 -6
- package/api/module/import.js +4 -9
- package/api/module/import.js.map +1 -1
- package/api/operators/await.d.ts +0 -2
- package/api/operators/await.js +0 -3
- package/api/operators/await.js.map +1 -1
- package/api/operators/chaining.d.ts +0 -1
- package/api/operators/chaining.js +0 -1
- package/api/operators/chaining.js.map +1 -1
- package/api/operators/comma.d.ts +0 -2
- package/api/operators/comma.js +0 -3
- package/api/operators/comma.js.map +1 -1
- package/api/operators/grouping.d.ts +0 -2
- package/api/operators/grouping.js +0 -3
- package/api/operators/grouping.js.map +1 -1
- package/api/operators/pipeline.d.ts +1 -3
- package/api/operators/pipeline.js +0 -7
- package/api/operators/pipeline.js.map +1 -1
- package/api/operators/ternary.d.ts +0 -2
- package/api/operators/ternary.js +0 -5
- package/api/operators/ternary.js.map +1 -1
- package/api/operators/unary.d.ts +0 -2
- package/api/operators/unary.js +0 -3
- package/api/operators/unary.js.map +1 -1
- package/api/operators/update.d.ts +0 -2
- package/api/operators/update.js +0 -3
- package/api/operators/update.js.map +1 -1
- package/api/program.d.ts +0 -2
- package/api/program.js +0 -1
- package/api/program.js.map +1 -1
- package/api/statement/control/block.d.ts +0 -2
- package/api/statement/control/block.js +3 -8
- package/api/statement/control/block.js.map +1 -1
- package/api/statement/control/empty.d.ts +0 -2
- package/api/statement/control/empty.js +0 -1
- package/api/statement/control/empty.js.map +1 -1
- package/api/statement/control/if.d.ts +0 -2
- package/api/statement/control/if.js +0 -5
- package/api/statement/control/if.js.map +1 -1
- package/api/statement/control/switch.d.ts +0 -3
- package/api/statement/control/switch.js +0 -8
- package/api/statement/control/switch.js.map +1 -1
- package/api/statement/control/terminate.d.ts +0 -3
- package/api/statement/control/terminate.js +0 -4
- package/api/statement/control/terminate.js.map +1 -1
- package/api/statement/declarations/declares.d.ts +1 -4
- package/api/statement/declarations/declares.js +0 -6
- package/api/statement/declarations/declares.js.map +1 -1
- package/api/statement/iterations/for.d.ts +1 -6
- package/api/statement/iterations/for.js +0 -18
- package/api/statement/iterations/for.js.map +1 -1
- package/api/statement/iterations/while.d.ts +0 -3
- package/api/statement/iterations/while.js +0 -8
- package/api/statement/iterations/while.js.map +1 -1
- package/package.json +2 -2
- package/scope/scope.d.ts +6 -22
- package/scope/scope.js +12 -59
- package/scope/scope.js.map +1 -1
- package/scope/stack.d.ts +15 -3
- package/scope/stack.js +26 -9
- package/scope/stack.js.map +1 -1
- package/v8/inline.d.ts +3 -1
- package/v8/inline.js +29 -16
- package/v8/inline.js.map +1 -1
- package/v8/nodes.d.ts +1 -1
package/api/class/class.js
CHANGED
|
@@ -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
|
|
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
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
128
|
+
let MetaProperty = MetaProperty_1 = class MetaProperty extends AbstractExpressionNode {
|
|
68
129
|
constructor(meta, property) {
|
|
69
|
-
super(
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
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,
|
|
148
|
-
|
|
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 =
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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,
|
|
307
|
+
get(stack, initializer) {
|
|
247
308
|
if (this.kind === 'constructor') {
|
|
248
|
-
this.initConstructor(stack,
|
|
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 '
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
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,
|
|
351
|
+
initConstructor(stack, initializer) {
|
|
279
352
|
const body = this.value.getBody().getBody();
|
|
280
353
|
let superIndex = body
|
|
281
|
-
.findIndex(call => call instanceof CallExpression &&
|
|
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
|
-
|
|
289
|
-
|
|
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
|
-
|
|
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 =
|
|
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,
|
|
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
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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 =
|
|
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,
|
|
412
|
-
const target = this.getTarget(classConstructor);
|
|
489
|
+
get(stack, initializer) {
|
|
413
490
|
const name = this.getKeyName(stack);
|
|
414
|
-
const
|
|
415
|
-
|
|
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 (
|
|
421
|
-
this[PRIVATE_SYMBOL][name] =
|
|
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
|
-
|
|
432
|
-
|
|
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 =
|
|
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,
|
|
473
|
-
this.body.forEach(definition => definition.get(stack,
|
|
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 =
|
|
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
|
-
|
|
523
|
-
|
|
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
|
-
|
|
601
|
+
const initializer = new ClassInitializer();
|
|
602
|
+
const ClassConstructor = this.createClass(SuperClass, className, initializer);
|
|
526
603
|
// build class body
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
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 =
|
|
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 =
|
|
699
|
+
ClassExpression = ClassExpression_1 = __decorate([
|
|
636
700
|
Deserializer('ClassExpression')
|
|
637
701
|
], ClassExpression);
|
|
638
702
|
export { ClassExpression };
|