@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.
Files changed (137) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -0
  3. package/api/abstract.d.ts +3 -3
  4. package/api/abstract.js +7 -2
  5. package/api/abstract.js.map +1 -1
  6. package/api/class/class.d.ts +45 -24
  7. package/api/class/class.js +158 -112
  8. package/api/class/class.js.map +1 -1
  9. package/api/computing/debugger.d.ts +15 -0
  10. package/api/computing/debugger.js +35 -0
  11. package/api/computing/debugger.js.map +1 -0
  12. package/api/computing/rest.d.ts +4 -4
  13. package/api/computing/rest.js.map +1 -1
  14. package/api/computing/return.d.ts +4 -0
  15. package/api/computing/return.js +5 -0
  16. package/api/computing/return.js.map +1 -1
  17. package/api/computing/throw.d.ts +4 -0
  18. package/api/computing/throw.js +4 -0
  19. package/api/computing/throw.js.map +1 -1
  20. package/api/definition/array.d.ts +7 -6
  21. package/api/definition/array.js +20 -14
  22. package/api/definition/array.js.map +1 -1
  23. package/api/definition/bind.d.ts +6 -0
  24. package/api/definition/bind.js +6 -0
  25. package/api/definition/bind.js.map +1 -1
  26. package/api/definition/function.d.ts +35 -46
  27. package/api/definition/function.js +282 -299
  28. package/api/definition/function.js.map +1 -1
  29. package/api/definition/member.js.map +1 -1
  30. package/api/definition/object.d.ts +9 -6
  31. package/api/definition/object.js +35 -5
  32. package/api/definition/object.js.map +1 -1
  33. package/api/definition/statement.js +5 -1
  34. package/api/definition/statement.js.map +1 -1
  35. package/api/definition/values.d.ts +43 -50
  36. package/api/definition/values.js +84 -149
  37. package/api/definition/values.js.map +1 -1
  38. package/api/deserialize/deserialize.d.ts +7 -1
  39. package/api/deserialize/deserialize.js +9 -1
  40. package/api/deserialize/deserialize.js.map +1 -1
  41. package/api/deserialize/type-store.d.ts +2 -2
  42. package/api/deserialize/type-store.js.map +1 -1
  43. package/api/expression.d.ts +156 -12
  44. package/api/expression.js.map +1 -1
  45. package/api/index.d.ts +2 -0
  46. package/api/index.js +2 -0
  47. package/api/index.js.map +1 -1
  48. package/api/module/common.d.ts +29 -0
  49. package/api/module/common.js +71 -0
  50. package/api/module/common.js.map +1 -0
  51. package/api/module/export.d.ts +78 -9
  52. package/api/module/export.js +120 -15
  53. package/api/module/export.js.map +1 -1
  54. package/api/module/import.d.ts +56 -8
  55. package/api/module/import.js +62 -19
  56. package/api/module/import.js.map +1 -1
  57. package/api/operators/grouping.d.ts +7 -0
  58. package/api/operators/grouping.js +7 -0
  59. package/api/operators/grouping.js.map +1 -1
  60. package/api/operators/pipeline.d.ts +12 -0
  61. package/api/operators/pipeline.js +12 -0
  62. package/api/operators/pipeline.js.map +1 -1
  63. package/api/operators/unary.js +3 -0
  64. package/api/operators/unary.js.map +1 -1
  65. package/api/{module/app/program.d.ts → program.d.ts} +5 -5
  66. package/api/{module/app/program.js → program.js} +3 -3
  67. package/api/program.js.map +1 -0
  68. package/api/statement/control/block.d.ts +5 -2
  69. package/api/statement/control/block.js +24 -21
  70. package/api/statement/control/block.js.map +1 -1
  71. package/api/statement/control/empty.d.ts +7 -0
  72. package/api/statement/control/empty.js +7 -0
  73. package/api/statement/control/empty.js.map +1 -1
  74. package/api/statement/control/if.d.ts +5 -0
  75. package/api/statement/control/if.js +5 -0
  76. package/api/statement/control/if.js.map +1 -1
  77. package/api/statement/control/switch.d.ts +6 -0
  78. package/api/statement/control/switch.js +17 -3
  79. package/api/statement/control/switch.js.map +1 -1
  80. package/api/statement/control/terminate.d.ts +44 -11
  81. package/api/statement/control/terminate.js +87 -18
  82. package/api/statement/control/terminate.js.map +1 -1
  83. package/api/statement/declarations/declares.d.ts +7 -7
  84. package/api/statement/declarations/declares.js +1 -1
  85. package/api/statement/declarations/declares.js.map +1 -1
  86. package/api/statement/iterations/for.d.ts +5 -0
  87. package/api/statement/iterations/for.js +35 -16
  88. package/api/statement/iterations/for.js.map +1 -1
  89. package/api/statement/iterations/while.d.ts +6 -0
  90. package/api/statement/iterations/while.js +25 -11
  91. package/api/statement/iterations/while.js.map +1 -1
  92. package/api/utils.d.ts +2 -0
  93. package/api/utils.js +3 -1
  94. package/api/utils.js.map +1 -1
  95. package/package.json +7 -5
  96. package/scope/event.d.ts +3 -3
  97. package/scope/event.js +2 -2
  98. package/scope/event.js.map +1 -1
  99. package/scope/pool.d.ts +7 -0
  100. package/scope/pool.js +29 -0
  101. package/scope/pool.js.map +1 -0
  102. package/scope/proxy.d.ts +6 -11
  103. package/scope/proxy.js +23 -52
  104. package/scope/proxy.js.map +1 -1
  105. package/scope/scope.d.ts +161 -38
  106. package/scope/scope.js +260 -106
  107. package/scope/scope.js.map +1 -1
  108. package/scope/stack.d.ts +97 -21
  109. package/scope/stack.js +13 -0
  110. package/scope/stack.js.map +1 -1
  111. package/v8/enums.d.ts +204 -0
  112. package/v8/enums.js +406 -0
  113. package/v8/enums.js.map +1 -0
  114. package/v8/index.d.ts +2 -1
  115. package/v8/index.js +2 -1
  116. package/v8/index.js.map +1 -1
  117. package/v8/inline.d.ts +213 -0
  118. package/v8/inline.js +2375 -0
  119. package/v8/inline.js.map +1 -0
  120. package/v8/nodes.d.ts +8 -7
  121. package/v8/nodes.js +39 -64
  122. package/v8/nodes.js.map +1 -1
  123. package/v8/parser.d.ts +49 -151
  124. package/v8/parser.js +839 -1608
  125. package/v8/parser.js.map +1 -1
  126. package/v8/stream.d.ts +39 -3
  127. package/v8/stream.js +685 -171
  128. package/v8/stream.js.map +1 -1
  129. package/v8/token.d.ts +244 -9
  130. package/v8/token.js +315 -47
  131. package/v8/token.js.map +1 -1
  132. package/visit/visitor.d.ts +3 -0
  133. package/visit/visitor.js.map +1 -1
  134. package/api/module/app/program.js.map +0 -1
  135. package/v8/app.d.ts +0 -0
  136. package/v8/app.js +0 -2
  137. package/v8/app.js.map +0 -1
