sval 0.6.2 → 0.6.4
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/.github/workflows/coverage.yml +1 -1
- package/.swcrc +6 -0
- package/dist/src/evaluate/declaration.d.ts +27 -0
- package/dist/src/evaluate/expression.d.ts +40 -0
- package/dist/src/evaluate/helper.d.ts +18 -0
- package/dist/src/evaluate/identifier.d.ts +7 -0
- package/dist/src/evaluate/index.d.ts +3 -0
- package/dist/src/evaluate/literal.d.ts +3 -0
- package/dist/src/evaluate/pattern.d.ts +13 -0
- package/dist/src/evaluate/program.d.ts +3 -0
- package/dist/src/evaluate/statement.d.ts +35 -0
- package/dist/src/evaluate_n/declaration.d.ts +27 -0
- package/dist/src/evaluate_n/expression.d.ts +38 -0
- package/dist/src/evaluate_n/helper.d.ts +18 -0
- package/dist/src/evaluate_n/identifier.d.ts +7 -0
- package/dist/src/evaluate_n/index.d.ts +3 -0
- package/dist/src/evaluate_n/literal.d.ts +3 -0
- package/dist/src/evaluate_n/pattern.d.ts +13 -0
- package/dist/src/evaluate_n/program.d.ts +3 -0
- package/dist/src/evaluate_n/statement.d.ts +35 -0
- package/{types → dist/src}/index.d.ts +17 -17
- package/dist/src/scope/index.d.ts +15 -0
- package/dist/src/scope/variable.d.ts +20 -0
- package/dist/src/share/async.d.ts +7 -0
- package/dist/src/share/const.d.ts +22 -0
- package/dist/src/share/util.d.ts +33 -0
- package/dist/sval.js +5956 -5171
- package/dist/sval.min.js +1 -1
- package/dist/sval.umd.cjs +9 -0
- package/index.html +32 -0
- package/package.json +21 -16
- package/vite.config.ts +20 -0
- package/dist/sval.es6.js +0 -4059
package/dist/sval.es6.js
DELETED
|
@@ -1,4059 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('acorn')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['acorn'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Sval = factory(global.acorn));
|
|
5
|
-
})(this, (function (acorn) { 'use strict';
|
|
6
|
-
|
|
7
|
-
var statement$1 = /*#__PURE__*/Object.freeze({
|
|
8
|
-
__proto__: null,
|
|
9
|
-
get ExpressionStatement () { return ExpressionStatement$1; },
|
|
10
|
-
get BlockStatement () { return BlockStatement$1; },
|
|
11
|
-
get EmptyStatement () { return EmptyStatement$1; },
|
|
12
|
-
get DebuggerStatement () { return DebuggerStatement$1; },
|
|
13
|
-
get ReturnStatement () { return ReturnStatement$1; },
|
|
14
|
-
get BreakStatement () { return BreakStatement$1; },
|
|
15
|
-
get ContinueStatement () { return ContinueStatement$1; },
|
|
16
|
-
get LabeledStatement () { return LabeledStatement$1; },
|
|
17
|
-
get WithStatement () { return WithStatement$1; },
|
|
18
|
-
get IfStatement () { return IfStatement$1; },
|
|
19
|
-
get SwitchStatement () { return SwitchStatement$1; },
|
|
20
|
-
get SwitchCase () { return SwitchCase$1; },
|
|
21
|
-
get ThrowStatement () { return ThrowStatement$1; },
|
|
22
|
-
get TryStatement () { return TryStatement$1; },
|
|
23
|
-
get CatchClause () { return CatchClause$1; },
|
|
24
|
-
get WhileStatement () { return WhileStatement$1; },
|
|
25
|
-
get DoWhileStatement () { return DoWhileStatement$1; },
|
|
26
|
-
get ForStatement () { return ForStatement$1; },
|
|
27
|
-
get ForInStatement () { return ForInStatement$1; },
|
|
28
|
-
get ForOfStatement () { return ForOfStatement$1; }
|
|
29
|
-
});
|
|
30
|
-
var declaration$1 = /*#__PURE__*/Object.freeze({
|
|
31
|
-
__proto__: null,
|
|
32
|
-
get FunctionDeclaration () { return FunctionDeclaration$1; },
|
|
33
|
-
get VariableDeclaration () { return VariableDeclaration$1; },
|
|
34
|
-
get VariableDeclarator () { return VariableDeclarator$1; },
|
|
35
|
-
get ClassDeclaration () { return ClassDeclaration$1; },
|
|
36
|
-
get ClassBody () { return ClassBody$1; },
|
|
37
|
-
get MethodDefinition () { return MethodDefinition$1; },
|
|
38
|
-
get PropertyDefinition () { return PropertyDefinition$1; },
|
|
39
|
-
get StaticBlock () { return StaticBlock$1; },
|
|
40
|
-
get ImportDeclaration () { return ImportDeclaration$1; },
|
|
41
|
-
get ExportDefaultDeclaration () { return ExportDefaultDeclaration$1; },
|
|
42
|
-
get ExportNamedDeclaration () { return ExportNamedDeclaration$1; },
|
|
43
|
-
get ExportAllDeclaration () { return ExportAllDeclaration$1; }
|
|
44
|
-
});
|
|
45
|
-
var statement = /*#__PURE__*/Object.freeze({
|
|
46
|
-
__proto__: null,
|
|
47
|
-
get ExpressionStatement () { return ExpressionStatement; },
|
|
48
|
-
get BlockStatement () { return BlockStatement; },
|
|
49
|
-
get EmptyStatement () { return EmptyStatement; },
|
|
50
|
-
get DebuggerStatement () { return DebuggerStatement; },
|
|
51
|
-
get ReturnStatement () { return ReturnStatement; },
|
|
52
|
-
get BreakStatement () { return BreakStatement; },
|
|
53
|
-
get ContinueStatement () { return ContinueStatement; },
|
|
54
|
-
get LabeledStatement () { return LabeledStatement; },
|
|
55
|
-
get WithStatement () { return WithStatement; },
|
|
56
|
-
get IfStatement () { return IfStatement; },
|
|
57
|
-
get SwitchStatement () { return SwitchStatement; },
|
|
58
|
-
get SwitchCase () { return SwitchCase; },
|
|
59
|
-
get ThrowStatement () { return ThrowStatement; },
|
|
60
|
-
get TryStatement () { return TryStatement; },
|
|
61
|
-
get CatchClause () { return CatchClause; },
|
|
62
|
-
get WhileStatement () { return WhileStatement; },
|
|
63
|
-
get DoWhileStatement () { return DoWhileStatement; },
|
|
64
|
-
get ForStatement () { return ForStatement; },
|
|
65
|
-
get ForInStatement () { return ForInStatement; },
|
|
66
|
-
get ForOfStatement () { return ForOfStatement; }
|
|
67
|
-
});
|
|
68
|
-
var declaration = /*#__PURE__*/Object.freeze({
|
|
69
|
-
__proto__: null,
|
|
70
|
-
get FunctionDeclaration () { return FunctionDeclaration; },
|
|
71
|
-
get VariableDeclaration () { return VariableDeclaration; },
|
|
72
|
-
get VariableDeclarator () { return VariableDeclarator; },
|
|
73
|
-
get ClassDeclaration () { return ClassDeclaration; },
|
|
74
|
-
get ClassBody () { return ClassBody; },
|
|
75
|
-
get MethodDefinition () { return MethodDefinition; },
|
|
76
|
-
get PropertyDefinition () { return PropertyDefinition; },
|
|
77
|
-
get StaticBlock () { return StaticBlock; },
|
|
78
|
-
get ImportDeclaration () { return ImportDeclaration; },
|
|
79
|
-
get ExportDefaultDeclaration () { return ExportDefaultDeclaration; },
|
|
80
|
-
get ExportNamedDeclaration () { return ExportNamedDeclaration; },
|
|
81
|
-
get ExportAllDeclaration () { return ExportAllDeclaration; }
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const freeze = Object.freeze;
|
|
85
|
-
const define = Object.defineProperty;
|
|
86
|
-
const getDptor = Object.getOwnPropertyDescriptor;
|
|
87
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
88
|
-
function hasOwn(obj, key) {
|
|
89
|
-
return hasOwnProperty.call(obj, key);
|
|
90
|
-
}
|
|
91
|
-
const getOwnNames = Object.getOwnPropertyNames;
|
|
92
|
-
const setPrototypeOf = Object.setPrototypeOf;
|
|
93
|
-
function setProto(obj, proto) {
|
|
94
|
-
setPrototypeOf ? setPrototypeOf(obj, proto) : obj.__proto__ = proto;
|
|
95
|
-
}
|
|
96
|
-
const getPrototypeOf = Object.getPrototypeOf;
|
|
97
|
-
function getProto(obj) {
|
|
98
|
-
return getPrototypeOf ? getPrototypeOf(obj) : obj.__proto__;
|
|
99
|
-
}
|
|
100
|
-
const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
101
|
-
function getGetterOrSetter(method, obj, key) {
|
|
102
|
-
while (obj) {
|
|
103
|
-
const descriptor = getOwnPropertyDescriptor(obj, key);
|
|
104
|
-
const value = typeof descriptor !== 'undefined'
|
|
105
|
-
&& typeof descriptor.writable === 'undefined'
|
|
106
|
-
&& typeof descriptor[method] === 'function'
|
|
107
|
-
&& descriptor[method];
|
|
108
|
-
if (value) {
|
|
109
|
-
return value;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
obj = getProto(obj);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function getGetter(obj, key) {
|
|
117
|
-
return getGetterOrSetter('get', obj, key);
|
|
118
|
-
}
|
|
119
|
-
function getSetter(obj, key) {
|
|
120
|
-
return getGetterOrSetter('set', obj, key);
|
|
121
|
-
}
|
|
122
|
-
const create = Object.create;
|
|
123
|
-
function inherits(subClass, superClass) {
|
|
124
|
-
setProto(subClass, superClass);
|
|
125
|
-
subClass.prototype = create(superClass.prototype, {
|
|
126
|
-
constructor: {
|
|
127
|
-
value: subClass,
|
|
128
|
-
writable: true,
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
function callSuper(target, superClass, args = []) {
|
|
133
|
-
let supportReflect = false;
|
|
134
|
-
try {
|
|
135
|
-
supportReflect = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () { }));
|
|
136
|
-
}
|
|
137
|
-
catch (err) { }
|
|
138
|
-
return supportReflect
|
|
139
|
-
? Reflect.construct(superClass, args, getProto(target).constructor)
|
|
140
|
-
: superClass.apply(target, args);
|
|
141
|
-
}
|
|
142
|
-
function _assign(target) {
|
|
143
|
-
for (let i = 1; i < arguments.length; ++i) {
|
|
144
|
-
const source = arguments[i];
|
|
145
|
-
for (const key in source) {
|
|
146
|
-
if (hasOwn(source, key)) {
|
|
147
|
-
target[key] = source[key];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return target;
|
|
152
|
-
}
|
|
153
|
-
const assign = Object.assign || _assign;
|
|
154
|
-
let names = [];
|
|
155
|
-
let globalObj = create(null);
|
|
156
|
-
const setGlobalObj = (g) => {
|
|
157
|
-
if (!g.Object)
|
|
158
|
-
throw 0;
|
|
159
|
-
names = getOwnNames(globalObj = g).filter(n => ['webkitStorageInfo', 'GLOBAL', 'root'].indexOf(n) === -1);
|
|
160
|
-
};
|
|
161
|
-
try {
|
|
162
|
-
setGlobalObj(window);
|
|
163
|
-
}
|
|
164
|
-
catch (err) {
|
|
165
|
-
try {
|
|
166
|
-
setGlobalObj(self);
|
|
167
|
-
}
|
|
168
|
-
catch (err) {
|
|
169
|
-
try {
|
|
170
|
-
setGlobalObj(global);
|
|
171
|
-
}
|
|
172
|
-
catch (err) {
|
|
173
|
-
try {
|
|
174
|
-
setGlobalObj(globalThis);
|
|
175
|
-
}
|
|
176
|
-
catch (err) {
|
|
177
|
-
try {
|
|
178
|
-
globalObj.Object = Object;
|
|
179
|
-
}
|
|
180
|
-
catch (err) { }
|
|
181
|
-
try {
|
|
182
|
-
globalObj.Function = Function;
|
|
183
|
-
}
|
|
184
|
-
catch (err) { }
|
|
185
|
-
try {
|
|
186
|
-
globalObj.Array = Array;
|
|
187
|
-
}
|
|
188
|
-
catch (err) { }
|
|
189
|
-
try {
|
|
190
|
-
globalObj.Number = Number;
|
|
191
|
-
}
|
|
192
|
-
catch (err) { }
|
|
193
|
-
try {
|
|
194
|
-
globalObj.parseFloat = parseFloat;
|
|
195
|
-
}
|
|
196
|
-
catch (err) { }
|
|
197
|
-
try {
|
|
198
|
-
globalObj.parseInt = parseInt;
|
|
199
|
-
}
|
|
200
|
-
catch (err) { }
|
|
201
|
-
try {
|
|
202
|
-
globalObj.Infinity = Infinity;
|
|
203
|
-
}
|
|
204
|
-
catch (err) { }
|
|
205
|
-
try {
|
|
206
|
-
globalObj.NaN = NaN;
|
|
207
|
-
}
|
|
208
|
-
catch (err) { }
|
|
209
|
-
try {
|
|
210
|
-
globalObj.undefined = undefined;
|
|
211
|
-
}
|
|
212
|
-
catch (err) { }
|
|
213
|
-
try {
|
|
214
|
-
globalObj.Boolean = Boolean;
|
|
215
|
-
}
|
|
216
|
-
catch (err) { }
|
|
217
|
-
try {
|
|
218
|
-
globalObj.String = String;
|
|
219
|
-
}
|
|
220
|
-
catch (err) { }
|
|
221
|
-
try {
|
|
222
|
-
globalObj.Symbol = Symbol;
|
|
223
|
-
}
|
|
224
|
-
catch (err) { }
|
|
225
|
-
try {
|
|
226
|
-
globalObj.Date = Date;
|
|
227
|
-
}
|
|
228
|
-
catch (err) { }
|
|
229
|
-
try {
|
|
230
|
-
globalObj.Promise = Promise;
|
|
231
|
-
}
|
|
232
|
-
catch (err) { }
|
|
233
|
-
try {
|
|
234
|
-
globalObj.RegExp = RegExp;
|
|
235
|
-
}
|
|
236
|
-
catch (err) { }
|
|
237
|
-
try {
|
|
238
|
-
globalObj.Error = Error;
|
|
239
|
-
}
|
|
240
|
-
catch (err) { }
|
|
241
|
-
try {
|
|
242
|
-
globalObj.EvalError = EvalError;
|
|
243
|
-
}
|
|
244
|
-
catch (err) { }
|
|
245
|
-
try {
|
|
246
|
-
globalObj.RangeError = RangeError;
|
|
247
|
-
}
|
|
248
|
-
catch (err) { }
|
|
249
|
-
try {
|
|
250
|
-
globalObj.ReferenceError = ReferenceError;
|
|
251
|
-
}
|
|
252
|
-
catch (err) { }
|
|
253
|
-
try {
|
|
254
|
-
globalObj.SyntaxError = SyntaxError;
|
|
255
|
-
}
|
|
256
|
-
catch (err) { }
|
|
257
|
-
try {
|
|
258
|
-
globalObj.TypeError = TypeError;
|
|
259
|
-
}
|
|
260
|
-
catch (err) { }
|
|
261
|
-
try {
|
|
262
|
-
globalObj.URIError = URIError;
|
|
263
|
-
}
|
|
264
|
-
catch (err) { }
|
|
265
|
-
try {
|
|
266
|
-
globalObj.JSON = JSON;
|
|
267
|
-
}
|
|
268
|
-
catch (err) { }
|
|
269
|
-
try {
|
|
270
|
-
globalObj.Math = Math;
|
|
271
|
-
}
|
|
272
|
-
catch (err) { }
|
|
273
|
-
try {
|
|
274
|
-
globalObj.console = console;
|
|
275
|
-
}
|
|
276
|
-
catch (err) { }
|
|
277
|
-
try {
|
|
278
|
-
globalObj.Intl = Intl;
|
|
279
|
-
}
|
|
280
|
-
catch (err) { }
|
|
281
|
-
try {
|
|
282
|
-
globalObj.ArrayBuffer = ArrayBuffer;
|
|
283
|
-
}
|
|
284
|
-
catch (err) { }
|
|
285
|
-
try {
|
|
286
|
-
globalObj.Uint8Array = Uint8Array;
|
|
287
|
-
}
|
|
288
|
-
catch (err) { }
|
|
289
|
-
try {
|
|
290
|
-
globalObj.Int8Array = Int8Array;
|
|
291
|
-
}
|
|
292
|
-
catch (err) { }
|
|
293
|
-
try {
|
|
294
|
-
globalObj.Uint16Array = Uint16Array;
|
|
295
|
-
}
|
|
296
|
-
catch (err) { }
|
|
297
|
-
try {
|
|
298
|
-
globalObj.Int16Array = Int16Array;
|
|
299
|
-
}
|
|
300
|
-
catch (err) { }
|
|
301
|
-
try {
|
|
302
|
-
globalObj.Uint32Array = Uint32Array;
|
|
303
|
-
}
|
|
304
|
-
catch (err) { }
|
|
305
|
-
try {
|
|
306
|
-
globalObj.Int32Array = Int32Array;
|
|
307
|
-
}
|
|
308
|
-
catch (err) { }
|
|
309
|
-
try {
|
|
310
|
-
globalObj.Float32Array = Float32Array;
|
|
311
|
-
}
|
|
312
|
-
catch (err) { }
|
|
313
|
-
try {
|
|
314
|
-
globalObj.Float64Array = Float64Array;
|
|
315
|
-
}
|
|
316
|
-
catch (err) { }
|
|
317
|
-
try {
|
|
318
|
-
globalObj.Uint8ClampedArray = Uint8ClampedArray;
|
|
319
|
-
}
|
|
320
|
-
catch (err) { }
|
|
321
|
-
try {
|
|
322
|
-
globalObj.DataView = DataView;
|
|
323
|
-
}
|
|
324
|
-
catch (err) { }
|
|
325
|
-
try {
|
|
326
|
-
globalObj.Map = Map;
|
|
327
|
-
}
|
|
328
|
-
catch (err) { }
|
|
329
|
-
try {
|
|
330
|
-
globalObj.Set = Set;
|
|
331
|
-
}
|
|
332
|
-
catch (err) { }
|
|
333
|
-
try {
|
|
334
|
-
globalObj.WeakMap = WeakMap;
|
|
335
|
-
}
|
|
336
|
-
catch (err) { }
|
|
337
|
-
try {
|
|
338
|
-
globalObj.WeakSet = WeakSet;
|
|
339
|
-
}
|
|
340
|
-
catch (err) { }
|
|
341
|
-
try {
|
|
342
|
-
globalObj.Proxy = Proxy;
|
|
343
|
-
}
|
|
344
|
-
catch (err) { }
|
|
345
|
-
try {
|
|
346
|
-
globalObj.Reflect = Reflect;
|
|
347
|
-
}
|
|
348
|
-
catch (err) { }
|
|
349
|
-
try {
|
|
350
|
-
globalObj.BigInt = BigInt;
|
|
351
|
-
}
|
|
352
|
-
catch (err) { }
|
|
353
|
-
try {
|
|
354
|
-
globalObj.decodeURI = decodeURI;
|
|
355
|
-
}
|
|
356
|
-
catch (err) { }
|
|
357
|
-
try {
|
|
358
|
-
globalObj.decodeURIComponent = decodeURIComponent;
|
|
359
|
-
}
|
|
360
|
-
catch (err) { }
|
|
361
|
-
try {
|
|
362
|
-
globalObj.encodeURI = encodeURI;
|
|
363
|
-
}
|
|
364
|
-
catch (err) { }
|
|
365
|
-
try {
|
|
366
|
-
globalObj.encodeURIComponent = encodeURIComponent;
|
|
367
|
-
}
|
|
368
|
-
catch (err) { }
|
|
369
|
-
try {
|
|
370
|
-
globalObj.escape = escape;
|
|
371
|
-
}
|
|
372
|
-
catch (err) { }
|
|
373
|
-
try {
|
|
374
|
-
globalObj.unescape = unescape;
|
|
375
|
-
}
|
|
376
|
-
catch (err) { }
|
|
377
|
-
try {
|
|
378
|
-
globalObj.eval = eval;
|
|
379
|
-
}
|
|
380
|
-
catch (err) { }
|
|
381
|
-
try {
|
|
382
|
-
globalObj.isFinite = isFinite;
|
|
383
|
-
}
|
|
384
|
-
catch (err) { }
|
|
385
|
-
try {
|
|
386
|
-
globalObj.isNaN = isNaN;
|
|
387
|
-
}
|
|
388
|
-
catch (err) { }
|
|
389
|
-
try {
|
|
390
|
-
globalObj.SharedArrayBuffer = SharedArrayBuffer;
|
|
391
|
-
}
|
|
392
|
-
catch (err) { }
|
|
393
|
-
try {
|
|
394
|
-
globalObj.Atomics = Atomics;
|
|
395
|
-
}
|
|
396
|
-
catch (err) { }
|
|
397
|
-
try {
|
|
398
|
-
globalObj.WebAssembly = WebAssembly;
|
|
399
|
-
}
|
|
400
|
-
catch (err) { }
|
|
401
|
-
try {
|
|
402
|
-
globalObj.clearInterval = clearInterval;
|
|
403
|
-
}
|
|
404
|
-
catch (err) { }
|
|
405
|
-
try {
|
|
406
|
-
globalObj.clearTimeout = clearTimeout;
|
|
407
|
-
}
|
|
408
|
-
catch (err) { }
|
|
409
|
-
try {
|
|
410
|
-
globalObj.setInterval = setInterval;
|
|
411
|
-
}
|
|
412
|
-
catch (err) { }
|
|
413
|
-
try {
|
|
414
|
-
globalObj.setTimeout = setTimeout;
|
|
415
|
-
}
|
|
416
|
-
catch (err) { }
|
|
417
|
-
try {
|
|
418
|
-
globalObj.crypto = crypto;
|
|
419
|
-
}
|
|
420
|
-
catch (err) { }
|
|
421
|
-
try {
|
|
422
|
-
globalObj.URL = URL;
|
|
423
|
-
}
|
|
424
|
-
catch (err) { }
|
|
425
|
-
names = getOwnNames(globalObj);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
if (globalObj.Symbol) {
|
|
431
|
-
!globalObj.Symbol.iterator && (globalObj.Symbol.iterator = createSymbol('iterator'));
|
|
432
|
-
!globalObj.Symbol.asyncIterator && (globalObj.Symbol.asyncIterator = createSymbol('asynciterator'));
|
|
433
|
-
}
|
|
434
|
-
const win = create({});
|
|
435
|
-
for (let i = 0; i < names.length; i++) {
|
|
436
|
-
const name = names[i];
|
|
437
|
-
try {
|
|
438
|
-
win[name] = globalObj[name];
|
|
439
|
-
}
|
|
440
|
-
catch (err) { }
|
|
441
|
-
}
|
|
442
|
-
const WINDOW = createSymbol('window');
|
|
443
|
-
function createSandBox() {
|
|
444
|
-
return assign(create({ [WINDOW]: globalObj }), win);
|
|
445
|
-
}
|
|
446
|
-
function createSymbol(key) {
|
|
447
|
-
return key + Math.random().toString(36).substring(2);
|
|
448
|
-
}
|
|
449
|
-
function getAsyncIterator(obj) {
|
|
450
|
-
let iterator;
|
|
451
|
-
if (typeof Symbol === 'function') {
|
|
452
|
-
iterator = obj[Symbol.asyncIterator];
|
|
453
|
-
!iterator && (iterator = obj[Symbol.iterator]);
|
|
454
|
-
}
|
|
455
|
-
if (iterator) {
|
|
456
|
-
return iterator.call(obj);
|
|
457
|
-
}
|
|
458
|
-
else if (typeof obj.next === 'function') {
|
|
459
|
-
return obj;
|
|
460
|
-
}
|
|
461
|
-
else {
|
|
462
|
-
let i = 0;
|
|
463
|
-
return {
|
|
464
|
-
next() {
|
|
465
|
-
if (obj && i >= obj.length)
|
|
466
|
-
obj = undefined;
|
|
467
|
-
return { value: obj && obj[i++], done: !obj };
|
|
468
|
-
}
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
const AWAIT = { RES: undefined };
|
|
474
|
-
const RETURN = { RES: undefined };
|
|
475
|
-
const CONTINUE = { LABEL: undefined };
|
|
476
|
-
const BREAK = { LABEL: undefined };
|
|
477
|
-
const SUPER = createSymbol('super');
|
|
478
|
-
const SUPERCALL = createSymbol('supercall');
|
|
479
|
-
const NOCTOR = createSymbol('noctor');
|
|
480
|
-
const CLSCTOR = createSymbol('clsctor');
|
|
481
|
-
const NEWTARGET = createSymbol('newtarget');
|
|
482
|
-
const PRIVATE = createSymbol('private');
|
|
483
|
-
const NOINIT = createSymbol('noinit');
|
|
484
|
-
const DEADZONE = createSymbol('deadzone');
|
|
485
|
-
const IMPORT = createSymbol('import');
|
|
486
|
-
const EXPORTS = createSymbol('exports');
|
|
487
|
-
|
|
488
|
-
var version = "0.6.1";
|
|
489
|
-
|
|
490
|
-
class Var {
|
|
491
|
-
constructor(kind, value) {
|
|
492
|
-
this.kind = kind;
|
|
493
|
-
this.value = value;
|
|
494
|
-
}
|
|
495
|
-
get() {
|
|
496
|
-
return this.value;
|
|
497
|
-
}
|
|
498
|
-
set(value) {
|
|
499
|
-
if (this.kind === 'const') {
|
|
500
|
-
throw new TypeError('Assignment to constant variable');
|
|
501
|
-
}
|
|
502
|
-
else {
|
|
503
|
-
return this.value = value;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
class Prop {
|
|
508
|
-
constructor(object, property) {
|
|
509
|
-
this.object = object;
|
|
510
|
-
this.property = property;
|
|
511
|
-
}
|
|
512
|
-
get() {
|
|
513
|
-
return this.object[this.property];
|
|
514
|
-
}
|
|
515
|
-
set(value) {
|
|
516
|
-
this.object[this.property] = value;
|
|
517
|
-
return true;
|
|
518
|
-
}
|
|
519
|
-
del() {
|
|
520
|
-
return delete this.object[this.property];
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
class Scope {
|
|
525
|
-
constructor(parent = null, isolated = false) {
|
|
526
|
-
this.context = create(null);
|
|
527
|
-
this.withContext = create(null);
|
|
528
|
-
this.parent = parent;
|
|
529
|
-
this.isolated = isolated;
|
|
530
|
-
}
|
|
531
|
-
global() {
|
|
532
|
-
let scope = this;
|
|
533
|
-
while (scope.parent) {
|
|
534
|
-
scope = scope.parent;
|
|
535
|
-
}
|
|
536
|
-
return scope;
|
|
537
|
-
}
|
|
538
|
-
find(name) {
|
|
539
|
-
if (this.context[name]) {
|
|
540
|
-
return this.context[name];
|
|
541
|
-
}
|
|
542
|
-
else if (name in this.withContext) {
|
|
543
|
-
return new Prop(this.withContext, name);
|
|
544
|
-
}
|
|
545
|
-
else if (this.parent) {
|
|
546
|
-
return this.parent.find(name);
|
|
547
|
-
}
|
|
548
|
-
else {
|
|
549
|
-
const win = this.global().find('window').get();
|
|
550
|
-
if (name in win) {
|
|
551
|
-
return new Prop(win, name);
|
|
552
|
-
}
|
|
553
|
-
else {
|
|
554
|
-
return null;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
var(name, value) {
|
|
559
|
-
let scope = this;
|
|
560
|
-
while (scope.parent && !scope.isolated) {
|
|
561
|
-
scope = scope.parent;
|
|
562
|
-
}
|
|
563
|
-
const variable = scope.context[name];
|
|
564
|
-
if (!variable) {
|
|
565
|
-
scope.context[name] = new Var('var', value === NOINIT ? undefined : value);
|
|
566
|
-
}
|
|
567
|
-
else {
|
|
568
|
-
if (variable.kind === 'var') {
|
|
569
|
-
if (value !== NOINIT) {
|
|
570
|
-
variable.set(value);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
else {
|
|
574
|
-
throw new SyntaxError(`Identifier '${name}' has already been declared`);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
if (!scope.parent) {
|
|
578
|
-
const win = scope.find('window').get();
|
|
579
|
-
if (value !== NOINIT) {
|
|
580
|
-
define(win, name, { value, writable: true, enumerable: true });
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
let(name, value) {
|
|
585
|
-
const variable = this.context[name];
|
|
586
|
-
if (!variable || variable.get() === DEADZONE) {
|
|
587
|
-
this.context[name] = new Var('let', value);
|
|
588
|
-
}
|
|
589
|
-
else {
|
|
590
|
-
throw new SyntaxError(`Identifier '${name}' has already been declared`);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
const(name, value) {
|
|
594
|
-
const variable = this.context[name];
|
|
595
|
-
if (!variable || variable.get() === DEADZONE) {
|
|
596
|
-
this.context[name] = new Var('const', value);
|
|
597
|
-
}
|
|
598
|
-
else {
|
|
599
|
-
throw new SyntaxError(`Identifier '${name}' has already been declared`);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
func(name, value) {
|
|
603
|
-
const variable = this.context[name];
|
|
604
|
-
if (!variable || variable.kind === 'var') {
|
|
605
|
-
this.context[name] = new Var('var', value);
|
|
606
|
-
}
|
|
607
|
-
else {
|
|
608
|
-
throw new SyntaxError(`Identifier '${name}' has already been declared`);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
with(value) {
|
|
612
|
-
if (Object.keys(value)) {
|
|
613
|
-
this.withContext = value;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
function runAsync(iterator, options = {}) {
|
|
619
|
-
const { res, err, ret, fullRet } = options;
|
|
620
|
-
return new Promise((resolve, reject) => {
|
|
621
|
-
if ('ret' in options) {
|
|
622
|
-
return resolve(iterator.return(ret));
|
|
623
|
-
}
|
|
624
|
-
if ('err' in options) {
|
|
625
|
-
onRejected(err);
|
|
626
|
-
}
|
|
627
|
-
else {
|
|
628
|
-
onFulfilled(res);
|
|
629
|
-
}
|
|
630
|
-
function onFulfilled(res) {
|
|
631
|
-
let ret;
|
|
632
|
-
try {
|
|
633
|
-
ret = iterator.next(res);
|
|
634
|
-
}
|
|
635
|
-
catch (e) {
|
|
636
|
-
return reject(e);
|
|
637
|
-
}
|
|
638
|
-
next(ret);
|
|
639
|
-
return null;
|
|
640
|
-
}
|
|
641
|
-
function onRejected(err) {
|
|
642
|
-
let ret;
|
|
643
|
-
try {
|
|
644
|
-
ret = iterator.throw(err);
|
|
645
|
-
}
|
|
646
|
-
catch (e) {
|
|
647
|
-
return reject(e);
|
|
648
|
-
}
|
|
649
|
-
next(ret);
|
|
650
|
-
}
|
|
651
|
-
function next(ret) {
|
|
652
|
-
if (ret.done)
|
|
653
|
-
return resolve(fullRet ? ret : ret.value);
|
|
654
|
-
if (ret.value !== AWAIT)
|
|
655
|
-
return resolve(ret);
|
|
656
|
-
const awaitValue = ret.value.RES;
|
|
657
|
-
const value = awaitValue && awaitValue.then === 'function'
|
|
658
|
-
? awaitValue : Promise.resolve(awaitValue);
|
|
659
|
-
return value.then(onFulfilled, onRejected);
|
|
660
|
-
}
|
|
661
|
-
});
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
function* Identifier$1(node, scope, options = {}) {
|
|
665
|
-
const { getVar = false, throwErr = true } = options;
|
|
666
|
-
if (node.name === 'undefined') {
|
|
667
|
-
return undefined;
|
|
668
|
-
}
|
|
669
|
-
const variable = scope.find(node.name);
|
|
670
|
-
if (variable) {
|
|
671
|
-
if (getVar) {
|
|
672
|
-
return variable;
|
|
673
|
-
}
|
|
674
|
-
else {
|
|
675
|
-
const value = variable.get();
|
|
676
|
-
if (value === DEADZONE) {
|
|
677
|
-
throw new ReferenceError(`${node.name} is not defined`);
|
|
678
|
-
}
|
|
679
|
-
else {
|
|
680
|
-
return value;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
else if (throwErr) {
|
|
685
|
-
throw new ReferenceError(`${node.name} is not defined`);
|
|
686
|
-
}
|
|
687
|
-
else {
|
|
688
|
-
return undefined;
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
var identifier$1 = /*#__PURE__*/Object.freeze({
|
|
693
|
-
__proto__: null,
|
|
694
|
-
Identifier: Identifier$1
|
|
695
|
-
});
|
|
696
|
-
|
|
697
|
-
function* Literal$1(node, scope) {
|
|
698
|
-
return node.value;
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
var literal$1 = /*#__PURE__*/Object.freeze({
|
|
702
|
-
__proto__: null,
|
|
703
|
-
Literal: Literal$1
|
|
704
|
-
});
|
|
705
|
-
|
|
706
|
-
function* ThisExpression$1(node, scope) {
|
|
707
|
-
const superCall = scope.find(SUPERCALL);
|
|
708
|
-
if (superCall && superCall.get() !== true) {
|
|
709
|
-
throw new ReferenceError('Must call super constructor in derived class '
|
|
710
|
-
+ 'before accessing \'this\' or returning from derived constructor');
|
|
711
|
-
}
|
|
712
|
-
else {
|
|
713
|
-
return scope.find('this').get();
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
function* ArrayExpression$1(node, scope) {
|
|
717
|
-
let results = [];
|
|
718
|
-
for (let i = 0; i < node.elements.length; i++) {
|
|
719
|
-
const item = node.elements[i];
|
|
720
|
-
if (item.type === 'SpreadElement') {
|
|
721
|
-
results = results.concat(yield* SpreadElement$1(item, scope));
|
|
722
|
-
}
|
|
723
|
-
else {
|
|
724
|
-
results.push(yield* evaluate$1(item, scope));
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
return results;
|
|
728
|
-
}
|
|
729
|
-
function* ObjectExpression$1(node, scope) {
|
|
730
|
-
const object = {};
|
|
731
|
-
for (let i = 0; i < node.properties.length; i++) {
|
|
732
|
-
const property = node.properties[i];
|
|
733
|
-
if (property.type === 'SpreadElement') {
|
|
734
|
-
assign(object, yield* SpreadElement$1(property, scope, { spreadProps: true }));
|
|
735
|
-
}
|
|
736
|
-
else {
|
|
737
|
-
let key;
|
|
738
|
-
const propKey = property.key;
|
|
739
|
-
if (property.computed) {
|
|
740
|
-
key = yield* evaluate$1(propKey, scope);
|
|
741
|
-
}
|
|
742
|
-
else {
|
|
743
|
-
if (propKey.type === 'Identifier') {
|
|
744
|
-
key = propKey.name;
|
|
745
|
-
}
|
|
746
|
-
else {
|
|
747
|
-
key = '' + (yield* Literal$1(propKey));
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
const value = yield* evaluate$1(property.value, scope);
|
|
751
|
-
const propKind = property.kind;
|
|
752
|
-
if (propKind === 'init') {
|
|
753
|
-
object[key] = value;
|
|
754
|
-
}
|
|
755
|
-
else if (propKind === 'get') {
|
|
756
|
-
const oriDptor = getDptor(object, key);
|
|
757
|
-
define(object, key, {
|
|
758
|
-
get: value,
|
|
759
|
-
set: oriDptor && oriDptor.set,
|
|
760
|
-
enumerable: true,
|
|
761
|
-
configurable: true
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
|
-
else {
|
|
765
|
-
const oriDptor = getDptor(object, key);
|
|
766
|
-
define(object, key, {
|
|
767
|
-
get: oriDptor && oriDptor.get,
|
|
768
|
-
set: value,
|
|
769
|
-
enumerable: true,
|
|
770
|
-
configurable: true
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
return object;
|
|
776
|
-
}
|
|
777
|
-
function* FunctionExpression$1(node, scope) {
|
|
778
|
-
if (node.id && node.id.name) {
|
|
779
|
-
const tmpScope = new Scope(scope);
|
|
780
|
-
const func = createFunc(node, tmpScope);
|
|
781
|
-
tmpScope.const(node.id.name, func);
|
|
782
|
-
return func;
|
|
783
|
-
}
|
|
784
|
-
else {
|
|
785
|
-
return createFunc(node, scope);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
function* UnaryExpression$1(node, scope) {
|
|
789
|
-
const arg = node.argument;
|
|
790
|
-
switch (node.operator) {
|
|
791
|
-
case '+': return +(yield* evaluate$1(arg, scope));
|
|
792
|
-
case '-': return -(yield* evaluate$1(arg, scope));
|
|
793
|
-
case '!': return !(yield* evaluate$1(arg, scope));
|
|
794
|
-
case '~': return ~(yield* evaluate$1(arg, scope));
|
|
795
|
-
case 'void': return void (yield* evaluate$1(arg, scope));
|
|
796
|
-
case 'typeof':
|
|
797
|
-
if (arg.type === 'Identifier') {
|
|
798
|
-
return typeof (yield* Identifier$1(arg, scope, { throwErr: false }));
|
|
799
|
-
}
|
|
800
|
-
else {
|
|
801
|
-
return typeof (yield* evaluate$1(arg, scope));
|
|
802
|
-
}
|
|
803
|
-
case 'delete':
|
|
804
|
-
if (arg.type === 'MemberExpression') {
|
|
805
|
-
const variable = yield* MemberExpression$1(arg, scope, { getVar: true });
|
|
806
|
-
return variable.del();
|
|
807
|
-
}
|
|
808
|
-
else if (arg.type === 'Identifier') {
|
|
809
|
-
throw new SyntaxError('Delete of an unqualified identifier in strict mode');
|
|
810
|
-
}
|
|
811
|
-
else {
|
|
812
|
-
yield* evaluate$1(arg, scope);
|
|
813
|
-
return true;
|
|
814
|
-
}
|
|
815
|
-
default: throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
function* UpdateExpression$1(node, scope) {
|
|
819
|
-
const arg = node.argument;
|
|
820
|
-
let variable;
|
|
821
|
-
if (arg.type === 'Identifier') {
|
|
822
|
-
variable = yield* Identifier$1(arg, scope, { getVar: true });
|
|
823
|
-
}
|
|
824
|
-
else if (arg.type === 'MemberExpression') {
|
|
825
|
-
variable = yield* MemberExpression$1(arg, scope, { getVar: true });
|
|
826
|
-
}
|
|
827
|
-
else {
|
|
828
|
-
throw new SyntaxError('Unexpected token');
|
|
829
|
-
}
|
|
830
|
-
const value = variable.get();
|
|
831
|
-
if (node.operator === '++') {
|
|
832
|
-
variable.set(value + 1);
|
|
833
|
-
return node.prefix ? variable.get() : value;
|
|
834
|
-
}
|
|
835
|
-
else if (node.operator === '--') {
|
|
836
|
-
variable.set(value - 1);
|
|
837
|
-
return node.prefix ? variable.get() : value;
|
|
838
|
-
}
|
|
839
|
-
else {
|
|
840
|
-
throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
function* BinaryExpression$1(node, scope) {
|
|
844
|
-
let left;
|
|
845
|
-
let right;
|
|
846
|
-
if (node.left.type === 'PrivateIdentifier') {
|
|
847
|
-
left = node.left.name;
|
|
848
|
-
right = yield* evaluate$1(node.right, scope);
|
|
849
|
-
right = right[PRIVATE] || {};
|
|
850
|
-
}
|
|
851
|
-
else {
|
|
852
|
-
left = yield* evaluate$1(node.left, scope);
|
|
853
|
-
right = yield* evaluate$1(node.right, scope);
|
|
854
|
-
}
|
|
855
|
-
switch (node.operator) {
|
|
856
|
-
case '==': return left == right;
|
|
857
|
-
case '!=': return left != right;
|
|
858
|
-
case '===': return left === right;
|
|
859
|
-
case '!==': return left !== right;
|
|
860
|
-
case '<': return left < right;
|
|
861
|
-
case '<=': return left <= right;
|
|
862
|
-
case '>': return left > right;
|
|
863
|
-
case '>=': return left >= right;
|
|
864
|
-
case '<<': return left << right;
|
|
865
|
-
case '>>': return left >> right;
|
|
866
|
-
case '>>>': return left >>> right;
|
|
867
|
-
case '+': return left + right;
|
|
868
|
-
case '-': return left - right;
|
|
869
|
-
case '*': return left * right;
|
|
870
|
-
case '**': return Math.pow(left, right);
|
|
871
|
-
case '/': return left / right;
|
|
872
|
-
case '%': return left % right;
|
|
873
|
-
case '|': return left | right;
|
|
874
|
-
case '^': return left ^ right;
|
|
875
|
-
case '&': return left & right;
|
|
876
|
-
case 'in': return left in right;
|
|
877
|
-
case 'instanceof': return left instanceof right;
|
|
878
|
-
default: throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
function* AssignmentExpression$1(node, scope) {
|
|
882
|
-
var _a;
|
|
883
|
-
const left = node.left;
|
|
884
|
-
let variable;
|
|
885
|
-
if (left.type === 'Identifier') {
|
|
886
|
-
variable = yield* Identifier$1(left, scope, { getVar: true, throwErr: false });
|
|
887
|
-
if (!variable) {
|
|
888
|
-
const win = scope.global().find('window').get();
|
|
889
|
-
variable = new Prop(win, left.name);
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
else if (left.type === 'MemberExpression') {
|
|
893
|
-
variable = yield* MemberExpression$1(left, scope, { getVar: true });
|
|
894
|
-
}
|
|
895
|
-
else {
|
|
896
|
-
const value = yield* evaluate$1(node.right, scope);
|
|
897
|
-
return yield* pattern(left, scope, { feed: value });
|
|
898
|
-
}
|
|
899
|
-
const value = yield* evaluate$1(node.right, scope);
|
|
900
|
-
switch (node.operator) {
|
|
901
|
-
case '=':
|
|
902
|
-
variable.set(value);
|
|
903
|
-
return variable.get();
|
|
904
|
-
case '+=':
|
|
905
|
-
variable.set(variable.get() + value);
|
|
906
|
-
return variable.get();
|
|
907
|
-
case '-=':
|
|
908
|
-
variable.set(variable.get() - value);
|
|
909
|
-
return variable.get();
|
|
910
|
-
case '*=':
|
|
911
|
-
variable.set(variable.get() * value);
|
|
912
|
-
return variable.get();
|
|
913
|
-
case '/=':
|
|
914
|
-
variable.set(variable.get() / value);
|
|
915
|
-
return variable.get();
|
|
916
|
-
case '%=':
|
|
917
|
-
variable.set(variable.get() % value);
|
|
918
|
-
return variable.get();
|
|
919
|
-
case '**=':
|
|
920
|
-
variable.set(Math.pow(variable.get(), value));
|
|
921
|
-
return variable.get();
|
|
922
|
-
case '<<=':
|
|
923
|
-
variable.set(variable.get() << value);
|
|
924
|
-
return variable.get();
|
|
925
|
-
case '>>=':
|
|
926
|
-
variable.set(variable.get() >> value);
|
|
927
|
-
return variable.get();
|
|
928
|
-
case '>>>=':
|
|
929
|
-
variable.set(variable.get() >>> value);
|
|
930
|
-
return variable.get();
|
|
931
|
-
case '|=':
|
|
932
|
-
variable.set(variable.get() | value);
|
|
933
|
-
return variable.get();
|
|
934
|
-
case '^=':
|
|
935
|
-
variable.set(variable.get() ^ value);
|
|
936
|
-
return variable.get();
|
|
937
|
-
case '&=':
|
|
938
|
-
variable.set(variable.get() & value);
|
|
939
|
-
return variable.get();
|
|
940
|
-
case '??=':
|
|
941
|
-
variable.set((_a = variable.get()) !== null && _a !== void 0 ? _a : value);
|
|
942
|
-
return variable.get();
|
|
943
|
-
case '&&=':
|
|
944
|
-
variable.set(variable.get() && value);
|
|
945
|
-
return variable.get();
|
|
946
|
-
case '||=':
|
|
947
|
-
variable.set(variable.get() || value);
|
|
948
|
-
return variable.get();
|
|
949
|
-
default: throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
function* LogicalExpression$1(node, scope) {
|
|
953
|
-
var _a;
|
|
954
|
-
switch (node.operator) {
|
|
955
|
-
case '||':
|
|
956
|
-
return (yield* evaluate$1(node.left, scope)) || (yield* evaluate$1(node.right, scope));
|
|
957
|
-
case '&&':
|
|
958
|
-
return (yield* evaluate$1(node.left, scope)) && (yield* evaluate$1(node.right, scope));
|
|
959
|
-
case '??':
|
|
960
|
-
return (_a = (yield* evaluate$1(node.left, scope))) !== null && _a !== void 0 ? _a : (yield* evaluate$1(node.right, scope));
|
|
961
|
-
default:
|
|
962
|
-
throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
function* MemberExpression$1(node, scope, options = {}) {
|
|
966
|
-
const { getObj = false, getVar = false } = options;
|
|
967
|
-
let object;
|
|
968
|
-
if (node.object.type === 'Super') {
|
|
969
|
-
object = yield* Super$1(node.object, scope, { getProto: true });
|
|
970
|
-
}
|
|
971
|
-
else {
|
|
972
|
-
object = yield* evaluate$1(node.object, scope);
|
|
973
|
-
}
|
|
974
|
-
if (getObj)
|
|
975
|
-
return object;
|
|
976
|
-
let key;
|
|
977
|
-
let priv = false;
|
|
978
|
-
if (node.computed) {
|
|
979
|
-
key = yield* evaluate$1(node.property, scope);
|
|
980
|
-
}
|
|
981
|
-
else if (node.property.type === 'PrivateIdentifier') {
|
|
982
|
-
key = node.property.name;
|
|
983
|
-
priv = true;
|
|
984
|
-
}
|
|
985
|
-
else {
|
|
986
|
-
key = node.property.name;
|
|
987
|
-
}
|
|
988
|
-
if (priv) {
|
|
989
|
-
object = object[PRIVATE];
|
|
990
|
-
}
|
|
991
|
-
if (getVar) {
|
|
992
|
-
const setter = getSetter(object, key);
|
|
993
|
-
if (node.object.type === 'Super' && setter) {
|
|
994
|
-
const thisObject = scope.find('this').get();
|
|
995
|
-
const privateKey = createSymbol(key);
|
|
996
|
-
define(thisObject, privateKey, { set: setter });
|
|
997
|
-
return new Prop(thisObject, privateKey);
|
|
998
|
-
}
|
|
999
|
-
else {
|
|
1000
|
-
return new Prop(object, key);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
else {
|
|
1004
|
-
const getter = getGetter(object, key);
|
|
1005
|
-
if (node.object.type === 'Super' && getter) {
|
|
1006
|
-
const thisObject = scope.find('this').get();
|
|
1007
|
-
if (node.optional && thisObject == null) {
|
|
1008
|
-
return undefined;
|
|
1009
|
-
}
|
|
1010
|
-
return getter.call(thisObject);
|
|
1011
|
-
}
|
|
1012
|
-
else {
|
|
1013
|
-
if (node.optional && object == null) {
|
|
1014
|
-
return undefined;
|
|
1015
|
-
}
|
|
1016
|
-
return object[key];
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
function* ConditionalExpression$1(node, scope) {
|
|
1021
|
-
return (yield* evaluate$1(node.test, scope))
|
|
1022
|
-
? (yield* evaluate$1(node.consequent, scope))
|
|
1023
|
-
: (yield* evaluate$1(node.alternate, scope));
|
|
1024
|
-
}
|
|
1025
|
-
function* CallExpression$1(node, scope) {
|
|
1026
|
-
let func;
|
|
1027
|
-
let object;
|
|
1028
|
-
if (node.callee.type === 'MemberExpression') {
|
|
1029
|
-
object = yield* MemberExpression$1(node.callee, scope, { getObj: true });
|
|
1030
|
-
if (node.callee.optional && object == null) {
|
|
1031
|
-
return undefined;
|
|
1032
|
-
}
|
|
1033
|
-
let key;
|
|
1034
|
-
let priv = false;
|
|
1035
|
-
if (node.callee.computed) {
|
|
1036
|
-
key = yield* evaluate$1(node.callee.property, scope);
|
|
1037
|
-
}
|
|
1038
|
-
else if (node.callee.property.type === 'PrivateIdentifier') {
|
|
1039
|
-
key = node.callee.property.name;
|
|
1040
|
-
priv = true;
|
|
1041
|
-
}
|
|
1042
|
-
else {
|
|
1043
|
-
key = node.callee.property.name;
|
|
1044
|
-
}
|
|
1045
|
-
let obj = object;
|
|
1046
|
-
if (priv) {
|
|
1047
|
-
obj = obj[PRIVATE];
|
|
1048
|
-
}
|
|
1049
|
-
if (node.callee.object.type === 'Super') {
|
|
1050
|
-
const thisObject = scope.find('this').get();
|
|
1051
|
-
func = obj[key].bind(thisObject);
|
|
1052
|
-
}
|
|
1053
|
-
else {
|
|
1054
|
-
func = obj[key];
|
|
1055
|
-
}
|
|
1056
|
-
if (node.optional && func == null) {
|
|
1057
|
-
return undefined;
|
|
1058
|
-
}
|
|
1059
|
-
if (typeof func !== 'function') {
|
|
1060
|
-
throw new TypeError(`${key} is not a function`);
|
|
1061
|
-
}
|
|
1062
|
-
else if (func[CLSCTOR]) {
|
|
1063
|
-
throw new TypeError(`Class constructor ${key} cannot be invoked without 'new'`);
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
else {
|
|
1067
|
-
object = scope.find('this').get();
|
|
1068
|
-
func = yield* evaluate$1(node.callee, scope);
|
|
1069
|
-
if (node.optional && func == null) {
|
|
1070
|
-
return undefined;
|
|
1071
|
-
}
|
|
1072
|
-
if (typeof func !== 'function' || node.callee.type !== 'Super' && func[CLSCTOR]) {
|
|
1073
|
-
let name;
|
|
1074
|
-
if (node.callee.type === 'Identifier') {
|
|
1075
|
-
name = node.callee.name;
|
|
1076
|
-
}
|
|
1077
|
-
else {
|
|
1078
|
-
try {
|
|
1079
|
-
name = JSON.stringify(func);
|
|
1080
|
-
}
|
|
1081
|
-
catch (err) {
|
|
1082
|
-
name = '' + func;
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
if (typeof func !== 'function') {
|
|
1086
|
-
throw new TypeError(`${name} is not a function`);
|
|
1087
|
-
}
|
|
1088
|
-
else {
|
|
1089
|
-
throw new TypeError(`Class constructor ${name} cannot be invoked without 'new'`);
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
let args = [];
|
|
1094
|
-
for (let i = 0; i < node.arguments.length; i++) {
|
|
1095
|
-
const arg = node.arguments[i];
|
|
1096
|
-
if (arg.type === 'SpreadElement') {
|
|
1097
|
-
args = args.concat(yield* SpreadElement$1(arg, scope));
|
|
1098
|
-
}
|
|
1099
|
-
else {
|
|
1100
|
-
args.push(yield* evaluate$1(arg, scope));
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
if (node.callee.type === 'Super') {
|
|
1104
|
-
const superCall = scope.find(SUPERCALL);
|
|
1105
|
-
const construct = superCall.get();
|
|
1106
|
-
if (construct === true) {
|
|
1107
|
-
throw new ReferenceError('Super constructor may only be called once');
|
|
1108
|
-
}
|
|
1109
|
-
const inst = callSuper(object, func, args);
|
|
1110
|
-
yield* construct(inst);
|
|
1111
|
-
scope.find('this').set(inst);
|
|
1112
|
-
scope.find(SUPERCALL).set(true);
|
|
1113
|
-
return inst;
|
|
1114
|
-
}
|
|
1115
|
-
try {
|
|
1116
|
-
return func.apply(object, args);
|
|
1117
|
-
}
|
|
1118
|
-
catch (err) {
|
|
1119
|
-
if (err instanceof TypeError && err.message === 'Illegal invocation'
|
|
1120
|
-
&& func.toString().indexOf('[native code]') !== -1) {
|
|
1121
|
-
const win = scope.global().find('window').get();
|
|
1122
|
-
if (win && win[WINDOW]) {
|
|
1123
|
-
return func.apply(win[WINDOW], args);
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
throw err;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
function* NewExpression$1(node, scope) {
|
|
1130
|
-
const constructor = yield* evaluate$1(node.callee, scope);
|
|
1131
|
-
if (typeof constructor !== 'function') {
|
|
1132
|
-
let name;
|
|
1133
|
-
if (node.callee.type === 'Identifier') {
|
|
1134
|
-
name = node.callee.name;
|
|
1135
|
-
}
|
|
1136
|
-
else {
|
|
1137
|
-
try {
|
|
1138
|
-
name = JSON.stringify(constructor);
|
|
1139
|
-
}
|
|
1140
|
-
catch (err) {
|
|
1141
|
-
name = '' + constructor;
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
throw new TypeError(`${name} is not a constructor`);
|
|
1145
|
-
}
|
|
1146
|
-
else if (constructor[NOCTOR]) {
|
|
1147
|
-
throw new TypeError(`${constructor.name || '(intermediate value)'} is not a constructor`);
|
|
1148
|
-
}
|
|
1149
|
-
let args = [];
|
|
1150
|
-
for (let i = 0; i < node.arguments.length; i++) {
|
|
1151
|
-
const arg = node.arguments[i];
|
|
1152
|
-
if (arg.type === 'SpreadElement') {
|
|
1153
|
-
args = args.concat(yield* SpreadElement$1(arg, scope));
|
|
1154
|
-
}
|
|
1155
|
-
else {
|
|
1156
|
-
args.push(yield* evaluate$1(arg, scope));
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
return new constructor(...args);
|
|
1160
|
-
}
|
|
1161
|
-
function* MetaProperty$1(node, scope) {
|
|
1162
|
-
if (node.meta.name === 'new' && node.property.name === 'target') {
|
|
1163
|
-
return scope.find(NEWTARGET).get();
|
|
1164
|
-
}
|
|
1165
|
-
else if (node.meta.name === 'import' && node.property.name === 'meta') {
|
|
1166
|
-
return { url: '' };
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
function* SequenceExpression$1(node, scope) {
|
|
1170
|
-
let result;
|
|
1171
|
-
for (let i = 0; i < node.expressions.length; i++) {
|
|
1172
|
-
result = yield* evaluate$1(node.expressions[i], scope);
|
|
1173
|
-
}
|
|
1174
|
-
return result;
|
|
1175
|
-
}
|
|
1176
|
-
function* ArrowFunctionExpression$1(node, scope) {
|
|
1177
|
-
return createFunc(node, scope);
|
|
1178
|
-
}
|
|
1179
|
-
function* TemplateLiteral$1(node, scope) {
|
|
1180
|
-
const quasis = node.quasis.slice();
|
|
1181
|
-
const expressions = node.expressions.slice();
|
|
1182
|
-
let result = '';
|
|
1183
|
-
let temEl;
|
|
1184
|
-
let expr;
|
|
1185
|
-
while (temEl = quasis.shift()) {
|
|
1186
|
-
result += yield* TemplateElement$1(temEl);
|
|
1187
|
-
expr = expressions.shift();
|
|
1188
|
-
if (expr) {
|
|
1189
|
-
result += yield* evaluate$1(expr, scope);
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
return result;
|
|
1193
|
-
}
|
|
1194
|
-
function* TaggedTemplateExpression$1(node, scope) {
|
|
1195
|
-
const tagFunc = yield* evaluate$1(node.tag, scope);
|
|
1196
|
-
const quasis = node.quasi.quasis;
|
|
1197
|
-
const str = quasis.map(v => v.value.cooked);
|
|
1198
|
-
const raw = quasis.map(v => v.value.raw);
|
|
1199
|
-
define(str, 'raw', {
|
|
1200
|
-
value: freeze(raw)
|
|
1201
|
-
});
|
|
1202
|
-
const expressions = node.quasi.expressions;
|
|
1203
|
-
const args = [];
|
|
1204
|
-
if (expressions) {
|
|
1205
|
-
for (let i = 0; i < expressions.length; i++) {
|
|
1206
|
-
args.push(yield* evaluate$1(expressions[i], scope));
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
return tagFunc(freeze(str), ...args);
|
|
1210
|
-
}
|
|
1211
|
-
function* TemplateElement$1(node, scope) {
|
|
1212
|
-
return node.value.raw;
|
|
1213
|
-
}
|
|
1214
|
-
function* ClassExpression$1(node, scope) {
|
|
1215
|
-
if (node.id && node.id.name) {
|
|
1216
|
-
const tmpScope = new Scope(scope);
|
|
1217
|
-
const klass = yield* createClass(node, tmpScope);
|
|
1218
|
-
tmpScope.const(node.id.name, klass);
|
|
1219
|
-
return klass;
|
|
1220
|
-
}
|
|
1221
|
-
else {
|
|
1222
|
-
return yield* createClass(node, scope);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
function* Super$1(node, scope, options = {}) {
|
|
1226
|
-
const { getProto = false } = options;
|
|
1227
|
-
const superClass = scope.find(SUPER).get();
|
|
1228
|
-
return getProto ? superClass.prototype : superClass;
|
|
1229
|
-
}
|
|
1230
|
-
function* SpreadElement$1(node, scope, options = {}) {
|
|
1231
|
-
const result = yield* evaluate$1(node.argument, scope);
|
|
1232
|
-
if (options.spreadProps) {
|
|
1233
|
-
return result;
|
|
1234
|
-
}
|
|
1235
|
-
if (typeof Symbol === 'function' && typeof result[Symbol.iterator] !== 'function') {
|
|
1236
|
-
throw new TypeError('Spread syntax requires ...iterable[Symbol.iterator] to be a function');
|
|
1237
|
-
}
|
|
1238
|
-
return [...result];
|
|
1239
|
-
}
|
|
1240
|
-
function* ChainExpression$1(node, scope) {
|
|
1241
|
-
return yield* evaluate$1(node.expression, scope);
|
|
1242
|
-
}
|
|
1243
|
-
function* ImportExpression$1(node, scope) {
|
|
1244
|
-
const globalScope = scope.global();
|
|
1245
|
-
const source = yield* evaluate$1(node.source, scope);
|
|
1246
|
-
const module = globalScope.find(IMPORT + source);
|
|
1247
|
-
let value;
|
|
1248
|
-
if (module) {
|
|
1249
|
-
const result = module.get();
|
|
1250
|
-
if (result) {
|
|
1251
|
-
if (typeof result === 'function') {
|
|
1252
|
-
value = result();
|
|
1253
|
-
}
|
|
1254
|
-
else if (typeof result === 'object') {
|
|
1255
|
-
value = result;
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
if (!value || typeof value !== 'object') {
|
|
1260
|
-
return Promise.reject(new TypeError(`Failed to resolve module specifier "${source}"`));
|
|
1261
|
-
}
|
|
1262
|
-
return Promise.resolve(value);
|
|
1263
|
-
}
|
|
1264
|
-
function* YieldExpression(node, scope) {
|
|
1265
|
-
const res = yield* evaluate$1(node.argument, scope);
|
|
1266
|
-
return node.delegate ? yield* res : yield res;
|
|
1267
|
-
}
|
|
1268
|
-
function* AwaitExpression(node, scope) {
|
|
1269
|
-
AWAIT.RES = yield* evaluate$1(node.argument, scope);
|
|
1270
|
-
return yield AWAIT;
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
var expression$1 = /*#__PURE__*/Object.freeze({
|
|
1274
|
-
__proto__: null,
|
|
1275
|
-
ThisExpression: ThisExpression$1,
|
|
1276
|
-
ArrayExpression: ArrayExpression$1,
|
|
1277
|
-
ObjectExpression: ObjectExpression$1,
|
|
1278
|
-
FunctionExpression: FunctionExpression$1,
|
|
1279
|
-
UnaryExpression: UnaryExpression$1,
|
|
1280
|
-
UpdateExpression: UpdateExpression$1,
|
|
1281
|
-
BinaryExpression: BinaryExpression$1,
|
|
1282
|
-
AssignmentExpression: AssignmentExpression$1,
|
|
1283
|
-
LogicalExpression: LogicalExpression$1,
|
|
1284
|
-
MemberExpression: MemberExpression$1,
|
|
1285
|
-
ConditionalExpression: ConditionalExpression$1,
|
|
1286
|
-
CallExpression: CallExpression$1,
|
|
1287
|
-
NewExpression: NewExpression$1,
|
|
1288
|
-
MetaProperty: MetaProperty$1,
|
|
1289
|
-
SequenceExpression: SequenceExpression$1,
|
|
1290
|
-
ArrowFunctionExpression: ArrowFunctionExpression$1,
|
|
1291
|
-
TemplateLiteral: TemplateLiteral$1,
|
|
1292
|
-
TaggedTemplateExpression: TaggedTemplateExpression$1,
|
|
1293
|
-
TemplateElement: TemplateElement$1,
|
|
1294
|
-
ClassExpression: ClassExpression$1,
|
|
1295
|
-
Super: Super$1,
|
|
1296
|
-
SpreadElement: SpreadElement$1,
|
|
1297
|
-
ChainExpression: ChainExpression$1,
|
|
1298
|
-
ImportExpression: ImportExpression$1,
|
|
1299
|
-
YieldExpression: YieldExpression,
|
|
1300
|
-
AwaitExpression: AwaitExpression
|
|
1301
|
-
});
|
|
1302
|
-
|
|
1303
|
-
function* ObjectPattern$1(node, scope, options = {}) {
|
|
1304
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed = {} } = options;
|
|
1305
|
-
const fedKeys = [];
|
|
1306
|
-
for (let i = 0; i < node.properties.length; i++) {
|
|
1307
|
-
const property = node.properties[i];
|
|
1308
|
-
if (hoist) {
|
|
1309
|
-
if (onlyBlock || kind === 'var') {
|
|
1310
|
-
if (property.type === 'Property') {
|
|
1311
|
-
const value = property.value;
|
|
1312
|
-
if (value.type === 'Identifier') {
|
|
1313
|
-
scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1314
|
-
}
|
|
1315
|
-
else {
|
|
1316
|
-
yield* pattern(value, scope, { kind, hoist, onlyBlock });
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
else {
|
|
1320
|
-
yield* RestElement$1(property, scope, { kind, hoist, onlyBlock });
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
else if (property.type === 'Property') {
|
|
1325
|
-
let key;
|
|
1326
|
-
if (property.computed) {
|
|
1327
|
-
key = yield* evaluate$1(property.key, scope);
|
|
1328
|
-
}
|
|
1329
|
-
else {
|
|
1330
|
-
key = property.key.name;
|
|
1331
|
-
}
|
|
1332
|
-
fedKeys.push(key);
|
|
1333
|
-
const value = property.value;
|
|
1334
|
-
if (value.type === 'Identifier') {
|
|
1335
|
-
scope[kind](value.name, feed[key]);
|
|
1336
|
-
}
|
|
1337
|
-
else {
|
|
1338
|
-
yield* pattern(value, scope, { kind, feed: feed[key] });
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
else {
|
|
1342
|
-
const rest = assign({}, feed);
|
|
1343
|
-
for (let i = 0; i < fedKeys.length; i++)
|
|
1344
|
-
delete rest[fedKeys[i]];
|
|
1345
|
-
yield* RestElement$1(property, scope, { kind, feed: rest });
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
function* ArrayPattern$1(node, scope, options = {}) {
|
|
1350
|
-
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
1351
|
-
const result = [];
|
|
1352
|
-
for (let i = 0; i < node.elements.length; i++) {
|
|
1353
|
-
const element = node.elements[i];
|
|
1354
|
-
if (!element)
|
|
1355
|
-
continue;
|
|
1356
|
-
if (hoist) {
|
|
1357
|
-
if (onlyBlock || kind === 'var') {
|
|
1358
|
-
if (element.type === 'Identifier') {
|
|
1359
|
-
scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1360
|
-
}
|
|
1361
|
-
else {
|
|
1362
|
-
yield* pattern(element, scope, { kind, hoist, onlyBlock });
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
else if (element.type === 'Identifier') {
|
|
1367
|
-
if (kind) {
|
|
1368
|
-
scope[kind](element.name, feed[i]);
|
|
1369
|
-
}
|
|
1370
|
-
else {
|
|
1371
|
-
const variable = yield* Identifier$1(element, scope, { getVar: true });
|
|
1372
|
-
variable.set(feed[i]);
|
|
1373
|
-
result.push(variable.get());
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
else if (element.type === 'RestElement') {
|
|
1377
|
-
yield* RestElement$1(element, scope, { kind, feed: feed.slice(i) });
|
|
1378
|
-
}
|
|
1379
|
-
else {
|
|
1380
|
-
yield* pattern(element, scope, { kind, feed: feed[i] });
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
if (result.length) {
|
|
1384
|
-
return result;
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
function* RestElement$1(node, scope, options = {}) {
|
|
1388
|
-
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
1389
|
-
const arg = node.argument;
|
|
1390
|
-
if (hoist) {
|
|
1391
|
-
if (onlyBlock || kind === 'var') {
|
|
1392
|
-
if (arg.type === 'Identifier') {
|
|
1393
|
-
scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1394
|
-
}
|
|
1395
|
-
else {
|
|
1396
|
-
yield* pattern(arg, scope, { kind, hoist, onlyBlock });
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
else if (arg.type === 'Identifier') {
|
|
1401
|
-
if (kind) {
|
|
1402
|
-
scope[kind](arg.name, feed);
|
|
1403
|
-
}
|
|
1404
|
-
else {
|
|
1405
|
-
const variable = yield* Identifier$1(arg, scope, { getVar: true });
|
|
1406
|
-
variable.set(feed);
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
else {
|
|
1410
|
-
yield* pattern(arg, scope, { kind, feed });
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
function* AssignmentPattern$1(node, scope, options = {}) {
|
|
1414
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed = yield* evaluate$1(node.right, scope) } = options;
|
|
1415
|
-
const left = node.left;
|
|
1416
|
-
if (hoist) {
|
|
1417
|
-
if (onlyBlock || kind === 'var') {
|
|
1418
|
-
if (left.type === 'Identifier') {
|
|
1419
|
-
scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1420
|
-
}
|
|
1421
|
-
else {
|
|
1422
|
-
yield* pattern(left, scope, { kind, hoist, onlyBlock });
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
else if (left.type === 'Identifier') {
|
|
1427
|
-
scope[kind](left.name, feed);
|
|
1428
|
-
}
|
|
1429
|
-
else {
|
|
1430
|
-
yield* pattern(left, scope, { kind, feed });
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
|
-
var pattern$3 = /*#__PURE__*/Object.freeze({
|
|
1435
|
-
__proto__: null,
|
|
1436
|
-
ObjectPattern: ObjectPattern$1,
|
|
1437
|
-
ArrayPattern: ArrayPattern$1,
|
|
1438
|
-
RestElement: RestElement$1,
|
|
1439
|
-
AssignmentPattern: AssignmentPattern$1
|
|
1440
|
-
});
|
|
1441
|
-
|
|
1442
|
-
function* Program$1(program, scope) {
|
|
1443
|
-
for (let i = 0; i < program.body.length; i++) {
|
|
1444
|
-
yield* evaluate$1(program.body[i], scope);
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
var program$1 = /*#__PURE__*/Object.freeze({
|
|
1449
|
-
__proto__: null,
|
|
1450
|
-
Program: Program$1
|
|
1451
|
-
});
|
|
1452
|
-
|
|
1453
|
-
let evaluateOps$1;
|
|
1454
|
-
function* evaluate$1(node, scope) {
|
|
1455
|
-
if (!node)
|
|
1456
|
-
return;
|
|
1457
|
-
if (!evaluateOps$1) {
|
|
1458
|
-
evaluateOps$1 = assign({}, declaration$1, expression$1, identifier$1, statement$1, literal$1, pattern$3, program$1);
|
|
1459
|
-
}
|
|
1460
|
-
const handler = evaluateOps$1[node.type];
|
|
1461
|
-
if (handler) {
|
|
1462
|
-
return yield* handler(node, scope);
|
|
1463
|
-
}
|
|
1464
|
-
else {
|
|
1465
|
-
throw new Error(`${node.type} isn't implemented`);
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
|
|
1469
|
-
function* ExpressionStatement$1(node, scope) {
|
|
1470
|
-
yield* evaluate$1(node.expression, scope);
|
|
1471
|
-
}
|
|
1472
|
-
function* BlockStatement$1(block, scope, options = {}) {
|
|
1473
|
-
const { invasived = false, hoisted = false, } = options;
|
|
1474
|
-
const subScope = invasived ? scope : new Scope(scope);
|
|
1475
|
-
if (!hoisted) {
|
|
1476
|
-
yield* hoist(block, subScope, { onlyBlock: true });
|
|
1477
|
-
}
|
|
1478
|
-
for (let i = 0; i < block.body.length; i++) {
|
|
1479
|
-
const result = yield* evaluate$1(block.body[i], subScope);
|
|
1480
|
-
if (result === BREAK) {
|
|
1481
|
-
if (result.LABEL && result.LABEL === options.label) {
|
|
1482
|
-
break;
|
|
1483
|
-
}
|
|
1484
|
-
return result;
|
|
1485
|
-
}
|
|
1486
|
-
if (result === CONTINUE || result === RETURN) {
|
|
1487
|
-
return result;
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
function* EmptyStatement$1() {
|
|
1492
|
-
}
|
|
1493
|
-
function* DebuggerStatement$1() {
|
|
1494
|
-
debugger;
|
|
1495
|
-
}
|
|
1496
|
-
function* ReturnStatement$1(node, scope) {
|
|
1497
|
-
RETURN.RES = node.argument ? (yield* evaluate$1(node.argument, scope)) : undefined;
|
|
1498
|
-
return RETURN;
|
|
1499
|
-
}
|
|
1500
|
-
function* BreakStatement$1(node) {
|
|
1501
|
-
var _a;
|
|
1502
|
-
BREAK.LABEL = (_a = node.label) === null || _a === void 0 ? void 0 : _a.name;
|
|
1503
|
-
return BREAK;
|
|
1504
|
-
}
|
|
1505
|
-
function* ContinueStatement$1(node) {
|
|
1506
|
-
var _a;
|
|
1507
|
-
CONTINUE.LABEL = (_a = node.label) === null || _a === void 0 ? void 0 : _a.name;
|
|
1508
|
-
return CONTINUE;
|
|
1509
|
-
}
|
|
1510
|
-
function* LabeledStatement$1(node, scope) {
|
|
1511
|
-
const label = node.label.name;
|
|
1512
|
-
if (node.body.type === 'WhileStatement') {
|
|
1513
|
-
return yield* WhileStatement$1(node.body, scope, { label });
|
|
1514
|
-
}
|
|
1515
|
-
if (node.body.type === 'DoWhileStatement') {
|
|
1516
|
-
return yield* DoWhileStatement$1(node.body, scope, { label });
|
|
1517
|
-
}
|
|
1518
|
-
if (node.body.type === 'ForStatement') {
|
|
1519
|
-
return yield* ForStatement$1(node.body, scope, { label });
|
|
1520
|
-
}
|
|
1521
|
-
if (node.body.type === 'ForInStatement') {
|
|
1522
|
-
return yield* ForInStatement$1(node.body, scope, { label });
|
|
1523
|
-
}
|
|
1524
|
-
if (node.body.type === 'ForOfStatement') {
|
|
1525
|
-
return yield* ForOfStatement$1(node.body, scope, { label });
|
|
1526
|
-
}
|
|
1527
|
-
if (node.body.type === 'BlockStatement') {
|
|
1528
|
-
return yield* BlockStatement$1(node.body, scope, { label });
|
|
1529
|
-
}
|
|
1530
|
-
if (node.body.type === 'WithStatement') {
|
|
1531
|
-
return yield* WithStatement$1(node.body, scope, { label });
|
|
1532
|
-
}
|
|
1533
|
-
if (node.body.type === 'IfStatement') {
|
|
1534
|
-
return yield* IfStatement$1(node.body, scope, { label });
|
|
1535
|
-
}
|
|
1536
|
-
if (node.body.type === 'SwitchStatement') {
|
|
1537
|
-
return yield* SwitchStatement$1(node.body, scope, { label });
|
|
1538
|
-
}
|
|
1539
|
-
if (node.body.type === 'TryStatement') {
|
|
1540
|
-
return yield* TryStatement$1(node.body, scope, { label });
|
|
1541
|
-
}
|
|
1542
|
-
throw new SyntaxError(`${node.body.type} cannot be labeled`);
|
|
1543
|
-
}
|
|
1544
|
-
function* WithStatement$1(node, scope, options = {}) {
|
|
1545
|
-
const withScope = new Scope(scope);
|
|
1546
|
-
withScope.with(yield* evaluate$1(node.object, scope));
|
|
1547
|
-
const result = yield* evaluate$1(node.body, withScope);
|
|
1548
|
-
if (result === BREAK) {
|
|
1549
|
-
if (result.LABEL && result.LABEL === options.label) {
|
|
1550
|
-
return;
|
|
1551
|
-
}
|
|
1552
|
-
return result;
|
|
1553
|
-
}
|
|
1554
|
-
if (result === CONTINUE || result === RETURN) {
|
|
1555
|
-
return result;
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
function* IfStatement$1(node, scope, options = {}) {
|
|
1559
|
-
let result;
|
|
1560
|
-
if (yield* evaluate$1(node.test, scope)) {
|
|
1561
|
-
result = yield* evaluate$1(node.consequent, scope);
|
|
1562
|
-
}
|
|
1563
|
-
else {
|
|
1564
|
-
result = yield* evaluate$1(node.alternate, scope);
|
|
1565
|
-
}
|
|
1566
|
-
if (result === BREAK) {
|
|
1567
|
-
if (result.LABEL && result.LABEL === options.label) {
|
|
1568
|
-
return;
|
|
1569
|
-
}
|
|
1570
|
-
return result;
|
|
1571
|
-
}
|
|
1572
|
-
if (result === CONTINUE || result === RETURN) {
|
|
1573
|
-
return result;
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
function* SwitchStatement$1(node, scope, options = {}) {
|
|
1577
|
-
const discriminant = yield* evaluate$1(node.discriminant, scope);
|
|
1578
|
-
let matched = false;
|
|
1579
|
-
for (let i = 0; i < node.cases.length; i++) {
|
|
1580
|
-
const eachCase = node.cases[i];
|
|
1581
|
-
if (!matched
|
|
1582
|
-
&& (!eachCase.test
|
|
1583
|
-
|| (yield* evaluate$1(eachCase.test, scope)) === discriminant)) {
|
|
1584
|
-
matched = true;
|
|
1585
|
-
}
|
|
1586
|
-
if (matched) {
|
|
1587
|
-
const result = yield* SwitchCase$1(eachCase, scope);
|
|
1588
|
-
if (result === BREAK) {
|
|
1589
|
-
if (result.LABEL === options.label) {
|
|
1590
|
-
break;
|
|
1591
|
-
}
|
|
1592
|
-
return result;
|
|
1593
|
-
}
|
|
1594
|
-
if (result === CONTINUE || result === RETURN) {
|
|
1595
|
-
return result;
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
function* SwitchCase$1(node, scope) {
|
|
1601
|
-
for (let i = 0; i < node.consequent.length; i++) {
|
|
1602
|
-
const result = yield* evaluate$1(node.consequent[i], scope);
|
|
1603
|
-
if (result === BREAK || result === CONTINUE || result === RETURN) {
|
|
1604
|
-
return result;
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
function* ThrowStatement$1(node, scope) {
|
|
1609
|
-
throw yield* evaluate$1(node.argument, scope);
|
|
1610
|
-
}
|
|
1611
|
-
function* TryStatement$1(node, scope, options = {}) {
|
|
1612
|
-
let result;
|
|
1613
|
-
try {
|
|
1614
|
-
result = yield* BlockStatement$1(node.block, scope);
|
|
1615
|
-
}
|
|
1616
|
-
catch (err) {
|
|
1617
|
-
if (node.handler) {
|
|
1618
|
-
const subScope = new Scope(scope);
|
|
1619
|
-
const param = node.handler.param;
|
|
1620
|
-
if (param) {
|
|
1621
|
-
if (param.type === 'Identifier') {
|
|
1622
|
-
const name = param.name;
|
|
1623
|
-
subScope.var(name, err);
|
|
1624
|
-
}
|
|
1625
|
-
else {
|
|
1626
|
-
yield* pattern(param, scope, { feed: err });
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
result = yield* CatchClause$1(node.handler, subScope);
|
|
1630
|
-
}
|
|
1631
|
-
else {
|
|
1632
|
-
throw err;
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
finally {
|
|
1636
|
-
if (node.finalizer) {
|
|
1637
|
-
result = yield* BlockStatement$1(node.finalizer, scope);
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
if (result === BREAK) {
|
|
1641
|
-
if (result.LABEL && result.LABEL === options.label) {
|
|
1642
|
-
return;
|
|
1643
|
-
}
|
|
1644
|
-
return result;
|
|
1645
|
-
}
|
|
1646
|
-
if (result === CONTINUE || result === RETURN) {
|
|
1647
|
-
return result;
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
function* CatchClause$1(node, scope) {
|
|
1651
|
-
return yield* BlockStatement$1(node.body, scope, { invasived: true });
|
|
1652
|
-
}
|
|
1653
|
-
function* WhileStatement$1(node, scope, options = {}) {
|
|
1654
|
-
while (yield* evaluate$1(node.test, scope)) {
|
|
1655
|
-
const result = yield* evaluate$1(node.body, scope);
|
|
1656
|
-
if (result === BREAK) {
|
|
1657
|
-
if (result.LABEL === options.label) {
|
|
1658
|
-
break;
|
|
1659
|
-
}
|
|
1660
|
-
return result;
|
|
1661
|
-
}
|
|
1662
|
-
else if (result === CONTINUE) {
|
|
1663
|
-
if (result.LABEL === options.label) {
|
|
1664
|
-
continue;
|
|
1665
|
-
}
|
|
1666
|
-
return result;
|
|
1667
|
-
}
|
|
1668
|
-
else if (result === RETURN) {
|
|
1669
|
-
return result;
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
function* DoWhileStatement$1(node, scope, options = {}) {
|
|
1674
|
-
do {
|
|
1675
|
-
const result = yield* evaluate$1(node.body, scope);
|
|
1676
|
-
if (result === BREAK) {
|
|
1677
|
-
if (result.LABEL === options.label) {
|
|
1678
|
-
break;
|
|
1679
|
-
}
|
|
1680
|
-
return result;
|
|
1681
|
-
}
|
|
1682
|
-
else if (result === CONTINUE) {
|
|
1683
|
-
if (result.LABEL === options.label) {
|
|
1684
|
-
continue;
|
|
1685
|
-
}
|
|
1686
|
-
return result;
|
|
1687
|
-
}
|
|
1688
|
-
else if (result === RETURN) {
|
|
1689
|
-
return result;
|
|
1690
|
-
}
|
|
1691
|
-
} while (yield* evaluate$1(node.test, scope));
|
|
1692
|
-
}
|
|
1693
|
-
function* ForStatement$1(node, scope, options = {}) {
|
|
1694
|
-
const forScope = new Scope(scope);
|
|
1695
|
-
for (yield* evaluate$1(node.init, forScope); node.test ? (yield* evaluate$1(node.test, forScope)) : true; yield* evaluate$1(node.update, forScope)) {
|
|
1696
|
-
const subScope = new Scope(forScope);
|
|
1697
|
-
let result;
|
|
1698
|
-
if (node.body.type === 'BlockStatement') {
|
|
1699
|
-
result = yield* BlockStatement$1(node.body, subScope, { invasived: true });
|
|
1700
|
-
}
|
|
1701
|
-
else {
|
|
1702
|
-
result = yield* evaluate$1(node.body, subScope);
|
|
1703
|
-
}
|
|
1704
|
-
if (result === BREAK) {
|
|
1705
|
-
if (result.LABEL === options.label) {
|
|
1706
|
-
break;
|
|
1707
|
-
}
|
|
1708
|
-
return result;
|
|
1709
|
-
}
|
|
1710
|
-
else if (result === CONTINUE) {
|
|
1711
|
-
if (result.LABEL === options.label) {
|
|
1712
|
-
continue;
|
|
1713
|
-
}
|
|
1714
|
-
return result;
|
|
1715
|
-
}
|
|
1716
|
-
else if (result === RETURN) {
|
|
1717
|
-
return result;
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
function* ForInStatement$1(node, scope, options = {}) {
|
|
1722
|
-
for (const value in yield* evaluate$1(node.right, scope)) {
|
|
1723
|
-
const result = yield* ForXHandler(node, scope, { value });
|
|
1724
|
-
if (result === BREAK) {
|
|
1725
|
-
if (result.LABEL === options.label) {
|
|
1726
|
-
break;
|
|
1727
|
-
}
|
|
1728
|
-
return result;
|
|
1729
|
-
}
|
|
1730
|
-
else if (result === CONTINUE) {
|
|
1731
|
-
if (result.LABEL === options.label) {
|
|
1732
|
-
continue;
|
|
1733
|
-
}
|
|
1734
|
-
return result;
|
|
1735
|
-
}
|
|
1736
|
-
else if (result === RETURN) {
|
|
1737
|
-
return result;
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
function* ForOfStatement$1(node, scope, options = {}) {
|
|
1742
|
-
const right = yield* evaluate$1(node.right, scope);
|
|
1743
|
-
if (node.await) {
|
|
1744
|
-
const iterator = getAsyncIterator(right);
|
|
1745
|
-
let ret;
|
|
1746
|
-
for (AWAIT.RES = iterator.next(), ret = yield AWAIT; !ret.done; AWAIT.RES = iterator.next(), ret = yield AWAIT) {
|
|
1747
|
-
const result = yield* ForXHandler(node, scope, { value: ret.value });
|
|
1748
|
-
if (result === BREAK) {
|
|
1749
|
-
if (result.LABEL === options.label) {
|
|
1750
|
-
break;
|
|
1751
|
-
}
|
|
1752
|
-
return result;
|
|
1753
|
-
}
|
|
1754
|
-
else if (result === CONTINUE) {
|
|
1755
|
-
if (result.LABEL === options.label) {
|
|
1756
|
-
continue;
|
|
1757
|
-
}
|
|
1758
|
-
return result;
|
|
1759
|
-
}
|
|
1760
|
-
else if (result === RETURN) {
|
|
1761
|
-
return result;
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
else {
|
|
1766
|
-
for (const value of right) {
|
|
1767
|
-
const result = yield* ForXHandler(node, scope, { value });
|
|
1768
|
-
if (result === BREAK) {
|
|
1769
|
-
if (result.LABEL === options.label) {
|
|
1770
|
-
break;
|
|
1771
|
-
}
|
|
1772
|
-
return result;
|
|
1773
|
-
}
|
|
1774
|
-
else if (result === CONTINUE) {
|
|
1775
|
-
if (result.LABEL === options.label) {
|
|
1776
|
-
continue;
|
|
1777
|
-
}
|
|
1778
|
-
return result;
|
|
1779
|
-
}
|
|
1780
|
-
else if (result === RETURN) {
|
|
1781
|
-
return result;
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1787
|
-
function* FunctionDeclaration$1(node, scope) {
|
|
1788
|
-
scope.func(node.id.name, createFunc(node, scope));
|
|
1789
|
-
}
|
|
1790
|
-
function* VariableDeclaration$1(node, scope, options = {}) {
|
|
1791
|
-
for (let i = 0; i < node.declarations.length; i++) {
|
|
1792
|
-
yield* VariableDeclarator$1(node.declarations[i], scope, assign({ kind: node.kind }, options));
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
function* VariableDeclarator$1(node, scope, options = {}) {
|
|
1796
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed } = options;
|
|
1797
|
-
if (hoist) {
|
|
1798
|
-
if (onlyBlock || kind === 'var') {
|
|
1799
|
-
if (node.id.type === 'Identifier') {
|
|
1800
|
-
scope[kind](node.id.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1801
|
-
}
|
|
1802
|
-
else {
|
|
1803
|
-
yield* pattern(node.id, scope, { kind, hoist, onlyBlock });
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
else {
|
|
1808
|
-
const hasFeed = 'feed' in options;
|
|
1809
|
-
const value = hasFeed ? feed : yield* evaluate$1(node.init, scope);
|
|
1810
|
-
if (node.id.type === 'Identifier') {
|
|
1811
|
-
const name = node.id.name;
|
|
1812
|
-
if (kind === 'var' && !node.init && !hasFeed) {
|
|
1813
|
-
scope.var(name, NOINIT);
|
|
1814
|
-
}
|
|
1815
|
-
else {
|
|
1816
|
-
scope[kind](name, value);
|
|
1817
|
-
}
|
|
1818
|
-
if (node.init
|
|
1819
|
-
&& ['ClassExpression', 'FunctionExpression', 'ArrowFunctionExpression']
|
|
1820
|
-
.indexOf(node.init.type) !== -1
|
|
1821
|
-
&& !value.name) {
|
|
1822
|
-
define(value, 'name', {
|
|
1823
|
-
value: name,
|
|
1824
|
-
configurable: true
|
|
1825
|
-
});
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
else {
|
|
1829
|
-
yield* pattern(node.id, scope, { kind, feed: value });
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
function* ClassDeclaration$1(node, scope) {
|
|
1834
|
-
scope.func(node.id.name, yield* createClass(node, scope));
|
|
1835
|
-
}
|
|
1836
|
-
function* ClassBody$1(node, scope, options = {}) {
|
|
1837
|
-
const { klass, superClass } = options;
|
|
1838
|
-
for (let i = 0; i < node.body.length; i++) {
|
|
1839
|
-
const def = node.body[i];
|
|
1840
|
-
if (def.type === 'MethodDefinition') {
|
|
1841
|
-
yield* MethodDefinition$1(def, scope, { klass, superClass });
|
|
1842
|
-
}
|
|
1843
|
-
else if (def.type === 'PropertyDefinition' && def.static) {
|
|
1844
|
-
yield* PropertyDefinition$1(def, scope, { klass, superClass });
|
|
1845
|
-
}
|
|
1846
|
-
else if (def.type === 'StaticBlock') {
|
|
1847
|
-
yield* StaticBlock$1(def, scope, { klass, superClass });
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
function* MethodDefinition$1(node, scope, options = {}) {
|
|
1852
|
-
const { klass, superClass } = options;
|
|
1853
|
-
let key;
|
|
1854
|
-
let priv = false;
|
|
1855
|
-
if (node.computed) {
|
|
1856
|
-
key = yield* evaluate$1(node.key, scope);
|
|
1857
|
-
}
|
|
1858
|
-
else if (node.key.type === 'Identifier') {
|
|
1859
|
-
key = node.key.name;
|
|
1860
|
-
}
|
|
1861
|
-
else if (node.key.type === 'PrivateIdentifier') {
|
|
1862
|
-
key = node.key.name;
|
|
1863
|
-
priv = true;
|
|
1864
|
-
}
|
|
1865
|
-
else {
|
|
1866
|
-
throw new SyntaxError('Unexpected token');
|
|
1867
|
-
}
|
|
1868
|
-
let obj = node.static ? klass : klass.prototype;
|
|
1869
|
-
if (priv) {
|
|
1870
|
-
if (!obj[PRIVATE]) {
|
|
1871
|
-
define(obj, PRIVATE, { value: {} });
|
|
1872
|
-
}
|
|
1873
|
-
obj = obj[PRIVATE];
|
|
1874
|
-
}
|
|
1875
|
-
const value = createFunc(node.value, scope, { superClass });
|
|
1876
|
-
switch (node.kind) {
|
|
1877
|
-
case 'constructor':
|
|
1878
|
-
break;
|
|
1879
|
-
case 'method':
|
|
1880
|
-
define(obj, key, {
|
|
1881
|
-
value,
|
|
1882
|
-
writable: true,
|
|
1883
|
-
configurable: true,
|
|
1884
|
-
});
|
|
1885
|
-
break;
|
|
1886
|
-
case 'get': {
|
|
1887
|
-
const oriDptor = getDptor(obj, key);
|
|
1888
|
-
define(obj, key, {
|
|
1889
|
-
get: value,
|
|
1890
|
-
set: oriDptor && oriDptor.set,
|
|
1891
|
-
configurable: true,
|
|
1892
|
-
});
|
|
1893
|
-
break;
|
|
1894
|
-
}
|
|
1895
|
-
case 'set': {
|
|
1896
|
-
const oriDptor = getDptor(obj, key);
|
|
1897
|
-
define(obj, key, {
|
|
1898
|
-
get: oriDptor && oriDptor.get,
|
|
1899
|
-
set: value,
|
|
1900
|
-
configurable: true,
|
|
1901
|
-
});
|
|
1902
|
-
break;
|
|
1903
|
-
}
|
|
1904
|
-
default:
|
|
1905
|
-
throw new SyntaxError('Unexpected token');
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
function* PropertyDefinition$1(node, scope, options = {}) {
|
|
1909
|
-
const { klass, superClass } = options;
|
|
1910
|
-
let key;
|
|
1911
|
-
let priv = false;
|
|
1912
|
-
if (node.computed) {
|
|
1913
|
-
key = yield* evaluate$1(node.key, scope);
|
|
1914
|
-
}
|
|
1915
|
-
else if (node.key.type === 'Identifier') {
|
|
1916
|
-
key = node.key.name;
|
|
1917
|
-
}
|
|
1918
|
-
else if (node.key.type === 'PrivateIdentifier') {
|
|
1919
|
-
key = node.key.name;
|
|
1920
|
-
priv = true;
|
|
1921
|
-
}
|
|
1922
|
-
else {
|
|
1923
|
-
throw new SyntaxError('Unexpected token');
|
|
1924
|
-
}
|
|
1925
|
-
const subScope = new Scope(scope, true);
|
|
1926
|
-
subScope.const('this', klass);
|
|
1927
|
-
let obj = klass;
|
|
1928
|
-
if (priv) {
|
|
1929
|
-
if (!obj[PRIVATE]) {
|
|
1930
|
-
define(obj, PRIVATE, { value: {} });
|
|
1931
|
-
}
|
|
1932
|
-
obj = obj[PRIVATE];
|
|
1933
|
-
}
|
|
1934
|
-
if (!node.value) {
|
|
1935
|
-
obj[key] = undefined;
|
|
1936
|
-
}
|
|
1937
|
-
else if (node.value.type === 'FunctionExpression' || node.value.type === 'ArrowFunctionExpression') {
|
|
1938
|
-
obj[key] = createFunc(node.value, subScope, { superClass });
|
|
1939
|
-
}
|
|
1940
|
-
else {
|
|
1941
|
-
obj[key] = yield* evaluate$1(node.value, subScope);
|
|
1942
|
-
}
|
|
1943
|
-
}
|
|
1944
|
-
function* StaticBlock$1(node, scope, options = {}) {
|
|
1945
|
-
const { klass } = options;
|
|
1946
|
-
const subScope = new Scope(scope, true);
|
|
1947
|
-
subScope.const('this', klass);
|
|
1948
|
-
return yield* BlockStatement$1(node, subScope, { invasived: true });
|
|
1949
|
-
}
|
|
1950
|
-
function* ImportDeclaration$1(node, scope) {
|
|
1951
|
-
const globalScope = scope.global();
|
|
1952
|
-
const module = globalScope.find(IMPORT + node.source.value);
|
|
1953
|
-
let value;
|
|
1954
|
-
if (module) {
|
|
1955
|
-
const result = module.get();
|
|
1956
|
-
if (result) {
|
|
1957
|
-
if (typeof result === 'function') {
|
|
1958
|
-
value = result();
|
|
1959
|
-
}
|
|
1960
|
-
else if (typeof result === 'object') {
|
|
1961
|
-
value = result;
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
if (!value || typeof value !== 'object') {
|
|
1966
|
-
throw new TypeError(`Failed to resolve module specifier "${node.source.value}"`);
|
|
1967
|
-
}
|
|
1968
|
-
for (let i = 0; i < node.specifiers.length; i++) {
|
|
1969
|
-
const spec = node.specifiers[i];
|
|
1970
|
-
let name;
|
|
1971
|
-
if (spec.type === 'ImportSpecifier') {
|
|
1972
|
-
name = spec.imported.type === 'Identifier'
|
|
1973
|
-
? spec.imported.name : spec.imported.value;
|
|
1974
|
-
}
|
|
1975
|
-
else if (spec.type === 'ImportDefaultSpecifier') {
|
|
1976
|
-
name = 'default';
|
|
1977
|
-
}
|
|
1978
|
-
else if (spec.type === 'ImportNamespaceSpecifier') {
|
|
1979
|
-
name = '*';
|
|
1980
|
-
}
|
|
1981
|
-
if (name !== '*' && !hasOwn(value, name)) {
|
|
1982
|
-
throw new SyntaxError(`The requested module "${node.source.value}" does not provide an export named "${name}"`);
|
|
1983
|
-
}
|
|
1984
|
-
scope.var(spec.local.name, name === '*' ? assign({}, value) : value[name]);
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
function* ExportDefaultDeclaration$1(node, scope) {
|
|
1988
|
-
const globalScope = scope.global();
|
|
1989
|
-
let value;
|
|
1990
|
-
if (node.declaration.type === 'FunctionDeclaration') {
|
|
1991
|
-
value = createFunc(node.declaration, scope);
|
|
1992
|
-
scope.func(node.declaration.id.name, value);
|
|
1993
|
-
}
|
|
1994
|
-
else if (node.declaration.type === 'ClassDeclaration') {
|
|
1995
|
-
value = yield* createClass(node.declaration, scope);
|
|
1996
|
-
scope.func(node.declaration.id.name, value);
|
|
1997
|
-
}
|
|
1998
|
-
else {
|
|
1999
|
-
value = yield* evaluate$1(node.declaration, scope);
|
|
2000
|
-
}
|
|
2001
|
-
const variable = globalScope.find(EXPORTS);
|
|
2002
|
-
if (variable) {
|
|
2003
|
-
const exports = variable.get();
|
|
2004
|
-
if (exports && typeof exports === 'object') {
|
|
2005
|
-
exports.default = value;
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
}
|
|
2009
|
-
function* ExportNamedDeclaration$1(node, scope) {
|
|
2010
|
-
const globalScope = scope.global();
|
|
2011
|
-
if (node.declaration) {
|
|
2012
|
-
if (node.declaration.type === 'FunctionDeclaration') {
|
|
2013
|
-
const value = createFunc(node.declaration, scope);
|
|
2014
|
-
scope.func(node.declaration.id.name, value);
|
|
2015
|
-
const variable = globalScope.find(EXPORTS);
|
|
2016
|
-
if (variable) {
|
|
2017
|
-
const exports = variable.get();
|
|
2018
|
-
if (exports && typeof exports === 'object') {
|
|
2019
|
-
exports[node.declaration.id.name] = value;
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
2023
|
-
else if (node.declaration.type === 'ClassDeclaration') {
|
|
2024
|
-
const value = yield* createClass(node.declaration, scope);
|
|
2025
|
-
scope.func(node.declaration.id.name, value);
|
|
2026
|
-
const variable = globalScope.find(EXPORTS);
|
|
2027
|
-
if (variable) {
|
|
2028
|
-
const exports = variable.get();
|
|
2029
|
-
if (exports && typeof exports === 'object') {
|
|
2030
|
-
exports[node.declaration.id.name] = value;
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
|
-
}
|
|
2034
|
-
else if (node.declaration.type === 'VariableDeclaration') {
|
|
2035
|
-
yield* VariableDeclaration$1(node.declaration, scope);
|
|
2036
|
-
const variable = globalScope.find(EXPORTS);
|
|
2037
|
-
if (variable) {
|
|
2038
|
-
const exports = variable.get();
|
|
2039
|
-
if (exports && typeof exports === 'object') {
|
|
2040
|
-
for (let i = 0; i < node.declaration.declarations.length; i++) {
|
|
2041
|
-
const name = node.declaration.declarations[i].id.name;
|
|
2042
|
-
const item = scope.find(name);
|
|
2043
|
-
if (item) {
|
|
2044
|
-
exports[name] = item.get();
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
else if (node.specifiers) {
|
|
2052
|
-
const variable = globalScope.find(EXPORTS);
|
|
2053
|
-
if (variable) {
|
|
2054
|
-
const exports = variable.get();
|
|
2055
|
-
if (exports && typeof exports === 'object') {
|
|
2056
|
-
for (let i = 0; i < node.specifiers.length; i++) {
|
|
2057
|
-
const spec = node.specifiers[i];
|
|
2058
|
-
const name = spec.local.type === 'Identifier'
|
|
2059
|
-
? spec.local.name : spec.local.value;
|
|
2060
|
-
const item = scope.find(name);
|
|
2061
|
-
if (item) {
|
|
2062
|
-
exports[spec.exported.type === 'Identifier'
|
|
2063
|
-
? spec.exported.name : spec.exported.value] = item.get();
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
}
|
|
2068
|
-
}
|
|
2069
|
-
}
|
|
2070
|
-
function* ExportAllDeclaration$1(node, scope) {
|
|
2071
|
-
const globalScope = scope.global();
|
|
2072
|
-
const module = globalScope.find(IMPORT + node.source.value);
|
|
2073
|
-
let value;
|
|
2074
|
-
if (module) {
|
|
2075
|
-
const result = module.get();
|
|
2076
|
-
if (result) {
|
|
2077
|
-
if (typeof result === 'function') {
|
|
2078
|
-
value = result();
|
|
2079
|
-
}
|
|
2080
|
-
else if (typeof result === 'object') {
|
|
2081
|
-
value = result;
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
if (!value || typeof value !== 'object') {
|
|
2086
|
-
throw new TypeError(`Failed to resolve module specifier "${node.source.value}"`);
|
|
2087
|
-
}
|
|
2088
|
-
const variable = globalScope.find(EXPORTS);
|
|
2089
|
-
if (variable) {
|
|
2090
|
-
const exports = variable.get();
|
|
2091
|
-
if (exports && typeof exports === 'object') {
|
|
2092
|
-
assign(exports, value);
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2095
|
-
}
|
|
2096
|
-
|
|
2097
|
-
function Identifier(node, scope, options = {}) {
|
|
2098
|
-
const { getVar = false, throwErr = true } = options;
|
|
2099
|
-
if (node.name === 'undefined') {
|
|
2100
|
-
return undefined;
|
|
2101
|
-
}
|
|
2102
|
-
const variable = scope.find(node.name);
|
|
2103
|
-
if (variable) {
|
|
2104
|
-
if (getVar) {
|
|
2105
|
-
return variable;
|
|
2106
|
-
}
|
|
2107
|
-
else {
|
|
2108
|
-
const value = variable.get();
|
|
2109
|
-
if (value === DEADZONE) {
|
|
2110
|
-
throw new ReferenceError(`${node.name} is not defined`);
|
|
2111
|
-
}
|
|
2112
|
-
else {
|
|
2113
|
-
return value;
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
else if (throwErr) {
|
|
2118
|
-
throw new ReferenceError(`${node.name} is not defined`);
|
|
2119
|
-
}
|
|
2120
|
-
else {
|
|
2121
|
-
return undefined;
|
|
2122
|
-
}
|
|
2123
|
-
}
|
|
2124
|
-
|
|
2125
|
-
var identifier = /*#__PURE__*/Object.freeze({
|
|
2126
|
-
__proto__: null,
|
|
2127
|
-
Identifier: Identifier
|
|
2128
|
-
});
|
|
2129
|
-
|
|
2130
|
-
function Literal(node, scope) {
|
|
2131
|
-
return node.value;
|
|
2132
|
-
}
|
|
2133
|
-
|
|
2134
|
-
var literal = /*#__PURE__*/Object.freeze({
|
|
2135
|
-
__proto__: null,
|
|
2136
|
-
Literal: Literal
|
|
2137
|
-
});
|
|
2138
|
-
|
|
2139
|
-
function ThisExpression(node, scope) {
|
|
2140
|
-
const superCall = scope.find(SUPERCALL);
|
|
2141
|
-
if (superCall && superCall.get() !== true) {
|
|
2142
|
-
throw new ReferenceError('Must call super constructor in derived class '
|
|
2143
|
-
+ 'before accessing \'this\' or returning from derived constructor');
|
|
2144
|
-
}
|
|
2145
|
-
else {
|
|
2146
|
-
return scope.find('this').get();
|
|
2147
|
-
}
|
|
2148
|
-
}
|
|
2149
|
-
function ArrayExpression(node, scope) {
|
|
2150
|
-
let results = [];
|
|
2151
|
-
for (let i = 0; i < node.elements.length; i++) {
|
|
2152
|
-
const item = node.elements[i];
|
|
2153
|
-
if (item.type === 'SpreadElement') {
|
|
2154
|
-
results = results.concat(SpreadElement(item, scope));
|
|
2155
|
-
}
|
|
2156
|
-
else {
|
|
2157
|
-
results.push(evaluate(item, scope));
|
|
2158
|
-
}
|
|
2159
|
-
}
|
|
2160
|
-
return results;
|
|
2161
|
-
}
|
|
2162
|
-
function ObjectExpression(node, scope) {
|
|
2163
|
-
const object = {};
|
|
2164
|
-
for (let i = 0; i < node.properties.length; i++) {
|
|
2165
|
-
const property = node.properties[i];
|
|
2166
|
-
if (property.type === 'SpreadElement') {
|
|
2167
|
-
assign(object, SpreadElement(property, scope, { spreadProps: true }));
|
|
2168
|
-
}
|
|
2169
|
-
else {
|
|
2170
|
-
let key;
|
|
2171
|
-
const propKey = property.key;
|
|
2172
|
-
if (property.computed) {
|
|
2173
|
-
key = evaluate(propKey, scope);
|
|
2174
|
-
}
|
|
2175
|
-
else {
|
|
2176
|
-
if (propKey.type === 'Identifier') {
|
|
2177
|
-
key = propKey.name;
|
|
2178
|
-
}
|
|
2179
|
-
else {
|
|
2180
|
-
key = '' + (Literal(propKey));
|
|
2181
|
-
}
|
|
2182
|
-
}
|
|
2183
|
-
const value = evaluate(property.value, scope);
|
|
2184
|
-
const propKind = property.kind;
|
|
2185
|
-
if (propKind === 'init') {
|
|
2186
|
-
object[key] = value;
|
|
2187
|
-
}
|
|
2188
|
-
else if (propKind === 'get') {
|
|
2189
|
-
const oriDptor = getDptor(object, key);
|
|
2190
|
-
define(object, key, {
|
|
2191
|
-
get: value,
|
|
2192
|
-
set: oriDptor && oriDptor.set,
|
|
2193
|
-
enumerable: true,
|
|
2194
|
-
configurable: true
|
|
2195
|
-
});
|
|
2196
|
-
}
|
|
2197
|
-
else {
|
|
2198
|
-
const oriDptor = getDptor(object, key);
|
|
2199
|
-
define(object, key, {
|
|
2200
|
-
get: oriDptor && oriDptor.get,
|
|
2201
|
-
set: value,
|
|
2202
|
-
enumerable: true,
|
|
2203
|
-
configurable: true
|
|
2204
|
-
});
|
|
2205
|
-
}
|
|
2206
|
-
}
|
|
2207
|
-
}
|
|
2208
|
-
return object;
|
|
2209
|
-
}
|
|
2210
|
-
function FunctionExpression(node, scope) {
|
|
2211
|
-
if (node.id && node.id.name) {
|
|
2212
|
-
const tmpScope = new Scope(scope);
|
|
2213
|
-
const func = createFunc$1(node, tmpScope);
|
|
2214
|
-
tmpScope.const(node.id.name, func);
|
|
2215
|
-
return func;
|
|
2216
|
-
}
|
|
2217
|
-
else {
|
|
2218
|
-
return createFunc$1(node, scope);
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
|
-
function UnaryExpression(node, scope) {
|
|
2222
|
-
const arg = node.argument;
|
|
2223
|
-
switch (node.operator) {
|
|
2224
|
-
case '+': return +(evaluate(arg, scope));
|
|
2225
|
-
case '-': return -(evaluate(arg, scope));
|
|
2226
|
-
case '!': return !(evaluate(arg, scope));
|
|
2227
|
-
case '~': return ~(evaluate(arg, scope));
|
|
2228
|
-
case 'void': return void (evaluate(arg, scope));
|
|
2229
|
-
case 'typeof':
|
|
2230
|
-
if (arg.type === 'Identifier') {
|
|
2231
|
-
return typeof (Identifier(arg, scope, { throwErr: false }));
|
|
2232
|
-
}
|
|
2233
|
-
else {
|
|
2234
|
-
return typeof (evaluate(arg, scope));
|
|
2235
|
-
}
|
|
2236
|
-
case 'delete':
|
|
2237
|
-
if (arg.type === 'MemberExpression') {
|
|
2238
|
-
const variable = MemberExpression(arg, scope, { getVar: true });
|
|
2239
|
-
return variable.del();
|
|
2240
|
-
}
|
|
2241
|
-
else if (arg.type === 'Identifier') {
|
|
2242
|
-
throw new SyntaxError('Delete of an unqualified identifier in strict mode');
|
|
2243
|
-
}
|
|
2244
|
-
else {
|
|
2245
|
-
evaluate(arg, scope);
|
|
2246
|
-
return true;
|
|
2247
|
-
}
|
|
2248
|
-
default: throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
2249
|
-
}
|
|
2250
|
-
}
|
|
2251
|
-
function UpdateExpression(node, scope) {
|
|
2252
|
-
const arg = node.argument;
|
|
2253
|
-
let variable;
|
|
2254
|
-
if (arg.type === 'Identifier') {
|
|
2255
|
-
variable = Identifier(arg, scope, { getVar: true });
|
|
2256
|
-
}
|
|
2257
|
-
else if (arg.type === 'MemberExpression') {
|
|
2258
|
-
variable = MemberExpression(arg, scope, { getVar: true });
|
|
2259
|
-
}
|
|
2260
|
-
else {
|
|
2261
|
-
throw new SyntaxError('Unexpected token');
|
|
2262
|
-
}
|
|
2263
|
-
const value = variable.get();
|
|
2264
|
-
if (node.operator === '++') {
|
|
2265
|
-
variable.set(value + 1);
|
|
2266
|
-
return node.prefix ? variable.get() : value;
|
|
2267
|
-
}
|
|
2268
|
-
else if (node.operator === '--') {
|
|
2269
|
-
variable.set(value - 1);
|
|
2270
|
-
return node.prefix ? variable.get() : value;
|
|
2271
|
-
}
|
|
2272
|
-
else {
|
|
2273
|
-
throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
2274
|
-
}
|
|
2275
|
-
}
|
|
2276
|
-
function BinaryExpression(node, scope) {
|
|
2277
|
-
let left;
|
|
2278
|
-
let right;
|
|
2279
|
-
if (node.left.type === 'PrivateIdentifier') {
|
|
2280
|
-
left = node.left.name;
|
|
2281
|
-
right = evaluate(node.right, scope);
|
|
2282
|
-
right = right[PRIVATE] || {};
|
|
2283
|
-
}
|
|
2284
|
-
else {
|
|
2285
|
-
left = evaluate(node.left, scope);
|
|
2286
|
-
right = evaluate(node.right, scope);
|
|
2287
|
-
}
|
|
2288
|
-
switch (node.operator) {
|
|
2289
|
-
case '==': return left == right;
|
|
2290
|
-
case '!=': return left != right;
|
|
2291
|
-
case '===': return left === right;
|
|
2292
|
-
case '!==': return left !== right;
|
|
2293
|
-
case '<': return left < right;
|
|
2294
|
-
case '<=': return left <= right;
|
|
2295
|
-
case '>': return left > right;
|
|
2296
|
-
case '>=': return left >= right;
|
|
2297
|
-
case '<<': return left << right;
|
|
2298
|
-
case '>>': return left >> right;
|
|
2299
|
-
case '>>>': return left >>> right;
|
|
2300
|
-
case '+': return left + right;
|
|
2301
|
-
case '-': return left - right;
|
|
2302
|
-
case '*': return left * right;
|
|
2303
|
-
case '**': return Math.pow(left, right);
|
|
2304
|
-
case '/': return left / right;
|
|
2305
|
-
case '%': return left % right;
|
|
2306
|
-
case '|': return left | right;
|
|
2307
|
-
case '^': return left ^ right;
|
|
2308
|
-
case '&': return left & right;
|
|
2309
|
-
case 'in': return left in right;
|
|
2310
|
-
case 'instanceof': return left instanceof right;
|
|
2311
|
-
default: throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
2312
|
-
}
|
|
2313
|
-
}
|
|
2314
|
-
function AssignmentExpression(node, scope) {
|
|
2315
|
-
var _a;
|
|
2316
|
-
const left = node.left;
|
|
2317
|
-
let variable;
|
|
2318
|
-
if (left.type === 'Identifier') {
|
|
2319
|
-
variable = Identifier(left, scope, { getVar: true, throwErr: false });
|
|
2320
|
-
if (!variable) {
|
|
2321
|
-
const win = scope.global().find('window').get();
|
|
2322
|
-
variable = new Prop(win, left.name);
|
|
2323
|
-
}
|
|
2324
|
-
}
|
|
2325
|
-
else if (left.type === 'MemberExpression') {
|
|
2326
|
-
variable = MemberExpression(left, scope, { getVar: true });
|
|
2327
|
-
}
|
|
2328
|
-
else {
|
|
2329
|
-
const value = evaluate(node.right, scope);
|
|
2330
|
-
return pattern$1(left, scope, { feed: value });
|
|
2331
|
-
}
|
|
2332
|
-
const value = evaluate(node.right, scope);
|
|
2333
|
-
switch (node.operator) {
|
|
2334
|
-
case '=':
|
|
2335
|
-
variable.set(value);
|
|
2336
|
-
return variable.get();
|
|
2337
|
-
case '+=':
|
|
2338
|
-
variable.set(variable.get() + value);
|
|
2339
|
-
return variable.get();
|
|
2340
|
-
case '-=':
|
|
2341
|
-
variable.set(variable.get() - value);
|
|
2342
|
-
return variable.get();
|
|
2343
|
-
case '*=':
|
|
2344
|
-
variable.set(variable.get() * value);
|
|
2345
|
-
return variable.get();
|
|
2346
|
-
case '/=':
|
|
2347
|
-
variable.set(variable.get() / value);
|
|
2348
|
-
return variable.get();
|
|
2349
|
-
case '%=':
|
|
2350
|
-
variable.set(variable.get() % value);
|
|
2351
|
-
return variable.get();
|
|
2352
|
-
case '**=':
|
|
2353
|
-
variable.set(Math.pow(variable.get(), value));
|
|
2354
|
-
return variable.get();
|
|
2355
|
-
case '<<=':
|
|
2356
|
-
variable.set(variable.get() << value);
|
|
2357
|
-
return variable.get();
|
|
2358
|
-
case '>>=':
|
|
2359
|
-
variable.set(variable.get() >> value);
|
|
2360
|
-
return variable.get();
|
|
2361
|
-
case '>>>=':
|
|
2362
|
-
variable.set(variable.get() >>> value);
|
|
2363
|
-
return variable.get();
|
|
2364
|
-
case '|=':
|
|
2365
|
-
variable.set(variable.get() | value);
|
|
2366
|
-
return variable.get();
|
|
2367
|
-
case '^=':
|
|
2368
|
-
variable.set(variable.get() ^ value);
|
|
2369
|
-
return variable.get();
|
|
2370
|
-
case '&=':
|
|
2371
|
-
variable.set(variable.get() & value);
|
|
2372
|
-
return variable.get();
|
|
2373
|
-
case '??=':
|
|
2374
|
-
variable.set((_a = variable.get()) !== null && _a !== void 0 ? _a : value);
|
|
2375
|
-
return variable.get();
|
|
2376
|
-
case '&&=':
|
|
2377
|
-
variable.set(variable.get() && value);
|
|
2378
|
-
return variable.get();
|
|
2379
|
-
case '||=':
|
|
2380
|
-
variable.set(variable.get() || value);
|
|
2381
|
-
return variable.get();
|
|
2382
|
-
default: throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
2383
|
-
}
|
|
2384
|
-
}
|
|
2385
|
-
function LogicalExpression(node, scope) {
|
|
2386
|
-
var _a;
|
|
2387
|
-
switch (node.operator) {
|
|
2388
|
-
case '||':
|
|
2389
|
-
return (evaluate(node.left, scope)) || (evaluate(node.right, scope));
|
|
2390
|
-
case '&&':
|
|
2391
|
-
return (evaluate(node.left, scope)) && (evaluate(node.right, scope));
|
|
2392
|
-
case '??':
|
|
2393
|
-
return (_a = (evaluate(node.left, scope))) !== null && _a !== void 0 ? _a : (evaluate(node.right, scope));
|
|
2394
|
-
default:
|
|
2395
|
-
throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
2396
|
-
}
|
|
2397
|
-
}
|
|
2398
|
-
function MemberExpression(node, scope, options = {}) {
|
|
2399
|
-
const { getObj = false, getVar = false } = options;
|
|
2400
|
-
let object;
|
|
2401
|
-
if (node.object.type === 'Super') {
|
|
2402
|
-
object = Super(node.object, scope, { getProto: true });
|
|
2403
|
-
}
|
|
2404
|
-
else {
|
|
2405
|
-
object = evaluate(node.object, scope);
|
|
2406
|
-
}
|
|
2407
|
-
if (getObj)
|
|
2408
|
-
return object;
|
|
2409
|
-
let key;
|
|
2410
|
-
let priv = false;
|
|
2411
|
-
if (node.computed) {
|
|
2412
|
-
key = evaluate(node.property, scope);
|
|
2413
|
-
}
|
|
2414
|
-
else if (node.property.type === 'PrivateIdentifier') {
|
|
2415
|
-
key = node.property.name;
|
|
2416
|
-
priv = true;
|
|
2417
|
-
}
|
|
2418
|
-
else {
|
|
2419
|
-
key = node.property.name;
|
|
2420
|
-
}
|
|
2421
|
-
if (priv) {
|
|
2422
|
-
object = object[PRIVATE];
|
|
2423
|
-
}
|
|
2424
|
-
if (getVar) {
|
|
2425
|
-
const setter = getSetter(object, key);
|
|
2426
|
-
if (node.object.type === 'Super' && setter) {
|
|
2427
|
-
const thisObject = scope.find('this').get();
|
|
2428
|
-
const privateKey = createSymbol(key);
|
|
2429
|
-
define(thisObject, privateKey, { set: setter });
|
|
2430
|
-
return new Prop(thisObject, privateKey);
|
|
2431
|
-
}
|
|
2432
|
-
else {
|
|
2433
|
-
return new Prop(object, key);
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
else {
|
|
2437
|
-
const getter = getGetter(object, key);
|
|
2438
|
-
if (node.object.type === 'Super' && getter) {
|
|
2439
|
-
const thisObject = scope.find('this').get();
|
|
2440
|
-
if (node.optional && thisObject == null) {
|
|
2441
|
-
return undefined;
|
|
2442
|
-
}
|
|
2443
|
-
return getter.call(thisObject);
|
|
2444
|
-
}
|
|
2445
|
-
else {
|
|
2446
|
-
if (node.optional && object == null) {
|
|
2447
|
-
return undefined;
|
|
2448
|
-
}
|
|
2449
|
-
return object[key];
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
}
|
|
2453
|
-
function ConditionalExpression(node, scope) {
|
|
2454
|
-
return (evaluate(node.test, scope))
|
|
2455
|
-
? (evaluate(node.consequent, scope))
|
|
2456
|
-
: (evaluate(node.alternate, scope));
|
|
2457
|
-
}
|
|
2458
|
-
function CallExpression(node, scope) {
|
|
2459
|
-
let func;
|
|
2460
|
-
let object;
|
|
2461
|
-
if (node.callee.type === 'MemberExpression') {
|
|
2462
|
-
object = MemberExpression(node.callee, scope, { getObj: true });
|
|
2463
|
-
if (node.callee.optional && object == null) {
|
|
2464
|
-
return undefined;
|
|
2465
|
-
}
|
|
2466
|
-
let key;
|
|
2467
|
-
let priv = false;
|
|
2468
|
-
if (node.callee.computed) {
|
|
2469
|
-
key = evaluate(node.callee.property, scope);
|
|
2470
|
-
}
|
|
2471
|
-
else if (node.callee.property.type === 'PrivateIdentifier') {
|
|
2472
|
-
key = node.callee.property.name;
|
|
2473
|
-
priv = true;
|
|
2474
|
-
}
|
|
2475
|
-
else {
|
|
2476
|
-
key = node.callee.property.name;
|
|
2477
|
-
}
|
|
2478
|
-
let obj = object;
|
|
2479
|
-
if (priv) {
|
|
2480
|
-
obj = obj[PRIVATE];
|
|
2481
|
-
}
|
|
2482
|
-
if (node.callee.object.type === 'Super') {
|
|
2483
|
-
const thisObject = scope.find('this').get();
|
|
2484
|
-
func = obj[key].bind(thisObject);
|
|
2485
|
-
}
|
|
2486
|
-
else {
|
|
2487
|
-
func = obj[key];
|
|
2488
|
-
}
|
|
2489
|
-
if (node.optional && func == null) {
|
|
2490
|
-
return undefined;
|
|
2491
|
-
}
|
|
2492
|
-
if (typeof func !== 'function') {
|
|
2493
|
-
throw new TypeError(`${key} is not a function`);
|
|
2494
|
-
}
|
|
2495
|
-
else if (func[CLSCTOR]) {
|
|
2496
|
-
throw new TypeError(`Class constructor ${key} cannot be invoked without 'new'`);
|
|
2497
|
-
}
|
|
2498
|
-
}
|
|
2499
|
-
else {
|
|
2500
|
-
object = scope.find('this').get();
|
|
2501
|
-
func = evaluate(node.callee, scope);
|
|
2502
|
-
if (node.optional && func == null) {
|
|
2503
|
-
return undefined;
|
|
2504
|
-
}
|
|
2505
|
-
if (typeof func !== 'function' || node.callee.type !== 'Super' && func[CLSCTOR]) {
|
|
2506
|
-
let name;
|
|
2507
|
-
if (node.callee.type === 'Identifier') {
|
|
2508
|
-
name = node.callee.name;
|
|
2509
|
-
}
|
|
2510
|
-
else {
|
|
2511
|
-
try {
|
|
2512
|
-
name = JSON.stringify(func);
|
|
2513
|
-
}
|
|
2514
|
-
catch (err) {
|
|
2515
|
-
name = '' + func;
|
|
2516
|
-
}
|
|
2517
|
-
}
|
|
2518
|
-
if (typeof func !== 'function') {
|
|
2519
|
-
throw new TypeError(`${name} is not a function`);
|
|
2520
|
-
}
|
|
2521
|
-
else {
|
|
2522
|
-
throw new TypeError(`Class constructor ${name} cannot be invoked without 'new'`);
|
|
2523
|
-
}
|
|
2524
|
-
}
|
|
2525
|
-
}
|
|
2526
|
-
let args = [];
|
|
2527
|
-
for (let i = 0; i < node.arguments.length; i++) {
|
|
2528
|
-
const arg = node.arguments[i];
|
|
2529
|
-
if (arg.type === 'SpreadElement') {
|
|
2530
|
-
args = args.concat(SpreadElement(arg, scope));
|
|
2531
|
-
}
|
|
2532
|
-
else {
|
|
2533
|
-
args.push(evaluate(arg, scope));
|
|
2534
|
-
}
|
|
2535
|
-
}
|
|
2536
|
-
if (node.callee.type === 'Super') {
|
|
2537
|
-
const superCall = scope.find(SUPERCALL);
|
|
2538
|
-
const construct = superCall.get();
|
|
2539
|
-
if (construct === true) {
|
|
2540
|
-
throw new ReferenceError('Super constructor may only be called once');
|
|
2541
|
-
}
|
|
2542
|
-
const inst = callSuper(object, func, args);
|
|
2543
|
-
construct(inst);
|
|
2544
|
-
scope.find('this').set(inst);
|
|
2545
|
-
scope.find(SUPERCALL).set(true);
|
|
2546
|
-
return inst;
|
|
2547
|
-
}
|
|
2548
|
-
try {
|
|
2549
|
-
return func.apply(object, args);
|
|
2550
|
-
}
|
|
2551
|
-
catch (err) {
|
|
2552
|
-
if (err instanceof TypeError && err.message === 'Illegal invocation'
|
|
2553
|
-
&& func.toString().indexOf('[native code]') !== -1) {
|
|
2554
|
-
const win = scope.global().find('window').get();
|
|
2555
|
-
if (win && win[WINDOW]) {
|
|
2556
|
-
return func.apply(win[WINDOW], args);
|
|
2557
|
-
}
|
|
2558
|
-
}
|
|
2559
|
-
throw err;
|
|
2560
|
-
}
|
|
2561
|
-
}
|
|
2562
|
-
function NewExpression(node, scope) {
|
|
2563
|
-
const constructor = evaluate(node.callee, scope);
|
|
2564
|
-
if (typeof constructor !== 'function') {
|
|
2565
|
-
let name;
|
|
2566
|
-
if (node.callee.type === 'Identifier') {
|
|
2567
|
-
name = node.callee.name;
|
|
2568
|
-
}
|
|
2569
|
-
else {
|
|
2570
|
-
try {
|
|
2571
|
-
name = JSON.stringify(constructor);
|
|
2572
|
-
}
|
|
2573
|
-
catch (err) {
|
|
2574
|
-
name = '' + constructor;
|
|
2575
|
-
}
|
|
2576
|
-
}
|
|
2577
|
-
throw new TypeError(`${name} is not a constructor`);
|
|
2578
|
-
}
|
|
2579
|
-
else if (constructor[NOCTOR]) {
|
|
2580
|
-
throw new TypeError(`${constructor.name || '(intermediate value)'} is not a constructor`);
|
|
2581
|
-
}
|
|
2582
|
-
let args = [];
|
|
2583
|
-
for (let i = 0; i < node.arguments.length; i++) {
|
|
2584
|
-
const arg = node.arguments[i];
|
|
2585
|
-
if (arg.type === 'SpreadElement') {
|
|
2586
|
-
args = args.concat(SpreadElement(arg, scope));
|
|
2587
|
-
}
|
|
2588
|
-
else {
|
|
2589
|
-
args.push(evaluate(arg, scope));
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
return new constructor(...args);
|
|
2593
|
-
}
|
|
2594
|
-
function MetaProperty(node, scope) {
|
|
2595
|
-
if (node.meta.name === 'new' && node.property.name === 'target') {
|
|
2596
|
-
return scope.find(NEWTARGET).get();
|
|
2597
|
-
}
|
|
2598
|
-
else if (node.meta.name === 'import' && node.property.name === 'meta') {
|
|
2599
|
-
return { url: '' };
|
|
2600
|
-
}
|
|
2601
|
-
}
|
|
2602
|
-
function SequenceExpression(node, scope) {
|
|
2603
|
-
let result;
|
|
2604
|
-
for (let i = 0; i < node.expressions.length; i++) {
|
|
2605
|
-
result = evaluate(node.expressions[i], scope);
|
|
2606
|
-
}
|
|
2607
|
-
return result;
|
|
2608
|
-
}
|
|
2609
|
-
function ArrowFunctionExpression(node, scope) {
|
|
2610
|
-
return createFunc$1(node, scope);
|
|
2611
|
-
}
|
|
2612
|
-
function TemplateLiteral(node, scope) {
|
|
2613
|
-
const quasis = node.quasis.slice();
|
|
2614
|
-
const expressions = node.expressions.slice();
|
|
2615
|
-
let result = '';
|
|
2616
|
-
let temEl;
|
|
2617
|
-
let expr;
|
|
2618
|
-
while (temEl = quasis.shift()) {
|
|
2619
|
-
result += TemplateElement(temEl);
|
|
2620
|
-
expr = expressions.shift();
|
|
2621
|
-
if (expr) {
|
|
2622
|
-
result += evaluate(expr, scope);
|
|
2623
|
-
}
|
|
2624
|
-
}
|
|
2625
|
-
return result;
|
|
2626
|
-
}
|
|
2627
|
-
function TaggedTemplateExpression(node, scope) {
|
|
2628
|
-
const tagFunc = evaluate(node.tag, scope);
|
|
2629
|
-
const quasis = node.quasi.quasis;
|
|
2630
|
-
const str = quasis.map(v => v.value.cooked);
|
|
2631
|
-
const raw = quasis.map(v => v.value.raw);
|
|
2632
|
-
define(str, 'raw', {
|
|
2633
|
-
value: freeze(raw)
|
|
2634
|
-
});
|
|
2635
|
-
const expressions = node.quasi.expressions;
|
|
2636
|
-
const args = [];
|
|
2637
|
-
if (expressions) {
|
|
2638
|
-
for (let i = 0; i < expressions.length; i++) {
|
|
2639
|
-
args.push(evaluate(expressions[i], scope));
|
|
2640
|
-
}
|
|
2641
|
-
}
|
|
2642
|
-
return tagFunc(freeze(str), ...args);
|
|
2643
|
-
}
|
|
2644
|
-
function TemplateElement(node, scope) {
|
|
2645
|
-
return node.value.raw;
|
|
2646
|
-
}
|
|
2647
|
-
function ClassExpression(node, scope) {
|
|
2648
|
-
if (node.id && node.id.name) {
|
|
2649
|
-
const tmpScope = new Scope(scope);
|
|
2650
|
-
const klass = createClass$1(node, tmpScope);
|
|
2651
|
-
tmpScope.const(node.id.name, klass);
|
|
2652
|
-
return klass;
|
|
2653
|
-
}
|
|
2654
|
-
else {
|
|
2655
|
-
return createClass$1(node, scope);
|
|
2656
|
-
}
|
|
2657
|
-
}
|
|
2658
|
-
function Super(node, scope, options = {}) {
|
|
2659
|
-
const { getProto = false } = options;
|
|
2660
|
-
const superClass = scope.find(SUPER).get();
|
|
2661
|
-
return getProto ? superClass.prototype : superClass;
|
|
2662
|
-
}
|
|
2663
|
-
function SpreadElement(node, scope, options = {}) {
|
|
2664
|
-
const result = evaluate(node.argument, scope);
|
|
2665
|
-
if (options.spreadProps) {
|
|
2666
|
-
return result;
|
|
2667
|
-
}
|
|
2668
|
-
if (typeof Symbol === 'function' && typeof result[Symbol.iterator] !== 'function') {
|
|
2669
|
-
throw new TypeError('Spread syntax requires ...iterable[Symbol.iterator] to be a function');
|
|
2670
|
-
}
|
|
2671
|
-
return [...result];
|
|
2672
|
-
}
|
|
2673
|
-
function ChainExpression(node, scope) {
|
|
2674
|
-
return evaluate(node.expression, scope);
|
|
2675
|
-
}
|
|
2676
|
-
function ImportExpression(node, scope) {
|
|
2677
|
-
const globalScope = scope.global();
|
|
2678
|
-
const source = evaluate(node.source, scope);
|
|
2679
|
-
const module = globalScope.find(IMPORT + source);
|
|
2680
|
-
let value;
|
|
2681
|
-
if (module) {
|
|
2682
|
-
const result = module.get();
|
|
2683
|
-
if (result) {
|
|
2684
|
-
if (typeof result === 'function') {
|
|
2685
|
-
value = result();
|
|
2686
|
-
}
|
|
2687
|
-
else if (typeof result === 'object') {
|
|
2688
|
-
value = result;
|
|
2689
|
-
}
|
|
2690
|
-
}
|
|
2691
|
-
}
|
|
2692
|
-
if (!value || typeof value !== 'object') {
|
|
2693
|
-
return Promise.reject(new TypeError(`Failed to resolve module specifier "${source}"`));
|
|
2694
|
-
}
|
|
2695
|
-
return Promise.resolve(value);
|
|
2696
|
-
}
|
|
2697
|
-
|
|
2698
|
-
var expression = /*#__PURE__*/Object.freeze({
|
|
2699
|
-
__proto__: null,
|
|
2700
|
-
ThisExpression: ThisExpression,
|
|
2701
|
-
ArrayExpression: ArrayExpression,
|
|
2702
|
-
ObjectExpression: ObjectExpression,
|
|
2703
|
-
FunctionExpression: FunctionExpression,
|
|
2704
|
-
UnaryExpression: UnaryExpression,
|
|
2705
|
-
UpdateExpression: UpdateExpression,
|
|
2706
|
-
BinaryExpression: BinaryExpression,
|
|
2707
|
-
AssignmentExpression: AssignmentExpression,
|
|
2708
|
-
LogicalExpression: LogicalExpression,
|
|
2709
|
-
MemberExpression: MemberExpression,
|
|
2710
|
-
ConditionalExpression: ConditionalExpression,
|
|
2711
|
-
CallExpression: CallExpression,
|
|
2712
|
-
NewExpression: NewExpression,
|
|
2713
|
-
MetaProperty: MetaProperty,
|
|
2714
|
-
SequenceExpression: SequenceExpression,
|
|
2715
|
-
ArrowFunctionExpression: ArrowFunctionExpression,
|
|
2716
|
-
TemplateLiteral: TemplateLiteral,
|
|
2717
|
-
TaggedTemplateExpression: TaggedTemplateExpression,
|
|
2718
|
-
TemplateElement: TemplateElement,
|
|
2719
|
-
ClassExpression: ClassExpression,
|
|
2720
|
-
Super: Super,
|
|
2721
|
-
SpreadElement: SpreadElement,
|
|
2722
|
-
ChainExpression: ChainExpression,
|
|
2723
|
-
ImportExpression: ImportExpression
|
|
2724
|
-
});
|
|
2725
|
-
|
|
2726
|
-
function ObjectPattern(node, scope, options = {}) {
|
|
2727
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed = {} } = options;
|
|
2728
|
-
const fedKeys = [];
|
|
2729
|
-
for (let i = 0; i < node.properties.length; i++) {
|
|
2730
|
-
const property = node.properties[i];
|
|
2731
|
-
if (hoist) {
|
|
2732
|
-
if (onlyBlock || kind === 'var') {
|
|
2733
|
-
if (property.type === 'Property') {
|
|
2734
|
-
const value = property.value;
|
|
2735
|
-
if (value.type === 'Identifier') {
|
|
2736
|
-
scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2737
|
-
}
|
|
2738
|
-
else {
|
|
2739
|
-
pattern$1(value, scope, { kind, hoist, onlyBlock });
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
else {
|
|
2743
|
-
RestElement(property, scope, { kind, hoist, onlyBlock });
|
|
2744
|
-
}
|
|
2745
|
-
}
|
|
2746
|
-
}
|
|
2747
|
-
else if (property.type === 'Property') {
|
|
2748
|
-
let key;
|
|
2749
|
-
if (property.computed) {
|
|
2750
|
-
key = evaluate(property.key, scope);
|
|
2751
|
-
}
|
|
2752
|
-
else {
|
|
2753
|
-
key = property.key.name;
|
|
2754
|
-
}
|
|
2755
|
-
fedKeys.push(key);
|
|
2756
|
-
const value = property.value;
|
|
2757
|
-
if (value.type === 'Identifier') {
|
|
2758
|
-
scope[kind](value.name, feed[key]);
|
|
2759
|
-
}
|
|
2760
|
-
else {
|
|
2761
|
-
pattern$1(value, scope, { kind, feed: feed[key] });
|
|
2762
|
-
}
|
|
2763
|
-
}
|
|
2764
|
-
else {
|
|
2765
|
-
const rest = assign({}, feed);
|
|
2766
|
-
for (let i = 0; i < fedKeys.length; i++)
|
|
2767
|
-
delete rest[fedKeys[i]];
|
|
2768
|
-
RestElement(property, scope, { kind, feed: rest });
|
|
2769
|
-
}
|
|
2770
|
-
}
|
|
2771
|
-
}
|
|
2772
|
-
function ArrayPattern(node, scope, options = {}) {
|
|
2773
|
-
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
2774
|
-
const result = [];
|
|
2775
|
-
for (let i = 0; i < node.elements.length; i++) {
|
|
2776
|
-
const element = node.elements[i];
|
|
2777
|
-
if (!element)
|
|
2778
|
-
continue;
|
|
2779
|
-
if (hoist) {
|
|
2780
|
-
if (onlyBlock || kind === 'var') {
|
|
2781
|
-
if (element.type === 'Identifier') {
|
|
2782
|
-
scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2783
|
-
}
|
|
2784
|
-
else {
|
|
2785
|
-
pattern$1(element, scope, { kind, hoist, onlyBlock });
|
|
2786
|
-
}
|
|
2787
|
-
}
|
|
2788
|
-
}
|
|
2789
|
-
else if (element.type === 'Identifier') {
|
|
2790
|
-
if (kind) {
|
|
2791
|
-
scope[kind](element.name, feed[i]);
|
|
2792
|
-
}
|
|
2793
|
-
else {
|
|
2794
|
-
const variable = Identifier(element, scope, { getVar: true });
|
|
2795
|
-
variable.set(feed[i]);
|
|
2796
|
-
result.push(variable.get());
|
|
2797
|
-
}
|
|
2798
|
-
}
|
|
2799
|
-
else if (element.type === 'RestElement') {
|
|
2800
|
-
RestElement(element, scope, { kind, feed: feed.slice(i) });
|
|
2801
|
-
}
|
|
2802
|
-
else {
|
|
2803
|
-
pattern$1(element, scope, { kind, feed: feed[i] });
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2806
|
-
if (result.length) {
|
|
2807
|
-
return result;
|
|
2808
|
-
}
|
|
2809
|
-
}
|
|
2810
|
-
function RestElement(node, scope, options = {}) {
|
|
2811
|
-
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
2812
|
-
const arg = node.argument;
|
|
2813
|
-
if (hoist) {
|
|
2814
|
-
if (onlyBlock || kind === 'var') {
|
|
2815
|
-
if (arg.type === 'Identifier') {
|
|
2816
|
-
scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2817
|
-
}
|
|
2818
|
-
else {
|
|
2819
|
-
pattern$1(arg, scope, { kind, hoist, onlyBlock });
|
|
2820
|
-
}
|
|
2821
|
-
}
|
|
2822
|
-
}
|
|
2823
|
-
else if (arg.type === 'Identifier') {
|
|
2824
|
-
if (kind) {
|
|
2825
|
-
scope[kind](arg.name, feed);
|
|
2826
|
-
}
|
|
2827
|
-
else {
|
|
2828
|
-
const variable = Identifier(arg, scope, { getVar: true });
|
|
2829
|
-
variable.set(feed);
|
|
2830
|
-
}
|
|
2831
|
-
}
|
|
2832
|
-
else {
|
|
2833
|
-
pattern$1(arg, scope, { kind, feed });
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2836
|
-
function AssignmentPattern(node, scope, options = {}) {
|
|
2837
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed = evaluate(node.right, scope) } = options;
|
|
2838
|
-
const left = node.left;
|
|
2839
|
-
if (hoist) {
|
|
2840
|
-
if (onlyBlock || kind === 'var') {
|
|
2841
|
-
if (left.type === 'Identifier') {
|
|
2842
|
-
scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2843
|
-
}
|
|
2844
|
-
else {
|
|
2845
|
-
pattern$1(left, scope, { kind, hoist, onlyBlock });
|
|
2846
|
-
}
|
|
2847
|
-
}
|
|
2848
|
-
}
|
|
2849
|
-
else if (left.type === 'Identifier') {
|
|
2850
|
-
scope[kind](left.name, feed);
|
|
2851
|
-
}
|
|
2852
|
-
else {
|
|
2853
|
-
pattern$1(left, scope, { kind, feed });
|
|
2854
|
-
}
|
|
2855
|
-
}
|
|
2856
|
-
|
|
2857
|
-
var pattern$2 = /*#__PURE__*/Object.freeze({
|
|
2858
|
-
__proto__: null,
|
|
2859
|
-
ObjectPattern: ObjectPattern,
|
|
2860
|
-
ArrayPattern: ArrayPattern,
|
|
2861
|
-
RestElement: RestElement,
|
|
2862
|
-
AssignmentPattern: AssignmentPattern
|
|
2863
|
-
});
|
|
2864
|
-
|
|
2865
|
-
function Program(program, scope) {
|
|
2866
|
-
for (let i = 0; i < program.body.length; i++) {
|
|
2867
|
-
evaluate(program.body[i], scope);
|
|
2868
|
-
}
|
|
2869
|
-
}
|
|
2870
|
-
|
|
2871
|
-
var program = /*#__PURE__*/Object.freeze({
|
|
2872
|
-
__proto__: null,
|
|
2873
|
-
Program: Program
|
|
2874
|
-
});
|
|
2875
|
-
|
|
2876
|
-
let evaluateOps;
|
|
2877
|
-
function evaluate(node, scope) {
|
|
2878
|
-
if (!node)
|
|
2879
|
-
return;
|
|
2880
|
-
if (!evaluateOps) {
|
|
2881
|
-
evaluateOps = assign({}, declaration, expression, identifier, statement, literal, pattern$2, program);
|
|
2882
|
-
}
|
|
2883
|
-
const handler = evaluateOps[node.type];
|
|
2884
|
-
if (handler) {
|
|
2885
|
-
return handler(node, scope);
|
|
2886
|
-
}
|
|
2887
|
-
else {
|
|
2888
|
-
throw new Error(`${node.type} isn't implemented`);
|
|
2889
|
-
}
|
|
2890
|
-
}
|
|
2891
|
-
|
|
2892
|
-
function ExpressionStatement(node, scope) {
|
|
2893
|
-
evaluate(node.expression, scope);
|
|
2894
|
-
}
|
|
2895
|
-
function BlockStatement(block, scope, options = {}) {
|
|
2896
|
-
const { invasived = false, hoisted = false, } = options;
|
|
2897
|
-
const subScope = invasived ? scope : new Scope(scope);
|
|
2898
|
-
if (!hoisted) {
|
|
2899
|
-
hoist$1(block, subScope, { onlyBlock: true });
|
|
2900
|
-
}
|
|
2901
|
-
for (let i = 0; i < block.body.length; i++) {
|
|
2902
|
-
const result = evaluate(block.body[i], subScope);
|
|
2903
|
-
if (result === BREAK) {
|
|
2904
|
-
if (result.LABEL && result.LABEL === options.label) {
|
|
2905
|
-
break;
|
|
2906
|
-
}
|
|
2907
|
-
return result;
|
|
2908
|
-
}
|
|
2909
|
-
if (result === CONTINUE || result === RETURN) {
|
|
2910
|
-
return result;
|
|
2911
|
-
}
|
|
2912
|
-
}
|
|
2913
|
-
}
|
|
2914
|
-
function EmptyStatement() {
|
|
2915
|
-
}
|
|
2916
|
-
function DebuggerStatement() {
|
|
2917
|
-
debugger;
|
|
2918
|
-
}
|
|
2919
|
-
function ReturnStatement(node, scope) {
|
|
2920
|
-
RETURN.RES = node.argument ? (evaluate(node.argument, scope)) : undefined;
|
|
2921
|
-
return RETURN;
|
|
2922
|
-
}
|
|
2923
|
-
function BreakStatement(node) {
|
|
2924
|
-
var _a;
|
|
2925
|
-
BREAK.LABEL = (_a = node.label) === null || _a === void 0 ? void 0 : _a.name;
|
|
2926
|
-
return BREAK;
|
|
2927
|
-
}
|
|
2928
|
-
function ContinueStatement(node) {
|
|
2929
|
-
var _a;
|
|
2930
|
-
CONTINUE.LABEL = (_a = node.label) === null || _a === void 0 ? void 0 : _a.name;
|
|
2931
|
-
return CONTINUE;
|
|
2932
|
-
}
|
|
2933
|
-
function LabeledStatement(node, scope) {
|
|
2934
|
-
const label = node.label.name;
|
|
2935
|
-
if (node.body.type === 'WhileStatement') {
|
|
2936
|
-
return WhileStatement(node.body, scope, { label });
|
|
2937
|
-
}
|
|
2938
|
-
if (node.body.type === 'DoWhileStatement') {
|
|
2939
|
-
return DoWhileStatement(node.body, scope, { label });
|
|
2940
|
-
}
|
|
2941
|
-
if (node.body.type === 'ForStatement') {
|
|
2942
|
-
return ForStatement(node.body, scope, { label });
|
|
2943
|
-
}
|
|
2944
|
-
if (node.body.type === 'ForInStatement') {
|
|
2945
|
-
return ForInStatement(node.body, scope, { label });
|
|
2946
|
-
}
|
|
2947
|
-
if (node.body.type === 'ForOfStatement') {
|
|
2948
|
-
return ForOfStatement(node.body, scope, { label });
|
|
2949
|
-
}
|
|
2950
|
-
if (node.body.type === 'BlockStatement') {
|
|
2951
|
-
return BlockStatement(node.body, scope, { label });
|
|
2952
|
-
}
|
|
2953
|
-
if (node.body.type === 'WithStatement') {
|
|
2954
|
-
return WithStatement(node.body, scope, { label });
|
|
2955
|
-
}
|
|
2956
|
-
if (node.body.type === 'IfStatement') {
|
|
2957
|
-
return IfStatement(node.body, scope, { label });
|
|
2958
|
-
}
|
|
2959
|
-
if (node.body.type === 'SwitchStatement') {
|
|
2960
|
-
return SwitchStatement(node.body, scope, { label });
|
|
2961
|
-
}
|
|
2962
|
-
if (node.body.type === 'TryStatement') {
|
|
2963
|
-
return TryStatement(node.body, scope, { label });
|
|
2964
|
-
}
|
|
2965
|
-
throw new SyntaxError(`${node.body.type} cannot be labeled`);
|
|
2966
|
-
}
|
|
2967
|
-
function WithStatement(node, scope, options = {}) {
|
|
2968
|
-
const withScope = new Scope(scope);
|
|
2969
|
-
withScope.with(evaluate(node.object, scope));
|
|
2970
|
-
const result = evaluate(node.body, withScope);
|
|
2971
|
-
if (result === BREAK) {
|
|
2972
|
-
if (result.LABEL && result.LABEL === options.label) {
|
|
2973
|
-
return;
|
|
2974
|
-
}
|
|
2975
|
-
return result;
|
|
2976
|
-
}
|
|
2977
|
-
if (result === CONTINUE || result === RETURN) {
|
|
2978
|
-
return result;
|
|
2979
|
-
}
|
|
2980
|
-
}
|
|
2981
|
-
function IfStatement(node, scope, options = {}) {
|
|
2982
|
-
let result;
|
|
2983
|
-
if (evaluate(node.test, scope)) {
|
|
2984
|
-
result = evaluate(node.consequent, scope);
|
|
2985
|
-
}
|
|
2986
|
-
else {
|
|
2987
|
-
result = evaluate(node.alternate, scope);
|
|
2988
|
-
}
|
|
2989
|
-
if (result === BREAK) {
|
|
2990
|
-
if (result.LABEL && result.LABEL === options.label) {
|
|
2991
|
-
return;
|
|
2992
|
-
}
|
|
2993
|
-
return result;
|
|
2994
|
-
}
|
|
2995
|
-
if (result === CONTINUE || result === RETURN) {
|
|
2996
|
-
return result;
|
|
2997
|
-
}
|
|
2998
|
-
}
|
|
2999
|
-
function SwitchStatement(node, scope, options = {}) {
|
|
3000
|
-
const discriminant = evaluate(node.discriminant, scope);
|
|
3001
|
-
let matched = false;
|
|
3002
|
-
for (let i = 0; i < node.cases.length; i++) {
|
|
3003
|
-
const eachCase = node.cases[i];
|
|
3004
|
-
if (!matched
|
|
3005
|
-
&& (!eachCase.test
|
|
3006
|
-
|| (evaluate(eachCase.test, scope)) === discriminant)) {
|
|
3007
|
-
matched = true;
|
|
3008
|
-
}
|
|
3009
|
-
if (matched) {
|
|
3010
|
-
const result = SwitchCase(eachCase, scope);
|
|
3011
|
-
if (result === BREAK) {
|
|
3012
|
-
if (result.LABEL === options.label) {
|
|
3013
|
-
break;
|
|
3014
|
-
}
|
|
3015
|
-
return result;
|
|
3016
|
-
}
|
|
3017
|
-
if (result === CONTINUE || result === RETURN) {
|
|
3018
|
-
return result;
|
|
3019
|
-
}
|
|
3020
|
-
}
|
|
3021
|
-
}
|
|
3022
|
-
}
|
|
3023
|
-
function SwitchCase(node, scope) {
|
|
3024
|
-
for (let i = 0; i < node.consequent.length; i++) {
|
|
3025
|
-
const result = evaluate(node.consequent[i], scope);
|
|
3026
|
-
if (result === BREAK || result === CONTINUE || result === RETURN) {
|
|
3027
|
-
return result;
|
|
3028
|
-
}
|
|
3029
|
-
}
|
|
3030
|
-
}
|
|
3031
|
-
function ThrowStatement(node, scope) {
|
|
3032
|
-
throw evaluate(node.argument, scope);
|
|
3033
|
-
}
|
|
3034
|
-
function TryStatement(node, scope, options = {}) {
|
|
3035
|
-
let result;
|
|
3036
|
-
try {
|
|
3037
|
-
result = BlockStatement(node.block, scope);
|
|
3038
|
-
}
|
|
3039
|
-
catch (err) {
|
|
3040
|
-
if (node.handler) {
|
|
3041
|
-
const subScope = new Scope(scope);
|
|
3042
|
-
const param = node.handler.param;
|
|
3043
|
-
if (param) {
|
|
3044
|
-
if (param.type === 'Identifier') {
|
|
3045
|
-
const name = param.name;
|
|
3046
|
-
subScope.var(name, err);
|
|
3047
|
-
}
|
|
3048
|
-
else {
|
|
3049
|
-
pattern$1(param, scope, { feed: err });
|
|
3050
|
-
}
|
|
3051
|
-
}
|
|
3052
|
-
result = CatchClause(node.handler, subScope);
|
|
3053
|
-
}
|
|
3054
|
-
else {
|
|
3055
|
-
throw err;
|
|
3056
|
-
}
|
|
3057
|
-
}
|
|
3058
|
-
finally {
|
|
3059
|
-
if (node.finalizer) {
|
|
3060
|
-
result = BlockStatement(node.finalizer, scope);
|
|
3061
|
-
}
|
|
3062
|
-
}
|
|
3063
|
-
if (result === BREAK) {
|
|
3064
|
-
if (result.LABEL && result.LABEL === options.label) {
|
|
3065
|
-
return;
|
|
3066
|
-
}
|
|
3067
|
-
return result;
|
|
3068
|
-
}
|
|
3069
|
-
if (result === CONTINUE || result === RETURN) {
|
|
3070
|
-
return result;
|
|
3071
|
-
}
|
|
3072
|
-
}
|
|
3073
|
-
function CatchClause(node, scope) {
|
|
3074
|
-
return BlockStatement(node.body, scope, { invasived: true });
|
|
3075
|
-
}
|
|
3076
|
-
function WhileStatement(node, scope, options = {}) {
|
|
3077
|
-
while (evaluate(node.test, scope)) {
|
|
3078
|
-
const result = evaluate(node.body, scope);
|
|
3079
|
-
if (result === BREAK) {
|
|
3080
|
-
if (result.LABEL === options.label) {
|
|
3081
|
-
break;
|
|
3082
|
-
}
|
|
3083
|
-
return result;
|
|
3084
|
-
}
|
|
3085
|
-
else if (result === CONTINUE) {
|
|
3086
|
-
if (result.LABEL === options.label) {
|
|
3087
|
-
continue;
|
|
3088
|
-
}
|
|
3089
|
-
return result;
|
|
3090
|
-
}
|
|
3091
|
-
else if (result === RETURN) {
|
|
3092
|
-
return result;
|
|
3093
|
-
}
|
|
3094
|
-
}
|
|
3095
|
-
}
|
|
3096
|
-
function DoWhileStatement(node, scope, options = {}) {
|
|
3097
|
-
do {
|
|
3098
|
-
const result = evaluate(node.body, scope);
|
|
3099
|
-
if (result === BREAK) {
|
|
3100
|
-
if (result.LABEL === options.label) {
|
|
3101
|
-
break;
|
|
3102
|
-
}
|
|
3103
|
-
return result;
|
|
3104
|
-
}
|
|
3105
|
-
else if (result === CONTINUE) {
|
|
3106
|
-
if (result.LABEL === options.label) {
|
|
3107
|
-
continue;
|
|
3108
|
-
}
|
|
3109
|
-
return result;
|
|
3110
|
-
}
|
|
3111
|
-
else if (result === RETURN) {
|
|
3112
|
-
return result;
|
|
3113
|
-
}
|
|
3114
|
-
} while (evaluate(node.test, scope));
|
|
3115
|
-
}
|
|
3116
|
-
function ForStatement(node, scope, options = {}) {
|
|
3117
|
-
const forScope = new Scope(scope);
|
|
3118
|
-
for (evaluate(node.init, forScope); node.test ? (evaluate(node.test, forScope)) : true; evaluate(node.update, forScope)) {
|
|
3119
|
-
const subScope = new Scope(forScope);
|
|
3120
|
-
let result;
|
|
3121
|
-
if (node.body.type === 'BlockStatement') {
|
|
3122
|
-
result = BlockStatement(node.body, subScope, { invasived: true });
|
|
3123
|
-
}
|
|
3124
|
-
else {
|
|
3125
|
-
result = evaluate(node.body, subScope);
|
|
3126
|
-
}
|
|
3127
|
-
if (result === BREAK) {
|
|
3128
|
-
if (result.LABEL === options.label) {
|
|
3129
|
-
break;
|
|
3130
|
-
}
|
|
3131
|
-
return result;
|
|
3132
|
-
}
|
|
3133
|
-
else if (result === CONTINUE) {
|
|
3134
|
-
if (result.LABEL === options.label) {
|
|
3135
|
-
continue;
|
|
3136
|
-
}
|
|
3137
|
-
return result;
|
|
3138
|
-
}
|
|
3139
|
-
else if (result === RETURN) {
|
|
3140
|
-
return result;
|
|
3141
|
-
}
|
|
3142
|
-
}
|
|
3143
|
-
}
|
|
3144
|
-
function ForInStatement(node, scope, options = {}) {
|
|
3145
|
-
for (const value in evaluate(node.right, scope)) {
|
|
3146
|
-
const result = ForXHandler$1(node, scope, { value });
|
|
3147
|
-
if (result === BREAK) {
|
|
3148
|
-
if (result.LABEL === options.label) {
|
|
3149
|
-
break;
|
|
3150
|
-
}
|
|
3151
|
-
return result;
|
|
3152
|
-
}
|
|
3153
|
-
else if (result === CONTINUE) {
|
|
3154
|
-
if (result.LABEL === options.label) {
|
|
3155
|
-
continue;
|
|
3156
|
-
}
|
|
3157
|
-
return result;
|
|
3158
|
-
}
|
|
3159
|
-
else if (result === RETURN) {
|
|
3160
|
-
return result;
|
|
3161
|
-
}
|
|
3162
|
-
}
|
|
3163
|
-
}
|
|
3164
|
-
function ForOfStatement(node, scope, options = {}) {
|
|
3165
|
-
const right = evaluate(node.right, scope);
|
|
3166
|
-
for (const value of right) {
|
|
3167
|
-
const result = ForXHandler$1(node, scope, { value });
|
|
3168
|
-
if (result === BREAK) {
|
|
3169
|
-
if (result.LABEL === options.label) {
|
|
3170
|
-
break;
|
|
3171
|
-
}
|
|
3172
|
-
return result;
|
|
3173
|
-
}
|
|
3174
|
-
else if (result === CONTINUE) {
|
|
3175
|
-
if (result.LABEL === options.label) {
|
|
3176
|
-
continue;
|
|
3177
|
-
}
|
|
3178
|
-
return result;
|
|
3179
|
-
}
|
|
3180
|
-
else if (result === RETURN) {
|
|
3181
|
-
return result;
|
|
3182
|
-
}
|
|
3183
|
-
}
|
|
3184
|
-
}
|
|
3185
|
-
|
|
3186
|
-
function FunctionDeclaration(node, scope) {
|
|
3187
|
-
scope.func(node.id.name, createFunc$1(node, scope));
|
|
3188
|
-
}
|
|
3189
|
-
function VariableDeclaration(node, scope, options = {}) {
|
|
3190
|
-
for (let i = 0; i < node.declarations.length; i++) {
|
|
3191
|
-
VariableDeclarator(node.declarations[i], scope, assign({ kind: node.kind }, options));
|
|
3192
|
-
}
|
|
3193
|
-
}
|
|
3194
|
-
function VariableDeclarator(node, scope, options = {}) {
|
|
3195
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed } = options;
|
|
3196
|
-
if (hoist) {
|
|
3197
|
-
if (onlyBlock || kind === 'var') {
|
|
3198
|
-
if (node.id.type === 'Identifier') {
|
|
3199
|
-
scope[kind](node.id.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
3200
|
-
}
|
|
3201
|
-
else {
|
|
3202
|
-
pattern$1(node.id, scope, { kind, hoist, onlyBlock });
|
|
3203
|
-
}
|
|
3204
|
-
}
|
|
3205
|
-
}
|
|
3206
|
-
else {
|
|
3207
|
-
const hasFeed = 'feed' in options;
|
|
3208
|
-
const value = hasFeed ? feed : evaluate(node.init, scope);
|
|
3209
|
-
if (node.id.type === 'Identifier') {
|
|
3210
|
-
const name = node.id.name;
|
|
3211
|
-
if (kind === 'var' && !node.init && !hasFeed) {
|
|
3212
|
-
scope.var(name, NOINIT);
|
|
3213
|
-
}
|
|
3214
|
-
else {
|
|
3215
|
-
scope[kind](name, value);
|
|
3216
|
-
}
|
|
3217
|
-
if (node.init
|
|
3218
|
-
&& ['ClassExpression', 'FunctionExpression', 'ArrowFunctionExpression']
|
|
3219
|
-
.indexOf(node.init.type) !== -1
|
|
3220
|
-
&& !value.name) {
|
|
3221
|
-
define(value, 'name', {
|
|
3222
|
-
value: name,
|
|
3223
|
-
configurable: true
|
|
3224
|
-
});
|
|
3225
|
-
}
|
|
3226
|
-
}
|
|
3227
|
-
else {
|
|
3228
|
-
pattern$1(node.id, scope, { kind, feed: value });
|
|
3229
|
-
}
|
|
3230
|
-
}
|
|
3231
|
-
}
|
|
3232
|
-
function ClassDeclaration(node, scope) {
|
|
3233
|
-
scope.func(node.id.name, createClass$1(node, scope));
|
|
3234
|
-
}
|
|
3235
|
-
function ClassBody(node, scope, options = {}) {
|
|
3236
|
-
const { klass, superClass } = options;
|
|
3237
|
-
for (let i = 0; i < node.body.length; i++) {
|
|
3238
|
-
const def = node.body[i];
|
|
3239
|
-
if (def.type === 'MethodDefinition') {
|
|
3240
|
-
MethodDefinition(def, scope, { klass, superClass });
|
|
3241
|
-
}
|
|
3242
|
-
else if (def.type === 'PropertyDefinition' && def.static) {
|
|
3243
|
-
PropertyDefinition(def, scope, { klass, superClass });
|
|
3244
|
-
}
|
|
3245
|
-
else if (def.type === 'StaticBlock') {
|
|
3246
|
-
StaticBlock(def, scope, { klass, superClass });
|
|
3247
|
-
}
|
|
3248
|
-
}
|
|
3249
|
-
}
|
|
3250
|
-
function MethodDefinition(node, scope, options = {}) {
|
|
3251
|
-
const { klass, superClass } = options;
|
|
3252
|
-
let key;
|
|
3253
|
-
let priv = false;
|
|
3254
|
-
if (node.computed) {
|
|
3255
|
-
key = evaluate(node.key, scope);
|
|
3256
|
-
}
|
|
3257
|
-
else if (node.key.type === 'Identifier') {
|
|
3258
|
-
key = node.key.name;
|
|
3259
|
-
}
|
|
3260
|
-
else if (node.key.type === 'PrivateIdentifier') {
|
|
3261
|
-
key = node.key.name;
|
|
3262
|
-
priv = true;
|
|
3263
|
-
}
|
|
3264
|
-
else {
|
|
3265
|
-
throw new SyntaxError('Unexpected token');
|
|
3266
|
-
}
|
|
3267
|
-
let obj = node.static ? klass : klass.prototype;
|
|
3268
|
-
if (priv) {
|
|
3269
|
-
if (!obj[PRIVATE]) {
|
|
3270
|
-
define(obj, PRIVATE, { value: {} });
|
|
3271
|
-
}
|
|
3272
|
-
obj = obj[PRIVATE];
|
|
3273
|
-
}
|
|
3274
|
-
const value = createFunc$1(node.value, scope, { superClass });
|
|
3275
|
-
switch (node.kind) {
|
|
3276
|
-
case 'constructor':
|
|
3277
|
-
break;
|
|
3278
|
-
case 'method':
|
|
3279
|
-
define(obj, key, {
|
|
3280
|
-
value,
|
|
3281
|
-
writable: true,
|
|
3282
|
-
configurable: true,
|
|
3283
|
-
});
|
|
3284
|
-
break;
|
|
3285
|
-
case 'get': {
|
|
3286
|
-
const oriDptor = getDptor(obj, key);
|
|
3287
|
-
define(obj, key, {
|
|
3288
|
-
get: value,
|
|
3289
|
-
set: oriDptor && oriDptor.set,
|
|
3290
|
-
configurable: true,
|
|
3291
|
-
});
|
|
3292
|
-
break;
|
|
3293
|
-
}
|
|
3294
|
-
case 'set': {
|
|
3295
|
-
const oriDptor = getDptor(obj, key);
|
|
3296
|
-
define(obj, key, {
|
|
3297
|
-
get: oriDptor && oriDptor.get,
|
|
3298
|
-
set: value,
|
|
3299
|
-
configurable: true,
|
|
3300
|
-
});
|
|
3301
|
-
break;
|
|
3302
|
-
}
|
|
3303
|
-
default:
|
|
3304
|
-
throw new SyntaxError('Unexpected token');
|
|
3305
|
-
}
|
|
3306
|
-
}
|
|
3307
|
-
function PropertyDefinition(node, scope, options = {}) {
|
|
3308
|
-
const { klass, superClass } = options;
|
|
3309
|
-
let key;
|
|
3310
|
-
let priv = false;
|
|
3311
|
-
if (node.computed) {
|
|
3312
|
-
key = evaluate(node.key, scope);
|
|
3313
|
-
}
|
|
3314
|
-
else if (node.key.type === 'Identifier') {
|
|
3315
|
-
key = node.key.name;
|
|
3316
|
-
}
|
|
3317
|
-
else if (node.key.type === 'PrivateIdentifier') {
|
|
3318
|
-
key = node.key.name;
|
|
3319
|
-
priv = true;
|
|
3320
|
-
}
|
|
3321
|
-
else {
|
|
3322
|
-
throw new SyntaxError('Unexpected token');
|
|
3323
|
-
}
|
|
3324
|
-
const subScope = new Scope(scope, true);
|
|
3325
|
-
subScope.const('this', klass);
|
|
3326
|
-
let obj = klass;
|
|
3327
|
-
if (priv) {
|
|
3328
|
-
if (!obj[PRIVATE]) {
|
|
3329
|
-
define(obj, PRIVATE, { value: {} });
|
|
3330
|
-
}
|
|
3331
|
-
obj = obj[PRIVATE];
|
|
3332
|
-
}
|
|
3333
|
-
if (!node.value) {
|
|
3334
|
-
obj[key] = undefined;
|
|
3335
|
-
}
|
|
3336
|
-
else if (node.value.type === 'FunctionExpression' || node.value.type === 'ArrowFunctionExpression') {
|
|
3337
|
-
obj[key] = createFunc$1(node.value, subScope, { superClass });
|
|
3338
|
-
}
|
|
3339
|
-
else {
|
|
3340
|
-
obj[key] = evaluate(node.value, subScope);
|
|
3341
|
-
}
|
|
3342
|
-
}
|
|
3343
|
-
function StaticBlock(node, scope, options = {}) {
|
|
3344
|
-
const { klass } = options;
|
|
3345
|
-
const subScope = new Scope(scope, true);
|
|
3346
|
-
subScope.const('this', klass);
|
|
3347
|
-
return BlockStatement(node, subScope, { invasived: true });
|
|
3348
|
-
}
|
|
3349
|
-
function ImportDeclaration(node, scope) {
|
|
3350
|
-
const globalScope = scope.global();
|
|
3351
|
-
const module = globalScope.find(IMPORT + node.source.value);
|
|
3352
|
-
let value;
|
|
3353
|
-
if (module) {
|
|
3354
|
-
const result = module.get();
|
|
3355
|
-
if (result) {
|
|
3356
|
-
if (typeof result === 'function') {
|
|
3357
|
-
value = result();
|
|
3358
|
-
}
|
|
3359
|
-
else if (typeof result === 'object') {
|
|
3360
|
-
value = result;
|
|
3361
|
-
}
|
|
3362
|
-
}
|
|
3363
|
-
}
|
|
3364
|
-
if (!value || typeof value !== 'object') {
|
|
3365
|
-
throw new TypeError(`Failed to resolve module specifier "${node.source.value}"`);
|
|
3366
|
-
}
|
|
3367
|
-
for (let i = 0; i < node.specifiers.length; i++) {
|
|
3368
|
-
const spec = node.specifiers[i];
|
|
3369
|
-
let name;
|
|
3370
|
-
if (spec.type === 'ImportSpecifier') {
|
|
3371
|
-
name = spec.imported.type === 'Identifier'
|
|
3372
|
-
? spec.imported.name : spec.imported.value;
|
|
3373
|
-
}
|
|
3374
|
-
else if (spec.type === 'ImportDefaultSpecifier') {
|
|
3375
|
-
name = 'default';
|
|
3376
|
-
}
|
|
3377
|
-
else if (spec.type === 'ImportNamespaceSpecifier') {
|
|
3378
|
-
name = '*';
|
|
3379
|
-
}
|
|
3380
|
-
if (name !== '*' && !hasOwn(value, name)) {
|
|
3381
|
-
throw new SyntaxError(`The requested module "${node.source.value}" does not provide an export named "${name}"`);
|
|
3382
|
-
}
|
|
3383
|
-
scope.var(spec.local.name, name === '*' ? assign({}, value) : value[name]);
|
|
3384
|
-
}
|
|
3385
|
-
}
|
|
3386
|
-
function ExportDefaultDeclaration(node, scope) {
|
|
3387
|
-
const globalScope = scope.global();
|
|
3388
|
-
let value;
|
|
3389
|
-
if (node.declaration.type === 'FunctionDeclaration') {
|
|
3390
|
-
value = createFunc$1(node.declaration, scope);
|
|
3391
|
-
scope.func(node.declaration.id.name, value);
|
|
3392
|
-
}
|
|
3393
|
-
else if (node.declaration.type === 'ClassDeclaration') {
|
|
3394
|
-
value = createClass$1(node.declaration, scope);
|
|
3395
|
-
scope.func(node.declaration.id.name, value);
|
|
3396
|
-
}
|
|
3397
|
-
else {
|
|
3398
|
-
value = evaluate(node.declaration, scope);
|
|
3399
|
-
}
|
|
3400
|
-
const variable = globalScope.find(EXPORTS);
|
|
3401
|
-
if (variable) {
|
|
3402
|
-
const exports = variable.get();
|
|
3403
|
-
if (exports && typeof exports === 'object') {
|
|
3404
|
-
exports.default = value;
|
|
3405
|
-
}
|
|
3406
|
-
}
|
|
3407
|
-
}
|
|
3408
|
-
function ExportNamedDeclaration(node, scope) {
|
|
3409
|
-
const globalScope = scope.global();
|
|
3410
|
-
if (node.declaration) {
|
|
3411
|
-
if (node.declaration.type === 'FunctionDeclaration') {
|
|
3412
|
-
const value = createFunc$1(node.declaration, scope);
|
|
3413
|
-
scope.func(node.declaration.id.name, value);
|
|
3414
|
-
const variable = globalScope.find(EXPORTS);
|
|
3415
|
-
if (variable) {
|
|
3416
|
-
const exports = variable.get();
|
|
3417
|
-
if (exports && typeof exports === 'object') {
|
|
3418
|
-
exports[node.declaration.id.name] = value;
|
|
3419
|
-
}
|
|
3420
|
-
}
|
|
3421
|
-
}
|
|
3422
|
-
else if (node.declaration.type === 'ClassDeclaration') {
|
|
3423
|
-
const value = createClass$1(node.declaration, scope);
|
|
3424
|
-
scope.func(node.declaration.id.name, value);
|
|
3425
|
-
const variable = globalScope.find(EXPORTS);
|
|
3426
|
-
if (variable) {
|
|
3427
|
-
const exports = variable.get();
|
|
3428
|
-
if (exports && typeof exports === 'object') {
|
|
3429
|
-
exports[node.declaration.id.name] = value;
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
}
|
|
3433
|
-
else if (node.declaration.type === 'VariableDeclaration') {
|
|
3434
|
-
VariableDeclaration(node.declaration, scope);
|
|
3435
|
-
const variable = globalScope.find(EXPORTS);
|
|
3436
|
-
if (variable) {
|
|
3437
|
-
const exports = variable.get();
|
|
3438
|
-
if (exports && typeof exports === 'object') {
|
|
3439
|
-
for (let i = 0; i < node.declaration.declarations.length; i++) {
|
|
3440
|
-
const name = node.declaration.declarations[i].id.name;
|
|
3441
|
-
const item = scope.find(name);
|
|
3442
|
-
if (item) {
|
|
3443
|
-
exports[name] = item.get();
|
|
3444
|
-
}
|
|
3445
|
-
}
|
|
3446
|
-
}
|
|
3447
|
-
}
|
|
3448
|
-
}
|
|
3449
|
-
}
|
|
3450
|
-
else if (node.specifiers) {
|
|
3451
|
-
const variable = globalScope.find(EXPORTS);
|
|
3452
|
-
if (variable) {
|
|
3453
|
-
const exports = variable.get();
|
|
3454
|
-
if (exports && typeof exports === 'object') {
|
|
3455
|
-
for (let i = 0; i < node.specifiers.length; i++) {
|
|
3456
|
-
const spec = node.specifiers[i];
|
|
3457
|
-
const name = spec.local.type === 'Identifier'
|
|
3458
|
-
? spec.local.name : spec.local.value;
|
|
3459
|
-
const item = scope.find(name);
|
|
3460
|
-
if (item) {
|
|
3461
|
-
exports[spec.exported.type === 'Identifier'
|
|
3462
|
-
? spec.exported.name : spec.exported.value] = item.get();
|
|
3463
|
-
}
|
|
3464
|
-
}
|
|
3465
|
-
}
|
|
3466
|
-
}
|
|
3467
|
-
}
|
|
3468
|
-
}
|
|
3469
|
-
function ExportAllDeclaration(node, scope) {
|
|
3470
|
-
const globalScope = scope.global();
|
|
3471
|
-
const module = globalScope.find(IMPORT + node.source.value);
|
|
3472
|
-
let value;
|
|
3473
|
-
if (module) {
|
|
3474
|
-
const result = module.get();
|
|
3475
|
-
if (result) {
|
|
3476
|
-
if (typeof result === 'function') {
|
|
3477
|
-
value = result();
|
|
3478
|
-
}
|
|
3479
|
-
else if (typeof result === 'object') {
|
|
3480
|
-
value = result;
|
|
3481
|
-
}
|
|
3482
|
-
}
|
|
3483
|
-
}
|
|
3484
|
-
if (!value || typeof value !== 'object') {
|
|
3485
|
-
throw new TypeError(`Failed to resolve module specifier "${node.source.value}"`);
|
|
3486
|
-
}
|
|
3487
|
-
const variable = globalScope.find(EXPORTS);
|
|
3488
|
-
if (variable) {
|
|
3489
|
-
const exports = variable.get();
|
|
3490
|
-
if (exports && typeof exports === 'object') {
|
|
3491
|
-
assign(exports, value);
|
|
3492
|
-
}
|
|
3493
|
-
}
|
|
3494
|
-
}
|
|
3495
|
-
|
|
3496
|
-
function hoist$1(block, scope, options = {}) {
|
|
3497
|
-
const { onlyBlock = false } = options;
|
|
3498
|
-
const funcDclrList = [];
|
|
3499
|
-
const funcDclrIdxs = [];
|
|
3500
|
-
for (let i = 0; i < block.body.length; i++) {
|
|
3501
|
-
const statement = block.body[i];
|
|
3502
|
-
if (statement.type === 'FunctionDeclaration') {
|
|
3503
|
-
funcDclrList.push(statement);
|
|
3504
|
-
funcDclrIdxs.push(i);
|
|
3505
|
-
}
|
|
3506
|
-
else if (statement.type === 'VariableDeclaration'
|
|
3507
|
-
&& ['const', 'let'].indexOf(statement.kind) !== -1) {
|
|
3508
|
-
VariableDeclaration(statement, scope, { hoist: true, onlyBlock: true });
|
|
3509
|
-
}
|
|
3510
|
-
else if (!onlyBlock) {
|
|
3511
|
-
hoistVarRecursion$1(statement, scope);
|
|
3512
|
-
}
|
|
3513
|
-
}
|
|
3514
|
-
if (funcDclrIdxs.length) {
|
|
3515
|
-
for (let i = funcDclrIdxs.length - 1; i > -1; i--) {
|
|
3516
|
-
block.body.splice(funcDclrIdxs[i], 1);
|
|
3517
|
-
}
|
|
3518
|
-
block.body = funcDclrList.concat(block.body);
|
|
3519
|
-
}
|
|
3520
|
-
}
|
|
3521
|
-
function hoistVarRecursion$1(statement, scope) {
|
|
3522
|
-
switch (statement.type) {
|
|
3523
|
-
case 'VariableDeclaration':
|
|
3524
|
-
VariableDeclaration(statement, scope, { hoist: true });
|
|
3525
|
-
break;
|
|
3526
|
-
case 'ForInStatement':
|
|
3527
|
-
case 'ForOfStatement':
|
|
3528
|
-
if (statement.left.type === 'VariableDeclaration') {
|
|
3529
|
-
VariableDeclaration(statement.left, scope, { hoist: true });
|
|
3530
|
-
}
|
|
3531
|
-
case 'ForStatement':
|
|
3532
|
-
if (statement.type === 'ForStatement' && statement.init.type === 'VariableDeclaration') {
|
|
3533
|
-
VariableDeclaration(statement.init, scope, { hoist: true });
|
|
3534
|
-
}
|
|
3535
|
-
case 'WhileStatement':
|
|
3536
|
-
case 'DoWhileStatement':
|
|
3537
|
-
hoistVarRecursion$1(statement.body, scope);
|
|
3538
|
-
break;
|
|
3539
|
-
case 'IfStatement':
|
|
3540
|
-
hoistVarRecursion$1(statement.consequent, scope);
|
|
3541
|
-
if (statement.alternate) {
|
|
3542
|
-
hoistVarRecursion$1(statement.alternate, scope);
|
|
3543
|
-
}
|
|
3544
|
-
break;
|
|
3545
|
-
case 'BlockStatement':
|
|
3546
|
-
for (let i = 0; i < statement.body.length; i++) {
|
|
3547
|
-
hoistVarRecursion$1(statement.body[i], scope);
|
|
3548
|
-
}
|
|
3549
|
-
break;
|
|
3550
|
-
case 'SwitchStatement':
|
|
3551
|
-
for (let i = 0; i < statement.cases.length; i++) {
|
|
3552
|
-
for (let j = 0; j < statement.cases[i].consequent.length; j++) {
|
|
3553
|
-
hoistVarRecursion$1(statement.cases[i].consequent[j], scope);
|
|
3554
|
-
}
|
|
3555
|
-
}
|
|
3556
|
-
break;
|
|
3557
|
-
case 'TryStatement': {
|
|
3558
|
-
const tryBlock = statement.block.body;
|
|
3559
|
-
for (let i = 0; i < tryBlock.length; i++) {
|
|
3560
|
-
hoistVarRecursion$1(tryBlock[i], scope);
|
|
3561
|
-
}
|
|
3562
|
-
const catchBlock = statement.handler && statement.handler.body.body;
|
|
3563
|
-
if (catchBlock) {
|
|
3564
|
-
for (let i = 0; i < catchBlock.length; i++) {
|
|
3565
|
-
hoistVarRecursion$1(catchBlock[i], scope);
|
|
3566
|
-
}
|
|
3567
|
-
}
|
|
3568
|
-
const finalBlock = statement.finalizer && statement.finalizer.body;
|
|
3569
|
-
if (finalBlock) {
|
|
3570
|
-
for (let i = 0; i < finalBlock.length; i++) {
|
|
3571
|
-
hoistVarRecursion$1(finalBlock[i], scope);
|
|
3572
|
-
}
|
|
3573
|
-
}
|
|
3574
|
-
break;
|
|
3575
|
-
}
|
|
3576
|
-
}
|
|
3577
|
-
}
|
|
3578
|
-
function pattern$1(node, scope, options = {}) {
|
|
3579
|
-
switch (node.type) {
|
|
3580
|
-
case 'ObjectPattern':
|
|
3581
|
-
return ObjectPattern(node, scope, options);
|
|
3582
|
-
case 'ArrayPattern':
|
|
3583
|
-
return ArrayPattern(node, scope, options);
|
|
3584
|
-
case 'RestElement':
|
|
3585
|
-
return RestElement(node, scope, options);
|
|
3586
|
-
case 'AssignmentPattern':
|
|
3587
|
-
return AssignmentPattern(node, scope, options);
|
|
3588
|
-
default:
|
|
3589
|
-
throw new SyntaxError('Unexpected token');
|
|
3590
|
-
}
|
|
3591
|
-
}
|
|
3592
|
-
function createFunc$1(node, scope, options = {}) {
|
|
3593
|
-
var _a;
|
|
3594
|
-
if (node.generator || node.async) {
|
|
3595
|
-
return createFunc(node, scope, options);
|
|
3596
|
-
}
|
|
3597
|
-
const { superClass, construct } = options;
|
|
3598
|
-
const params = node.params;
|
|
3599
|
-
const tmpFunc = function (...args) {
|
|
3600
|
-
const subScope = new Scope(scope, true);
|
|
3601
|
-
if (node.type !== 'ArrowFunctionExpression') {
|
|
3602
|
-
subScope.let('this', this);
|
|
3603
|
-
subScope.let('arguments', arguments);
|
|
3604
|
-
subScope.const(NEWTARGET, new.target);
|
|
3605
|
-
if (superClass) {
|
|
3606
|
-
subScope.const(SUPER, superClass);
|
|
3607
|
-
if (construct)
|
|
3608
|
-
subScope.let(SUPERCALL, construct);
|
|
3609
|
-
}
|
|
3610
|
-
else if (construct) {
|
|
3611
|
-
construct(this);
|
|
3612
|
-
}
|
|
3613
|
-
}
|
|
3614
|
-
for (let i = 0; i < params.length; i++) {
|
|
3615
|
-
const param = params[i];
|
|
3616
|
-
if (param.type === 'Identifier') {
|
|
3617
|
-
subScope.var(param.name, args[i]);
|
|
3618
|
-
}
|
|
3619
|
-
else if (param.type === 'RestElement') {
|
|
3620
|
-
RestElement(param, subScope, { kind: 'var', feed: args.slice(i) });
|
|
3621
|
-
}
|
|
3622
|
-
else {
|
|
3623
|
-
pattern$1(param, subScope, { kind: 'var', feed: args[i] });
|
|
3624
|
-
}
|
|
3625
|
-
}
|
|
3626
|
-
let result;
|
|
3627
|
-
if (node.body.type === 'BlockStatement') {
|
|
3628
|
-
hoist$1(node.body, subScope);
|
|
3629
|
-
result = BlockStatement(node.body, subScope, {
|
|
3630
|
-
invasived: true,
|
|
3631
|
-
hoisted: true
|
|
3632
|
-
});
|
|
3633
|
-
}
|
|
3634
|
-
else {
|
|
3635
|
-
result = evaluate(node.body, subScope);
|
|
3636
|
-
if (node.type === 'ArrowFunctionExpression') {
|
|
3637
|
-
RETURN.RES = result;
|
|
3638
|
-
result = RETURN;
|
|
3639
|
-
}
|
|
3640
|
-
}
|
|
3641
|
-
if (result === RETURN) {
|
|
3642
|
-
return result.RES;
|
|
3643
|
-
}
|
|
3644
|
-
else if (new.target) {
|
|
3645
|
-
return subScope.find('this').get();
|
|
3646
|
-
}
|
|
3647
|
-
};
|
|
3648
|
-
let func = tmpFunc;
|
|
3649
|
-
if (node.type === 'ArrowFunctionExpression') {
|
|
3650
|
-
define(func, NOCTOR, { value: true });
|
|
3651
|
-
}
|
|
3652
|
-
define(func, 'name', {
|
|
3653
|
-
value: node.id
|
|
3654
|
-
&& node.id.name
|
|
3655
|
-
|| '',
|
|
3656
|
-
configurable: true
|
|
3657
|
-
});
|
|
3658
|
-
define(func, 'length', {
|
|
3659
|
-
value: params.length,
|
|
3660
|
-
configurable: true
|
|
3661
|
-
});
|
|
3662
|
-
const source = (_a = node.loc) === null || _a === void 0 ? void 0 : _a.source;
|
|
3663
|
-
if (source) {
|
|
3664
|
-
define(func, 'toString', {
|
|
3665
|
-
value: () => source.substring(node.start, node.end),
|
|
3666
|
-
configurable: true
|
|
3667
|
-
});
|
|
3668
|
-
}
|
|
3669
|
-
return func;
|
|
3670
|
-
}
|
|
3671
|
-
function createClass$1(node, scope) {
|
|
3672
|
-
const superClass = evaluate(node.superClass, scope);
|
|
3673
|
-
const methodBody = node.body.body;
|
|
3674
|
-
const construct = function (object) {
|
|
3675
|
-
for (let i = 0; i < methodBody.length; i++) {
|
|
3676
|
-
const def = methodBody[i];
|
|
3677
|
-
if (def.type === 'PropertyDefinition' && !def.static) {
|
|
3678
|
-
PropertyDefinition(def, scope, { klass: object, superClass });
|
|
3679
|
-
}
|
|
3680
|
-
}
|
|
3681
|
-
};
|
|
3682
|
-
let klass = function () {
|
|
3683
|
-
const inst = superClass ? callSuper(this, superClass) : this;
|
|
3684
|
-
construct(inst);
|
|
3685
|
-
return inst;
|
|
3686
|
-
};
|
|
3687
|
-
for (let i = 0; i < methodBody.length; i++) {
|
|
3688
|
-
const method = methodBody[i];
|
|
3689
|
-
if (method.type === 'MethodDefinition' && method.kind === 'constructor') {
|
|
3690
|
-
klass = createFunc$1(method.value, scope, { superClass, construct });
|
|
3691
|
-
break;
|
|
3692
|
-
}
|
|
3693
|
-
}
|
|
3694
|
-
if (superClass) {
|
|
3695
|
-
inherits(klass, superClass);
|
|
3696
|
-
}
|
|
3697
|
-
ClassBody(node.body, scope, { klass, superClass });
|
|
3698
|
-
define(klass, CLSCTOR, { value: true });
|
|
3699
|
-
define(klass, 'name', {
|
|
3700
|
-
value: node.id && node.id.name || '',
|
|
3701
|
-
configurable: true
|
|
3702
|
-
});
|
|
3703
|
-
return klass;
|
|
3704
|
-
}
|
|
3705
|
-
function ForXHandler$1(node, scope, options) {
|
|
3706
|
-
const { value } = options;
|
|
3707
|
-
const left = node.left;
|
|
3708
|
-
const subScope = new Scope(scope);
|
|
3709
|
-
if (left.type === 'VariableDeclaration') {
|
|
3710
|
-
VariableDeclaration(left, subScope, { feed: value });
|
|
3711
|
-
}
|
|
3712
|
-
else if (left.type === 'Identifier') {
|
|
3713
|
-
const variable = Identifier(left, scope, { getVar: true });
|
|
3714
|
-
variable.set(value);
|
|
3715
|
-
}
|
|
3716
|
-
else {
|
|
3717
|
-
pattern$1(left, scope, { feed: value });
|
|
3718
|
-
}
|
|
3719
|
-
let result;
|
|
3720
|
-
if (node.body.type === 'BlockStatement') {
|
|
3721
|
-
result = BlockStatement(node.body, subScope, { invasived: true });
|
|
3722
|
-
}
|
|
3723
|
-
else {
|
|
3724
|
-
result = evaluate(node.body, subScope);
|
|
3725
|
-
}
|
|
3726
|
-
return result;
|
|
3727
|
-
}
|
|
3728
|
-
|
|
3729
|
-
function* hoist(block, scope, options = {}) {
|
|
3730
|
-
const { onlyBlock = false } = options;
|
|
3731
|
-
const funcDclrList = [];
|
|
3732
|
-
const funcDclrIdxs = [];
|
|
3733
|
-
for (let i = 0; i < block.body.length; i++) {
|
|
3734
|
-
const statement = block.body[i];
|
|
3735
|
-
if (statement.type === 'FunctionDeclaration') {
|
|
3736
|
-
funcDclrList.push(statement);
|
|
3737
|
-
funcDclrIdxs.push(i);
|
|
3738
|
-
}
|
|
3739
|
-
else if (statement.type === 'VariableDeclaration'
|
|
3740
|
-
&& ['const', 'let'].indexOf(statement.kind) !== -1) {
|
|
3741
|
-
yield* VariableDeclaration$1(statement, scope, { hoist: true, onlyBlock: true });
|
|
3742
|
-
}
|
|
3743
|
-
else if (!onlyBlock) {
|
|
3744
|
-
yield* hoistVarRecursion(statement, scope);
|
|
3745
|
-
}
|
|
3746
|
-
}
|
|
3747
|
-
if (funcDclrIdxs.length) {
|
|
3748
|
-
for (let i = funcDclrIdxs.length - 1; i > -1; i--) {
|
|
3749
|
-
block.body.splice(funcDclrIdxs[i], 1);
|
|
3750
|
-
}
|
|
3751
|
-
block.body = funcDclrList.concat(block.body);
|
|
3752
|
-
}
|
|
3753
|
-
}
|
|
3754
|
-
function* hoistVarRecursion(statement, scope) {
|
|
3755
|
-
switch (statement.type) {
|
|
3756
|
-
case 'VariableDeclaration':
|
|
3757
|
-
yield* VariableDeclaration$1(statement, scope, { hoist: true });
|
|
3758
|
-
break;
|
|
3759
|
-
case 'ForInStatement':
|
|
3760
|
-
case 'ForOfStatement':
|
|
3761
|
-
if (statement.left.type === 'VariableDeclaration') {
|
|
3762
|
-
yield* VariableDeclaration$1(statement.left, scope, { hoist: true });
|
|
3763
|
-
}
|
|
3764
|
-
case 'ForStatement':
|
|
3765
|
-
if (statement.type === 'ForStatement' && statement.init.type === 'VariableDeclaration') {
|
|
3766
|
-
yield* VariableDeclaration$1(statement.init, scope, { hoist: true });
|
|
3767
|
-
}
|
|
3768
|
-
case 'WhileStatement':
|
|
3769
|
-
case 'DoWhileStatement':
|
|
3770
|
-
yield* hoistVarRecursion(statement.body, scope);
|
|
3771
|
-
break;
|
|
3772
|
-
case 'IfStatement':
|
|
3773
|
-
yield* hoistVarRecursion(statement.consequent, scope);
|
|
3774
|
-
if (statement.alternate) {
|
|
3775
|
-
yield* hoistVarRecursion(statement.alternate, scope);
|
|
3776
|
-
}
|
|
3777
|
-
break;
|
|
3778
|
-
case 'BlockStatement':
|
|
3779
|
-
for (let i = 0; i < statement.body.length; i++) {
|
|
3780
|
-
yield* hoistVarRecursion(statement.body[i], scope);
|
|
3781
|
-
}
|
|
3782
|
-
break;
|
|
3783
|
-
case 'SwitchStatement':
|
|
3784
|
-
for (let i = 0; i < statement.cases.length; i++) {
|
|
3785
|
-
for (let j = 0; j < statement.cases[i].consequent.length; j++) {
|
|
3786
|
-
yield* hoistVarRecursion(statement.cases[i].consequent[j], scope);
|
|
3787
|
-
}
|
|
3788
|
-
}
|
|
3789
|
-
break;
|
|
3790
|
-
case 'TryStatement': {
|
|
3791
|
-
const tryBlock = statement.block.body;
|
|
3792
|
-
for (let i = 0; i < tryBlock.length; i++) {
|
|
3793
|
-
yield* hoistVarRecursion(tryBlock[i], scope);
|
|
3794
|
-
}
|
|
3795
|
-
const catchBlock = statement.handler && statement.handler.body.body;
|
|
3796
|
-
if (catchBlock) {
|
|
3797
|
-
for (let i = 0; i < catchBlock.length; i++) {
|
|
3798
|
-
yield* hoistVarRecursion(catchBlock[i], scope);
|
|
3799
|
-
}
|
|
3800
|
-
}
|
|
3801
|
-
const finalBlock = statement.finalizer && statement.finalizer.body;
|
|
3802
|
-
if (finalBlock) {
|
|
3803
|
-
for (let i = 0; i < finalBlock.length; i++) {
|
|
3804
|
-
yield* hoistVarRecursion(finalBlock[i], scope);
|
|
3805
|
-
}
|
|
3806
|
-
}
|
|
3807
|
-
break;
|
|
3808
|
-
}
|
|
3809
|
-
}
|
|
3810
|
-
}
|
|
3811
|
-
function* pattern(node, scope, options = {}) {
|
|
3812
|
-
switch (node.type) {
|
|
3813
|
-
case 'ObjectPattern':
|
|
3814
|
-
return yield* ObjectPattern$1(node, scope, options);
|
|
3815
|
-
case 'ArrayPattern':
|
|
3816
|
-
return yield* ArrayPattern$1(node, scope, options);
|
|
3817
|
-
case 'RestElement':
|
|
3818
|
-
return yield* RestElement$1(node, scope, options);
|
|
3819
|
-
case 'AssignmentPattern':
|
|
3820
|
-
return yield* AssignmentPattern$1(node, scope, options);
|
|
3821
|
-
default:
|
|
3822
|
-
throw new SyntaxError('Unexpected token');
|
|
3823
|
-
}
|
|
3824
|
-
}
|
|
3825
|
-
function createFunc(node, scope, options = {}) {
|
|
3826
|
-
var _a;
|
|
3827
|
-
if (!node.generator && !node.async) {
|
|
3828
|
-
return createFunc$1(node, scope, options);
|
|
3829
|
-
}
|
|
3830
|
-
const { superClass, construct } = options;
|
|
3831
|
-
const params = node.params;
|
|
3832
|
-
const tmpFunc = function* (...args) {
|
|
3833
|
-
const subScope = new Scope(scope, true);
|
|
3834
|
-
if (node.type !== 'ArrowFunctionExpression') {
|
|
3835
|
-
subScope.let('this', this);
|
|
3836
|
-
subScope.let('arguments', arguments);
|
|
3837
|
-
subScope.const(NEWTARGET, new.target);
|
|
3838
|
-
if (superClass) {
|
|
3839
|
-
subScope.const(SUPER, superClass);
|
|
3840
|
-
if (construct)
|
|
3841
|
-
subScope.let(SUPERCALL, construct);
|
|
3842
|
-
}
|
|
3843
|
-
else if (construct) {
|
|
3844
|
-
yield* construct(this);
|
|
3845
|
-
}
|
|
3846
|
-
}
|
|
3847
|
-
for (let i = 0; i < params.length; i++) {
|
|
3848
|
-
const param = params[i];
|
|
3849
|
-
if (param.type === 'Identifier') {
|
|
3850
|
-
subScope.var(param.name, args[i]);
|
|
3851
|
-
}
|
|
3852
|
-
else if (param.type === 'RestElement') {
|
|
3853
|
-
yield* RestElement$1(param, subScope, { kind: 'var', feed: args.slice(i) });
|
|
3854
|
-
}
|
|
3855
|
-
else {
|
|
3856
|
-
yield* pattern(param, subScope, { kind: 'var', feed: args[i] });
|
|
3857
|
-
}
|
|
3858
|
-
}
|
|
3859
|
-
let result;
|
|
3860
|
-
if (node.body.type === 'BlockStatement') {
|
|
3861
|
-
yield* hoist(node.body, subScope);
|
|
3862
|
-
result = yield* BlockStatement$1(node.body, subScope, {
|
|
3863
|
-
invasived: true,
|
|
3864
|
-
hoisted: true
|
|
3865
|
-
});
|
|
3866
|
-
}
|
|
3867
|
-
else {
|
|
3868
|
-
result = yield* evaluate$1(node.body, subScope);
|
|
3869
|
-
if (node.type === 'ArrowFunctionExpression') {
|
|
3870
|
-
RETURN.RES = result;
|
|
3871
|
-
result = RETURN;
|
|
3872
|
-
}
|
|
3873
|
-
}
|
|
3874
|
-
if (result === RETURN) {
|
|
3875
|
-
return result.RES;
|
|
3876
|
-
}
|
|
3877
|
-
else if (new.target) {
|
|
3878
|
-
return subScope.find('this').get();
|
|
3879
|
-
}
|
|
3880
|
-
};
|
|
3881
|
-
let func;
|
|
3882
|
-
if (node.async && node.generator) {
|
|
3883
|
-
func = function () {
|
|
3884
|
-
const iterator = tmpFunc.apply(this, arguments);
|
|
3885
|
-
let last = Promise.resolve();
|
|
3886
|
-
let hasCatch = false;
|
|
3887
|
-
const run = (opts) => last = last
|
|
3888
|
-
.then(() => runAsync(iterator, assign({ fullRet: true }, opts)))
|
|
3889
|
-
.catch(err => {
|
|
3890
|
-
if (!hasCatch) {
|
|
3891
|
-
hasCatch = true;
|
|
3892
|
-
return Promise.reject(err);
|
|
3893
|
-
}
|
|
3894
|
-
});
|
|
3895
|
-
const asyncIterator = {
|
|
3896
|
-
next: (res) => run({ res }),
|
|
3897
|
-
throw: (err) => run({ err }),
|
|
3898
|
-
return: (ret) => run({ ret })
|
|
3899
|
-
};
|
|
3900
|
-
if (typeof Symbol === 'function') {
|
|
3901
|
-
asyncIterator[Symbol.iterator] = function () { return this; };
|
|
3902
|
-
}
|
|
3903
|
-
return asyncIterator;
|
|
3904
|
-
};
|
|
3905
|
-
}
|
|
3906
|
-
else if (node.async) {
|
|
3907
|
-
func = function () { return runAsync(tmpFunc.apply(this, arguments)); };
|
|
3908
|
-
}
|
|
3909
|
-
else {
|
|
3910
|
-
func = tmpFunc;
|
|
3911
|
-
}
|
|
3912
|
-
define(func, NOCTOR, { value: true });
|
|
3913
|
-
define(func, 'name', {
|
|
3914
|
-
value: node.id
|
|
3915
|
-
&& node.id.name
|
|
3916
|
-
|| '',
|
|
3917
|
-
configurable: true
|
|
3918
|
-
});
|
|
3919
|
-
define(func, 'length', {
|
|
3920
|
-
value: params.length,
|
|
3921
|
-
configurable: true
|
|
3922
|
-
});
|
|
3923
|
-
const source = (_a = node.loc) === null || _a === void 0 ? void 0 : _a.source;
|
|
3924
|
-
if (source) {
|
|
3925
|
-
define(func, 'toString', {
|
|
3926
|
-
value: () => source.substring(node.start, node.end),
|
|
3927
|
-
configurable: true
|
|
3928
|
-
});
|
|
3929
|
-
}
|
|
3930
|
-
return func;
|
|
3931
|
-
}
|
|
3932
|
-
function* createClass(node, scope) {
|
|
3933
|
-
const superClass = yield* evaluate$1(node.superClass, scope);
|
|
3934
|
-
const methodBody = node.body.body;
|
|
3935
|
-
const construct = function* (object) {
|
|
3936
|
-
for (let i = 0; i < methodBody.length; i++) {
|
|
3937
|
-
const def = methodBody[i];
|
|
3938
|
-
if (def.type === 'PropertyDefinition' && !def.static) {
|
|
3939
|
-
yield* PropertyDefinition$1(def, scope, { klass: object, superClass });
|
|
3940
|
-
}
|
|
3941
|
-
}
|
|
3942
|
-
};
|
|
3943
|
-
let klass = function* () {
|
|
3944
|
-
const inst = superClass ? callSuper(this, superClass) : this;
|
|
3945
|
-
yield* construct(inst);
|
|
3946
|
-
return inst;
|
|
3947
|
-
};
|
|
3948
|
-
for (let i = 0; i < methodBody.length; i++) {
|
|
3949
|
-
const method = methodBody[i];
|
|
3950
|
-
if (method.type === 'MethodDefinition' && method.kind === 'constructor') {
|
|
3951
|
-
klass = createFunc(method.value, scope, { superClass, construct });
|
|
3952
|
-
break;
|
|
3953
|
-
}
|
|
3954
|
-
}
|
|
3955
|
-
if (superClass) {
|
|
3956
|
-
inherits(klass, superClass);
|
|
3957
|
-
}
|
|
3958
|
-
yield* ClassBody$1(node.body, scope, { klass, superClass });
|
|
3959
|
-
define(klass, CLSCTOR, { value: true });
|
|
3960
|
-
define(klass, 'name', {
|
|
3961
|
-
value: node.id && node.id.name || '',
|
|
3962
|
-
configurable: true
|
|
3963
|
-
});
|
|
3964
|
-
return klass;
|
|
3965
|
-
}
|
|
3966
|
-
function* ForXHandler(node, scope, options) {
|
|
3967
|
-
const { value } = options;
|
|
3968
|
-
const left = node.left;
|
|
3969
|
-
const subScope = new Scope(scope);
|
|
3970
|
-
if (left.type === 'VariableDeclaration') {
|
|
3971
|
-
yield* VariableDeclaration$1(left, subScope, { feed: value });
|
|
3972
|
-
}
|
|
3973
|
-
else if (left.type === 'Identifier') {
|
|
3974
|
-
const variable = yield* Identifier(left, scope, { getVar: true });
|
|
3975
|
-
variable.set(value);
|
|
3976
|
-
}
|
|
3977
|
-
else {
|
|
3978
|
-
yield* pattern(left, scope, { feed: value });
|
|
3979
|
-
}
|
|
3980
|
-
let result;
|
|
3981
|
-
if (node.body.type === 'BlockStatement') {
|
|
3982
|
-
result = yield* BlockStatement$1(node.body, subScope, { invasived: true });
|
|
3983
|
-
}
|
|
3984
|
-
else {
|
|
3985
|
-
result = yield* evaluate$1(node.body, subScope);
|
|
3986
|
-
}
|
|
3987
|
-
return result;
|
|
3988
|
-
}
|
|
3989
|
-
|
|
3990
|
-
const latestVer = 15;
|
|
3991
|
-
class Sval {
|
|
3992
|
-
constructor(options = {}) {
|
|
3993
|
-
this.options = { ecmaVersion: 'latest' };
|
|
3994
|
-
this.scope = new Scope(null, true);
|
|
3995
|
-
this.exports = {};
|
|
3996
|
-
let { ecmaVer = 'latest', sandBox = true, sourceType = 'script' } = options;
|
|
3997
|
-
if (typeof ecmaVer === 'number') {
|
|
3998
|
-
ecmaVer -= ecmaVer < 2015 ? 0 : 2009;
|
|
3999
|
-
}
|
|
4000
|
-
if (ecmaVer !== 'latest' && ecmaVer !== 3 && (ecmaVer < 5 || ecmaVer > latestVer)) {
|
|
4001
|
-
throw new Error(`unsupported ecmaVer`);
|
|
4002
|
-
}
|
|
4003
|
-
this.options.ecmaVersion = ecmaVer;
|
|
4004
|
-
this.options.sourceType = sourceType;
|
|
4005
|
-
if (sandBox) {
|
|
4006
|
-
const win = createSandBox();
|
|
4007
|
-
this.scope.let('globalThis', win);
|
|
4008
|
-
this.scope.let('window', win);
|
|
4009
|
-
this.scope.let('self', win);
|
|
4010
|
-
this.scope.let('this', win);
|
|
4011
|
-
}
|
|
4012
|
-
else {
|
|
4013
|
-
this.scope.let('globalThis', globalObj);
|
|
4014
|
-
this.scope.let('window', globalObj);
|
|
4015
|
-
this.scope.let('self', globalObj);
|
|
4016
|
-
this.scope.let('this', globalObj);
|
|
4017
|
-
}
|
|
4018
|
-
this.scope.const(sourceType === 'module' ? EXPORTS : 'exports', this.exports = {});
|
|
4019
|
-
}
|
|
4020
|
-
import(nameOrModules, mod) {
|
|
4021
|
-
if (typeof nameOrModules === 'string') {
|
|
4022
|
-
nameOrModules = { [nameOrModules]: mod };
|
|
4023
|
-
}
|
|
4024
|
-
if (typeof nameOrModules !== 'object')
|
|
4025
|
-
return;
|
|
4026
|
-
const names = getOwnNames(nameOrModules);
|
|
4027
|
-
for (let i = 0; i < names.length; i++) {
|
|
4028
|
-
const name = names[i];
|
|
4029
|
-
const modName = this.options.sourceType === 'module' ? IMPORT + name : name;
|
|
4030
|
-
this.scope.var(modName, nameOrModules[name]);
|
|
4031
|
-
}
|
|
4032
|
-
}
|
|
4033
|
-
parse(code, parser) {
|
|
4034
|
-
if (typeof parser === 'function') {
|
|
4035
|
-
return parser(code, assign({}, this.options));
|
|
4036
|
-
}
|
|
4037
|
-
return acorn.parse(code, this.options);
|
|
4038
|
-
}
|
|
4039
|
-
run(code) {
|
|
4040
|
-
const ast = typeof code === 'string' ? this.parse(code) : code;
|
|
4041
|
-
const scope = this.scope;
|
|
4042
|
-
if (this.options.sourceType === 'module' && (this.options.ecmaVersion === 'latest'
|
|
4043
|
-
|| this.options.ecmaVersion >= 13)) {
|
|
4044
|
-
runAsync((function* () {
|
|
4045
|
-
yield* hoist(ast, scope);
|
|
4046
|
-
yield* evaluate$1(ast, scope);
|
|
4047
|
-
})());
|
|
4048
|
-
}
|
|
4049
|
-
else {
|
|
4050
|
-
hoist$1(ast, scope);
|
|
4051
|
-
evaluate(ast, scope);
|
|
4052
|
-
}
|
|
4053
|
-
}
|
|
4054
|
-
}
|
|
4055
|
-
Sval.version = version;
|
|
4056
|
-
|
|
4057
|
-
return Sval;
|
|
4058
|
-
|
|
4059
|
-
}));
|