@ibyar/expressions 0.3.0 → 0.3.8
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 +79 -6
- package/api/abstract.d.ts +5 -7
- package/api/abstract.js +2 -5
- package/api/abstract.js.map +1 -1
- package/api/app/class.d.ts +99 -8
- package/api/app/class.js +250 -29
- package/api/app/class.js.map +1 -1
- package/api/app/program.d.ts +1 -2
- package/api/app/program.js +1 -4
- package/api/app/program.js.map +1 -1
- package/api/computing/call.d.ts +4 -4
- package/api/computing/call.js +20 -22
- package/api/computing/call.js.map +1 -1
- package/api/computing/new.d.ts +1 -2
- package/api/computing/new.js +4 -7
- package/api/computing/new.js.map +1 -1
- package/api/computing/rest.d.ts +16 -0
- package/api/computing/rest.js +40 -0
- package/api/computing/rest.js.map +1 -0
- package/api/computing/return.d.ts +1 -2
- package/api/computing/return.js +2 -5
- package/api/computing/return.js.map +1 -1
- package/api/computing/spread.d.ts +1 -2
- package/api/computing/spread.js +3 -9
- package/api/computing/spread.js.map +1 -1
- package/api/computing/throw.d.ts +3 -6
- package/api/computing/throw.js +5 -14
- package/api/computing/throw.js.map +1 -1
- package/api/definition/array.d.ts +12 -10
- package/api/definition/array.js +44 -16
- package/api/definition/array.js.map +1 -1
- package/api/definition/bind.d.ts +21 -0
- package/api/definition/bind.js +81 -0
- package/api/definition/bind.js.map +1 -0
- package/api/definition/comment.d.ts +1 -2
- package/api/definition/comment.js +1 -4
- package/api/definition/comment.js.map +1 -1
- package/api/definition/function.d.ts +12 -15
- package/api/definition/function.js +49 -58
- package/api/definition/function.js.map +1 -1
- package/api/definition/member.d.ts +8 -5
- package/api/definition/member.js +40 -31
- package/api/definition/member.js.map +1 -1
- package/api/definition/object.d.ts +16 -17
- package/api/definition/object.js +24 -16
- package/api/definition/object.js.map +1 -1
- package/api/definition/statement.d.ts +1 -2
- package/api/definition/statement.js +2 -5
- package/api/definition/statement.js.map +1 -1
- package/api/definition/values.d.ts +12 -11
- package/api/definition/values.js +17 -12
- package/api/definition/values.js.map +1 -1
- package/api/expression.d.ts +8 -4
- package/api/expression.js.map +1 -1
- package/api/index.d.ts +7 -6
- package/api/index.js +7 -6
- package/api/index.js.map +1 -1
- package/api/module/export.d.ts +1 -2
- package/api/module/export.js +1 -4
- package/api/module/export.js.map +1 -1
- package/api/module/import.d.ts +1 -2
- package/api/module/import.js +1 -4
- package/api/module/import.js.map +1 -1
- package/api/module/module.d.ts +1 -2
- package/api/module/module.js +2 -5
- package/api/module/module.js.map +1 -1
- package/api/operators/assignment.js +2 -2
- package/api/operators/assignment.js.map +1 -1
- package/api/operators/await.d.ts +1 -2
- package/api/operators/await.js +2 -5
- package/api/operators/await.js.map +1 -1
- package/api/operators/binary.js +4 -4
- package/api/operators/binary.js.map +1 -1
- package/api/operators/chaining.d.ts +9 -13
- package/api/operators/chaining.js +14 -48
- package/api/operators/chaining.js.map +1 -1
- package/api/operators/comma.d.ts +1 -2
- package/api/operators/comma.js +2 -5
- package/api/operators/comma.js.map +1 -1
- package/api/operators/grouping.d.ts +1 -2
- package/api/operators/grouping.js +2 -5
- package/api/operators/grouping.js.map +1 -1
- package/api/operators/logical.js.map +1 -1
- package/api/operators/pipeline.d.ts +4 -5
- package/api/operators/pipeline.js +23 -25
- package/api/operators/pipeline.js.map +1 -1
- package/api/operators/ternary.d.ts +1 -2
- package/api/operators/ternary.js +1 -4
- package/api/operators/ternary.js.map +1 -1
- package/api/operators/unary.d.ts +1 -2
- package/api/operators/unary.js +2 -5
- package/api/operators/unary.js.map +1 -1
- package/api/operators/update.d.ts +1 -2
- package/api/operators/update.js +2 -5
- package/api/operators/update.js.map +1 -1
- package/api/statement/{controlflow → control}/block.d.ts +1 -2
- package/api/statement/{controlflow → control}/block.js +2 -5
- package/api/statement/control/block.js.map +1 -0
- package/api/statement/{controlflow → control}/empty.d.ts +1 -2
- package/api/statement/{controlflow → control}/empty.js +1 -4
- package/api/statement/control/empty.js.map +1 -0
- package/api/statement/{controlflow → control}/if.d.ts +1 -2
- package/api/statement/{controlflow → control}/if.js +2 -5
- package/api/statement/control/if.js.map +1 -0
- package/api/statement/{controlflow → control}/switch.d.ts +2 -4
- package/api/statement/{controlflow → control}/switch.js +5 -11
- package/api/statement/control/switch.js.map +1 -0
- package/api/statement/{controlflow → control}/terminate.d.ts +1 -2
- package/api/statement/{controlflow → control}/terminate.js +1 -4
- package/api/statement/control/terminate.js.map +1 -0
- package/api/statement/declarations/declares.d.ts +13 -14
- package/api/statement/declarations/declares.js +10 -9
- package/api/statement/declarations/declares.js.map +1 -1
- package/api/statement/iterations/for.d.ts +14 -14
- package/api/statement/iterations/for.js +12 -24
- package/api/statement/iterations/for.js.map +1 -1
- package/api/statement/iterations/while.d.ts +2 -4
- package/api/statement/iterations/while.js +4 -10
- package/api/statement/iterations/while.js.map +1 -1
- package/package.json +18 -4
- package/scope/scope.d.ts +23 -3
- package/scope/scope.js +67 -1
- package/scope/scope.js.map +1 -1
- package/scope/stack.d.ts +14 -3
- package/scope/stack.js +61 -1
- package/scope/stack.js.map +1 -1
- package/v8/app.js.map +1 -1
- package/v8/nodes.d.ts +1 -2
- package/v8/nodes.js +2 -11
- package/v8/nodes.js.map +1 -1
- package/v8/parser.d.ts +5 -4
- package/v8/parser.js +165 -69
- package/v8/parser.js.map +1 -1
- package/v8/stream.js +20 -6
- package/v8/stream.js.map +1 -1
- package/v8/token.d.ts +3 -0
- package/v8/token.js +9 -0
- package/v8/token.js.map +1 -1
- package/api/operators/destruct.d.ts +0 -19
- package/api/operators/destruct.js +0 -95
- package/api/operators/destruct.js.map +0 -1
- package/api/statement/controlflow/block.js.map +0 -1
- package/api/statement/controlflow/empty.js.map +0 -1
- package/api/statement/controlflow/if.js.map +0 -1
- package/api/statement/controlflow/switch.js.map +0 -1
- package/api/statement/controlflow/terminate.js.map +0 -1
package/api/definition/array.js
CHANGED
|
@@ -2,7 +2,7 @@ var ArrayExpression_1, ArrayPattern_1;
|
|
|
2
2
|
import { __decorate, __metadata } from "tslib";
|
|
3
3
|
import { AbstractExpressionNode } from '../abstract.js';
|
|
4
4
|
import { Deserializer } from '../deserialize/deserialize.js';
|
|
5
|
-
import {
|
|
5
|
+
import { RestElement } from '../computing/rest.js';
|
|
6
6
|
let ArrayExpression = ArrayExpression_1 = class ArrayExpression extends AbstractExpressionNode {
|
|
7
7
|
constructor(elements) {
|
|
8
8
|
super();
|
|
@@ -20,11 +20,8 @@ let ArrayExpression = ArrayExpression_1 = class ArrayExpression extends Abstract
|
|
|
20
20
|
get(stack) {
|
|
21
21
|
return this.elements.map(item => item.get(stack));
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
return this.elements.flatMap(item => item.
|
|
25
|
-
}
|
|
26
|
-
event(parent) {
|
|
27
|
-
return this.elements.flatMap(item => item.event());
|
|
23
|
+
events(parent) {
|
|
24
|
+
return this.elements.flatMap(item => item.events());
|
|
28
25
|
}
|
|
29
26
|
toString() {
|
|
30
27
|
return this.elements.map(item => item.toString()).toString();
|
|
@@ -52,24 +49,55 @@ let ArrayPattern = ArrayPattern_1 = class ArrayPattern extends AbstractExpressio
|
|
|
52
49
|
return this.elements;
|
|
53
50
|
}
|
|
54
51
|
set(stack, values) {
|
|
52
|
+
throw new Error('ArrayPattern#set() has no implementation.');
|
|
53
|
+
}
|
|
54
|
+
get(scopeProvider) {
|
|
55
|
+
throw new Error('ArrayPattern#get() has no implementation.');
|
|
56
|
+
}
|
|
57
|
+
declareVariable(stack, scopeType, values) {
|
|
58
|
+
if (Array.isArray(values)) {
|
|
59
|
+
this.declareVariableFromArray(stack, scopeType, values);
|
|
60
|
+
}
|
|
61
|
+
else if (Reflect.has(values, Symbol.iterator)) {
|
|
62
|
+
this.declareVariableFromIterator(stack, scopeType, values);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
declareVariableFromArray(stack, scopeType, values) {
|
|
55
66
|
for (let index = 0; index < this.elements.length; index++) {
|
|
56
67
|
const elem = this.elements[index];
|
|
57
|
-
if (elem instanceof
|
|
68
|
+
if (elem instanceof RestElement) {
|
|
58
69
|
const rest = values.slice(index);
|
|
59
|
-
elem.
|
|
70
|
+
elem.declareVariable(stack, 'block', rest);
|
|
60
71
|
break;
|
|
61
72
|
}
|
|
62
|
-
elem.
|
|
73
|
+
elem.declareVariable(stack, 'block', values[index]);
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
76
|
+
declareVariableFromIterator(stack, scopeType, iterator) {
|
|
77
|
+
let index = 0;
|
|
78
|
+
while (true) {
|
|
79
|
+
let iteratorResult = iterator.next();
|
|
80
|
+
if (iteratorResult.done) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
const elem = this.elements[index++];
|
|
84
|
+
if (elem instanceof RestElement) {
|
|
85
|
+
const rest = [iteratorResult.value];
|
|
86
|
+
while (!iteratorResult.done) {
|
|
87
|
+
iteratorResult = iterator.next();
|
|
88
|
+
rest.push(iteratorResult.value);
|
|
89
|
+
}
|
|
90
|
+
elem.declareVariable(stack, 'block', rest);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
elem.declareVariable(stack, 'block', iteratorResult.value);
|
|
94
|
+
if (index >= this.elements.length) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
70
98
|
}
|
|
71
|
-
|
|
72
|
-
return this.elements.flatMap(item => item.
|
|
99
|
+
events(parent) {
|
|
100
|
+
return this.elements.flatMap(item => item.events());
|
|
73
101
|
}
|
|
74
102
|
toString() {
|
|
75
103
|
return this.elements.map(item => item.toString()).toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../../../src/expressions/api/definition/array.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,+B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AAI,CAAC,QAAQ,CAAC,MAAM,EAAE;gBAClC,MAAM;aACN;SACD;IACF,CAAC;IACD,MAAM,CAAC,MAAe;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACrD,CAAC;IACD,QAAQ;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC9D,CAAC;IACD,MAAM;QACL,OAAO;YACN,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;SAClD,CAAC;IACH,CAAC;CACD,CAAA;AApEY,YAAY;IADxB,YAAY,CAAC,cAAc,CAAC;;GAChB,YAAY,CAoExB;SApEY,YAAY","sourcesContent":["import type { NodeDeserializer, ExpressionNode, CanDeclareExpression } from '../expression.js';\nimport type { Stack } from '../../scope/stack.js';\nimport { AbstractExpressionNode } from '../abstract.js';\nimport { Deserializer } from '../deserialize/deserialize.js';\nimport { RestElement } from '../computing/rest.js';\nimport { ScopeType } from '../../scope/scope.js';\n\n@Deserializer('ArrayExpression')\nexport class ArrayExpression extends AbstractExpressionNode {\n\tstatic fromJSON(node: ArrayExpression, deserializer: NodeDeserializer): ArrayExpression {\n\t\treturn new ArrayExpression(node.elements.map(expression => deserializer(expression)));\n\t}\n\tconstructor(private elements: ExpressionNode[]) {\n\t\tsuper();\n\t}\n\tgetElements() {\n\t\treturn this.elements;\n\t}\n\tset(stack: Stack) {\n\t\tthrow new Error(\"ArrayExpression#set() has no implementation.\");\n\t}\n\tget(stack: Stack) {\n\t\treturn this.elements.map(item => item.get(stack));\n\t}\n\tevents(parent?: string): string[] {\n\t\treturn this.elements.flatMap(item => item.events());\n\t}\n\ttoString() {\n\t\treturn this.elements.map(item => item.toString()).toString();\n\t}\n\ttoJson(): object {\n\t\treturn {\n\t\t\telements: this.elements.map(item => item.toJSON())\n\t\t};\n\t}\n}\n\n\n@Deserializer('ArrayPattern')\nexport class ArrayPattern extends AbstractExpressionNode implements CanDeclareExpression {\n\tstatic fromJSON(node: ArrayPattern, deserializer: NodeDeserializer): ArrayPattern {\n\t\treturn new ArrayPattern(node.elements.map(expression => deserializer(expression)) as CanDeclareExpression[]);\n\t}\n\tconstructor(private elements: CanDeclareExpression[]) {\n\t\tsuper();\n\t}\n\tgetElements() {\n\t\treturn this.elements;\n\t}\n\tset(stack: Stack, values: any) {\n\t\tthrow new Error('ArrayPattern#set() has no implementation.');\n\t}\n\tget(scopeProvider: Stack) {\n\t\tthrow new Error('ArrayPattern#get() has no implementation.');\n\t}\n\tdeclareVariable(stack: Stack, scopeType: ScopeType, values: any) {\n\t\tif (Array.isArray(values)) {\n\t\t\tthis.declareVariableFromArray(stack, scopeType, values);\n\t\t} else if (Reflect.has(values, Symbol.iterator)) {\n\t\t\tthis.declareVariableFromIterator(stack, scopeType, values);\n\t\t}\n\t}\n\tdeclareVariableFromArray(stack: Stack, scopeType: ScopeType, values: any[]) {\n\t\tfor (let index = 0; index < this.elements.length; index++) {\n\t\t\tconst elem = this.elements[index];\n\t\t\tif (elem instanceof RestElement) {\n\t\t\t\tconst rest = values.slice(index);\n\t\t\t\telem.declareVariable(stack, 'block', rest);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telem.declareVariable(stack, 'block', values[index]);\n\t\t}\n\t}\n\tdeclareVariableFromIterator(stack: Stack, scopeType: ScopeType, iterator: Iterator<any>) {\n\t\tlet index = 0;\n\t\twhile (true) {\n\t\t\tlet iteratorResult = iterator.next();\n\t\t\tif (iteratorResult.done) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst elem = this.elements[index++];\n\t\t\tif (elem instanceof RestElement) {\n\t\t\t\tconst rest = [iteratorResult.value];\n\t\t\t\twhile (!iteratorResult.done) {\n\t\t\t\t\titeratorResult = iterator.next();\n\t\t\t\t\trest.push(iteratorResult.value);\n\t\t\t\t}\n\t\t\t\telem.declareVariable(stack, 'block', rest);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telem.declareVariable(stack, 'block', iteratorResult.value);\n\t\t\tif (index >= this.elements.length) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tevents(parent?: string): string[] {\n\t\treturn this.elements.flatMap(item => item.events());\n\t}\n\ttoString() {\n\t\treturn this.elements.map(item => item.toString()).toString();\n\t}\n\ttoJson(): object {\n\t\treturn {\n\t\t\telements: this.elements.map(item => item.toJSON())\n\t\t};\n\t}\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { NodeDeserializer, ExpressionNode, CanFindScope } from '../expression.js';
|
|
2
|
+
import type { Scope } from '../../scope/scope.js';
|
|
3
|
+
import type { Stack } from '../../scope/stack.js';
|
|
4
|
+
import { AbstractExpressionNode } from '../abstract.js';
|
|
5
|
+
export declare class BindExpression extends AbstractExpressionNode implements CanFindScope {
|
|
6
|
+
protected object: ExpressionNode;
|
|
7
|
+
protected property: ExpressionNode;
|
|
8
|
+
private computed;
|
|
9
|
+
private optional;
|
|
10
|
+
static fromJSON(node: BindExpression, deserializer: NodeDeserializer): BindExpression;
|
|
11
|
+
constructor(object: ExpressionNode, property: ExpressionNode, computed: boolean, optional?: boolean);
|
|
12
|
+
getObject(): ExpressionNode;
|
|
13
|
+
getProperty(): ExpressionNode;
|
|
14
|
+
set(stack: Stack): void;
|
|
15
|
+
get(stack: Stack, thisContext?: any): any;
|
|
16
|
+
findScope<T extends object>(stack: Stack): Scope<T>;
|
|
17
|
+
findScope<T extends object>(stack: Stack, scope: Scope<any>): Scope<T>;
|
|
18
|
+
events(parent?: string): string[];
|
|
19
|
+
toString(): string;
|
|
20
|
+
toJson(): object;
|
|
21
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var BindExpression_1;
|
|
2
|
+
import { __decorate, __metadata } from "tslib";
|
|
3
|
+
import { Deserializer } from '../deserialize/deserialize.js';
|
|
4
|
+
import { AbstractExpressionNode } from '../abstract.js';
|
|
5
|
+
let BindExpression = BindExpression_1 = class BindExpression extends AbstractExpressionNode {
|
|
6
|
+
constructor(object, property, computed, optional = false) {
|
|
7
|
+
super();
|
|
8
|
+
this.object = object;
|
|
9
|
+
this.property = property;
|
|
10
|
+
this.computed = computed;
|
|
11
|
+
this.optional = optional;
|
|
12
|
+
}
|
|
13
|
+
static fromJSON(node, deserializer) {
|
|
14
|
+
return new BindExpression_1(deserializer(node.object), deserializer(node.property), node.computed, node.optional);
|
|
15
|
+
}
|
|
16
|
+
getObject() {
|
|
17
|
+
return this.object;
|
|
18
|
+
}
|
|
19
|
+
getProperty() {
|
|
20
|
+
return this.property;
|
|
21
|
+
}
|
|
22
|
+
set(stack) {
|
|
23
|
+
throw new Error("BindExpression#set() has no implementation.");
|
|
24
|
+
}
|
|
25
|
+
get(stack, thisContext) {
|
|
26
|
+
const objectRef = thisContext ?? this.object.get(stack);
|
|
27
|
+
if (typeof objectRef === 'undefined') {
|
|
28
|
+
throw new TypeError(`Cannot read property '${this.property.toString()}' of undefined`);
|
|
29
|
+
}
|
|
30
|
+
let value;
|
|
31
|
+
if (this.computed) {
|
|
32
|
+
value = objectRef[this.property.get(stack)];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
value = this.property.get(stack, objectRef);
|
|
36
|
+
}
|
|
37
|
+
if (this.optional && (value === undefined || value === null)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (typeof value !== 'function') {
|
|
41
|
+
throw new Error(`can't bind to non-function type ${value}`);
|
|
42
|
+
}
|
|
43
|
+
return value.bind(objectRef);
|
|
44
|
+
}
|
|
45
|
+
findScope(stack, objectScope) {
|
|
46
|
+
if (!objectScope) {
|
|
47
|
+
objectScope = this.object.findScope(stack);
|
|
48
|
+
}
|
|
49
|
+
return this.property.findScope(stack, objectScope);
|
|
50
|
+
}
|
|
51
|
+
events(parent) {
|
|
52
|
+
if (this.computed) {
|
|
53
|
+
parent ??= '';
|
|
54
|
+
parent = `${parent}${this.object.events(parent)}`;
|
|
55
|
+
return [parent, `${parent}[${this.property.toString()}]`];
|
|
56
|
+
}
|
|
57
|
+
parent ||= '';
|
|
58
|
+
parent += this.object.toString() + '.';
|
|
59
|
+
return [...this.object.events(), ...this.property.events(parent)];
|
|
60
|
+
}
|
|
61
|
+
toString() {
|
|
62
|
+
if (this.computed) {
|
|
63
|
+
return `${this.object.toString()}${this.optional ? '?::' : '::'}[${this.property.toString()}]`;
|
|
64
|
+
}
|
|
65
|
+
return `${this.object.toString()}${this.optional ? '?::' : '::'}${this.property.toString()}`;
|
|
66
|
+
}
|
|
67
|
+
toJson() {
|
|
68
|
+
return {
|
|
69
|
+
object: this.object.toJSON(),
|
|
70
|
+
property: this.property.toJSON(),
|
|
71
|
+
computed: this.computed,
|
|
72
|
+
optional: this.optional
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
BindExpression = BindExpression_1 = __decorate([
|
|
77
|
+
Deserializer('BindExpression'),
|
|
78
|
+
__metadata("design:paramtypes", [Object, Object, Boolean, Boolean])
|
|
79
|
+
], BindExpression);
|
|
80
|
+
export { BindExpression };
|
|
81
|
+
//# sourceMappingURL=bind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bind.js","sourceRoot":"","sources":["../../../../src/expressions/api/definition/bind.ts"],"names":[],"mappings":";;AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAGxD,IAAa,cAAc,sBAA3B,MAAa,cAAe,SAAQ,sBAAsB;IASzD,YACW,MAAsB,EACtB,QAAwB,EAC1B,QAAiB,EACjB,WAAoB,KAAK;QACjC,KAAK,EAAE,CAAC;QAJE,WAAM,GAA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GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC9F,CAAC;IACD,MAAM;QACL,OAAO;YACN,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YAC5B,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;YAChC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACvB,CAAC;IACH,CAAC;CACD,CAAA;AA5EY,cAAc;IAD1B,YAAY,CAAC,gBAAgB,CAAC;;GAClB,cAAc,CA4E1B;SA5EY,cAAc","sourcesContent":["import type { NodeDeserializer, ExpressionNode, CanFindScope } from '../expression.js';\nimport type { Scope } from '../../scope/scope.js';\nimport type { Stack } from '../../scope/stack.js';\nimport { Deserializer } from '../deserialize/deserialize.js';\nimport { AbstractExpressionNode } from '../abstract.js';\n\n@Deserializer('BindExpression')\nexport class BindExpression extends AbstractExpressionNode implements CanFindScope {\n\tstatic fromJSON(node: BindExpression, deserializer: NodeDeserializer): BindExpression {\n\t\treturn new BindExpression(\n\t\t\tdeserializer(node.object),\n\t\t\tdeserializer(node.property),\n\t\t\tnode.computed,\n\t\t\tnode.optional\n\t\t);\n\t}\n\tconstructor(\n\t\tprotected object: ExpressionNode,\n\t\tprotected property: ExpressionNode,\n\t\tprivate computed: boolean,\n\t\tprivate optional: boolean = false) {\n\t\tsuper();\n\t}\n\tgetObject() {\n\t\treturn this.object;\n\t}\n\tgetProperty() {\n\t\treturn this.property;\n\t}\n\tset(stack: Stack) {\n\t\tthrow new Error(\"BindExpression#set() has no implementation.\");\n\t}\n\tget(stack: Stack, thisContext?: any) {\n\t\tconst objectRef = thisContext ?? this.object.get(stack);\n\t\tif (typeof objectRef === 'undefined') {\n\t\t\tthrow new TypeError(`Cannot read property '${this.property.toString()}' of undefined`);\n\t\t}\n\t\tlet value;\n\t\tif (this.computed) {\n\t\t\tvalue = objectRef[this.property.get(stack)];\n\t\t} else {\n\t\t\tvalue = this.property.get(stack, objectRef);\n\t\t}\n\t\tif (this.optional && (value === undefined || value === null)) {\n\t\t\treturn;\n\t\t}\n\t\tif (typeof value !== 'function') {\n\t\t\tthrow new Error(`can't bind to non-function type ${value}`);\n\t\t}\n\t\treturn (<Function>value).bind(objectRef);\n\t}\n\tfindScope<T extends object>(stack: Stack): Scope<T>;\n\tfindScope<T extends object>(stack: Stack, scope: Scope<any>): Scope<T>;\n\tfindScope<T extends object>(stack: Stack, objectScope?: Scope<any>): Scope<T> | undefined {\n\t\tif (!objectScope) {\n\t\t\tobjectScope = (this.object as ExpressionNode & CanFindScope).findScope(stack);\n\t\t}\n\t\treturn (this.property as ExpressionNode & CanFindScope).findScope(stack, objectScope);\n\t}\n\tevents(parent?: string): string[] {\n\t\tif (this.computed) {\n\t\t\tparent ??= '';\n\t\t\tparent = `${parent}${this.object.events(parent)}`;\n\t\t\treturn [parent, `${parent}[${this.property.toString()}]`];\n\t\t}\n\t\tparent ||= '';\n\t\tparent += this.object.toString() + '.';\n\t\treturn [...this.object.events(), ...this.property.events(parent)];\n\t}\n\ttoString() {\n\t\tif (this.computed) {\n\t\t\treturn `${this.object.toString()}${this.optional ? '?::' : '::'}[${this.property.toString()}]`;\n\t\t}\n\t\treturn `${this.object.toString()}${this.optional ? '?::' : '::'}${this.property.toString()}`;\n\t}\n\ttoJson(): object {\n\t\treturn {\n\t\t\tobject: this.object.toJSON(),\n\t\t\tproperty: this.property.toJSON(),\n\t\t\tcomputed: this.computed,\n\t\t\toptional: this.optional\n\t\t};\n\t}\n}\n"]}
|
|
@@ -7,8 +7,7 @@ export declare class CommentExpression extends AbstractExpressionNode {
|
|
|
7
7
|
getComment(): string;
|
|
8
8
|
set(stack: Stack, ...values: any[]): void;
|
|
9
9
|
get(stack: Stack): void;
|
|
10
|
-
|
|
11
|
-
event(parent?: string): string[];
|
|
10
|
+
events(parent?: string): string[];
|
|
12
11
|
toString(): string;
|
|
13
12
|
toJson(): object;
|
|
14
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment.js","sourceRoot":"","sources":["../../../../src/expressions/api/definition/comment.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D,IAAa,iBAAiB,yBAA9B,MAAa,iBAAkB,SAAQ,sBAAsB;IAI5D,YAAoB,OAAe;QAClC,KAAK,EAAE,CAAC;QADW,YAAO,GAAP,OAAO,CAAQ;IAEnC,CAAC;IALD,MAAM,CAAC,QAAQ,CAAC,OAA0B;QACzC,OAAO,IAAI,mBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAID,UAAU;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAOD,GAAG,CAAC,KAAY,EAAE,GAAG,MAAa;IAElC,CAAC;IAMD,GAAG,CAAC,KAAY;IAEhB,CAAC;IACD,
|
|
1
|
+
{"version":3,"file":"comment.js","sourceRoot":"","sources":["../../../../src/expressions/api/definition/comment.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D,IAAa,iBAAiB,yBAA9B,MAAa,iBAAkB,SAAQ,sBAAsB;IAI5D,YAAoB,OAAe;QAClC,KAAK,EAAE,CAAC;QADW,YAAO,GAAP,OAAO,CAAQ;IAEnC,CAAC;IALD,MAAM,CAAC,QAAQ,CAAC,OAA0B;QACzC,OAAO,IAAI,mBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAID,UAAU;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAOD,GAAG,CAAC,KAAY,EAAE,GAAG,MAAa;IAElC,CAAC;IAMD,GAAG,CAAC,KAAY;IAEhB,CAAC;IACD,MAAM,CAAC,MAAe;QACrB,OAAO,EAAE,CAAC;IACX,CAAC;IACD,QAAQ;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IACD,MAAM;QACL,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IAClC,CAAC;CACD,CAAA;AApCY,iBAAiB;IAD7B,YAAY,CAAC,mBAAmB,CAAC;;GACrB,iBAAiB,CAoC7B;SApCY,iBAAiB","sourcesContent":["\nimport type { Stack } from '../../scope/stack.js';\nimport { AbstractExpressionNode } from '../abstract.js';\nimport { Deserializer } from '../deserialize/deserialize.js';\n\n@Deserializer('CommentExpression')\nexport class CommentExpression extends AbstractExpressionNode {\n\tstatic fromJSON(nodeExp: CommentExpression): CommentExpression {\n\t\treturn new CommentExpression(nodeExp.comment);\n\t}\n\tconstructor(private comment: string) {\n\t\tsuper();\n\t}\n\tgetComment() {\n\t\treturn this.comment;\n\t}\n\n\t/**\n\t * \n\t * @param context execution stack/scope context\n\t * @param value any paramter\n\t */\n\tset(stack: Stack, ...values: any[]) {\n\n\t}\n\n\t/**\n\t * used when define a function\n\t * @param context execution stack/scope context\n\t */\n\tget(stack: Stack) {\n\n\t}\n\tevents(parent?: string): string[] {\n\t\treturn [];\n\t}\n\ttoString(): string {\n\t\treturn this.comment;\n\t}\n\ttoJson(): object {\n\t\treturn { comment: this.comment };\n\t}\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExpressionNode, NodeDeserializer } from '../expression.js';
|
|
1
|
+
import type { CanDeclareExpression, ExpressionNode, NodeDeserializer } from '../expression.js';
|
|
2
2
|
import type { Stack } from '../../scope/stack.js';
|
|
3
3
|
import { AbstractExpressionNode } from '../abstract.js';
|
|
4
4
|
export declare enum FunctionKind {
|
|
@@ -21,17 +21,16 @@ export declare enum ArrowFunctionType {
|
|
|
21
21
|
NORMAL = "NORMAL",
|
|
22
22
|
ASYNC = "ASYNC"
|
|
23
23
|
}
|
|
24
|
-
export declare class
|
|
24
|
+
export declare class Param extends AbstractExpressionNode {
|
|
25
25
|
private identifier;
|
|
26
26
|
private defaultValue?;
|
|
27
|
-
static fromJSON(node:
|
|
27
|
+
static fromJSON(node: Param, deserializer: NodeDeserializer): Param;
|
|
28
28
|
constructor(identifier: ExpressionNode, defaultValue?: ExpressionNode | undefined);
|
|
29
29
|
getIdentifier(): ExpressionNode;
|
|
30
30
|
getDefaultValue(): ExpressionNode | undefined;
|
|
31
31
|
set(stack: Stack, value: Function): void;
|
|
32
32
|
get(stack: Stack): void;
|
|
33
|
-
|
|
34
|
-
event(): string[];
|
|
33
|
+
events(): string[];
|
|
35
34
|
toString(): string;
|
|
36
35
|
toJson(): object;
|
|
37
36
|
}
|
|
@@ -39,27 +38,26 @@ export declare class FunctionExpression extends AbstractExpressionNode {
|
|
|
39
38
|
protected params: ExpressionNode[];
|
|
40
39
|
protected body: ExpressionNode[];
|
|
41
40
|
protected kind: FunctionKind;
|
|
42
|
-
protected id?:
|
|
41
|
+
protected id?: CanDeclareExpression | undefined;
|
|
43
42
|
protected rest?: boolean | undefined;
|
|
44
43
|
protected generator?: boolean | undefined;
|
|
45
44
|
static fromJSON(node: FunctionExpression, deserializer: NodeDeserializer): FunctionExpression;
|
|
46
|
-
constructor(params: ExpressionNode[], body: ExpressionNode[], kind: FunctionKind, id?:
|
|
45
|
+
constructor(params: ExpressionNode[], body: ExpressionNode[], kind: FunctionKind, id?: CanDeclareExpression | undefined, rest?: boolean | undefined, generator?: boolean | undefined);
|
|
47
46
|
getParams(): ExpressionNode[];
|
|
48
47
|
getBody(): ExpressionNode[];
|
|
49
48
|
getKind(): FunctionKind;
|
|
50
|
-
getId():
|
|
49
|
+
getId(): CanDeclareExpression | undefined;
|
|
51
50
|
getRest(): boolean | undefined;
|
|
52
51
|
set(stack: Stack, value: Function): void;
|
|
53
|
-
private
|
|
52
|
+
private setParameter;
|
|
54
53
|
get(stack: Stack): Function;
|
|
55
|
-
|
|
56
|
-
event(): string[];
|
|
54
|
+
events(): string[];
|
|
57
55
|
toString(): string;
|
|
58
56
|
toJson(): object;
|
|
59
57
|
}
|
|
60
58
|
export declare class FunctionDeclaration extends FunctionExpression {
|
|
61
59
|
static fromJSON(node: FunctionDeclaration, deserializer: NodeDeserializer): FunctionDeclaration;
|
|
62
|
-
constructor(params: ExpressionNode[], body: ExpressionNode[], kind: FunctionKind, id:
|
|
60
|
+
constructor(params: ExpressionNode[], body: ExpressionNode[], kind: FunctionKind, id: CanDeclareExpression, rest?: boolean, generator?: boolean);
|
|
63
61
|
}
|
|
64
62
|
export declare class ArrowFunctionExpression extends AbstractExpressionNode {
|
|
65
63
|
private params;
|
|
@@ -73,10 +71,9 @@ export declare class ArrowFunctionExpression extends AbstractExpressionNode {
|
|
|
73
71
|
getBody(): ExpressionNode[];
|
|
74
72
|
getRest(): boolean | undefined;
|
|
75
73
|
set(stack: Stack, value: Function): void;
|
|
76
|
-
private
|
|
74
|
+
private setParameter;
|
|
77
75
|
get(stack: Stack): Function;
|
|
78
|
-
|
|
79
|
-
event(): string[];
|
|
76
|
+
events(): string[];
|
|
80
77
|
toString(): string;
|
|
81
78
|
toJson(): object;
|
|
82
79
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Param_1, FunctionExpression_1, FunctionDeclaration_1, ArrowFunctionExpression_1;
|
|
2
2
|
import { __decorate, __metadata } from "tslib";
|
|
3
3
|
import { AbstractExpressionNode, AwaitPromise, ReturnValue } from '../abstract.js';
|
|
4
4
|
import { Deserializer } from '../deserialize/deserialize.js';
|
|
5
|
-
import { BreakStatement, ContinueStatement } from '../statement/
|
|
5
|
+
import { BreakStatement, ContinueStatement } from '../statement/control/terminate.js';
|
|
6
6
|
export var FunctionKind;
|
|
7
7
|
(function (FunctionKind) {
|
|
8
8
|
FunctionKind["NORMAL"] = "NORMAL";
|
|
@@ -25,14 +25,14 @@ export var ArrowFunctionType;
|
|
|
25
25
|
ArrowFunctionType["NORMAL"] = "NORMAL";
|
|
26
26
|
ArrowFunctionType["ASYNC"] = "ASYNC";
|
|
27
27
|
})(ArrowFunctionType || (ArrowFunctionType = {}));
|
|
28
|
-
let
|
|
28
|
+
let Param = Param_1 = class Param extends AbstractExpressionNode {
|
|
29
29
|
constructor(identifier, defaultValue) {
|
|
30
30
|
super();
|
|
31
31
|
this.identifier = identifier;
|
|
32
32
|
this.defaultValue = defaultValue;
|
|
33
33
|
}
|
|
34
34
|
static fromJSON(node, deserializer) {
|
|
35
|
-
return new
|
|
35
|
+
return new Param_1(deserializer(node.identifier), node.defaultValue ? deserializer(node.defaultValue) : void 0);
|
|
36
36
|
}
|
|
37
37
|
getIdentifier() {
|
|
38
38
|
return this.identifier;
|
|
@@ -44,13 +44,10 @@ let Paramter = Paramter_1 = class Paramter extends AbstractExpressionNode {
|
|
|
44
44
|
this.identifier.set(stack, value || this.defaultValue?.get(stack));
|
|
45
45
|
}
|
|
46
46
|
get(stack) {
|
|
47
|
-
throw new Error('
|
|
47
|
+
throw new Error('Param#get() has no implementation.');
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
return this.identifier.
|
|
51
|
-
}
|
|
52
|
-
event() {
|
|
53
|
-
return this.identifier.event().concat(this.defaultValue?.event() || []);
|
|
49
|
+
events() {
|
|
50
|
+
return this.identifier.events().concat(this.defaultValue?.events() || []);
|
|
54
51
|
}
|
|
55
52
|
toString() {
|
|
56
53
|
let init = this.defaultValue ? (' = ' + this.defaultValue.toString()) : '';
|
|
@@ -63,11 +60,11 @@ let Paramter = Paramter_1 = class Paramter extends AbstractExpressionNode {
|
|
|
63
60
|
};
|
|
64
61
|
}
|
|
65
62
|
};
|
|
66
|
-
|
|
67
|
-
Deserializer('
|
|
63
|
+
Param = Param_1 = __decorate([
|
|
64
|
+
Deserializer('Param'),
|
|
68
65
|
__metadata("design:paramtypes", [Object, Object])
|
|
69
|
-
],
|
|
70
|
-
export {
|
|
66
|
+
], Param);
|
|
67
|
+
export { Param };
|
|
71
68
|
let FunctionExpression = FunctionExpression_1 = class FunctionExpression extends AbstractExpressionNode {
|
|
72
69
|
constructor(params, body, kind, id, rest, generator) {
|
|
73
70
|
super();
|
|
@@ -99,7 +96,7 @@ let FunctionExpression = FunctionExpression_1 = class FunctionExpression extends
|
|
|
99
96
|
set(stack, value) {
|
|
100
97
|
throw new Error('FunctionExpression#set() has no implementation.');
|
|
101
98
|
}
|
|
102
|
-
|
|
99
|
+
setParameter(stack, args) {
|
|
103
100
|
const limit = this.rest ? this.params.length - 1 : this.params.length;
|
|
104
101
|
for (let i = 0; i < limit; i++) {
|
|
105
102
|
this.params[i].set(stack, args[i]);
|
|
@@ -114,9 +111,9 @@ let FunctionExpression = FunctionExpression_1 = class FunctionExpression extends
|
|
|
114
111
|
switch (this.kind) {
|
|
115
112
|
case FunctionKind.ASYNC:
|
|
116
113
|
func = async function (...args) {
|
|
117
|
-
stack.pushFunctionScope();
|
|
114
|
+
const scope = stack.pushFunctionScope();
|
|
118
115
|
stack.declareVariable('function', 'this', this);
|
|
119
|
-
self.
|
|
116
|
+
self.setParameter(stack, args);
|
|
120
117
|
let returnValue;
|
|
121
118
|
for (const state of self.body) {
|
|
122
119
|
returnValue = state.get(stack);
|
|
@@ -152,35 +149,35 @@ let FunctionExpression = FunctionExpression_1 = class FunctionExpression extends
|
|
|
152
149
|
returnValue = returnValue.value;
|
|
153
150
|
if (returnValue instanceof AwaitPromise) {
|
|
154
151
|
returnValue = await returnValue.promise;
|
|
155
|
-
stack.
|
|
152
|
+
stack.clearTo(scope);
|
|
156
153
|
return returnValue;
|
|
157
154
|
}
|
|
158
155
|
}
|
|
159
156
|
}
|
|
160
|
-
stack.
|
|
157
|
+
stack.clearTo(scope);
|
|
161
158
|
};
|
|
162
159
|
break;
|
|
163
160
|
case FunctionKind.GENERATOR:
|
|
164
161
|
func = function* (...args) {
|
|
165
|
-
stack.pushFunctionScope();
|
|
162
|
+
const scope = stack.pushFunctionScope();
|
|
166
163
|
stack.declareVariable('function', 'this', this);
|
|
167
|
-
self.
|
|
164
|
+
self.setParameter(stack, args);
|
|
168
165
|
let returnValue;
|
|
169
166
|
for (const state of self.body) {
|
|
170
167
|
returnValue = state.get(stack);
|
|
171
168
|
if (returnValue instanceof ReturnValue) {
|
|
172
|
-
stack.
|
|
169
|
+
stack.clearTo(scope);
|
|
173
170
|
return returnValue.value;
|
|
174
171
|
}
|
|
175
172
|
}
|
|
176
|
-
stack.
|
|
173
|
+
stack.clearTo(scope);
|
|
177
174
|
};
|
|
178
175
|
break;
|
|
179
176
|
case FunctionKind.ASYNC_GENERATOR:
|
|
180
177
|
func = async function* (...args) {
|
|
181
|
-
stack.pushFunctionScope();
|
|
178
|
+
const scope = stack.pushFunctionScope();
|
|
182
179
|
stack.declareVariable('function', 'this', this);
|
|
183
|
-
self.
|
|
180
|
+
self.setParameter(stack, args);
|
|
184
181
|
let returnValue;
|
|
185
182
|
for (const state of self.body) {
|
|
186
183
|
returnValue = state.get(stack);
|
|
@@ -207,7 +204,7 @@ let FunctionExpression = FunctionExpression_1 = class FunctionExpression extends
|
|
|
207
204
|
}
|
|
208
205
|
else if (result instanceof ReturnValue) {
|
|
209
206
|
returnValue = result;
|
|
210
|
-
stack.
|
|
207
|
+
stack.clearTo(scope);
|
|
211
208
|
break;
|
|
212
209
|
}
|
|
213
210
|
}
|
|
@@ -216,45 +213,38 @@ let FunctionExpression = FunctionExpression_1 = class FunctionExpression extends
|
|
|
216
213
|
if (returnValue instanceof ReturnValue) {
|
|
217
214
|
returnValue = returnValue.value;
|
|
218
215
|
if (returnValue instanceof AwaitPromise) {
|
|
219
|
-
stack.
|
|
216
|
+
stack.clearTo(scope);
|
|
220
217
|
return await returnValue.promise;
|
|
221
218
|
}
|
|
222
219
|
}
|
|
223
220
|
}
|
|
224
|
-
stack.
|
|
221
|
+
stack.clearTo(scope);
|
|
225
222
|
};
|
|
226
223
|
break;
|
|
227
224
|
default:
|
|
228
225
|
case FunctionKind.NORMAL:
|
|
229
226
|
func = function (...args) {
|
|
230
|
-
stack.pushFunctionScope();
|
|
227
|
+
const scope = stack.pushFunctionScope();
|
|
231
228
|
stack.declareVariable('function', 'this', this);
|
|
232
|
-
self.
|
|
229
|
+
self.setParameter(stack, args);
|
|
233
230
|
let returnValue;
|
|
234
231
|
for (const state of self.body) {
|
|
235
232
|
returnValue = state.get(stack);
|
|
236
233
|
if (returnValue instanceof ReturnValue) {
|
|
237
|
-
stack.
|
|
234
|
+
stack.clearTo(scope);
|
|
238
235
|
return returnValue.value;
|
|
239
236
|
}
|
|
240
237
|
}
|
|
241
|
-
stack.
|
|
238
|
+
stack.clearTo(scope);
|
|
242
239
|
};
|
|
243
240
|
break;
|
|
244
241
|
}
|
|
245
|
-
|
|
246
|
-
this.id.set(stack, func);
|
|
247
|
-
}
|
|
242
|
+
this.id?.declareVariable(stack, 'block', func);
|
|
248
243
|
return func;
|
|
249
244
|
}
|
|
250
|
-
|
|
251
|
-
return [
|
|
252
|
-
...this.params.flatMap(param => param.entry()),
|
|
253
|
-
];
|
|
254
|
-
}
|
|
255
|
-
event() {
|
|
245
|
+
events() {
|
|
256
246
|
return [
|
|
257
|
-
...this.params.flatMap(param => param.
|
|
247
|
+
...this.params.flatMap(param => param.events()),
|
|
258
248
|
];
|
|
259
249
|
}
|
|
260
250
|
toString() {
|
|
@@ -336,7 +326,7 @@ let ArrowFunctionExpression = ArrowFunctionExpression_1 = class ArrowFunctionExp
|
|
|
336
326
|
set(stack, value) {
|
|
337
327
|
throw new Error('ArrowFunctionExpression#set() has no implementation.');
|
|
338
328
|
}
|
|
339
|
-
|
|
329
|
+
setParameter(stack, args) {
|
|
340
330
|
const limit = this.rest ? this.params.length - 1 : this.params.length;
|
|
341
331
|
for (let i = 0; i < limit; i++) {
|
|
342
332
|
this.params[i].set(stack, args[i]);
|
|
@@ -350,8 +340,8 @@ let ArrowFunctionExpression = ArrowFunctionExpression_1 = class ArrowFunctionExp
|
|
|
350
340
|
switch (this.kind) {
|
|
351
341
|
case ArrowFunctionType.ASYNC:
|
|
352
342
|
func = async (...args) => {
|
|
353
|
-
stack.pushFunctionScope();
|
|
354
|
-
this.
|
|
343
|
+
const scope = stack.pushFunctionScope();
|
|
344
|
+
this.setParameter(stack, args);
|
|
355
345
|
let returnValue;
|
|
356
346
|
for (const state of this.body) {
|
|
357
347
|
returnValue = state.get(stack);
|
|
@@ -386,41 +376,42 @@ let ArrowFunctionExpression = ArrowFunctionExpression_1 = class ArrowFunctionExp
|
|
|
386
376
|
if (returnValue instanceof ReturnValue) {
|
|
387
377
|
returnValue = returnValue.value;
|
|
388
378
|
if (returnValue instanceof AwaitPromise) {
|
|
389
|
-
stack.
|
|
379
|
+
stack.clearTo(scope);
|
|
390
380
|
return await returnValue.promise;
|
|
391
381
|
}
|
|
392
382
|
}
|
|
393
383
|
}
|
|
394
|
-
stack.
|
|
384
|
+
stack.clearTo(scope);
|
|
385
|
+
if (this.body.length === 1) {
|
|
386
|
+
return returnValue;
|
|
387
|
+
}
|
|
395
388
|
};
|
|
396
389
|
break;
|
|
397
390
|
default:
|
|
398
391
|
case ArrowFunctionType.NORMAL:
|
|
399
392
|
func = (...args) => {
|
|
400
|
-
stack.pushFunctionScope();
|
|
401
|
-
this.
|
|
393
|
+
const scope = stack.pushFunctionScope();
|
|
394
|
+
this.setParameter(stack, args);
|
|
402
395
|
let returnValue;
|
|
403
396
|
for (const state of this.body) {
|
|
404
397
|
returnValue = state.get(stack);
|
|
405
398
|
if (returnValue instanceof ReturnValue) {
|
|
406
|
-
stack.
|
|
399
|
+
stack.clearTo(scope);
|
|
407
400
|
return returnValue.value;
|
|
408
401
|
}
|
|
409
402
|
}
|
|
410
|
-
stack.
|
|
403
|
+
stack.clearTo(scope);
|
|
404
|
+
if (this.body.length === 1) {
|
|
405
|
+
return returnValue;
|
|
406
|
+
}
|
|
411
407
|
};
|
|
412
408
|
break;
|
|
413
409
|
}
|
|
414
410
|
return func;
|
|
415
411
|
}
|
|
416
|
-
|
|
417
|
-
return [
|
|
418
|
-
...this.params.flatMap(param => param.entry()),
|
|
419
|
-
];
|
|
420
|
-
}
|
|
421
|
-
event() {
|
|
412
|
+
events() {
|
|
422
413
|
return [
|
|
423
|
-
...this.params.flatMap(param => param.
|
|
414
|
+
...this.params.flatMap(param => param.events()),
|
|
424
415
|
];
|
|
425
416
|
}
|
|
426
417
|
toString() {
|