@@ -3,29 +3,9 @@ import { __decorate, __metadata } from "tslib";
3
3
  import { Scope } from '../../scope/scope.js';
4
4
  import { AbstractExpressionNode, AwaitPromise, ReturnValue, YieldDelegateValue, YieldValue } from '../abstract.js';
5
5
  import { Deserializer } from '../deserialize/deserialize.js';
6
- import { BreakStatement, ContinueStatement } from '../statement/control/terminate.js';
7
- export var FunctionKind;
8
- (function (FunctionKind) {
9
- FunctionKind["NORMAL"] = "NORMAL";
10
- FunctionKind["ASYNC"] = "ASYNC";
11
- FunctionKind["GENERATOR"] = "GENERATOR";
12
- FunctionKind["ASYNC_GENERATOR"] = "ASYNC_GENERATOR";
13
- FunctionKind["CONCISE"] = "CONCISE";
14
- FunctionKind["ASYNC_CONCISE"] = "ASYNC_CONCISE";
15
- FunctionKind["CONCISE_GENERATOR"] = "CONCISE_GENERATOR";
16
- FunctionKind["ASYNC_CONCISE_GENERATOR"] = "ASYNC_CONCISE_GENERATOR";
17
- FunctionKind["STATIC_CONCISE"] = "STATIC_CONCISE";
18
- FunctionKind["STATIC_ASYNC_CONCISE"] = "STATIC_ASYNC_CONCISE";
19
- FunctionKind["STATIC_CONCISE_GENERATOR"] = "STATIC_CONCISE_GENERATOR";
20
- FunctionKind["STATIC_ASYNC_CONCISE_GENERATOR"] = "STATIC_ASYNC_CONCISE_GENERATOR";
21
- FunctionKind["DERIVED_CONSTRUCTOR"] = "DERIVED_CONSTRUCTOR";
22
- FunctionKind["BASE_CONSTRUCTOR"] = "BASE_CONSTRUCTOR";
23
- })(FunctionKind || (FunctionKind = {}));
24
- export var ArrowFunctionType;
25
- (function (ArrowFunctionType) {
26
- ArrowFunctionType["NORMAL"] = "NORMAL";
27
- ArrowFunctionType["ASYNC"] = "ASYNC";
28
- })(ArrowFunctionType || (ArrowFunctionType = {}));
6
+ import { Identifier } from './values.js';
7
+ import { TerminateReturnType } from '../statement/control/terminate.js';
8
+ import { RestElement } from '../computing/rest.js';
29
9
  let Param = Param_1 = class Param extends AbstractExpressionNode {
30
10
  constructor(identifier, defaultValue) {
31
11
  super();
@@ -76,7 +56,7 @@ Param = Param_1 = __decorate([
76
56
  __metadata("design:paramtypes", [Object, Object])
77
57
  ], Param);
78
58
  export { Param };
79
- export class FunctionBaseExpression extends AbstractExpressionNode {
59
+ export class BaseFunctionExpression extends AbstractExpressionNode {
80
60
  shareVariables(scopeList) {
81
61
  this.sharedVariables = scopeList;
82
62
  }
@@ -91,23 +71,22 @@ export class FunctionBaseExpression extends AbstractExpressionNode {
91
71
  stack.clearTo(innerScopes[0]);
92
72
  }
93
73
  }
94
- let FunctionExpression = FunctionExpression_1 = class FunctionExpression extends FunctionBaseExpression {
95
- constructor(params, body, kind, id, rest, generator) {
74
+ let FunctionExpression = FunctionExpression_1 = class FunctionExpression extends BaseFunctionExpression {
75
+ constructor(params, body, async, generator, id) {
96
76
  super();
97
77
  this.params = params;
98
78
  this.body = body;
99
- this.kind = kind;
100
- this.id = id;
101
- this.rest = rest;
79
+ this.async = async;
102
80
  this.generator = generator;
81
+ this.id = id;
103
82
  }
104
83
  static fromJSON(node, deserializer) {
105
- return new FunctionExpression_1(node.params.map(deserializer), node.body.map(deserializer), FunctionKind[node.kind], node.id ? deserializer(node.id) : void 0, node.rest, node.generator);
84
+ return new FunctionExpression_1(node.params.map(deserializer), deserializer(node.body), node.async, node.generator, node.id ? deserializer(node.id) : void 0);
106
85
  }
107
86
  static visit(node, visitNode) {
108
87
  node.id && visitNode(node.id);
109
88
  node.params.forEach(visitNode);
110
- node.body.forEach(visitNode);
89
+ visitNode(node.body);
111
90
  }
112
91
  getParams() {
113
92
  return this.params;
@@ -115,182 +94,203 @@ let FunctionExpression = FunctionExpression_1 = class FunctionExpression extends
115
94
  getBody() {
116
95
  return this.body;
117
96
  }
118
- getKind() {
119
- return this.kind;
97
+ getGenerator() {
98
+ return this.generator;
120
99
  }
121
100
  getId() {
122
101
  return this.id;
123
102
  }
124
- getRest() {
125
- return this.rest;
103
+ getAsync() {
104
+ return this.async;
126
105
  }
127
106
  set(stack, value) {
128
107
  throw new Error(`${this.constructor.name}#set() has no implementation.`);
129
108
  }
130
109
  setParameter(stack, args) {
131
- const limit = this.rest ? this.params.length - 1 : this.params.length;
110
+ const rest = this.params[this.params.length - 1] instanceof RestElement;
111
+ const limit = rest ? this.params.length - 1 : this.params.length;
132
112
  for (let i = 0; i < limit; i++) {
133
113
  this.params[i].set(stack, args[i]);
134
114
  }
135
- if (this.rest) {
115
+ if (rest) {
136
116
  this.params[limit].set(stack, args.slice(limit));
137
117
  }
138
118
  }
139
119
  get(stack) {
140
- const self = this;
141
120
  let func;
142
- switch (this.kind) {
143
- case FunctionKind.ASYNC:
144
- func = async function (...args) {
145
- const innerScopes = self.initFunctionScope(stack);
146
- stack.declareVariable('this', this);
147
- self.setParameter(stack, args);
148
- let returnValue;
149
- for (const statement of self.body) {
150
- statement.shareVariables(innerScopes);
151
- returnValue = statement.get(stack);
152
- if (stack.awaitPromise.length > 0) {
153
- for (const awaitRef of stack.awaitPromise) {
154
- const awaitValue = await awaitRef.promise;
155
- if (awaitRef.declareVariable) {
156
- awaitRef.node.declareVariable(stack, awaitValue);
157
- }
158
- else {
159
- awaitRef.node.set(stack, awaitValue);
160
- }
161
- }
162
- stack.awaitPromise.splice(0);
121
+ if (this.async && this.generator) {
122
+ func = this.getAsyncGeneratorFunction(stack);
123
+ }
124
+ else if (this.async) {
125
+ func = this.getAsyncFunction(stack);
126
+ }
127
+ else if (this.generator) {
128
+ func = this.getGeneratorFunction(stack);
129
+ }
130
+ else {
131
+ func = this.getFunction(stack);
132
+ }
133
+ // this.id?.declareVariable(stack, func);
134
+ return func;
135
+ }
136
+ getAsyncFunction(stack) {
137
+ const self = this;
138
+ return async function (...args) {
139
+ const innerScopes = self.initFunctionScope(stack);
140
+ stack.declareVariable('this', this);
141
+ self.setParameter(stack, args);
142
+ let returnValue;
143
+ const statements = self.body.getBody();
144
+ for (const statement of statements) {
145
+ statement.shareVariables(innerScopes);
146
+ returnValue = statement.get(stack);
147
+ if (stack.awaitPromise?.length > 0) {
148
+ for (const awaitRef of stack.awaitPromise) {
149
+ const awaitValue = await awaitRef.promise;
150
+ if (awaitRef.declareVariable) {
151
+ awaitRef.node.declareVariable(stack, awaitValue);
163
152
  }
164
- else if (stack.forAwaitAsyncIterable) {
165
- for await (let iterator of stack.forAwaitAsyncIterable.iterable) {
166
- const result = stack.forAwaitAsyncIterable.forAwaitBody(iterator);
167
- if (ContinueStatement.ContinueSymbol === result) {
168
- continue;
169
- }
170
- else if (BreakStatement.BreakSymbol === result) {
171
- break;
172
- }
173
- else if (result instanceof ReturnValue) {
174
- returnValue = result;
175
- break;
176
- }
177
- }
178
- stack.forAwaitAsyncIterable = undefined;
153
+ else {
154
+ awaitRef.node.set(stack, awaitValue);
179
155
  }
180
- if (returnValue instanceof ReturnValue) {
181
- returnValue = returnValue.value;
182
- if (returnValue instanceof AwaitPromise) {
183
- returnValue = await returnValue.promise;
184
- self.clearFunctionScope(stack, innerScopes);
185
- return returnValue;
156
+ }
157
+ stack.awaitPromise.splice(0);
158
+ }
159
+ else if (stack.forAwaitAsyncIterable) {
160
+ for await (let iterator of stack.forAwaitAsyncIterable.iterable) {
161
+ const result = stack.forAwaitAsyncIterable.forAwaitBody(iterator);
162
+ if (result instanceof TerminateReturnType) {
163
+ if (result.type === 'continue') {
164
+ continue;
165
+ }
166
+ else {
167
+ break;
186
168
  }
187
169
  }
170
+ else if (result instanceof ReturnValue) {
171
+ returnValue = result;
172
+ break;
173
+ }
174
+ }
175
+ stack.forAwaitAsyncIterable = undefined;
176
+ }
177
+ if (returnValue instanceof ReturnValue) {
178
+ returnValue = returnValue.value;
179
+ if (returnValue instanceof AwaitPromise) {
180
+ returnValue = await returnValue.promise;
188
181
  }
189
182
  self.clearFunctionScope(stack, innerScopes);
190
- };
191
- break;
192
- case FunctionKind.GENERATOR:
193
- func = function* (...args) {
194
- const innerScopes = self.initFunctionScope(stack);
195
- stack.declareVariable('this', this);
196
- self.setParameter(stack, args);
197
- let returnValue;
198
- for (const statement of self.body) {
199
- statement.shareVariables(innerScopes);
200
- returnValue = statement.get(stack);
201
- if (returnValue instanceof ReturnValue) {
202
- self.clearFunctionScope(stack, innerScopes);
203
- return returnValue.value;
204
- }
205
- else if (returnValue instanceof YieldValue) {
206
- yield returnValue.value;
183
+ return returnValue;
184
+ }
185
+ }
186
+ self.clearFunctionScope(stack, innerScopes);
187
+ };
188
+ }
189
+ getGeneratorFunction(stack) {
190
+ const self = this;
191
+ return function* (...args) {
192
+ const innerScopes = self.initFunctionScope(stack);
193
+ stack.declareVariable('this', this);
194
+ self.setParameter(stack, args);
195
+ let returnValue;
196
+ const statements = self.body.getBody();
197
+ for (const statement of statements) {
198
+ statement.shareVariables(innerScopes);
199
+ returnValue = statement.get(stack);
200
+ if (returnValue instanceof ReturnValue) {
201
+ self.clearFunctionScope(stack, innerScopes);
202
+ return returnValue.value;
203
+ }
204
+ else if (returnValue instanceof YieldValue) {
205
+ yield returnValue.value;
206
+ }
207
+ else if (returnValue instanceof YieldDelegateValue) {
208
+ yield* returnValue.value;
209
+ }
210
+ }
211
+ self.clearFunctionScope(stack, innerScopes);
212
+ };
213
+ }
214
+ getAsyncGeneratorFunction(stack) {
215
+ const self = this;
216
+ return async function* (...args) {
217
+ const innerScopes = self.initFunctionScope(stack);
218
+ stack.declareVariable('this', this);
219
+ self.setParameter(stack, args);
220
+ let returnValue;
221
+ const statements = self.body.getBody();
222
+ for (const statement of statements) {
223
+ statement.shareVariables(innerScopes);
224
+ returnValue = statement.get(stack);
225
+ if (stack.awaitPromise?.length > 0) {
226
+ for (const awaitRef of stack.awaitPromise) {
227
+ const awaitValue = await awaitRef.promise;
228
+ if (awaitRef.declareVariable) {
229
+ awaitRef.node.declareVariable(stack, awaitValue);
207
230
  }
208
- else if (returnValue instanceof YieldDelegateValue) {
209
- yield* returnValue.value;
231
+ else {
232
+ awaitRef.node.set(stack, awaitValue);
210
233
  }
211
234
  }
212
- self.clearFunctionScope(stack, innerScopes);
213
- };
214
- break;
215
- case FunctionKind.ASYNC_GENERATOR:
216
- func = async function* (...args) {
217
- const innerScopes = self.initFunctionScope(stack);
218
- stack.declareVariable('this', this);
219
- self.setParameter(stack, args);
220
- let returnValue;
221
- for (const statement of self.body) {
222
- statement.shareVariables(innerScopes);
223
- returnValue = statement.get(stack);
224
- if (stack.awaitPromise.length > 0) {
225
- for (const awaitRef of stack.awaitPromise) {
226
- const awaitValue = await awaitRef.promise;
227
- if (awaitRef.declareVariable) {
228
- awaitRef.node.declareVariable(stack, awaitValue);
229
- }
230
- else {
231
- awaitRef.node.set(stack, awaitValue);
232
- }
235
+ stack.awaitPromise.splice(0);
236
+ }
237
+ else if (stack.forAwaitAsyncIterable) {
238
+ for await (let iterator of stack.forAwaitAsyncIterable.iterable) {
239
+ const result = stack.forAwaitAsyncIterable.forAwaitBody(iterator);
240
+ if (result instanceof TerminateReturnType) {
241
+ if (result.type === 'continue') {
242
+ continue;
233
243
  }
234
- stack.awaitPromise.splice(0);
235
- }
236
- else if (stack.forAwaitAsyncIterable) {
237
- for await (let iterator of stack.forAwaitAsyncIterable.iterable) {
238
- const result = stack.forAwaitAsyncIterable.forAwaitBody(iterator);
239
- if (ContinueStatement.ContinueSymbol === result) {
240
- continue;
241
- }
242
- else if (BreakStatement.BreakSymbol === result) {
243
- break;
244
- }
245
- else if (result instanceof ReturnValue) {
246
- self.clearFunctionScope(stack, innerScopes);
247
- returnValue = returnValue.value;
248
- if (returnValue instanceof AwaitPromise) {
249
- return await returnValue.promise;
250
- }
251
- else if (returnValue instanceof YieldValue) {
252
- yield returnValue.value;
253
- }
254
- else if (returnValue instanceof YieldDelegateValue) {
255
- yield* returnValue.value;
256
- }
257
- return returnValue;
258
- }
244
+ else {
245
+ break;
259
246
  }
260
- stack.forAwaitAsyncIterable = undefined;
261
247
  }
262
- if (returnValue instanceof ReturnValue) {
248
+ else if (result instanceof ReturnValue) {
249
+ self.clearFunctionScope(stack, innerScopes);
263
250
  returnValue = returnValue.value;
264
251
  if (returnValue instanceof AwaitPromise) {
265
252
  return await returnValue.promise;
266
253
  }
254
+ else if (returnValue instanceof YieldValue) {
255
+ yield returnValue.value;
256
+ }
257
+ else if (returnValue instanceof YieldDelegateValue) {
258
+ yield* returnValue.value;
259
+ }
267
260
  return returnValue;
268
261
  }
269
262
  }
270
- self.clearFunctionScope(stack, innerScopes);
271
- };
272
- break;
273
- default:
274
- case FunctionKind.NORMAL:
275
- func = function (...args) {
276
- const innerScopes = self.initFunctionScope(stack);
277
- stack.declareVariable('this', this);
278
- self.setParameter(stack, args);
279
- let returnValue;
280
- for (const statement of self.body) {
281
- statement.shareVariables(innerScopes);
282
- returnValue = statement.get(stack);
283
- if (returnValue instanceof ReturnValue) {
284
- self.clearFunctionScope(stack, innerScopes);
285
- return returnValue.value;
286
- }
263
+ stack.forAwaitAsyncIterable = undefined;
264
+ }
265
+ if (returnValue instanceof ReturnValue) {
266
+ returnValue = returnValue.value;
267
+ if (returnValue instanceof AwaitPromise) {
268
+ return await returnValue.promise;
287
269
  }
270
+ return returnValue;
271
+ }
272
+ }
273
+ self.clearFunctionScope(stack, innerScopes);
274
+ };
275
+ }
276
+ getFunction(stack) {
277
+ const self = this;
278
+ return function (...args) {
279
+ const innerScopes = self.initFunctionScope(stack);
280
+ stack.declareVariable('this', this);
281
+ self.setParameter(stack, args);
282
+ let returnValue;
283
+ const statements = self.body.getBody();
284
+ for (const statement of statements) {
285
+ statement.shareVariables(innerScopes);
286
+ returnValue = statement.get(stack);
287
+ if (returnValue instanceof ReturnValue) {
288
288
  self.clearFunctionScope(stack, innerScopes);
289
- };
290
- break;
291
- }
292
- this.id?.declareVariable(stack, func);
293
- return func;
289
+ return returnValue.value;
290
+ }
291
+ }
292
+ self.clearFunctionScope(stack, innerScopes);
293
+ };
294
294
  }
295
295
  dependency(computed) {
296
296
  return this.params.flatMap(param => param.dependency());
@@ -299,78 +299,75 @@ let FunctionExpression = FunctionExpression_1 = class FunctionExpression extends
299
299
  return this.params.flatMap(param => param.dependencyPath(computed));
300
300
  }
301
301
  toString() {
302
- let declare;
303
- switch (this.kind) {
304
- case FunctionKind.ASYNC:
305
- declare = 'async function';
306
- break;
307
- case FunctionKind.GENERATOR:
308
- declare = 'function*';
309
- break;
310
- case FunctionKind.ASYNC_GENERATOR:
311
- declare = 'async function*';
312
- break;
313
- default:
314
- case FunctionKind.NORMAL:
315
- declare = 'function';
316
- break;
302
+ let declare = 'function ';
303
+ if (this.async && this.generator) {
304
+ declare = 'async function* ';
317
305
  }
318
- return `${declare} ${this.id?.toString() || ''}(${this.params.map((param, index, array) => {
319
- if (index === array.length - 1 && this.rest) {
320
- return '...' + param.toString();
321
- }
322
- else {
323
- return param.toString();
324
- }
325
- }).join(', ')}) ${this.body.toString()}`;
306
+ else if (this.async) {
307
+ declare = 'async function ';
308
+ }
309
+ else if (this.generator) {
310
+ declare = 'function* ';
311
+ }
312
+ return `${declare}${this.id?.toString() || ''}${this.paramsAndBodyToString()}`;
313
+ }
314
+ paramsAndBodyToString() {
315
+ return `(${this.params.map(param => param.toString()).join(', ')}) ${this.body.toString()}`;
326
316
  }
327
317
  toJson() {
328
318
  return {
329
319
  params: this.params.map(param => param.toJSON()),
330
- body: this.body.map(statement => statement.toJSON()),
331
- kind: this.kind,
320
+ body: this.body.toJSON(),
321
+ async: this.async,
332
322
  id: this.id?.toJSON(),
333
- rest: this.rest,
334
323
  generator: this.generator
335
324
  };
336
325
  }
337
326
  };
338
327
  FunctionExpression = FunctionExpression_1 = __decorate([
339
328
  Deserializer('FunctionExpression'),
340
- __metadata("design:paramtypes", [Array, Array, String, Object, Boolean, Boolean])
329
+ __metadata("design:paramtypes", [Array, Object, Boolean, Boolean, Identifier])
341
330
  ], FunctionExpression);
342
331
  export { FunctionExpression };
343
332
  let FunctionDeclaration = FunctionDeclaration_1 = class FunctionDeclaration extends FunctionExpression {
344
333
  static fromJSON(node, deserializer) {
345
- return new FunctionDeclaration_1(node.params.map(deserializer), node.body.map(deserializer), FunctionKind[node.kind], node.id ? deserializer(node.id) : void 0, node.rest, node.generator);
334
+ return new FunctionDeclaration_1(node.params.map(deserializer), deserializer(node.body), node.async, node.generator, deserializer(node.id));
346
335
  }
347
336
  static visit(node, visitNode) {
348
- node.id && visitNode(node.id);
337
+ visitNode(node.id);
349
338
  node.params.forEach(visitNode);
350
- node.body.forEach(visitNode);
339
+ visitNode(node.body);
340
+ }
341
+ constructor(params, body, async, generator, id) {
342
+ super(params, body, async, generator, id);
343
+ }
344
+ get(stack) {
345
+ const func = super.get(stack);
346
+ this.declareVariable(stack, func);
347
+ return func;
351
348
  }
352
- constructor(params, body, kind, id, rest, generator) {
353
- super(params, body, kind, id, rest, generator);
349
+ declareVariable(stack, value) {
350
+ this.id.declareVariable(stack, value);
354
351
  }
355
352
  };
356
353
  FunctionDeclaration = FunctionDeclaration_1 = __decorate([
357
354
  Deserializer('FunctionDeclaration'),
358
- __metadata("design:paramtypes", [Array, Array, String, Object, Boolean, Boolean])
355
+ __metadata("design:paramtypes", [Array, Object, Boolean, Boolean, Identifier])
359
356
  ], FunctionDeclaration);
360
357
  export { FunctionDeclaration };
361
- let ArrowFunctionExpression = ArrowFunctionExpression_1 = class ArrowFunctionExpression extends FunctionBaseExpression {
362
- constructor(params, body, kind, rest, generator) {
358
+ let ArrowFunctionExpression = ArrowFunctionExpression_1 = class ArrowFunctionExpression extends BaseFunctionExpression {
359
+ constructor(params, body, expression, async) {
363
360
  super();
364
361
  this.params = params;
365
362
  this.body = body;
366
- this.kind = kind;
367
- this.rest = rest;
368
- this.generator = generator;
363
+ this.expression = expression;
364
+ this.async = async;
365
+ this.generator = false;
369
366
  }
370
367
  static fromJSON(node, deserializer) {
371
368
  return new ArrowFunctionExpression_1(node.params.map(deserializer), Array.isArray(node.body)
372
369
  ? node.body.map(deserializer)
373
- : deserializer(node.body), ArrowFunctionType[node.kind], node.rest, node.generator);
370
+ : deserializer(node.body), node.expression, node.async);
374
371
  }
375
372
  static visit(node, visitNode) {
376
373
  node.params.forEach(visitNode);
@@ -384,98 +381,97 @@ let ArrowFunctionExpression = ArrowFunctionExpression_1 = class ArrowFunctionExp
384
381
  getBody() {
385
382
  return this.body;
386
383
  }
387
- getRest() {
388
- return this.rest;
384
+ getExpression() {
385
+ return this.expression;
389
386
  }
390
387
  set(stack, value) {
391
388
  throw new Error('ArrowFunctionExpression#set() has no implementation.');
392
389
  }
393
390
  setParameter(stack, args) {
394
- const limit = this.rest ? this.params.length - 1 : this.params.length;
391
+ const rest = this.params[this.params.length - 1] instanceof RestElement;
392
+ const limit = rest ? this.params.length - 1 : this.params.length;
395
393
  for (let i = 0; i < limit; i++) {
396
394
  this.params[i].set(stack, args[i]);
397
395
  }
398
- if (this.rest) {
396
+ if (rest) {
399
397
  this.params[limit].set(stack, args.slice(limit));
400
398
  }
401
399
  }
402
400
  get(stack) {
403
- let func;
404
- switch (this.kind) {
405
- case ArrowFunctionType.ASYNC:
406
- func = async (...args) => {
407
- const innerScopes = this.initFunctionScope(stack);
408
- this.setParameter(stack, args);
409
- let returnValue;
410
- const statements = Array.isArray(this.body) ? this.body : [this.body];
411
- for (const state of statements) {
412
- state.shareVariables(innerScopes);
413
- returnValue = state.get(stack);
414
- if (stack.awaitPromise.length > 0) {
415
- for (const awaitRef of stack.awaitPromise) {
416
- const awaitValue = await awaitRef.promise;
417
- if (awaitRef.declareVariable) {
418
- awaitRef.node.declareVariable(stack, awaitValue);
419
- }
420
- else {
421
- awaitRef.node.set(stack, awaitValue);
422
- }
423
- }
424
- stack.awaitPromise.splice(0);
401
+ return this.async ? this.getAsyncArrowFunction(stack) : this.getArrowFunction(stack);
402
+ }
403
+ getAsyncArrowFunction(stack) {
404
+ async (...args) => {
405
+ const innerScopes = this.initFunctionScope(stack);
406
+ this.setParameter(stack, args);
407
+ let returnValue;
408
+ const statements = Array.isArray(this.body) ? this.body : [this.body];
409
+ for (const state of statements) {
410
+ state.shareVariables(innerScopes);
411
+ returnValue = state.get(stack);
412
+ if (stack.awaitPromise?.length > 0) {
413
+ for (const awaitRef of stack.awaitPromise) {
414
+ const awaitValue = await awaitRef.promise;
415
+ if (awaitRef.declareVariable) {
416
+ awaitRef.node.declareVariable(stack, awaitValue);
425
417
  }
426
- else if (stack.forAwaitAsyncIterable) {
427
- for await (let iterator of stack.forAwaitAsyncIterable.iterable) {
428
- const result = stack.forAwaitAsyncIterable.forAwaitBody(iterator);
429
- if (ContinueStatement.ContinueSymbol === result) {
430
- continue;
431
- }
432
- else if (BreakStatement.BreakSymbol === result) {
433
- break;
434
- }
435
- else if (result instanceof ReturnValue) {
436
- returnValue = result;
437
- break;
438
- }
439
- }
440
- stack.forAwaitAsyncIterable = undefined;
418
+ else {
419
+ awaitRef.node.set(stack, awaitValue);
441
420
  }
442
- if (returnValue instanceof ReturnValue) {
443
- returnValue = returnValue.value;
444
- if (returnValue instanceof AwaitPromise) {
445
- this.clearFunctionScope(stack, innerScopes);
446
- return await returnValue.promise;
421
+ }
422
+ stack.awaitPromise.splice(0);
423
+ }
424
+ else if (stack.forAwaitAsyncIterable) {
425
+ for await (let iterator of stack.forAwaitAsyncIterable.iterable) {
426
+ const result = stack.forAwaitAsyncIterable.forAwaitBody(iterator);
427
+ if (result instanceof TerminateReturnType) {
428
+ if (result.type === 'continue') {
429
+ continue;
430
+ }
431
+ else {
432
+ break;
447
433
  }
448
434
  }
449
- }
450
- this.clearFunctionScope(stack, innerScopes);
451
- if (!Array.isArray(this.body)) {
452
- return returnValue;
453
- }
454
- };
455
- break;
456
- default:
457
- case ArrowFunctionType.NORMAL:
458
- func = (...args) => {
459
- const innerScopes = this.initFunctionScope(stack);
460
- this.setParameter(stack, args);
461
- let returnValue;
462
- const statements = Array.isArray(this.body) ? this.body : [this.body];
463
- for (const statement of statements) {
464
- statement.shareVariables(innerScopes);
465
- returnValue = statement.get(stack);
466
- if (returnValue instanceof ReturnValue) {
467
- this.clearFunctionScope(stack, innerScopes);
468
- return returnValue.value;
435
+ else if (result instanceof ReturnValue) {
436
+ returnValue = result;
437
+ break;
469
438
  }
470
439
  }
471
- this.clearFunctionScope(stack, innerScopes);
472
- if (!Array.isArray(this.body)) {
473
- return returnValue;
440
+ stack.forAwaitAsyncIterable = undefined;
441
+ }
442
+ if (returnValue instanceof ReturnValue) {
443
+ returnValue = returnValue.value;
444
+ if (returnValue instanceof AwaitPromise) {
445
+ this.clearFunctionScope(stack, innerScopes);
446
+ return await returnValue.promise;
474
447
  }
475
- };
476
- break;
477
- }
478
- return func;
448
+ }
449
+ }
450
+ this.clearFunctionScope(stack, innerScopes);
451
+ if (this.expression) {
452
+ return returnValue;
453
+ }
454
+ };
455
+ }
456
+ getArrowFunction(stack) {
457
+ return (...args) => {
458
+ const innerScopes = this.initFunctionScope(stack);
459
+ this.setParameter(stack, args);
460
+ let returnValue;
461
+ const statements = Array.isArray(this.body) ? this.body : [this.body];
462
+ for (const statement of statements) {
463
+ statement.shareVariables(innerScopes);
464
+ returnValue = statement.get(stack);
465
+ if (returnValue instanceof ReturnValue) {
466
+ this.clearFunctionScope(stack, innerScopes);
467
+ return returnValue.value;
468
+ }
469
+ }
470
+ this.clearFunctionScope(stack, innerScopes);
471
+ if (this.expression) {
472
+ return returnValue;
473
+ }
474
+ };
479
475
  }
480
476
  dependency(computed) {
481
477
  return this.params.flatMap(param => param.dependency());
@@ -484,24 +480,12 @@ let ArrowFunctionExpression = ArrowFunctionExpression_1 = class ArrowFunctionExp
484
480
  return this.params.flatMap(param => param.dependencyPath(computed));
485
481
  }
486
482
  toString() {
487
- let str = this.kind === ArrowFunctionType.ASYNC ? 'async ' : '';
488
- if (this.params.length === 0) {
489
- str += '()';
490
- }
491
- else if (this.params.length === 1) {
483
+ let str = this.async ? 'async ' : '';
484
+ if (this.params.length === 1) {
492
485
  str += this.params[0].toString();
493
486
  }
494
487
  else {
495
- str += '(';
496
- str += this.params.map((param, index, array) => {
497
- if (index === array.length - 1 && this.rest) {
498
- return '...' + param.toString();
499
- }
500
- else {
501
- return param.toString();
502
- }
503
- }).join(', ');
504
- str += ')';
488
+ str += `(${this.params.map(param => param.toString()).join(', ')})`;
505
489
  }
506
490
  str += ' => ';
507
491
  str += this.body.toString();
@@ -512,15 +496,14 @@ let ArrowFunctionExpression = ArrowFunctionExpression_1 = class ArrowFunctionExp
512
496
  params: this.params.map(param => param.toJSON()),
513
497
  body: Array.isArray(this.body) ? this.body.map(item => item.toJSON()) : this.body.toJSON(),
514
498
  expression: true,
515
- kind: this.kind,
516
- rest: this.rest,
499
+ async: this.async,
517
500
  generator: this.generator
518
501
  };
519
502
  }
520
503
  };
521
504
  ArrowFunctionExpression = ArrowFunctionExpression_1 = __decorate([
522
505
  Deserializer('ArrowFunctionExpression'),
523
- __metadata("design:paramtypes", [Array, Object, String, Boolean, Boolean])
506
+ __metadata("design:paramtypes", [Array, Object, Boolean, Boolean])
524
507
  ], ArrowFunctionExpression);
525
508
  export { ArrowFunctionExpression };
526
509
  //# sourceMappingURL=function.js.map