@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,238 @@
1
+ import { CLSCTOR, STRICT, STRICT_FN, NEWTARGET, SUPER, SUPERCALL, RETURN, NOCTOR } from '../share/const.js';
2
+ import { VariableDeclaration, ClassBody, PropertyDefinition } from './declaration.js';
3
+ import { inherits, define, callSuper } from '../share/util.js';
4
+ import { Identifier } from './identifier.js';
5
+ import { BlockStatement } from './statement.js';
6
+ import Scope from '../scope/index.js';
7
+ import evaluate from './index.js';
8
+ import { AssignmentPattern, RestElement, ArrayPattern, ObjectPattern } from './pattern.js';
9
+ import { createFunc as createFunc$1 } from '../evaluate/helper.js';
10
+
11
+ function hoist(block, scope, options = {}) {
12
+ const { onlyBlock = false } = options;
13
+ const funcDclrList = [];
14
+ const funcDclrIdxs = [];
15
+ for (let i = 0; i < block.body.length; i++) {
16
+ const statement = block.body[i];
17
+ if (statement.type === "FunctionDeclaration") {
18
+ funcDclrList.push(statement);
19
+ funcDclrIdxs.push(i);
20
+ } else if (statement.type === "VariableDeclaration" && ["const", "let"].indexOf(statement.kind) !== -1) {
21
+ VariableDeclaration(statement, scope, { hoist: true, onlyBlock: true });
22
+ } else if (!onlyBlock) {
23
+ hoistVarRecursion(statement, scope);
24
+ }
25
+ }
26
+ if (funcDclrIdxs.length) {
27
+ for (let i = funcDclrIdxs.length - 1; i > -1; i--) {
28
+ block.body.splice(funcDclrIdxs[i], 1);
29
+ }
30
+ block.body = funcDclrList.concat(block.body);
31
+ }
32
+ }
33
+ function hoistVarRecursion(statement, scope) {
34
+ switch (statement.type) {
35
+ case "VariableDeclaration":
36
+ VariableDeclaration(statement, scope, { hoist: true });
37
+ break;
38
+ case "ForInStatement":
39
+ case "ForOfStatement":
40
+ if (statement.left.type === "VariableDeclaration") {
41
+ VariableDeclaration(statement.left, scope, { hoist: true });
42
+ }
43
+ case "ForStatement":
44
+ if (statement.type === "ForStatement" && statement.init && statement.init.type === "VariableDeclaration") {
45
+ VariableDeclaration(statement.init, scope, { hoist: true });
46
+ }
47
+ case "WhileStatement":
48
+ case "DoWhileStatement":
49
+ hoistVarRecursion(statement.body, scope);
50
+ break;
51
+ case "IfStatement":
52
+ hoistVarRecursion(statement.consequent, scope);
53
+ if (statement.alternate) {
54
+ hoistVarRecursion(statement.alternate, scope);
55
+ }
56
+ break;
57
+ case "BlockStatement":
58
+ for (let i = 0; i < statement.body.length; i++) {
59
+ hoistVarRecursion(statement.body[i], scope);
60
+ }
61
+ break;
62
+ case "SwitchStatement":
63
+ for (let i = 0; i < statement.cases.length; i++) {
64
+ for (let j = 0; j < statement.cases[i].consequent.length; j++) {
65
+ hoistVarRecursion(statement.cases[i].consequent[j], scope);
66
+ }
67
+ }
68
+ break;
69
+ case "TryStatement": {
70
+ const tryBlock = statement.block.body;
71
+ for (let i = 0; i < tryBlock.length; i++) {
72
+ hoistVarRecursion(tryBlock[i], scope);
73
+ }
74
+ const catchBlock = statement.handler && statement.handler.body.body;
75
+ if (catchBlock) {
76
+ for (let i = 0; i < catchBlock.length; i++) {
77
+ hoistVarRecursion(catchBlock[i], scope);
78
+ }
79
+ }
80
+ const finalBlock = statement.finalizer && statement.finalizer.body;
81
+ if (finalBlock) {
82
+ for (let i = 0; i < finalBlock.length; i++) {
83
+ hoistVarRecursion(finalBlock[i], scope);
84
+ }
85
+ }
86
+ break;
87
+ }
88
+ }
89
+ }
90
+ function pattern(node, scope, options = {}) {
91
+ switch (node.type) {
92
+ case "ObjectPattern":
93
+ return ObjectPattern(node, scope, options);
94
+ case "ArrayPattern":
95
+ return ArrayPattern(node, scope, options);
96
+ case "RestElement":
97
+ return RestElement(node, scope, options);
98
+ case "AssignmentPattern":
99
+ return AssignmentPattern(node, scope, options);
100
+ default:
101
+ throw new SyntaxError("Unexpected token");
102
+ }
103
+ }
104
+ function createFunc(node, scope, options = {}) {
105
+ if (node.generator || node.async) {
106
+ return createFunc$1(node, scope, options);
107
+ }
108
+ const { superClass, construct } = options;
109
+ const params = node.params;
110
+ const hasOwnUseStrict = node.body.type === "BlockStatement" && node.body.body.length > 0 && node.body.body[0].directive === "use strict";
111
+ const enclosingStrict = !!scope.find(STRICT)?.get();
112
+ const isFuncStrict = hasOwnUseStrict || enclosingStrict;
113
+ const tmpFunc = function(...args) {
114
+ const subScope = new Scope(scope, true);
115
+ if (hasOwnUseStrict && !enclosingStrict) {
116
+ subScope.const(STRICT, true);
117
+ }
118
+ if (node.type !== "ArrowFunctionExpression") {
119
+ subScope.let("this", this);
120
+ subScope.let("arguments", arguments);
121
+ subScope.const(NEWTARGET, new.target);
122
+ if (superClass) {
123
+ subScope.const(SUPER, superClass);
124
+ if (construct) subScope.let(SUPERCALL, construct);
125
+ } else if (construct) {
126
+ construct(this);
127
+ }
128
+ }
129
+ for (let i = 0; i < params.length; i++) {
130
+ const param = params[i];
131
+ if (param.type === "Identifier") {
132
+ subScope.var(param.name, args[i]);
133
+ } else if (param.type === "RestElement") {
134
+ RestElement(param, subScope, { kind: "var", feed: args.slice(i) });
135
+ } else {
136
+ pattern(param, subScope, { kind: "var", feed: args[i] });
137
+ }
138
+ }
139
+ let result;
140
+ if (node.body.type === "BlockStatement") {
141
+ hoist(node.body, subScope);
142
+ result = BlockStatement(node.body, subScope, {
143
+ invasived: true,
144
+ hoisted: true
145
+ });
146
+ } else {
147
+ result = evaluate(node.body, subScope);
148
+ if (node.type === "ArrowFunctionExpression") {
149
+ RETURN.RES = result;
150
+ result = RETURN;
151
+ }
152
+ }
153
+ if (result === RETURN) {
154
+ return result.RES;
155
+ } else if (new.target) {
156
+ return subScope.find("this").get();
157
+ }
158
+ };
159
+ let func = tmpFunc;
160
+ if (node.type === "ArrowFunctionExpression") {
161
+ define(func, NOCTOR, { value: true });
162
+ }
163
+ define(func, "name", {
164
+ value: node.id && node.id.name || "",
165
+ configurable: true
166
+ });
167
+ define(func, "length", {
168
+ value: params.length,
169
+ configurable: true
170
+ });
171
+ if (isFuncStrict) {
172
+ define(func, STRICT_FN, { value: true });
173
+ }
174
+ const source = node.loc?.source;
175
+ if (source) {
176
+ define(func, "toString", {
177
+ value: () => source.substring(node.start, node.end),
178
+ configurable: true
179
+ });
180
+ }
181
+ return func;
182
+ }
183
+ function createClass(node, scope) {
184
+ const superClass = evaluate(node.superClass, scope);
185
+ const methodBody = node.body.body;
186
+ const construct = function(object) {
187
+ for (let i = 0; i < methodBody.length; i++) {
188
+ const def = methodBody[i];
189
+ if (def.type === "PropertyDefinition" && !def.static) {
190
+ PropertyDefinition(def, scope, { klass: object, superClass });
191
+ }
192
+ }
193
+ };
194
+ let klass = function() {
195
+ const inst = superClass ? callSuper(this, superClass) : this;
196
+ construct(inst);
197
+ return inst;
198
+ };
199
+ for (let i = 0; i < methodBody.length; i++) {
200
+ const method = methodBody[i];
201
+ if (method.type === "MethodDefinition" && method.kind === "constructor") {
202
+ klass = createFunc(method.value, scope, { superClass, construct });
203
+ break;
204
+ }
205
+ }
206
+ if (superClass) {
207
+ inherits(klass, superClass);
208
+ }
209
+ ClassBody(node.body, scope, { klass, superClass });
210
+ define(klass, CLSCTOR, { value: true });
211
+ define(klass, "name", {
212
+ value: node.id && node.id.name || "",
213
+ configurable: true
214
+ });
215
+ return klass;
216
+ }
217
+ function ForXHandler(node, scope, options) {
218
+ const { value } = options;
219
+ const left = node.left;
220
+ const subScope = new Scope(scope);
221
+ if (left.type === "VariableDeclaration") {
222
+ VariableDeclaration(left, subScope, { feed: value });
223
+ } else if (left.type === "Identifier") {
224
+ const variable = Identifier(left, scope, { getVar: true });
225
+ variable.set(value);
226
+ } else {
227
+ pattern(left, scope, { feed: value });
228
+ }
229
+ let result;
230
+ if (node.body.type === "BlockStatement") {
231
+ result = BlockStatement(node.body, subScope, { invasived: true });
232
+ } else {
233
+ result = evaluate(node.body, subScope);
234
+ }
235
+ return result;
236
+ }
237
+
238
+ export { ForXHandler, createClass, createFunc, hoist, pattern };
@@ -0,0 +1,7 @@
1
+ import { default as Scope } from '../scope/index.ts';
2
+ import * as acorn from 'acorn';
3
+ export interface IdentifierOptions {
4
+ getVar?: boolean;
5
+ throwErr?: boolean;
6
+ }
7
+ export declare function Identifier(node: acorn.Identifier, scope: Scope, options?: IdentifierOptions): any;
@@ -0,0 +1,27 @@
1
+ import { DEADZONE } from '../share/const.js';
2
+
3
+ function Identifier(node, scope, options = {}) {
4
+ const { getVar = false, throwErr = true } = options;
5
+ if (node.name === "undefined") {
6
+ return void 0;
7
+ }
8
+ const variable = scope.find(node.name);
9
+ if (variable) {
10
+ if (getVar) {
11
+ return variable;
12
+ } else {
13
+ const value = variable.get();
14
+ if (value === DEADZONE) {
15
+ throw new ReferenceError(`${node.name} is not defined`);
16
+ } else {
17
+ return value;
18
+ }
19
+ }
20
+ } else if (throwErr) {
21
+ throw new ReferenceError(`${node.name} is not defined`);
22
+ } else {
23
+ return void 0;
24
+ }
25
+ }
26
+
27
+ export { Identifier };
@@ -0,0 +1,3 @@
1
+ import { Node } from 'acorn';
2
+ import { default as Scope } from '../scope/index.ts';
3
+ export default function evaluate(node: Node, scope: Scope): any;
@@ -0,0 +1,76 @@
1
+ import { assign } from '../share/util.js';
2
+ import * as declaration from './declaration.js';
3
+ import * as expression from './expression.js';
4
+ import * as identifier from './identifier.js';
5
+ import * as statement from './statement.js';
6
+ import * as literal from './literal.js';
7
+ import * as pattern from './pattern.js';
8
+ import * as program from './program.js';
9
+ import { UNASSIGNED, SEEN } from '../custom-types.js';
10
+ import { useModifiedEvaluator, captureReusables, callMonitor, isGenerator, refreshExeStack, pushHandler, callPerExe, cleanStack } from '../helper-functions.js';
11
+ import ansis from 'ansis';
12
+
13
+ let evaluateOps;
14
+ function evaluate(node, scope) {
15
+ if (!node) return;
16
+ if (!evaluateOps) {
17
+ evaluateOps = assign(
18
+ {},
19
+ declaration,
20
+ expression,
21
+ identifier,
22
+ statement,
23
+ literal,
24
+ pattern,
25
+ program
26
+ );
27
+ }
28
+ const handler = evaluateOps[node.type];
29
+ if (!handler) throw new Error(`${node.type} isn't implemented`);
30
+ const interpreter = scope.interpreter;
31
+ if (interpreter.onStep) {
32
+ interpreter.onStep();
33
+ }
34
+ if (!useModifiedEvaluator(scope)) {
35
+ return handler(node, scope);
36
+ }
37
+ const parentReusables = captureReusables(interpreter);
38
+ try {
39
+ interpreter.reusables.shared.evalStack.value += 1;
40
+ const feedback = callMonitor(node, scope, handler);
41
+ if (isGenerator(feedback)) {
42
+ const next = feedback.next();
43
+ const executedManually = interpreter.reusables.result !== UNASSIGNED;
44
+ const result = executedManually ? interpreter.reusables.result : handler(node, scope);
45
+ const manuallyExecutedResult = interpreter.reusables.result;
46
+ interpreter.reusables.result = SEEN;
47
+ if (!next.done) {
48
+ if (next.value !== manuallyExecutedResult) {
49
+ throw new Error(ansis.red(`For an eager node,inspectors that are generators can only yield the result of that node to be consistent but saw: ${String(next.value)} instead of: ${String(manuallyExecutedResult)}.`));
50
+ }
51
+ const next2 = feedback.next(result);
52
+ if (!next2.done) {
53
+ throw new Error(ansis.red(`In Eager Node:inspectors that are generators can only yield once.`));
54
+ }
55
+ }
56
+ const wasCleared = refreshExeStack(interpreter);
57
+ const pushedManually = executedManually && !wasCleared;
58
+ pushHandler(interpreter, result, pushedManually);
59
+ callPerExe(interpreter);
60
+ return result;
61
+ } else {
62
+ const executedManually = interpreter.reusables.result !== UNASSIGNED;
63
+ const result = executedManually ? interpreter.reusables.result : handler(node, scope);
64
+ interpreter.reusables.result = SEEN;
65
+ const wasCleared = refreshExeStack(interpreter);
66
+ const pushedManually = executedManually && !wasCleared;
67
+ pushHandler(interpreter, result, pushedManually);
68
+ callPerExe(interpreter);
69
+ return result;
70
+ }
71
+ } finally {
72
+ cleanStack(interpreter, parentReusables);
73
+ }
74
+ }
75
+
76
+ export { evaluate as default };
@@ -0,0 +1,3 @@
1
+ import { default as Scope } from '../scope/index.ts';
2
+ import * as acorn from 'acorn';
3
+ export declare function Literal(node: acorn.Literal, scope: Scope): string | number | bigint | boolean | RegExp;
@@ -0,0 +1,8 @@
1
+ function Literal(node, scope) {
2
+ if (node.regex) {
3
+ return new RegExp(node.regex.pattern, node.regex.flags);
4
+ }
5
+ return node.value;
6
+ }
7
+
8
+ export { Literal };
@@ -0,0 +1,13 @@
1
+ import { VarKind } from '../scope/variable.ts';
2
+ import { default as Scope } from '../scope/index.ts';
3
+ import * as acorn from 'acorn';
4
+ export interface PatternOptions {
5
+ kind?: VarKind;
6
+ hoist?: boolean;
7
+ onlyBlock?: boolean;
8
+ feed?: any;
9
+ }
10
+ export declare function ObjectPattern(node: acorn.ObjectPattern, scope: Scope, options?: PatternOptions): void;
11
+ export declare function ArrayPattern(node: acorn.ArrayPattern, scope: Scope, options?: PatternOptions): any[];
12
+ export declare function RestElement(node: acorn.RestElement, scope: Scope, options?: PatternOptions): void;
13
+ export declare function AssignmentPattern(node: acorn.AssignmentPattern, scope: Scope, options?: PatternOptions): void;
@@ -0,0 +1,118 @@
1
+ import { DEADZONE, NOINIT } from '../share/const.js';
2
+ import { Identifier } from './identifier.js';
3
+ import { assign } from '../share/util.js';
4
+ import { pattern } from './helper.js';
5
+ import evaluate from './index.js';
6
+
7
+ function ObjectPattern(node, scope, options = {}) {
8
+ const { kind = "var", hoist = false, onlyBlock = false, feed = {} } = options;
9
+ const fedKeys = [];
10
+ for (let i = 0; i < node.properties.length; i++) {
11
+ const property = node.properties[i];
12
+ if (hoist) {
13
+ if (onlyBlock || kind === "var") {
14
+ if (property.type === "Property") {
15
+ const value = property.value;
16
+ if (value.type === "Identifier") {
17
+ scope[kind](value.name, onlyBlock ? DEADZONE : kind === "var" ? NOINIT : void 0);
18
+ } else {
19
+ pattern(value, scope, { kind, hoist, onlyBlock });
20
+ }
21
+ } else {
22
+ RestElement(property, scope, { kind, hoist, onlyBlock });
23
+ }
24
+ }
25
+ } else if (property.type === "Property") {
26
+ let key;
27
+ if (property.computed) {
28
+ key = evaluate(property.key, scope);
29
+ } else {
30
+ key = property.key.name;
31
+ }
32
+ fedKeys.push(key);
33
+ const value = property.value;
34
+ if (value.type === "Identifier") {
35
+ scope[kind](value.name, feed[key]);
36
+ } else {
37
+ pattern(value, scope, { kind, feed: feed[key] });
38
+ }
39
+ } else {
40
+ const rest = assign({}, feed);
41
+ for (let i2 = 0; i2 < fedKeys.length; i2++) delete rest[fedKeys[i2]];
42
+ RestElement(property, scope, { kind, feed: rest });
43
+ }
44
+ }
45
+ }
46
+ function ArrayPattern(node, scope, options = {}) {
47
+ const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
48
+ const result = [];
49
+ for (let i = 0; i < node.elements.length; i++) {
50
+ const element = node.elements[i];
51
+ if (!element) continue;
52
+ if (hoist) {
53
+ if (onlyBlock || kind === "var") {
54
+ if (element.type === "Identifier") {
55
+ scope[kind](element.name, onlyBlock ? DEADZONE : kind === "var" ? NOINIT : void 0);
56
+ } else {
57
+ pattern(element, scope, { kind, hoist, onlyBlock });
58
+ }
59
+ }
60
+ } else if (element.type === "Identifier") {
61
+ if (kind) {
62
+ scope[kind](element.name, feed[i]);
63
+ } else {
64
+ const variable = Identifier(element, scope, { getVar: true });
65
+ variable.set(feed[i]);
66
+ result.push(variable.get());
67
+ }
68
+ } else if (element.type === "RestElement") {
69
+ RestElement(element, scope, { kind, feed: feed.slice(i) });
70
+ } else {
71
+ pattern(element, scope, { kind, feed: feed[i] });
72
+ }
73
+ }
74
+ if (result.length) {
75
+ return result;
76
+ }
77
+ }
78
+ function RestElement(node, scope, options = {}) {
79
+ const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
80
+ const arg = node.argument;
81
+ if (hoist) {
82
+ if (onlyBlock || kind === "var") {
83
+ if (arg.type === "Identifier") {
84
+ scope[kind](arg.name, onlyBlock ? DEADZONE : kind === "var" ? NOINIT : void 0);
85
+ } else {
86
+ pattern(arg, scope, { kind, hoist, onlyBlock });
87
+ }
88
+ }
89
+ } else if (arg.type === "Identifier") {
90
+ if (kind) {
91
+ scope[kind](arg.name, feed);
92
+ } else {
93
+ const variable = Identifier(arg, scope, { getVar: true });
94
+ variable.set(feed);
95
+ }
96
+ } else {
97
+ pattern(arg, scope, { kind, feed });
98
+ }
99
+ }
100
+ function AssignmentPattern(node, scope, options = {}) {
101
+ const { kind = "var", hoist = false, onlyBlock = false, feed = evaluate(node.right, scope) } = options;
102
+ const left = node.left;
103
+ if (hoist) {
104
+ if (onlyBlock || kind === "var") {
105
+ if (left.type === "Identifier") {
106
+ scope[kind](left.name, onlyBlock ? DEADZONE : kind === "var" ? NOINIT : void 0);
107
+ } else {
108
+ pattern(left, scope, { kind, hoist, onlyBlock });
109
+ }
110
+ }
111
+ } else if (left.type === "Identifier") {
112
+ scope[kind](left.name, feed);
113
+ } else {
114
+ pattern(left, scope, { kind, feed });
115
+ }
116
+ }
117
+
118
+ export { ArrayPattern, AssignmentPattern, ObjectPattern, RestElement };
@@ -0,0 +1,3 @@
1
+ import { default as Scope } from '../scope/index.ts';
2
+ import * as acorn from 'acorn';
3
+ export declare function Program(program: acorn.Program, scope: Scope): void;
@@ -0,0 +1,20 @@
1
+ import { STRICT } from '../share/const.js';
2
+ import evaluate from './index.js';
3
+
4
+ function Program(program, scope) {
5
+ for (let i = 0; i < program.body.length; i++) {
6
+ const stmt = program.body[i];
7
+ if (stmt.type === "ExpressionStatement" && stmt.directive) {
8
+ if (stmt.directive === "use strict" && !scope.find(STRICT)) {
9
+ scope.const(STRICT, true);
10
+ }
11
+ } else {
12
+ break;
13
+ }
14
+ }
15
+ for (let i = 0; i < program.body.length; i++) {
16
+ evaluate(program.body[i], scope);
17
+ }
18
+ }
19
+
20
+ export { Program };
@@ -0,0 +1,35 @@
1
+ import { default as Scope } from '../scope/index.ts';
2
+ import * as acorn from 'acorn';
3
+ export declare function ExpressionStatement(node: acorn.ExpressionStatement, scope: Scope): void;
4
+ export interface LabelOptions {
5
+ label?: string;
6
+ }
7
+ export interface BlockOptions {
8
+ invasived?: boolean;
9
+ hoisted?: boolean;
10
+ }
11
+ export declare function BlockStatement(block: acorn.BlockStatement | acorn.StaticBlock, scope: Scope, options?: BlockOptions & LabelOptions): any;
12
+ export declare function EmptyStatement(): any;
13
+ export declare function DebuggerStatement(): any;
14
+ export declare function ReturnStatement(node: acorn.ReturnStatement, scope: Scope): {
15
+ RES: any;
16
+ };
17
+ export declare function BreakStatement(node: acorn.BreakStatement): {
18
+ LABEL: string;
19
+ };
20
+ export declare function ContinueStatement(node: acorn.ContinueStatement): {
21
+ LABEL: string;
22
+ };
23
+ export declare function LabeledStatement(node: acorn.LabeledStatement, scope: Scope): any;
24
+ export declare function WithStatement(node: acorn.WithStatement, scope: Scope, options?: LabelOptions): any;
25
+ export declare function IfStatement(node: acorn.IfStatement, scope: Scope, options?: LabelOptions): any;
26
+ export declare function SwitchStatement(node: acorn.SwitchStatement, scope: Scope, options?: LabelOptions): any;
27
+ export declare function SwitchCase(node: acorn.SwitchCase, scope: Scope): any;
28
+ export declare function ThrowStatement(node: acorn.ThrowStatement, scope: Scope): void;
29
+ export declare function TryStatement(node: acorn.TryStatement, scope: Scope, options?: LabelOptions): any;
30
+ export declare function CatchClause(node: acorn.CatchClause, scope: Scope): any;
31
+ export declare function WhileStatement(node: acorn.WhileStatement, scope: Scope, options?: LabelOptions): any;
32
+ export declare function DoWhileStatement(node: acorn.DoWhileStatement, scope: Scope, options?: LabelOptions): any;
33
+ export declare function ForStatement(node: acorn.ForStatement, scope: Scope, options?: LabelOptions): any;
34
+ export declare function ForInStatement(node: acorn.ForInStatement, scope: Scope, options?: LabelOptions): any;
35
+ export declare function ForOfStatement(node: acorn.ForOfStatement, scope: Scope, options?: LabelOptions): any;