@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.
Files changed (62) hide show
  1. package/ACKNOWLEDGEMENTS.md +10 -0
  2. package/LICENSE.md +10 -0
  3. package/README.md +201 -0
  4. package/dist/custom-types.d.ts +239 -0
  5. package/dist/custom-types.js +341 -0
  6. package/dist/evaluate/declaration.d.ts +27 -0
  7. package/dist/evaluate/declaration.js +289 -0
  8. package/dist/evaluate/expression.d.ts +40 -0
  9. package/dist/evaluate/expression.js +604 -0
  10. package/dist/evaluate/helper.d.ts +18 -0
  11. package/dist/evaluate/helper.js +270 -0
  12. package/dist/evaluate/identifier.d.ts +7 -0
  13. package/dist/evaluate/identifier.js +27 -0
  14. package/dist/evaluate/index.d.ts +3 -0
  15. package/dist/evaluate/index.js +112 -0
  16. package/dist/evaluate/literal.d.ts +3 -0
  17. package/dist/evaluate/literal.js +8 -0
  18. package/dist/evaluate/pattern.d.ts +13 -0
  19. package/dist/evaluate/pattern.js +118 -0
  20. package/dist/evaluate/program.d.ts +3 -0
  21. package/dist/evaluate/program.js +20 -0
  22. package/dist/evaluate/statement.d.ts +35 -0
  23. package/dist/evaluate/statement.js +323 -0
  24. package/dist/evaluate_n/declaration.d.ts +27 -0
  25. package/dist/evaluate_n/declaration.js +289 -0
  26. package/dist/evaluate_n/expression.d.ts +38 -0
  27. package/dist/evaluate_n/expression.js +596 -0
  28. package/dist/evaluate_n/helper.d.ts +18 -0
  29. package/dist/evaluate_n/helper.js +238 -0
  30. package/dist/evaluate_n/identifier.d.ts +7 -0
  31. package/dist/evaluate_n/identifier.js +27 -0
  32. package/dist/evaluate_n/index.d.ts +3 -0
  33. package/dist/evaluate_n/index.js +76 -0
  34. package/dist/evaluate_n/literal.d.ts +3 -0
  35. package/dist/evaluate_n/literal.js +8 -0
  36. package/dist/evaluate_n/pattern.d.ts +13 -0
  37. package/dist/evaluate_n/pattern.js +118 -0
  38. package/dist/evaluate_n/program.d.ts +3 -0
  39. package/dist/evaluate_n/program.js +20 -0
  40. package/dist/evaluate_n/statement.d.ts +35 -0
  41. package/dist/evaluate_n/statement.js +301 -0
  42. package/dist/examples/example-2.d.ts +1 -0
  43. package/dist/examples/example.d.ts +1 -0
  44. package/dist/helper-functions.d.ts +15 -0
  45. package/dist/helper-functions.js +104 -0
  46. package/dist/index.d.ts +55 -0
  47. package/dist/index.js +312 -0
  48. package/dist/q-list.d.ts +39 -0
  49. package/dist/q-list.js +146 -0
  50. package/dist/scope/index.d.ts +81 -0
  51. package/dist/scope/index.js +168 -0
  52. package/dist/scope/variable.d.ts +20 -0
  53. package/dist/scope/variable.js +38 -0
  54. package/dist/share/async.d.ts +7 -0
  55. package/dist/share/async.js +43 -0
  56. package/dist/share/const.d.ts +25 -0
  57. package/dist/share/const.js +21 -0
  58. package/dist/share/util.d.ts +33 -0
  59. package/dist/share/util.js +379 -0
  60. package/dist/sval.d.ts +15 -0
  61. package/dist/sval.js +104 -0
  62. package/package.json +54 -0
