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