@ibyar/expressions 0.5.4 → 0.5.6

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