@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,379 @@
|
|
|
1
|
+
const freeze = Object.freeze;
|
|
2
|
+
const define = Object.defineProperty;
|
|
3
|
+
const getDptor = Object.getOwnPropertyDescriptor;
|
|
4
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
5
|
+
function hasOwn(obj, key) {
|
|
6
|
+
return hasOwnProperty.call(obj, key);
|
|
7
|
+
}
|
|
8
|
+
const getOwnNames = Object.getOwnPropertyNames;
|
|
9
|
+
const setPrototypeOf = Object.setPrototypeOf;
|
|
10
|
+
function setProto(obj, proto) {
|
|
11
|
+
setPrototypeOf ? setPrototypeOf(obj, proto) : obj.__proto__ = proto;
|
|
12
|
+
}
|
|
13
|
+
const getPrototypeOf = Object.getPrototypeOf;
|
|
14
|
+
function getProto(obj) {
|
|
15
|
+
return getPrototypeOf ? getPrototypeOf(obj) : obj.__proto__;
|
|
16
|
+
}
|
|
17
|
+
const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
18
|
+
function getGetterOrSetter(method, obj, key) {
|
|
19
|
+
while (obj) {
|
|
20
|
+
const descriptor = getOwnPropertyDescriptor(obj, key);
|
|
21
|
+
const value = typeof descriptor !== "undefined" && typeof descriptor.writable === "undefined" && typeof descriptor[method] === "function" && descriptor[method];
|
|
22
|
+
if (value) {
|
|
23
|
+
return value;
|
|
24
|
+
} else {
|
|
25
|
+
obj = getProto(obj);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function getGetter(obj, key) {
|
|
30
|
+
return getGetterOrSetter("get", obj, key);
|
|
31
|
+
}
|
|
32
|
+
function getSetter(obj, key) {
|
|
33
|
+
return getGetterOrSetter("set", obj, key);
|
|
34
|
+
}
|
|
35
|
+
const create = Object.create;
|
|
36
|
+
function inherits(subClass, superClass) {
|
|
37
|
+
setProto(subClass, superClass);
|
|
38
|
+
subClass.prototype = create(superClass.prototype, {
|
|
39
|
+
constructor: {
|
|
40
|
+
value: subClass,
|
|
41
|
+
writable: true
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function callSuper(target, superClass, args = []) {
|
|
46
|
+
let supportReflect = false;
|
|
47
|
+
try {
|
|
48
|
+
supportReflect = !Boolean.prototype.valueOf.call(
|
|
49
|
+
Reflect.construct(Boolean, [], function() {
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
}
|
|
54
|
+
return supportReflect ? Reflect.construct(superClass, args, getProto(target).constructor) : superClass.apply(target, args);
|
|
55
|
+
}
|
|
56
|
+
function _assign(target) {
|
|
57
|
+
for (let i = 1; i < arguments.length; ++i) {
|
|
58
|
+
const source = arguments[i];
|
|
59
|
+
for (const key in source) {
|
|
60
|
+
if (hasOwn(source, key)) {
|
|
61
|
+
target[key] = source[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return target;
|
|
66
|
+
}
|
|
67
|
+
const assign = Object.assign || _assign;
|
|
68
|
+
let names = [];
|
|
69
|
+
let globalObj = create(null);
|
|
70
|
+
const setGlobalObj = (g) => {
|
|
71
|
+
if (!g.Object) throw 0;
|
|
72
|
+
names = getOwnNames(globalObj = g).filter((n) => ["webkitStorageInfo", "GLOBAL", "root"].indexOf(n) === -1);
|
|
73
|
+
};
|
|
74
|
+
try {
|
|
75
|
+
setGlobalObj(window);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
try {
|
|
78
|
+
setGlobalObj(self);
|
|
79
|
+
} catch (err2) {
|
|
80
|
+
try {
|
|
81
|
+
setGlobalObj(global);
|
|
82
|
+
} catch (err3) {
|
|
83
|
+
try {
|
|
84
|
+
setGlobalObj(globalThis);
|
|
85
|
+
} catch (err4) {
|
|
86
|
+
try {
|
|
87
|
+
globalObj.Object = Object;
|
|
88
|
+
} catch (err5) {
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
globalObj.Function = Function;
|
|
92
|
+
} catch (err5) {
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
globalObj.Array = Array;
|
|
96
|
+
} catch (err5) {
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
globalObj.Number = Number;
|
|
100
|
+
} catch (err5) {
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
globalObj.parseFloat = parseFloat;
|
|
104
|
+
} catch (err5) {
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
globalObj.parseInt = parseInt;
|
|
108
|
+
} catch (err5) {
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
globalObj.Infinity = Infinity;
|
|
112
|
+
} catch (err5) {
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
globalObj.NaN = NaN;
|
|
116
|
+
} catch (err5) {
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
globalObj.undefined = void 0;
|
|
120
|
+
} catch (err5) {
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
globalObj.Boolean = Boolean;
|
|
124
|
+
} catch (err5) {
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
globalObj.String = String;
|
|
128
|
+
} catch (err5) {
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
globalObj.Symbol = Symbol;
|
|
132
|
+
} catch (err5) {
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
globalObj.Date = Date;
|
|
136
|
+
} catch (err5) {
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
globalObj.Promise = Promise;
|
|
140
|
+
} catch (err5) {
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
globalObj.RegExp = RegExp;
|
|
144
|
+
} catch (err5) {
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
globalObj.Error = Error;
|
|
148
|
+
} catch (err5) {
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
globalObj.EvalError = EvalError;
|
|
152
|
+
} catch (err5) {
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
globalObj.RangeError = RangeError;
|
|
156
|
+
} catch (err5) {
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
globalObj.ReferenceError = ReferenceError;
|
|
160
|
+
} catch (err5) {
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
globalObj.SyntaxError = SyntaxError;
|
|
164
|
+
} catch (err5) {
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
globalObj.TypeError = TypeError;
|
|
168
|
+
} catch (err5) {
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
globalObj.URIError = URIError;
|
|
172
|
+
} catch (err5) {
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
globalObj.JSON = JSON;
|
|
176
|
+
} catch (err5) {
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
globalObj.Math = Math;
|
|
180
|
+
} catch (err5) {
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
globalObj.console = console;
|
|
184
|
+
} catch (err5) {
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
globalObj.Intl = Intl;
|
|
188
|
+
} catch (err5) {
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
globalObj.ArrayBuffer = ArrayBuffer;
|
|
192
|
+
} catch (err5) {
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
globalObj.Uint8Array = Uint8Array;
|
|
196
|
+
} catch (err5) {
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
globalObj.Int8Array = Int8Array;
|
|
200
|
+
} catch (err5) {
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
globalObj.Uint16Array = Uint16Array;
|
|
204
|
+
} catch (err5) {
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
globalObj.Int16Array = Int16Array;
|
|
208
|
+
} catch (err5) {
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
globalObj.Uint32Array = Uint32Array;
|
|
212
|
+
} catch (err5) {
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
globalObj.Int32Array = Int32Array;
|
|
216
|
+
} catch (err5) {
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
globalObj.Float32Array = Float32Array;
|
|
220
|
+
} catch (err5) {
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
globalObj.Float64Array = Float64Array;
|
|
224
|
+
} catch (err5) {
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
globalObj.Uint8ClampedArray = Uint8ClampedArray;
|
|
228
|
+
} catch (err5) {
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
globalObj.DataView = DataView;
|
|
232
|
+
} catch (err5) {
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
globalObj.Map = Map;
|
|
236
|
+
} catch (err5) {
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
globalObj.Set = Set;
|
|
240
|
+
} catch (err5) {
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
globalObj.WeakMap = WeakMap;
|
|
244
|
+
} catch (err5) {
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
globalObj.WeakSet = WeakSet;
|
|
248
|
+
} catch (err5) {
|
|
249
|
+
}
|
|
250
|
+
try {
|
|
251
|
+
globalObj.Proxy = Proxy;
|
|
252
|
+
} catch (err5) {
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
globalObj.Reflect = Reflect;
|
|
256
|
+
} catch (err5) {
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
globalObj.BigInt = BigInt;
|
|
260
|
+
} catch (err5) {
|
|
261
|
+
}
|
|
262
|
+
try {
|
|
263
|
+
globalObj.decodeURI = decodeURI;
|
|
264
|
+
} catch (err5) {
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
globalObj.decodeURIComponent = decodeURIComponent;
|
|
268
|
+
} catch (err5) {
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
globalObj.encodeURI = encodeURI;
|
|
272
|
+
} catch (err5) {
|
|
273
|
+
}
|
|
274
|
+
try {
|
|
275
|
+
globalObj.encodeURIComponent = encodeURIComponent;
|
|
276
|
+
} catch (err5) {
|
|
277
|
+
}
|
|
278
|
+
try {
|
|
279
|
+
globalObj.escape = escape;
|
|
280
|
+
} catch (err5) {
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
globalObj.unescape = unescape;
|
|
284
|
+
} catch (err5) {
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
globalObj.eval = eval;
|
|
288
|
+
} catch (err5) {
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
globalObj.isFinite = isFinite;
|
|
292
|
+
} catch (err5) {
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
globalObj.isNaN = isNaN;
|
|
296
|
+
} catch (err5) {
|
|
297
|
+
}
|
|
298
|
+
try {
|
|
299
|
+
globalObj.SharedArrayBuffer = SharedArrayBuffer;
|
|
300
|
+
} catch (err5) {
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
globalObj.Atomics = Atomics;
|
|
304
|
+
} catch (err5) {
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
globalObj.WebAssembly = WebAssembly;
|
|
308
|
+
} catch (err5) {
|
|
309
|
+
}
|
|
310
|
+
try {
|
|
311
|
+
globalObj.clearInterval = clearInterval;
|
|
312
|
+
} catch (err5) {
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
globalObj.clearTimeout = clearTimeout;
|
|
316
|
+
} catch (err5) {
|
|
317
|
+
}
|
|
318
|
+
try {
|
|
319
|
+
globalObj.setInterval = setInterval;
|
|
320
|
+
} catch (err5) {
|
|
321
|
+
}
|
|
322
|
+
try {
|
|
323
|
+
globalObj.setTimeout = setTimeout;
|
|
324
|
+
} catch (err5) {
|
|
325
|
+
}
|
|
326
|
+
try {
|
|
327
|
+
globalObj.crypto = crypto;
|
|
328
|
+
} catch (err5) {
|
|
329
|
+
}
|
|
330
|
+
try {
|
|
331
|
+
globalObj.URL = URL;
|
|
332
|
+
} catch (err5) {
|
|
333
|
+
}
|
|
334
|
+
names = getOwnNames(globalObj);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (globalObj.Symbol) {
|
|
340
|
+
!globalObj.Symbol.iterator && (globalObj.Symbol.iterator = createSymbol("iterator"));
|
|
341
|
+
!globalObj.Symbol.asyncIterator && (globalObj.Symbol.asyncIterator = createSymbol("asynciterator"));
|
|
342
|
+
}
|
|
343
|
+
const win = create({});
|
|
344
|
+
for (let i = 0; i < names.length; i++) {
|
|
345
|
+
const name = names[i];
|
|
346
|
+
try {
|
|
347
|
+
win[name] = globalObj[name];
|
|
348
|
+
} catch (err) {
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const WINDOW = createSymbol("window");
|
|
352
|
+
function createSandBox() {
|
|
353
|
+
return assign(create({ [WINDOW]: globalObj }), win);
|
|
354
|
+
}
|
|
355
|
+
function createSymbol(key) {
|
|
356
|
+
return key + Math.random().toString(36).substring(2);
|
|
357
|
+
}
|
|
358
|
+
function getAsyncIterator(obj) {
|
|
359
|
+
let iterator;
|
|
360
|
+
if (typeof Symbol === "function") {
|
|
361
|
+
iterator = obj[Symbol.asyncIterator];
|
|
362
|
+
!iterator && (iterator = obj[Symbol.iterator]);
|
|
363
|
+
}
|
|
364
|
+
if (iterator) {
|
|
365
|
+
return iterator.call(obj);
|
|
366
|
+
} else if (typeof obj.next === "function") {
|
|
367
|
+
return obj;
|
|
368
|
+
} else {
|
|
369
|
+
let i = 0;
|
|
370
|
+
return {
|
|
371
|
+
next() {
|
|
372
|
+
if (obj && i >= obj.length) obj = void 0;
|
|
373
|
+
return { value: obj && obj[i++], done: !obj };
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export { WINDOW, _assign, assign, callSuper, create, createSandBox, createSymbol, define, freeze, getAsyncIterator, getDptor, getGetter, getOwnNames, getProto, getSetter, globalObj, hasOwn, inherits, setProto };
|
package/dist/sval.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Options, Node } from 'acorn';
|
|
2
|
+
export interface SvalOptions {
|
|
3
|
+
ecmaVer?: Options['ecmaVersion'];
|
|
4
|
+
sourceType?: Options['sourceType'];
|
|
5
|
+
sandBox?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export default class Sval {
|
|
8
|
+
private options;
|
|
9
|
+
private scope;
|
|
10
|
+
exports: Record<string, any>;
|
|
11
|
+
constructor(options?: SvalOptions);
|
|
12
|
+
import(nameOrModules: string | Record<string, any>, mod?: any): void;
|
|
13
|
+
parse(code: string, parser?: (code: string, options: Options) => Node): Node;
|
|
14
|
+
run(code: string | Node): void;
|
|
15
|
+
}
|
package/dist/sval.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createSandBox, globalObj, getOwnNames } from './share/util.js';
|
|
2
|
+
import { parse } from 'acorn';
|
|
3
|
+
import { EXPORTS, STRICT, IMPORT } from './share/const.js';
|
|
4
|
+
import Scope from './scope/index.js';
|
|
5
|
+
import { runAsync } from './share/async.js';
|
|
6
|
+
import { hoist } from './evaluate/helper.js';
|
|
7
|
+
import { hoist as hoist$1 } from './evaluate_n/helper.js';
|
|
8
|
+
import evaluate from './evaluate/index.js';
|
|
9
|
+
import evaluate$1 from './evaluate_n/index.js';
|
|
10
|
+
|
|
11
|
+
const latestVer = 15;
|
|
12
|
+
function improveSyntaxError(err, code) {
|
|
13
|
+
if (typeof err.pos !== "number" || !err.message.startsWith("Unexpected token")) return err;
|
|
14
|
+
const pos = err.pos;
|
|
15
|
+
const ch = pos < code.length ? code[pos] : void 0;
|
|
16
|
+
let ident = null;
|
|
17
|
+
if (ch !== void 0 && /[a-zA-Z_$]/.test(ch)) {
|
|
18
|
+
const m = code.slice(pos).match(/^[a-zA-Z_$][a-zA-Z0-9_$]*/);
|
|
19
|
+
if (m) ident = m[0];
|
|
20
|
+
} else if (ch === void 0 || ch === "(") {
|
|
21
|
+
let end = pos;
|
|
22
|
+
while (end > 0 && /\s/.test(code[end - 1])) end--;
|
|
23
|
+
if (end > 0 && /[a-zA-Z0-9_$]/.test(code[end - 1])) {
|
|
24
|
+
let start = end;
|
|
25
|
+
while (start > 0 && /[a-zA-Z0-9_$]/.test(code[start - 1])) start--;
|
|
26
|
+
const candidate = code.slice(start, end);
|
|
27
|
+
if (/^[a-zA-Z_$]/.test(candidate)) ident = candidate;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (ident) return new SyntaxError(`Unexpected identifier '${ident}'`);
|
|
31
|
+
return err;
|
|
32
|
+
}
|
|
33
|
+
class Sval {
|
|
34
|
+
options = { ecmaVersion: "latest" };
|
|
35
|
+
scope = new Scope(null, true, this);
|
|
36
|
+
exports = {};
|
|
37
|
+
constructor(options = {}) {
|
|
38
|
+
let { ecmaVer = "latest", sandBox = true, sourceType = "script" } = options;
|
|
39
|
+
if (typeof ecmaVer === "number") {
|
|
40
|
+
ecmaVer -= ecmaVer < 2015 ? 0 : 2009;
|
|
41
|
+
}
|
|
42
|
+
if (ecmaVer !== "latest" && ecmaVer !== 3 && (ecmaVer < 5 || ecmaVer > latestVer)) {
|
|
43
|
+
throw new Error(`unsupported ecmaVer`);
|
|
44
|
+
}
|
|
45
|
+
this.options.ecmaVersion = ecmaVer;
|
|
46
|
+
this.options.sourceType = sourceType;
|
|
47
|
+
this.options.ranges = true;
|
|
48
|
+
this.options.locations = true;
|
|
49
|
+
this.options.preserveParens = false;
|
|
50
|
+
if (sandBox) {
|
|
51
|
+
const win = createSandBox();
|
|
52
|
+
this.scope.let("globalThis", win);
|
|
53
|
+
this.scope.let("window", win);
|
|
54
|
+
this.scope.let("self", win);
|
|
55
|
+
this.scope.let("this", sourceType === "module" ? void 0 : win);
|
|
56
|
+
} else {
|
|
57
|
+
this.scope.let("globalThis", globalObj);
|
|
58
|
+
this.scope.let("window", globalObj);
|
|
59
|
+
this.scope.let("self", globalObj);
|
|
60
|
+
this.scope.let("this", sourceType === "module" ? void 0 : globalObj);
|
|
61
|
+
}
|
|
62
|
+
this.scope.const(sourceType === "module" ? EXPORTS : "exports", this.exports = {});
|
|
63
|
+
if (sourceType === "module") {
|
|
64
|
+
this.scope.const(STRICT, true);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
import(nameOrModules, mod) {
|
|
68
|
+
if (typeof nameOrModules === "string") {
|
|
69
|
+
nameOrModules = { [nameOrModules]: mod };
|
|
70
|
+
}
|
|
71
|
+
if (typeof nameOrModules !== "object") return;
|
|
72
|
+
const names = getOwnNames(nameOrModules);
|
|
73
|
+
for (let i = 0; i < names.length; i++) {
|
|
74
|
+
const name = names[i];
|
|
75
|
+
const modName = this.options.sourceType === "module" ? IMPORT + name : name;
|
|
76
|
+
this.scope.var(modName, nameOrModules[name]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
parse(code, parser) {
|
|
80
|
+
if (typeof parser === "function") {
|
|
81
|
+
return parser(code, this.options);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
return parse(code, this.options);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
throw improveSyntaxError(err, code);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
run(code) {
|
|
90
|
+
const ast = typeof code === "string" ? this.parse(code) : code;
|
|
91
|
+
const scope = this.scope;
|
|
92
|
+
if (this.options.sourceType === "module" && (this.options.ecmaVersion === "latest" || this.options.ecmaVersion >= 13)) {
|
|
93
|
+
runAsync((function* () {
|
|
94
|
+
yield* hoist(ast, scope);
|
|
95
|
+
yield* evaluate(ast, scope);
|
|
96
|
+
})());
|
|
97
|
+
} else {
|
|
98
|
+
hoist$1(ast, scope);
|
|
99
|
+
evaluate$1(ast, scope);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { Sval as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typescript-guy/fn-monitor",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "An augmentation of the sval JS-in-JS interpreter to monitor functions as they execute.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/**/*.js",
|
|
10
|
+
"dist/**/*.d.ts",
|
|
11
|
+
"ACKNOWLEDGEMENTS.md"
|
|
12
|
+
],
|
|
13
|
+
"author": "typescript-guy",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/The-BigMan-tech/fn-monitor.git"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"javascript",
|
|
21
|
+
"typescript",
|
|
22
|
+
"function",
|
|
23
|
+
"monitor",
|
|
24
|
+
"interpreter"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"start": "vite",
|
|
28
|
+
"build": "vite build",
|
|
29
|
+
"test": "vitest run --coverage",
|
|
30
|
+
"publish:public": "npm publish --registry=https://registry.npmjs.org/ --access public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@types/estree": "^1.0.8",
|
|
34
|
+
"acorn": "^8.14.0",
|
|
35
|
+
"ansis": "^4.3.1",
|
|
36
|
+
"js-beautify": "^1.15.4",
|
|
37
|
+
"js-sha256": "^0.11.1",
|
|
38
|
+
"lru-cache": "^11.3.5",
|
|
39
|
+
"meriyah": "^7.1.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@swc/core": "^1.11.24",
|
|
43
|
+
"@types/js-beautify": "^1.14.3",
|
|
44
|
+
"@types/node": "^22.15.3",
|
|
45
|
+
"@vitest/coverage-v8": "^3.1.2",
|
|
46
|
+
"happy-dom": "^20.0.11",
|
|
47
|
+
"rollup": "^4.62.2",
|
|
48
|
+
"rollup-plugin-dts": "^6.4.1",
|
|
49
|
+
"tsx": "^4.23.1",
|
|
50
|
+
"vite": "^6.3.4",
|
|
51
|
+
"vite-plugin-dts": "^4.5.3",
|
|
52
|
+
"vitest": "^3.1.2"
|
|
53
|
+
}
|
|
54
|
+
}
|