@@ -0,0 +1,323 @@
1
+ import { BREAK, CONTINUE, RETURN, AWAIT } from '../share/const.js';
2
+ import { hoist, ForXHandler, pattern } from './helper.js';
3
+ import { getAsyncIterator } from '../share/util.js';
4
+ import Scope from '../scope/index.js';
5
+ import evaluate from './index.js';
6
+
7
+ function* ExpressionStatement(node, scope) {
8
+ yield* evaluate(node.expression, scope);
9
+ }
10
+ function* BlockStatement(block, scope, options = {}) {
11
+ const {
12
+ invasived = false,
13
+ hoisted = false
14
+ } = options;
15
+ const subScope = invasived ? scope : new Scope(scope);
16
+ if (!hoisted) {
17
+ yield* hoist(block, subScope, { onlyBlock: true });
18
+ }
19
+ for (let i = 0; i < block.body.length; i++) {
20
+ const result = yield* evaluate(block.body[i], subScope);
21
+ if (result === BREAK) {
22
+ if (result.LABEL && result.LABEL === options.label) {
23
+ break;
24
+ }
25
+ return result;
26
+ }
27
+ if (result === CONTINUE || result === RETURN) {
28
+ return result;
29
+ }
30
+ }
31
+ }
32
+ function* EmptyStatement() {
33
+ }
34
+ function* DebuggerStatement() {
35
+ debugger;
36
+ }
37
+ function* ReturnStatement(node, scope) {
38
+ RETURN.RES = node.argument ? yield* evaluate(node.argument, scope) : void 0;
39
+ return RETURN;
40
+ }
41
+ function* BreakStatement(node) {
42
+ BREAK.LABEL = node.label?.name;
43
+ return BREAK;
44
+ }
45
+ function* ContinueStatement(node) {
46
+ CONTINUE.LABEL = node.label?.name;
47
+ return CONTINUE;
48
+ }
49
+ function* LabeledStatement(node, scope) {
50
+ const label = node.label.name;
51
+ if (node.body.type === "WhileStatement") {
52
+ return yield* WhileStatement(node.body, scope, { label });
53
+ }
54
+ if (node.body.type === "DoWhileStatement") {
55
+ return yield* DoWhileStatement(node.body, scope, { label });
56
+ }
57
+ if (node.body.type === "ForStatement") {
58
+ return yield* ForStatement(node.body, scope, { label });
59
+ }
60
+ if (node.body.type === "ForInStatement") {
61
+ return yield* ForInStatement(node.body, scope, { label });
62
+ }
63
+ if (node.body.type === "ForOfStatement") {
64
+ return yield* ForOfStatement(node.body, scope, { label });
65
+ }
66
+ if (node.body.type === "BlockStatement") {
67
+ return yield* BlockStatement(node.body, scope, { label });
68
+ }
69
+ if (node.body.type === "WithStatement") {
70
+ return yield* WithStatement(node.body, scope, { label });
71
+ }
72
+ if (node.body.type === "IfStatement") {
73
+ return yield* IfStatement(node.body, scope, { label });
74
+ }
75
+ if (node.body.type === "SwitchStatement") {
76
+ return yield* SwitchStatement(node.body, scope, { label });
77
+ }
78
+ if (node.body.type === "TryStatement") {
79
+ return yield* TryStatement(node.body, scope, { label });
80
+ }
81
+ throw new SyntaxError(`${node.body.type} cannot be labeled`);
82
+ }
83
+ function* WithStatement(node, scope, options = {}) {
84
+ const withScope = new Scope(scope);
85
+ withScope.with(yield* evaluate(node.object, scope));
86
+ const result = yield* evaluate(node.body, withScope);
87
+ if (result === BREAK) {
88
+ if (result.LABEL && result.LABEL === options.label) {
89
+ return;
90
+ }
91
+ return result;
92
+ }
93
+ if (result === CONTINUE || result === RETURN) {
94
+ return result;
95
+ }
96
+ }
97
+ function* IfStatement(node, scope, options = {}) {
98
+ let result;
99
+ if (yield* evaluate(node.test, scope)) {
100
+ result = yield* evaluate(node.consequent, scope);
101
+ } else {
102
+ result = yield* evaluate(node.alternate, scope);
103
+ }
104
+ if (result === BREAK) {
105
+ if (result.LABEL && result.LABEL === options.label) {
106
+ return;
107
+ }
108
+ return result;
109
+ }
110
+ if (result === CONTINUE || result === RETURN) {
111
+ return result;
112
+ }
113
+ }
114
+ function* SwitchStatement(node, scope, options = {}) {
115
+ const discriminant = yield* evaluate(node.discriminant, scope);
116
+ let matched = false;
117
+ let defaultIndex = -1;
118
+ for (let i = 0; i < node.cases.length; i++) {
119
+ const eachCase = node.cases[i];
120
+ if (!eachCase.test) {
121
+ defaultIndex = i;
122
+ } else if (!matched && (yield* evaluate(eachCase.test, scope)) === discriminant) {
123
+ matched = true;
124
+ defaultIndex = -1;
125
+ }
126
+ if (matched) {
127
+ const result = yield* SwitchCase(eachCase, scope);
128
+ if (result === BREAK) {
129
+ if (result.LABEL === options.label) {
130
+ break;
131
+ }
132
+ return result;
133
+ }
134
+ if (result === CONTINUE || result === RETURN) {
135
+ return result;
136
+ }
137
+ }
138
+ }
139
+ if (!matched && defaultIndex !== -1) {
140
+ for (let i = defaultIndex; i < node.cases.length; i++) {
141
+ const result = yield* SwitchCase(node.cases[i], scope);
142
+ if (result === BREAK) {
143
+ if (result.LABEL === options.label) {
144
+ break;
145
+ }
146
+ return result;
147
+ }
148
+ if (result === CONTINUE || result === RETURN) {
149
+ return result;
150
+ }
151
+ }
152
+ }
153
+ }
154
+ function* SwitchCase(node, scope) {
155
+ for (let i = 0; i < node.consequent.length; i++) {
156
+ const result = yield* evaluate(node.consequent[i], scope);
157
+ if (result === BREAK || result === CONTINUE || result === RETURN) {
158
+ return result;
159
+ }
160
+ }
161
+ }
162
+ function* ThrowStatement(node, scope) {
163
+ throw yield* evaluate(node.argument, scope);
164
+ }
165
+ function* TryStatement(node, scope, options = {}) {
166
+ let result;
167
+ try {
168
+ result = yield* BlockStatement(node.block, scope);
169
+ } catch (err) {
170
+ if (node.handler) {
171
+ const subScope = new Scope(scope);
172
+ const param = node.handler.param;
173
+ if (param) {
174
+ if (param.type === "Identifier") {
175
+ const name = param.name;
176
+ subScope.var(name, err);
177
+ } else {
178
+ yield* pattern(param, scope, { feed: err });
179
+ }
180
+ }
181
+ result = yield* CatchClause(node.handler, subScope);
182
+ } else {
183
+ throw err;
184
+ }
185
+ } finally {
186
+ if (node.finalizer) {
187
+ result = yield* BlockStatement(node.finalizer, scope);
188
+ }
189
+ }
190
+ if (result === BREAK) {
191
+ if (result.LABEL && result.LABEL === options.label) {
192
+ return;
193
+ }
194
+ return result;
195
+ }
196
+ if (result === CONTINUE || result === RETURN) {
197
+ return result;
198
+ }
199
+ }
200
+ function* CatchClause(node, scope) {
201
+ return yield* BlockStatement(node.body, scope, { invasived: true });
202
+ }
203
+ function* WhileStatement(node, scope, options = {}) {
204
+ while (yield* evaluate(node.test, scope)) {
205
+ const result = yield* evaluate(node.body, scope);
206
+ if (result === BREAK) {
207
+ if (result.LABEL === options.label) {
208
+ break;
209
+ }
210
+ return result;
211
+ } else if (result === CONTINUE) {
212
+ if (result.LABEL === options.label) {
213
+ continue;
214
+ }
215
+ return result;
216
+ } else if (result === RETURN) {
217
+ return result;
218
+ }
219
+ }
220
+ }
221
+ function* DoWhileStatement(node, scope, options = {}) {
222
+ do {
223
+ const result = yield* evaluate(node.body, scope);
224
+ if (result === BREAK) {
225
+ if (result.LABEL === options.label) {
226
+ break;
227
+ }
228
+ return result;
229
+ } else if (result === CONTINUE) {
230
+ if (result.LABEL === options.label) {
231
+ continue;
232
+ }
233
+ return result;
234
+ } else if (result === RETURN) {
235
+ return result;
236
+ }
237
+ } while (yield* evaluate(node.test, scope));
238
+ }
239
+ function* ForStatement(node, scope, options = {}) {
240
+ const forScope = new Scope(scope);
241
+ for (node.init ? yield* evaluate(node.init, forScope) : void 0; node.test ? yield* evaluate(node.test, forScope) : true; node.update ? yield* evaluate(node.update, forScope) : void 0) {
242
+ const subScope = new Scope(forScope);
243
+ let result;
244
+ if (node.body.type === "BlockStatement") {
245
+ result = yield* BlockStatement(node.body, subScope, { invasived: true });
246
+ } else {
247
+ result = yield* evaluate(node.body, subScope);
248
+ }
249
+ if (result === BREAK) {
250
+ if (result.LABEL === options.label) {
251
+ break;
252
+ }
253
+ return result;
254
+ } else if (result === CONTINUE) {
255
+ if (result.LABEL === options.label) {
256
+ continue;
257
+ }
258
+ return result;
259
+ } else if (result === RETURN) {
260
+ return result;
261
+ }
262
+ }
263
+ }
264
+ function* ForInStatement(node, scope, options = {}) {
265
+ for (const value in yield* evaluate(node.right, scope)) {
266
+ const result = yield* ForXHandler(node, scope, { value });
267
+ if (result === BREAK) {
268
+ if (result.LABEL === options.label) {
269
+ break;
270
+ }
271
+ return result;
272
+ } else if (result === CONTINUE) {
273
+ if (result.LABEL === options.label) {
274
+ continue;
275
+ }
276
+ return result;
277
+ } else if (result === RETURN) {
278
+ return result;
279
+ }
280
+ }
281
+ }
282
+ function* ForOfStatement(node, scope, options = {}) {
283
+ const right = yield* evaluate(node.right, scope);
284
+ if (node.await) {
285
+ const iterator = getAsyncIterator(right);
286
+ let ret;
287
+ for (AWAIT.RES = iterator.next(), ret = yield AWAIT; !ret.done; AWAIT.RES = iterator.next(), ret = yield AWAIT) {
288
+ const result = yield* ForXHandler(node, scope, { value: ret.value });
289
+ if (result === BREAK) {
290
+ if (result.LABEL === options.label) {
291
+ break;
292
+ }
293
+ return result;
294
+ } else if (result === CONTINUE) {
295
+ if (result.LABEL === options.label) {
296
+ continue;
297
+ }
298
+ return result;
299
+ } else if (result === RETURN) {
300
+ return result;
301
+ }
302
+ }
303
+ } else {
304
+ for (const value of right) {
305
+ const result = yield* ForXHandler(node, scope, { value });
306
+ if (result === BREAK) {
307
+ if (result.LABEL === options.label) {
308
+ break;
309
+ }
310
+ return result;
311
+ } else if (result === CONTINUE) {
312
+ if (result.LABEL === options.label) {
313
+ continue;
314
+ }
315
+ return result;
316
+ } else if (result === RETURN) {
317
+ return result;
318
+ }
319
+ }
320
+ }
321
+ }
322
+
323
+ export { BlockStatement, BreakStatement, CatchClause, ContinueStatement, DebuggerStatement, DoWhileStatement, EmptyStatement, ExpressionStatement, ForInStatement, ForOfStatement, ForStatement, IfStatement, LabeledStatement, ReturnStatement, SwitchCase, SwitchStatement, ThrowStatement, TryStatement, WhileStatement, WithStatement };
@@ -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): 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): void;
11
+ export interface VariableDeclaratorOptions {
12
+ kind?: VarKind;
13
+ }
14
+ export declare function VariableDeclarator(node: acorn.VariableDeclarator, scope: Scope, options?: VariableDeclaratorOptions & VariableDeclarationOptions): void;
15
+ export declare function ClassDeclaration(node: acorn.ClassDeclaration, scope: Scope): 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): void;
21
+ export declare function MethodDefinition(node: acorn.MethodDefinition, scope: Scope, options?: ClassOptions): void;
22
+ export declare function PropertyDefinition(node: acorn.PropertyDefinition, scope: Scope, options?: ClassOptions): void;
23
+ export declare function StaticBlock(node: acorn.StaticBlock, scope: Scope, options?: ClassOptions): any;
24
+ export declare function ImportDeclaration(node: acorn.ImportDeclaration, scope: Scope): void;
25
+ export declare function ExportDefaultDeclaration(node: acorn.ExportDefaultDeclaration, scope: Scope): void;
26
+ export declare function ExportNamedDeclaration(node: acorn.ExportNamedDeclaration, scope: Scope): void;
27
+ export declare function ExportAllDeclaration(node: acorn.ExportAllDeclaration, scope: Scope): void;
@@ -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
+ 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
+ pattern(node.id, scope, { kind, hoist, onlyBlock });
24
+ }
25
+ }
26
+ } else {
27
+ const hasFeed = "feed" in options;
28
+ const value = hasFeed ? feed : 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
+ pattern(node.id, scope, { kind, feed: value });
44
+ }
45
+ }
46
+ }
47
+ function ClassDeclaration(node, scope) {
48
+ scope.func(node.id.name, 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
+ MethodDefinition(def, scope, { klass, superClass });
56
+ } else if (def.type === "PropertyDefinition" && def.static) {
57
+ PropertyDefinition(def, scope, { klass, superClass });
58
+ } else if (def.type === "StaticBlock") {
59
+ 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 = 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 = 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] = 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 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 = createClass(node.declaration, scope);
195
+ scope.func(node.declaration.id.name, value);
196
+ } else {
197
+ value = 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 = 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
+ 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,38 @@
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): any;
4
+ export declare function ArrayExpression(node: acorn.ArrayExpression, scope: Scope): any[];
5
+ export declare function ObjectExpression(node: acorn.ObjectExpression, scope: Scope): {
6
+ [key: string]: any;
7
+ };
8
+ export declare function FunctionExpression(node: acorn.FunctionExpression, scope: Scope): any;
9
+ export declare function UnaryExpression(node: acorn.UnaryExpression, scope: Scope): number | boolean | "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
10
+ export declare function UpdateExpression(node: acorn.UpdateExpression, scope: Scope): any;
11
+ export declare function BinaryExpression(node: acorn.BinaryExpression, scope: Scope): any;
12
+ export declare function AssignmentExpression(node: acorn.AssignmentExpression, scope: Scope): any;
13
+ export declare function LogicalExpression(node: acorn.LogicalExpression, scope: Scope): any;
14
+ export interface MemberExpressionOptions {
15
+ getObj?: boolean;
16
+ getVar?: boolean;
17
+ }
18
+ export declare function MemberExpression(node: acorn.MemberExpression, scope: Scope, options?: MemberExpressionOptions): any;
19
+ export declare function ConditionalExpression(node: acorn.ConditionalExpression, scope: Scope): any;
20
+ export declare function CallExpression(node: acorn.CallExpression, scope: Scope): any;
21
+ export declare function NewExpression(node: acorn.NewExpression, scope: Scope): any;
22
+ export declare function MetaProperty(node: acorn.MetaProperty, scope: Scope): any;
23
+ export declare function SequenceExpression(node: acorn.SequenceExpression, scope: Scope): any;
24
+ export declare function ArrowFunctionExpression(node: acorn.ArrowFunctionExpression, scope: Scope): any;
25
+ export declare function TemplateLiteral(node: acorn.TemplateLiteral, scope: Scope): string;
26
+ export declare function TaggedTemplateExpression(node: acorn.TaggedTemplateExpression, scope: Scope): any;
27
+ export declare function TemplateElement(node: acorn.TemplateElement, scope: Scope): string;
28
+ export declare function ClassExpression(node: acorn.ClassExpression, scope: Scope): () => any;
29
+ export interface SuperOptions {
30
+ getProto?: boolean;
31
+ }
32
+ export declare function Super(node: acorn.Super, scope: Scope, options?: SuperOptions): any;
33
+ export interface SpreadOptions {
34
+ spreadProps?: boolean;
35
+ }
36
+ export declare function SpreadElement(node: acorn.SpreadElement, scope: Scope, options?: SpreadOptions): any;
37
+ export declare function ChainExpression(node: acorn.ChainExpression, scope: Scope): any;
38
+ export declare function ImportExpression(node: acorn.ImportExpression, scope: Scope): Promise<any>;