@typescript-guy/fn-monitor 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ACKNOWLEDGEMENTS.md +10 -0
- package/LICENSE.md +10 -0
- package/README.md +201 -0
- package/dist/custom-types.d.ts +239 -0
- package/dist/custom-types.js +341 -0
- package/dist/evaluate/declaration.d.ts +27 -0
- package/dist/evaluate/declaration.js +289 -0
- package/dist/evaluate/expression.d.ts +40 -0
- package/dist/evaluate/expression.js +604 -0
- package/dist/evaluate/helper.d.ts +18 -0
- package/dist/evaluate/helper.js +270 -0
- package/dist/evaluate/identifier.d.ts +7 -0
- package/dist/evaluate/identifier.js +27 -0
- package/dist/evaluate/index.d.ts +3 -0
- package/dist/evaluate/index.js +112 -0
- package/dist/evaluate/literal.d.ts +3 -0
- package/dist/evaluate/literal.js +8 -0
- package/dist/evaluate/pattern.d.ts +13 -0
- package/dist/evaluate/pattern.js +118 -0
- package/dist/evaluate/program.d.ts +3 -0
- package/dist/evaluate/program.js +20 -0
- package/dist/evaluate/statement.d.ts +35 -0
- package/dist/evaluate/statement.js +323 -0
- package/dist/evaluate_n/declaration.d.ts +27 -0
- package/dist/evaluate_n/declaration.js +289 -0
- package/dist/evaluate_n/expression.d.ts +38 -0
- package/dist/evaluate_n/expression.js +596 -0
- package/dist/evaluate_n/helper.d.ts +18 -0
- package/dist/evaluate_n/helper.js +238 -0
- package/dist/evaluate_n/identifier.d.ts +7 -0
- package/dist/evaluate_n/identifier.js +27 -0
- package/dist/evaluate_n/index.d.ts +3 -0
- package/dist/evaluate_n/index.js +76 -0
- package/dist/evaluate_n/literal.d.ts +3 -0
- package/dist/evaluate_n/literal.js +8 -0
- package/dist/evaluate_n/pattern.d.ts +13 -0
- package/dist/evaluate_n/pattern.js +118 -0
- package/dist/evaluate_n/program.d.ts +3 -0
- package/dist/evaluate_n/program.js +20 -0
- package/dist/evaluate_n/statement.d.ts +35 -0
- package/dist/evaluate_n/statement.js +301 -0
- package/dist/examples/example-2.d.ts +1 -0
- package/dist/examples/example.d.ts +1 -0
- package/dist/helper-functions.d.ts +15 -0
- package/dist/helper-functions.js +104 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +312 -0
- package/dist/q-list.d.ts +39 -0
- package/dist/q-list.js +146 -0
- package/dist/scope/index.d.ts +81 -0
- package/dist/scope/index.js +168 -0
- package/dist/scope/variable.d.ts +20 -0
- package/dist/scope/variable.js +38 -0
- package/dist/share/async.d.ts +7 -0
- package/dist/share/async.js +43 -0
- package/dist/share/const.d.ts +25 -0
- package/dist/share/const.js +21 -0
- package/dist/share/util.d.ts +33 -0
- package/dist/share/util.js +379 -0
- package/dist/sval.d.ts +15 -0
- package/dist/sval.js +104 -0
- package/package.json +54 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
const LAZY_NODE = Symbol("LAZY_NODE");
|
|
2
|
+
const NOT_ALLOCATED = Symbol("NOT_ALLOCATED");
|
|
3
|
+
const UNASSIGNED = Symbol("UNASSIGNED");
|
|
4
|
+
const SEEN = Symbol("SEEN");
|
|
5
|
+
class LangEvent {
|
|
6
|
+
//LangEvent is short for Language Event
|
|
7
|
+
node;
|
|
8
|
+
scope;
|
|
9
|
+
constructor(interpreter) {
|
|
10
|
+
this.node = interpreter.reusables.node;
|
|
11
|
+
this.scope = interpreter.createEventScope();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
class ExpressionStmtEvent extends LangEvent {
|
|
15
|
+
constructor(interpreter) {
|
|
16
|
+
super(interpreter);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
class ArrayExprEvent extends LangEvent {
|
|
20
|
+
constructor(interpreter) {
|
|
21
|
+
super(interpreter);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class ObjectExprEvent extends LangEvent {
|
|
25
|
+
constructor(interpreter) {
|
|
26
|
+
super(interpreter);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
class TemplateLiteralEvent extends LangEvent {
|
|
30
|
+
constructor(interpreter) {
|
|
31
|
+
super(interpreter);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class SequenceExprEvent extends LangEvent {
|
|
35
|
+
constructor(interpreter) {
|
|
36
|
+
super(interpreter);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
class UnaryExprEvent extends LangEvent {
|
|
40
|
+
constructor(interpreter) {
|
|
41
|
+
super(interpreter);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class BinaryExprEvent extends LangEvent {
|
|
45
|
+
constructor(interpreter) {
|
|
46
|
+
super(interpreter);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class CallExprEvent extends LangEvent {
|
|
50
|
+
constructor(interpreter) {
|
|
51
|
+
super(interpreter);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class AssignmentExprEvent extends LangEvent {
|
|
55
|
+
constructor(interpreter) {
|
|
56
|
+
super(interpreter);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class UpdateExprEvent extends LangEvent {
|
|
60
|
+
constructor(interpreter) {
|
|
61
|
+
super(interpreter);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
class LogicalExprEvent extends LangEvent {
|
|
65
|
+
constructor(interpreter) {
|
|
66
|
+
super(interpreter);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
class MemberExprEvent extends LangEvent {
|
|
70
|
+
constructor(interpreter) {
|
|
71
|
+
super(interpreter);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
class AwaitExprEvent extends LangEvent {
|
|
75
|
+
constructor(interpreter) {
|
|
76
|
+
super(interpreter);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
class FuncExprEvent extends LangEvent {
|
|
80
|
+
constructor(interpreter) {
|
|
81
|
+
super(interpreter);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
class ArrowFnExprEvent extends LangEvent {
|
|
85
|
+
constructor(interpreter) {
|
|
86
|
+
super(interpreter);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
class TernaryExprEvent extends LangEvent {
|
|
90
|
+
constructor(interpreter) {
|
|
91
|
+
super(interpreter);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
class NewExprEvent extends LangEvent {
|
|
95
|
+
constructor(interpreter) {
|
|
96
|
+
super(interpreter);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
class YieldExprEvent extends LangEvent {
|
|
100
|
+
constructor(interpreter) {
|
|
101
|
+
super(interpreter);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
class ReturnStmtEvent extends LangEvent {
|
|
105
|
+
constructor(interpreter) {
|
|
106
|
+
super(interpreter);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
class IfStmtEvent extends LangEvent {
|
|
110
|
+
constructor(interpreter) {
|
|
111
|
+
super(interpreter);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
class SwitchStmtEvent extends LangEvent {
|
|
115
|
+
constructor(interpreter) {
|
|
116
|
+
super(interpreter);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
class ThrowStmtEvent extends LangEvent {
|
|
120
|
+
constructor(interpreter) {
|
|
121
|
+
super(interpreter);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
class TryStmtEvent extends LangEvent {
|
|
125
|
+
constructor(interpreter) {
|
|
126
|
+
super(interpreter);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
class CatchClauseEvent extends LangEvent {
|
|
130
|
+
constructor(interpreter) {
|
|
131
|
+
super(interpreter);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
class VarDeclEvent extends LangEvent {
|
|
135
|
+
constructor(interpreter) {
|
|
136
|
+
super(interpreter);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
class FuncDeclEvent extends LangEvent {
|
|
140
|
+
constructor(interpreter) {
|
|
141
|
+
super(interpreter);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
class ForStmtEvent extends LangEvent {
|
|
145
|
+
constructor(interpreter) {
|
|
146
|
+
super(interpreter);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
class WhileStmtEvent extends LangEvent {
|
|
150
|
+
constructor(interpreter) {
|
|
151
|
+
super(interpreter);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
class DoWhileStmtEvent extends LangEvent {
|
|
155
|
+
constructor(interpreter) {
|
|
156
|
+
super(interpreter);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
class ForOfStmtEvent extends LangEvent {
|
|
160
|
+
constructor(interpreter) {
|
|
161
|
+
super(interpreter);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
class ForInStmtEvent extends LangEvent {
|
|
165
|
+
constructor(interpreter) {
|
|
166
|
+
super(interpreter);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
class LabeledStmtEvent extends LangEvent {
|
|
170
|
+
constructor(interpreter) {
|
|
171
|
+
super(interpreter);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
class BreakStmtEvent extends LangEvent {
|
|
175
|
+
constructor(interpreter) {
|
|
176
|
+
super(interpreter);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
class ContinueStmtEvent extends LangEvent {
|
|
180
|
+
constructor(interpreter) {
|
|
181
|
+
super(interpreter);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
class LiteralEvent extends LangEvent {
|
|
185
|
+
constructor(interpreter) {
|
|
186
|
+
super(interpreter);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function createEvent(query, interpreter) {
|
|
190
|
+
let event = null;
|
|
191
|
+
switch (query) {
|
|
192
|
+
case "BinaryExpression": {
|
|
193
|
+
event = new BinaryExprEvent(interpreter);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case "CallExpression": {
|
|
197
|
+
event = new CallExprEvent(interpreter);
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
case "AssignmentExpression": {
|
|
201
|
+
event = new AssignmentExprEvent(interpreter);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case "UpdateExpression": {
|
|
205
|
+
event = new UpdateExprEvent(interpreter);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
case "LogicalExpression": {
|
|
209
|
+
event = new LogicalExprEvent(interpreter);
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
case "MemberExpression": {
|
|
213
|
+
event = new MemberExprEvent(interpreter);
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
case "AwaitExpression": {
|
|
217
|
+
event = new AwaitExprEvent(interpreter);
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
case "FunctionExpression": {
|
|
221
|
+
event = new FuncExprEvent(interpreter);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case "ReturnStatement": {
|
|
225
|
+
event = new ReturnStmtEvent(interpreter);
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
case "IfStatement": {
|
|
229
|
+
event = new IfStmtEvent(interpreter);
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
case "SwitchStatement": {
|
|
233
|
+
event = new SwitchStmtEvent(interpreter);
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
case "ThrowStatement": {
|
|
237
|
+
event = new ThrowStmtEvent(interpreter);
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case "TryStatement": {
|
|
241
|
+
event = new TryStmtEvent(interpreter);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
case "CatchClause": {
|
|
245
|
+
event = new CatchClauseEvent(interpreter);
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
case "VariableDeclaration": {
|
|
249
|
+
event = new VarDeclEvent(interpreter);
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
case "FunctionDeclaration": {
|
|
253
|
+
event = new FuncDeclEvent(interpreter);
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
case "ForStatement": {
|
|
257
|
+
event = new ForStmtEvent(interpreter);
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
case "WhileStatement": {
|
|
261
|
+
event = new WhileStmtEvent(interpreter);
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
case "DoWhileStatement": {
|
|
265
|
+
event = new DoWhileStmtEvent(interpreter);
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
case "ForOfStatement": {
|
|
269
|
+
event = new ForOfStmtEvent(interpreter);
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case "ForInStatement": {
|
|
273
|
+
event = new ForInStmtEvent(interpreter);
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case "Literal": {
|
|
277
|
+
event = new LiteralEvent(interpreter);
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
case "LabeledStatement": {
|
|
281
|
+
event = new LabeledStmtEvent(interpreter);
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
case "BreakStatement": {
|
|
285
|
+
event = new BreakStmtEvent(interpreter);
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
case "ContinueStatement": {
|
|
289
|
+
event = new ContinueStmtEvent(interpreter);
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
case "NewExpression": {
|
|
293
|
+
event = new NewExprEvent(interpreter);
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
case "ArrowFunctionExpression": {
|
|
297
|
+
event = new ArrowFnExprEvent(interpreter);
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
case "ConditionalExpression": {
|
|
301
|
+
event = new TernaryExprEvent(interpreter);
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
case "YieldExpression": {
|
|
305
|
+
event = new YieldExprEvent(interpreter);
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
case "ExpressionStatement": {
|
|
309
|
+
event = new ExpressionStmtEvent(interpreter);
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
case "ArrayExpression": {
|
|
313
|
+
event = new ArrayExprEvent(interpreter);
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
case "ObjectExpression": {
|
|
317
|
+
event = new ObjectExprEvent(interpreter);
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
case "TemplateLiteral": {
|
|
321
|
+
event = new TemplateLiteralEvent(interpreter);
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
case "SequenceExpression": {
|
|
325
|
+
event = new SequenceExprEvent(interpreter);
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
case "UnaryExpression": {
|
|
329
|
+
event = new UnaryExprEvent(interpreter);
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
case "Any":
|
|
333
|
+
default: {
|
|
334
|
+
event = new LangEvent(interpreter);
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return event;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export { ArrayExprEvent, ArrowFnExprEvent, AssignmentExprEvent, AwaitExprEvent, BinaryExprEvent, BreakStmtEvent, CallExprEvent, CatchClauseEvent, ContinueStmtEvent, DoWhileStmtEvent, ExpressionStmtEvent, ForInStmtEvent, ForOfStmtEvent, ForStmtEvent, FuncDeclEvent, FuncExprEvent, IfStmtEvent, LAZY_NODE, LabeledStmtEvent, LangEvent, LiteralEvent, LogicalExprEvent, MemberExprEvent, NOT_ALLOCATED, NewExprEvent, ObjectExprEvent, ReturnStmtEvent, SEEN, SequenceExprEvent, SwitchStmtEvent, TemplateLiteralEvent, TernaryExprEvent, ThrowStmtEvent, TryStmtEvent, UNASSIGNED, UnaryExprEvent, UpdateExprEvent, VarDeclEvent, WhileStmtEvent, YieldExprEvent, createEvent };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { VarKind } from '../scope/variable.ts';
|
|
2
|
+
import { default as Scope } from '../scope/index.ts';
|
|
3
|
+
import * as acorn from 'acorn';
|
|
4
|
+
export declare function FunctionDeclaration(node: acorn.FunctionDeclaration, scope: Scope): IterableIterator<any>;
|
|
5
|
+
export interface VariableDeclarationOptions {
|
|
6
|
+
hoist?: boolean;
|
|
7
|
+
onlyBlock?: boolean;
|
|
8
|
+
feed?: any;
|
|
9
|
+
}
|
|
10
|
+
export declare function VariableDeclaration(node: acorn.VariableDeclaration, scope: Scope, options?: VariableDeclarationOptions): Generator<any, void, any>;
|
|
11
|
+
export interface VariableDeclaratorOptions {
|
|
12
|
+
kind?: VarKind;
|
|
13
|
+
}
|
|
14
|
+
export declare function VariableDeclarator(node: acorn.VariableDeclarator, scope: Scope, options?: VariableDeclaratorOptions & VariableDeclarationOptions): Generator<any, void, any>;
|
|
15
|
+
export declare function ClassDeclaration(node: acorn.ClassDeclaration, scope: Scope): IterableIterator<any>;
|
|
16
|
+
export interface ClassOptions {
|
|
17
|
+
klass?: any;
|
|
18
|
+
superClass?: (...args: any[]) => void;
|
|
19
|
+
}
|
|
20
|
+
export declare function ClassBody(node: acorn.ClassBody, scope: Scope, options?: ClassOptions): Generator<any, void, any>;
|
|
21
|
+
export declare function MethodDefinition(node: acorn.MethodDefinition, scope: Scope, options?: ClassOptions): Generator<any, void, any>;
|
|
22
|
+
export declare function PropertyDefinition(node: acorn.PropertyDefinition, scope: Scope, options?: ClassOptions): Generator<any, void, any>;
|
|
23
|
+
export declare function StaticBlock(node: acorn.StaticBlock, scope: Scope, options?: ClassOptions): Generator<any, any, any>;
|
|
24
|
+
export declare function ImportDeclaration(node: acorn.ImportDeclaration, scope: Scope): Generator<never, void, unknown>;
|
|
25
|
+
export declare function ExportDefaultDeclaration(node: acorn.ExportDefaultDeclaration, scope: Scope): Generator<any, void, any>;
|
|
26
|
+
export declare function ExportNamedDeclaration(node: acorn.ExportNamedDeclaration, scope: Scope): Generator<any, void, any>;
|
|
27
|
+
export declare function ExportAllDeclaration(node: acorn.ExportAllDeclaration, scope: Scope): Generator<never, void, unknown>;
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { IMPORT, EXPORTS, PRIVATE, DEADZONE, NOINIT } from '../share/const.js';
|
|
2
|
+
import { assign, hasOwn, define, getDptor } from '../share/util.js';
|
|
3
|
+
import { createClass, createFunc, pattern } from './helper.js';
|
|
4
|
+
import { BlockStatement } from './statement.js';
|
|
5
|
+
import Scope from '../scope/index.js';
|
|
6
|
+
import evaluate from './index.js';
|
|
7
|
+
|
|
8
|
+
function* FunctionDeclaration(node, scope) {
|
|
9
|
+
scope.func(node.id.name, createFunc(node, scope));
|
|
10
|
+
}
|
|
11
|
+
function* VariableDeclaration(node, scope, options = {}) {
|
|
12
|
+
for (let i = 0; i < node.declarations.length; i++) {
|
|
13
|
+
yield* VariableDeclarator(node.declarations[i], scope, assign({ kind: node.kind }, options));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function* VariableDeclarator(node, scope, options = {}) {
|
|
17
|
+
const { kind = "var", hoist = false, onlyBlock = false, feed } = options;
|
|
18
|
+
if (hoist) {
|
|
19
|
+
if (onlyBlock || kind === "var") {
|
|
20
|
+
if (node.id.type === "Identifier") {
|
|
21
|
+
scope[kind](node.id.name, onlyBlock ? DEADZONE : kind === "var" ? NOINIT : void 0);
|
|
22
|
+
} else {
|
|
23
|
+
yield* pattern(node.id, scope, { kind, hoist, onlyBlock });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
const hasFeed = "feed" in options;
|
|
28
|
+
const value = hasFeed ? feed : yield* evaluate(node.init, scope);
|
|
29
|
+
if (node.id.type === "Identifier") {
|
|
30
|
+
const name = node.id.name;
|
|
31
|
+
if (kind === "var" && !node.init && !hasFeed) {
|
|
32
|
+
scope.var(name, NOINIT);
|
|
33
|
+
} else {
|
|
34
|
+
scope[kind](name, value);
|
|
35
|
+
}
|
|
36
|
+
if (node.init && ["ClassExpression", "FunctionExpression", "ArrowFunctionExpression"].indexOf(node.init.type) !== -1 && !value.name) {
|
|
37
|
+
define(value, "name", {
|
|
38
|
+
value: name,
|
|
39
|
+
configurable: true
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
yield* pattern(node.id, scope, { kind, feed: value });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function* ClassDeclaration(node, scope) {
|
|
48
|
+
scope.func(node.id.name, yield* createClass(node, scope));
|
|
49
|
+
}
|
|
50
|
+
function* ClassBody(node, scope, options = {}) {
|
|
51
|
+
const { klass, superClass } = options;
|
|
52
|
+
for (let i = 0; i < node.body.length; i++) {
|
|
53
|
+
const def = node.body[i];
|
|
54
|
+
if (def.type === "MethodDefinition") {
|
|
55
|
+
yield* MethodDefinition(def, scope, { klass, superClass });
|
|
56
|
+
} else if (def.type === "PropertyDefinition" && def.static) {
|
|
57
|
+
yield* PropertyDefinition(def, scope, { klass, superClass });
|
|
58
|
+
} else if (def.type === "StaticBlock") {
|
|
59
|
+
yield* StaticBlock(def, scope, { klass});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function* MethodDefinition(node, scope, options = {}) {
|
|
64
|
+
const { klass, superClass } = options;
|
|
65
|
+
let key;
|
|
66
|
+
let priv = false;
|
|
67
|
+
if (node.computed) {
|
|
68
|
+
key = yield* evaluate(node.key, scope);
|
|
69
|
+
} else if (node.key.type === "Identifier") {
|
|
70
|
+
key = node.key.name;
|
|
71
|
+
} else if (node.key.type === "PrivateIdentifier") {
|
|
72
|
+
key = node.key.name;
|
|
73
|
+
priv = true;
|
|
74
|
+
} else {
|
|
75
|
+
throw new SyntaxError("Unexpected token");
|
|
76
|
+
}
|
|
77
|
+
let obj = node.static ? klass : klass.prototype;
|
|
78
|
+
if (priv) {
|
|
79
|
+
if (!obj[PRIVATE]) {
|
|
80
|
+
define(obj, PRIVATE, { value: {} });
|
|
81
|
+
}
|
|
82
|
+
obj = obj[PRIVATE];
|
|
83
|
+
}
|
|
84
|
+
const value = createFunc(node.value, scope, { superClass });
|
|
85
|
+
switch (node.kind) {
|
|
86
|
+
case "constructor":
|
|
87
|
+
break;
|
|
88
|
+
case "method":
|
|
89
|
+
define(obj, key, {
|
|
90
|
+
value,
|
|
91
|
+
writable: true,
|
|
92
|
+
configurable: true
|
|
93
|
+
});
|
|
94
|
+
break;
|
|
95
|
+
case "get": {
|
|
96
|
+
const oriDptor = getDptor(obj, key);
|
|
97
|
+
define(obj, key, {
|
|
98
|
+
get: value,
|
|
99
|
+
set: oriDptor && oriDptor.set,
|
|
100
|
+
configurable: true
|
|
101
|
+
});
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case "set": {
|
|
105
|
+
const oriDptor = getDptor(obj, key);
|
|
106
|
+
define(obj, key, {
|
|
107
|
+
get: oriDptor && oriDptor.get,
|
|
108
|
+
set: value,
|
|
109
|
+
configurable: true
|
|
110
|
+
});
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
default:
|
|
114
|
+
throw new SyntaxError("Unexpected token");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function* PropertyDefinition(node, scope, options = {}) {
|
|
118
|
+
const { klass, superClass } = options;
|
|
119
|
+
let key;
|
|
120
|
+
let priv = false;
|
|
121
|
+
if (node.computed) {
|
|
122
|
+
key = yield* evaluate(node.key, scope);
|
|
123
|
+
} else if (node.key.type === "Identifier") {
|
|
124
|
+
key = node.key.name;
|
|
125
|
+
} else if (node.key.type === "PrivateIdentifier") {
|
|
126
|
+
key = node.key.name;
|
|
127
|
+
priv = true;
|
|
128
|
+
} else {
|
|
129
|
+
throw new SyntaxError("Unexpected token");
|
|
130
|
+
}
|
|
131
|
+
const subScope = new Scope(scope, true);
|
|
132
|
+
subScope.const("this", klass);
|
|
133
|
+
let obj = klass;
|
|
134
|
+
if (priv) {
|
|
135
|
+
if (!obj[PRIVATE]) {
|
|
136
|
+
define(obj, PRIVATE, { value: {} });
|
|
137
|
+
}
|
|
138
|
+
obj = obj[PRIVATE];
|
|
139
|
+
}
|
|
140
|
+
if (!node.value) {
|
|
141
|
+
obj[key] = void 0;
|
|
142
|
+
} else if (node.value.type === "FunctionExpression" || node.value.type === "ArrowFunctionExpression") {
|
|
143
|
+
obj[key] = createFunc(node.value, subScope, { superClass });
|
|
144
|
+
} else {
|
|
145
|
+
obj[key] = yield* evaluate(node.value, subScope);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function* StaticBlock(node, scope, options = {}) {
|
|
149
|
+
const { klass } = options;
|
|
150
|
+
const subScope = new Scope(scope, true);
|
|
151
|
+
subScope.const("this", klass);
|
|
152
|
+
return yield* BlockStatement(node, subScope, { invasived: true });
|
|
153
|
+
}
|
|
154
|
+
function* ImportDeclaration(node, scope) {
|
|
155
|
+
const globalScope = scope.global();
|
|
156
|
+
const module = globalScope.find(IMPORT + node.source.value);
|
|
157
|
+
let value;
|
|
158
|
+
if (module) {
|
|
159
|
+
const result = module.get();
|
|
160
|
+
if (result) {
|
|
161
|
+
if (typeof result === "function") {
|
|
162
|
+
value = result();
|
|
163
|
+
} else if (typeof result === "object") {
|
|
164
|
+
value = result;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (!value || typeof value !== "object") {
|
|
169
|
+
throw new TypeError(`Failed to resolve module specifier "${node.source.value}"`);
|
|
170
|
+
}
|
|
171
|
+
for (let i = 0; i < node.specifiers.length; i++) {
|
|
172
|
+
const spec = node.specifiers[i];
|
|
173
|
+
let name;
|
|
174
|
+
if (spec.type === "ImportSpecifier") {
|
|
175
|
+
name = spec.imported.type === "Identifier" ? spec.imported.name : spec.imported.value;
|
|
176
|
+
} else if (spec.type === "ImportDefaultSpecifier") {
|
|
177
|
+
name = "default";
|
|
178
|
+
} else if (spec.type === "ImportNamespaceSpecifier") {
|
|
179
|
+
name = "*";
|
|
180
|
+
}
|
|
181
|
+
if (name !== "*" && !hasOwn(value, name)) {
|
|
182
|
+
throw new SyntaxError(`The requested module "${node.source.value}" does not provide an export named "${name}"`);
|
|
183
|
+
}
|
|
184
|
+
scope.var(spec.local.name, name === "*" ? assign({}, value) : value[name]);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function* ExportDefaultDeclaration(node, scope) {
|
|
188
|
+
const globalScope = scope.global();
|
|
189
|
+
let value;
|
|
190
|
+
if (node.declaration.type === "FunctionDeclaration") {
|
|
191
|
+
value = createFunc(node.declaration, scope);
|
|
192
|
+
scope.func(node.declaration.id.name, value);
|
|
193
|
+
} else if (node.declaration.type === "ClassDeclaration") {
|
|
194
|
+
value = yield* createClass(node.declaration, scope);
|
|
195
|
+
scope.func(node.declaration.id.name, value);
|
|
196
|
+
} else {
|
|
197
|
+
value = yield* evaluate(node.declaration, scope);
|
|
198
|
+
}
|
|
199
|
+
const variable = globalScope.find(EXPORTS);
|
|
200
|
+
if (variable) {
|
|
201
|
+
const exports = variable.get();
|
|
202
|
+
if (exports && typeof exports === "object") {
|
|
203
|
+
exports.default = value;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function* ExportNamedDeclaration(node, scope) {
|
|
208
|
+
const globalScope = scope.global();
|
|
209
|
+
if (node.declaration) {
|
|
210
|
+
if (node.declaration.type === "FunctionDeclaration") {
|
|
211
|
+
const value = createFunc(node.declaration, scope);
|
|
212
|
+
scope.func(node.declaration.id.name, value);
|
|
213
|
+
const variable = globalScope.find(EXPORTS);
|
|
214
|
+
if (variable) {
|
|
215
|
+
const exports = variable.get();
|
|
216
|
+
if (exports && typeof exports === "object") {
|
|
217
|
+
exports[node.declaration.id.name] = value;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
} else if (node.declaration.type === "ClassDeclaration") {
|
|
221
|
+
const value = yield* createClass(node.declaration, scope);
|
|
222
|
+
scope.func(node.declaration.id.name, value);
|
|
223
|
+
const variable = globalScope.find(EXPORTS);
|
|
224
|
+
if (variable) {
|
|
225
|
+
const exports = variable.get();
|
|
226
|
+
if (exports && typeof exports === "object") {
|
|
227
|
+
exports[node.declaration.id.name] = value;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
} else if (node.declaration.type === "VariableDeclaration") {
|
|
231
|
+
yield* VariableDeclaration(node.declaration, scope);
|
|
232
|
+
const variable = globalScope.find(EXPORTS);
|
|
233
|
+
if (variable) {
|
|
234
|
+
const exports = variable.get();
|
|
235
|
+
if (exports && typeof exports === "object") {
|
|
236
|
+
for (let i = 0; i < node.declaration.declarations.length; i++) {
|
|
237
|
+
const name = node.declaration.declarations[i].id.name;
|
|
238
|
+
const item = scope.find(name);
|
|
239
|
+
if (item) {
|
|
240
|
+
exports[name] = item.get();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
} else if (node.specifiers) {
|
|
247
|
+
const variable = globalScope.find(EXPORTS);
|
|
248
|
+
if (variable) {
|
|
249
|
+
const exports = variable.get();
|
|
250
|
+
if (exports && typeof exports === "object") {
|
|
251
|
+
for (let i = 0; i < node.specifiers.length; i++) {
|
|
252
|
+
const spec = node.specifiers[i];
|
|
253
|
+
const name = spec.local.type === "Identifier" ? spec.local.name : spec.local.value;
|
|
254
|
+
const item = scope.find(name);
|
|
255
|
+
if (item) {
|
|
256
|
+
exports[spec.exported.type === "Identifier" ? spec.exported.name : spec.exported.value] = item.get();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function* ExportAllDeclaration(node, scope) {
|
|
264
|
+
const globalScope = scope.global();
|
|
265
|
+
const module = globalScope.find(IMPORT + node.source.value);
|
|
266
|
+
let value;
|
|
267
|
+
if (module) {
|
|
268
|
+
const result = module.get();
|
|
269
|
+
if (result) {
|
|
270
|
+
if (typeof result === "function") {
|
|
271
|
+
value = result();
|
|
272
|
+
} else if (typeof result === "object") {
|
|
273
|
+
value = result;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (!value || typeof value !== "object") {
|
|
278
|
+
throw new TypeError(`Failed to resolve module specifier "${node.source.value}"`);
|
|
279
|
+
}
|
|
280
|
+
const variable = globalScope.find(EXPORTS);
|
|
281
|
+
if (variable) {
|
|
282
|
+
const exports = variable.get();
|
|
283
|
+
if (exports && typeof exports === "object") {
|
|
284
|
+
assign(exports, value);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export { ClassBody, ClassDeclaration, ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, FunctionDeclaration, ImportDeclaration, MethodDefinition, PropertyDefinition, StaticBlock, VariableDeclaration, VariableDeclarator };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { default as Scope } from '../scope/index.ts';
|
|
2
|
+
import * as acorn from 'acorn';
|
|
3
|
+
export declare function ThisExpression(node: acorn.ThisExpression, scope: Scope): Generator<never, any, unknown>;
|
|
4
|
+
export declare function ArrayExpression(node: acorn.ArrayExpression, scope: Scope): Generator<any, any[], any>;
|
|
5
|
+
export declare function ObjectExpression(node: acorn.ObjectExpression, scope: Scope): Generator<any, {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}, any>;
|
|
8
|
+
export declare function FunctionExpression(node: acorn.FunctionExpression, scope: Scope): Generator<never, any, unknown>;
|
|
9
|
+
export declare function UnaryExpression(node: acorn.UnaryExpression, scope: Scope): Generator<any, number | boolean | "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function", any>;
|
|
10
|
+
export declare function UpdateExpression(node: acorn.UpdateExpression, scope: Scope): Generator<any, any, any>;
|
|
11
|
+
export declare function BinaryExpression(node: acorn.BinaryExpression, scope: Scope): Generator<any, any, any>;
|
|
12
|
+
export declare function AssignmentExpression(node: acorn.AssignmentExpression, scope: Scope): Generator<any, any, any>;
|
|
13
|
+
export declare function LogicalExpression(node: acorn.LogicalExpression, scope: Scope): Generator<any, any, any>;
|
|
14
|
+
export interface MemberExpressionOptions {
|
|
15
|
+
getObj?: boolean;
|
|
16
|
+
getVar?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function MemberExpression(node: acorn.MemberExpression, scope: Scope, options?: MemberExpressionOptions): Generator<any, any, any>;
|
|
19
|
+
export declare function ConditionalExpression(node: acorn.ConditionalExpression, scope: Scope): Generator<any, any, any>;
|
|
20
|
+
export declare function CallExpression(node: acorn.CallExpression, scope: Scope): Generator<any, any, any>;
|
|
21
|
+
export declare function NewExpression(node: acorn.NewExpression, scope: Scope): Generator<any, any, any>;
|
|
22
|
+
export declare function MetaProperty(node: acorn.MetaProperty, scope: Scope): Generator<never, any, unknown>;
|
|
23
|
+
export declare function SequenceExpression(node: acorn.SequenceExpression, scope: Scope): Generator<any, any, any>;
|
|
24
|
+
export declare function ArrowFunctionExpression(node: acorn.ArrowFunctionExpression, scope: Scope): Generator<never, any, unknown>;
|
|
25
|
+
export declare function TemplateLiteral(node: acorn.TemplateLiteral, scope: Scope): Generator<any, string, any>;
|
|
26
|
+
export declare function TaggedTemplateExpression(node: acorn.TaggedTemplateExpression, scope: Scope): Generator<any, any, any>;
|
|
27
|
+
export declare function TemplateElement(node: acorn.TemplateElement, scope: Scope): Generator<never, string, unknown>;
|
|
28
|
+
export declare function ClassExpression(node: acorn.ClassExpression, scope: Scope): Generator<any, () => Generator<any, any, any>, any>;
|
|
29
|
+
export interface SuperOptions {
|
|
30
|
+
getProto?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare function Super(node: acorn.Super, scope: Scope, options?: SuperOptions): Generator<never, any, unknown>;
|
|
33
|
+
export interface SpreadOptions {
|
|
34
|
+
spreadProps?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export declare function SpreadElement(node: acorn.SpreadElement, scope: Scope, options?: SpreadOptions): Generator<any, any, any>;
|
|
37
|
+
export declare function ChainExpression(node: acorn.ChainExpression, scope: Scope): Generator<any, any, any>;
|
|
38
|
+
export declare function ImportExpression(node: acorn.ImportExpression, scope: Scope): Generator<any, Promise<any>, any>;
|
|
39
|
+
export declare function YieldExpression(node: acorn.YieldExpression, scope: Scope): any;
|
|
40
|
+
export declare function AwaitExpression(node: acorn.AwaitExpression, scope: Scope): any;
|