sval 0.5.0 → 0.5.1
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 +3 -3
- package/README.md +80 -28
- package/dist/sval.es6.js +975 -420
- package/dist/sval.js +1274 -617
- package/dist/sval.min.js +1 -1
- package/package.json +1 -2
- package/types/index.d.ts +6 -10
package/dist/sval.es6.js
CHANGED
|
@@ -4,6 +4,27 @@
|
|
|
4
4
|
(global = global || self, global.Sval = factory(global.acorn));
|
|
5
5
|
}(this, (function (acorn) { 'use strict';
|
|
6
6
|
|
|
7
|
+
var statement = /*#__PURE__*/Object.freeze({
|
|
8
|
+
__proto__: null,
|
|
9
|
+
get ExpressionStatement () { return ExpressionStatement; },
|
|
10
|
+
get BlockStatement () { return BlockStatement; },
|
|
11
|
+
get EmptyStatement () { return EmptyStatement; },
|
|
12
|
+
get DebuggerStatement () { return DebuggerStatement; },
|
|
13
|
+
get ReturnStatement () { return ReturnStatement; },
|
|
14
|
+
get BreakStatement () { return BreakStatement; },
|
|
15
|
+
get ContinueStatement () { return ContinueStatement; },
|
|
16
|
+
get IfStatement () { return IfStatement; },
|
|
17
|
+
get SwitchStatement () { return SwitchStatement; },
|
|
18
|
+
get SwitchCase () { return SwitchCase; },
|
|
19
|
+
get ThrowStatement () { return ThrowStatement; },
|
|
20
|
+
get TryStatement () { return TryStatement; },
|
|
21
|
+
get CatchClause () { return CatchClause; },
|
|
22
|
+
get WhileStatement () { return WhileStatement; },
|
|
23
|
+
get DoWhileStatement () { return DoWhileStatement; },
|
|
24
|
+
get ForStatement () { return ForStatement; },
|
|
25
|
+
get ForInStatement () { return ForInStatement; },
|
|
26
|
+
get ForOfStatement () { return ForOfStatement; }
|
|
27
|
+
});
|
|
7
28
|
var declaration = /*#__PURE__*/Object.freeze({
|
|
8
29
|
__proto__: null,
|
|
9
30
|
get FunctionDeclaration () { return FunctionDeclaration; },
|
|
@@ -11,7 +32,34 @@
|
|
|
11
32
|
get VariableDeclarator () { return VariableDeclarator; },
|
|
12
33
|
get ClassDeclaration () { return ClassDeclaration; },
|
|
13
34
|
get ClassBody () { return ClassBody; },
|
|
14
|
-
get MethodDefinition () { return MethodDefinition; }
|
|
35
|
+
get MethodDefinition () { return MethodDefinition; },
|
|
36
|
+
get PropertyDefinition () { return PropertyDefinition; },
|
|
37
|
+
get StaticBlock () { return StaticBlock; },
|
|
38
|
+
get ImportDeclaration () { return ImportDeclaration; },
|
|
39
|
+
get ExportDefaultDeclaration () { return ExportDefaultDeclaration; },
|
|
40
|
+
get ExportNamedDeclaration () { return ExportNamedDeclaration; },
|
|
41
|
+
get ExportAllDeclaration () { return ExportAllDeclaration; }
|
|
42
|
+
});
|
|
43
|
+
var statement$1 = /*#__PURE__*/Object.freeze({
|
|
44
|
+
__proto__: null,
|
|
45
|
+
get ExpressionStatement () { return ExpressionStatement$1; },
|
|
46
|
+
get BlockStatement () { return BlockStatement$1; },
|
|
47
|
+
get EmptyStatement () { return EmptyStatement$1; },
|
|
48
|
+
get DebuggerStatement () { return DebuggerStatement$1; },
|
|
49
|
+
get ReturnStatement () { return ReturnStatement$1; },
|
|
50
|
+
get BreakStatement () { return BreakStatement$1; },
|
|
51
|
+
get ContinueStatement () { return ContinueStatement$1; },
|
|
52
|
+
get IfStatement () { return IfStatement$1; },
|
|
53
|
+
get SwitchStatement () { return SwitchStatement$1; },
|
|
54
|
+
get SwitchCase () { return SwitchCase$1; },
|
|
55
|
+
get ThrowStatement () { return ThrowStatement$1; },
|
|
56
|
+
get TryStatement () { return TryStatement$1; },
|
|
57
|
+
get CatchClause () { return CatchClause$1; },
|
|
58
|
+
get WhileStatement () { return WhileStatement$1; },
|
|
59
|
+
get DoWhileStatement () { return DoWhileStatement$1; },
|
|
60
|
+
get ForStatement () { return ForStatement$1; },
|
|
61
|
+
get ForInStatement () { return ForInStatement$1; },
|
|
62
|
+
get ForOfStatement () { return ForOfStatement$1; }
|
|
15
63
|
});
|
|
16
64
|
var declaration$1 = /*#__PURE__*/Object.freeze({
|
|
17
65
|
__proto__: null,
|
|
@@ -20,7 +68,13 @@
|
|
|
20
68
|
get VariableDeclarator () { return VariableDeclarator$1; },
|
|
21
69
|
get ClassDeclaration () { return ClassDeclaration$1; },
|
|
22
70
|
get ClassBody () { return ClassBody$1; },
|
|
23
|
-
get MethodDefinition () { return MethodDefinition$1; }
|
|
71
|
+
get MethodDefinition () { return MethodDefinition$1; },
|
|
72
|
+
get PropertyDefinition () { return PropertyDefinition$1; },
|
|
73
|
+
get StaticBlock () { return StaticBlock$1; },
|
|
74
|
+
get ImportDeclaration () { return ImportDeclaration$1; },
|
|
75
|
+
get ExportDefaultDeclaration () { return ExportDefaultDeclaration$1; },
|
|
76
|
+
get ExportNamedDeclaration () { return ExportNamedDeclaration$1; },
|
|
77
|
+
get ExportAllDeclaration () { return ExportAllDeclaration$1; }
|
|
24
78
|
});
|
|
25
79
|
|
|
26
80
|
const freeze = Object.freeze;
|
|
@@ -269,6 +323,10 @@
|
|
|
269
323
|
globalObj.Reflect = Reflect;
|
|
270
324
|
}
|
|
271
325
|
catch (err) { }
|
|
326
|
+
try {
|
|
327
|
+
globalObj.BigInt = BigInt;
|
|
328
|
+
}
|
|
329
|
+
catch (err) { }
|
|
272
330
|
try {
|
|
273
331
|
globalObj.decodeURI = decodeURI;
|
|
274
332
|
}
|
|
@@ -383,8 +441,6 @@
|
|
|
383
441
|
}
|
|
384
442
|
}
|
|
385
443
|
|
|
386
|
-
var version = "0.5.0";
|
|
387
|
-
|
|
388
444
|
const AWAIT = { RES: undefined };
|
|
389
445
|
const RETURN = { RES: undefined };
|
|
390
446
|
const CONTINUE = createSymbol('continue');
|
|
@@ -394,8 +450,13 @@
|
|
|
394
450
|
const NOCTOR = createSymbol('noctor');
|
|
395
451
|
const CLSCTOR = createSymbol('clsctor');
|
|
396
452
|
const NEWTARGET = createSymbol('newtarget');
|
|
453
|
+
const PRIVATE = createSymbol('private');
|
|
397
454
|
const NOINIT = createSymbol('noinit');
|
|
398
|
-
const DEADZONE = createSymbol('deadzone');
|
|
455
|
+
const DEADZONE = createSymbol('deadzone');
|
|
456
|
+
const IMPORT = createSymbol('import');
|
|
457
|
+
const EXPORTS = createSymbol('exports');
|
|
458
|
+
|
|
459
|
+
var version = "0.5.1";
|
|
399
460
|
|
|
400
461
|
class Var {
|
|
401
462
|
constructor(kind, value) {
|
|
@@ -704,8 +765,17 @@
|
|
|
704
765
|
}
|
|
705
766
|
}
|
|
706
767
|
function BinaryExpression(node, scope) {
|
|
707
|
-
|
|
708
|
-
|
|
768
|
+
let left;
|
|
769
|
+
let right;
|
|
770
|
+
if (node.left.type === 'PrivateIdentifier') {
|
|
771
|
+
left = node.left.name;
|
|
772
|
+
right = evaluate(node.right, scope);
|
|
773
|
+
right = right[PRIVATE];
|
|
774
|
+
}
|
|
775
|
+
else {
|
|
776
|
+
left = evaluate(node.left, scope);
|
|
777
|
+
right = evaluate(node.right, scope);
|
|
778
|
+
}
|
|
709
779
|
switch (node.operator) {
|
|
710
780
|
case '==': return left == right;
|
|
711
781
|
case '!=': return left != right;
|
|
@@ -828,12 +898,20 @@
|
|
|
828
898
|
if (getObj)
|
|
829
899
|
return object;
|
|
830
900
|
let key;
|
|
901
|
+
let priv = false;
|
|
831
902
|
if (node.computed) {
|
|
832
903
|
key = evaluate(node.property, scope);
|
|
833
904
|
}
|
|
905
|
+
else if (node.property.type === 'PrivateIdentifier') {
|
|
906
|
+
key = node.property.name;
|
|
907
|
+
priv = true;
|
|
908
|
+
}
|
|
834
909
|
else {
|
|
835
910
|
key = node.property.name;
|
|
836
911
|
}
|
|
912
|
+
if (priv) {
|
|
913
|
+
object = object[PRIVATE];
|
|
914
|
+
}
|
|
837
915
|
if (getVar) {
|
|
838
916
|
const setter = getSetter(object, key);
|
|
839
917
|
if (node.object.type === 'Super' && setter) {
|
|
@@ -877,18 +955,27 @@
|
|
|
877
955
|
return undefined;
|
|
878
956
|
}
|
|
879
957
|
let key;
|
|
958
|
+
let priv = false;
|
|
880
959
|
if (node.callee.computed) {
|
|
881
960
|
key = evaluate(node.callee.property, scope);
|
|
882
961
|
}
|
|
962
|
+
else if (node.callee.property.type === 'PrivateIdentifier') {
|
|
963
|
+
key = node.callee.property.name;
|
|
964
|
+
priv = true;
|
|
965
|
+
}
|
|
883
966
|
else {
|
|
884
967
|
key = node.callee.property.name;
|
|
885
968
|
}
|
|
969
|
+
let obj = object;
|
|
970
|
+
if (priv) {
|
|
971
|
+
obj = obj[PRIVATE];
|
|
972
|
+
}
|
|
886
973
|
if (node.callee.object.type === 'Super') {
|
|
887
974
|
const thisObject = scope.find('this').get();
|
|
888
|
-
func =
|
|
975
|
+
func = obj[key].bind(thisObject);
|
|
889
976
|
}
|
|
890
977
|
else {
|
|
891
|
-
func =
|
|
978
|
+
func = obj[key];
|
|
892
979
|
}
|
|
893
980
|
if (node.optional && func == null) {
|
|
894
981
|
return undefined;
|
|
@@ -984,7 +1071,12 @@
|
|
|
984
1071
|
return new constructor(...args);
|
|
985
1072
|
}
|
|
986
1073
|
function MetaProperty(node, scope) {
|
|
987
|
-
|
|
1074
|
+
if (node.meta.name === 'new' && node.property.name === 'target') {
|
|
1075
|
+
return scope.find(NEWTARGET).get();
|
|
1076
|
+
}
|
|
1077
|
+
else if (node.meta.name === 'import' && node.property.name === 'meta') {
|
|
1078
|
+
return { url: '' };
|
|
1079
|
+
}
|
|
988
1080
|
}
|
|
989
1081
|
function SequenceExpression(node, scope) {
|
|
990
1082
|
let result;
|
|
@@ -1052,6 +1144,27 @@
|
|
|
1052
1144
|
}
|
|
1053
1145
|
function ChainExpression(node, scope) {
|
|
1054
1146
|
return evaluate(node.expression, scope);
|
|
1147
|
+
}
|
|
1148
|
+
function ImportExpression(node, scope) {
|
|
1149
|
+
const globalScope = scope.global();
|
|
1150
|
+
const source = evaluate(node.source, scope);
|
|
1151
|
+
const module = globalScope.find(IMPORT + source);
|
|
1152
|
+
let value;
|
|
1153
|
+
if (module) {
|
|
1154
|
+
const result = module.get();
|
|
1155
|
+
if (result) {
|
|
1156
|
+
if (typeof result === 'function') {
|
|
1157
|
+
value = result();
|
|
1158
|
+
}
|
|
1159
|
+
else if (typeof result === 'object') {
|
|
1160
|
+
value = result;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
if (!value || typeof value !== 'object') {
|
|
1165
|
+
return Promise.reject(new TypeError(`Failed to resolve module specifier "${source}"`));
|
|
1166
|
+
}
|
|
1167
|
+
return Promise.resolve(value);
|
|
1055
1168
|
}
|
|
1056
1169
|
|
|
1057
1170
|
var expression = /*#__PURE__*/Object.freeze({
|
|
@@ -1078,9 +1191,176 @@
|
|
|
1078
1191
|
ClassExpression: ClassExpression,
|
|
1079
1192
|
Super: Super,
|
|
1080
1193
|
SpreadElement: SpreadElement,
|
|
1081
|
-
ChainExpression: ChainExpression
|
|
1194
|
+
ChainExpression: ChainExpression,
|
|
1195
|
+
ImportExpression: ImportExpression
|
|
1196
|
+
});
|
|
1197
|
+
|
|
1198
|
+
function ObjectPattern(node, scope, options = {}) {
|
|
1199
|
+
const { kind = 'var', hoist = false, onlyBlock = false, feed = {} } = options;
|
|
1200
|
+
const fedKeys = [];
|
|
1201
|
+
for (let i = 0; i < node.properties.length; i++) {
|
|
1202
|
+
const property = node.properties[i];
|
|
1203
|
+
if (hoist) {
|
|
1204
|
+
if (onlyBlock || kind === 'var') {
|
|
1205
|
+
if (property.type === 'Property') {
|
|
1206
|
+
const value = property.value;
|
|
1207
|
+
if (value.type === 'Identifier') {
|
|
1208
|
+
scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1209
|
+
}
|
|
1210
|
+
else {
|
|
1211
|
+
pattern$3(value, scope, { kind, hoist, onlyBlock });
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
else {
|
|
1215
|
+
RestElement(property, scope, { kind, hoist, onlyBlock });
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
else if (property.type === 'Property') {
|
|
1220
|
+
let key;
|
|
1221
|
+
if (property.computed) {
|
|
1222
|
+
key = evaluate(property.key, scope);
|
|
1223
|
+
}
|
|
1224
|
+
else {
|
|
1225
|
+
key = property.key.name;
|
|
1226
|
+
}
|
|
1227
|
+
fedKeys.push(key);
|
|
1228
|
+
const value = property.value;
|
|
1229
|
+
if (value.type === 'Identifier') {
|
|
1230
|
+
scope[kind](value.name, feed[key]);
|
|
1231
|
+
}
|
|
1232
|
+
else {
|
|
1233
|
+
pattern$3(value, scope, { kind, feed: feed[key] });
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
else {
|
|
1237
|
+
const rest = assign({}, feed);
|
|
1238
|
+
for (let i = 0; i < fedKeys.length; i++)
|
|
1239
|
+
delete rest[fedKeys[i]];
|
|
1240
|
+
RestElement(property, scope, { kind, feed: rest });
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
function ArrayPattern(node, scope, options = {}) {
|
|
1245
|
+
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
1246
|
+
const result = [];
|
|
1247
|
+
for (let i = 0; i < node.elements.length; i++) {
|
|
1248
|
+
const element = node.elements[i];
|
|
1249
|
+
if (!element)
|
|
1250
|
+
continue;
|
|
1251
|
+
if (hoist) {
|
|
1252
|
+
if (onlyBlock || kind === 'var') {
|
|
1253
|
+
if (element.type === 'Identifier') {
|
|
1254
|
+
scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1255
|
+
}
|
|
1256
|
+
else {
|
|
1257
|
+
pattern$3(element, scope, { kind, hoist, onlyBlock });
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
else if (element.type === 'Identifier') {
|
|
1262
|
+
if (kind) {
|
|
1263
|
+
scope[kind](element.name, feed[i]);
|
|
1264
|
+
}
|
|
1265
|
+
else {
|
|
1266
|
+
const variable = Identifier(element, scope, { getVar: true });
|
|
1267
|
+
variable.set(feed[i]);
|
|
1268
|
+
result.push(variable.get());
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
else if (element.type === 'RestElement') {
|
|
1272
|
+
RestElement(element, scope, { kind, feed: feed.slice(i) });
|
|
1273
|
+
}
|
|
1274
|
+
else {
|
|
1275
|
+
pattern$3(element, scope, { kind, feed: feed[i] });
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
if (result.length) {
|
|
1279
|
+
return result;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
function RestElement(node, scope, options = {}) {
|
|
1283
|
+
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
1284
|
+
const arg = node.argument;
|
|
1285
|
+
if (hoist) {
|
|
1286
|
+
if (onlyBlock || kind === 'var') {
|
|
1287
|
+
if (arg.type === 'Identifier') {
|
|
1288
|
+
scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1289
|
+
}
|
|
1290
|
+
else {
|
|
1291
|
+
pattern$3(arg, scope, { kind, hoist, onlyBlock });
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
else if (arg.type === 'Identifier') {
|
|
1296
|
+
if (kind) {
|
|
1297
|
+
scope[kind](arg.name, feed);
|
|
1298
|
+
}
|
|
1299
|
+
else {
|
|
1300
|
+
const variable = Identifier(arg, scope, { getVar: true });
|
|
1301
|
+
variable.set(feed);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
else {
|
|
1305
|
+
pattern$3(arg, scope, { kind, feed });
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
function AssignmentPattern(node, scope, options = {}) {
|
|
1309
|
+
const { kind = 'var', hoist = false, onlyBlock = false, feed = evaluate(node.right, scope) } = options;
|
|
1310
|
+
const left = node.left;
|
|
1311
|
+
if (hoist) {
|
|
1312
|
+
if (onlyBlock || kind === 'var') {
|
|
1313
|
+
if (left.type === 'Identifier') {
|
|
1314
|
+
scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1315
|
+
}
|
|
1316
|
+
else {
|
|
1317
|
+
pattern$3(left, scope, { kind, hoist, onlyBlock });
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
else if (left.type === 'Identifier') {
|
|
1322
|
+
scope[kind](left.name, feed);
|
|
1323
|
+
}
|
|
1324
|
+
else {
|
|
1325
|
+
pattern$3(left, scope, { kind, feed });
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
var pattern = /*#__PURE__*/Object.freeze({
|
|
1330
|
+
__proto__: null,
|
|
1331
|
+
ObjectPattern: ObjectPattern,
|
|
1332
|
+
ArrayPattern: ArrayPattern,
|
|
1333
|
+
RestElement: RestElement,
|
|
1334
|
+
AssignmentPattern: AssignmentPattern
|
|
1335
|
+
});
|
|
1336
|
+
|
|
1337
|
+
function Program(program, scope) {
|
|
1338
|
+
for (let i = 0; i < program.body.length; i++) {
|
|
1339
|
+
evaluate(program.body[i], scope);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
var program = /*#__PURE__*/Object.freeze({
|
|
1344
|
+
__proto__: null,
|
|
1345
|
+
Program: Program
|
|
1082
1346
|
});
|
|
1083
1347
|
|
|
1348
|
+
let evaluateOps;
|
|
1349
|
+
function evaluate(node, scope) {
|
|
1350
|
+
if (!node)
|
|
1351
|
+
return;
|
|
1352
|
+
if (!evaluateOps) {
|
|
1353
|
+
evaluateOps = assign({}, declaration, expression, identifier, statement, literal, pattern, program);
|
|
1354
|
+
}
|
|
1355
|
+
const handler = evaluateOps[node.type];
|
|
1356
|
+
if (handler) {
|
|
1357
|
+
return handler(node, scope);
|
|
1358
|
+
}
|
|
1359
|
+
else {
|
|
1360
|
+
throw new Error(`${node.type} isn't implemented`);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1084
1364
|
function ExpressionStatement(node, scope) {
|
|
1085
1365
|
evaluate(node.expression, scope);
|
|
1086
1366
|
}
|
|
@@ -1267,224 +1547,36 @@
|
|
|
1267
1547
|
}
|
|
1268
1548
|
}
|
|
1269
1549
|
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
CatchClause: CatchClause,
|
|
1285
|
-
WhileStatement: WhileStatement,
|
|
1286
|
-
DoWhileStatement: DoWhileStatement,
|
|
1287
|
-
ForStatement: ForStatement,
|
|
1288
|
-
ForInStatement: ForInStatement,
|
|
1289
|
-
ForOfStatement: ForOfStatement
|
|
1290
|
-
});
|
|
1291
|
-
|
|
1292
|
-
function ObjectPattern(node, scope, options = {}) {
|
|
1293
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed = {} } = options;
|
|
1294
|
-
const fedKeys = [];
|
|
1295
|
-
for (let i = 0; i < node.properties.length; i++) {
|
|
1296
|
-
const property = node.properties[i];
|
|
1297
|
-
if (hoist) {
|
|
1298
|
-
if (onlyBlock || kind === 'var') {
|
|
1299
|
-
if (property.type === 'Property') {
|
|
1300
|
-
const value = property.value;
|
|
1301
|
-
if (value.type === 'Identifier') {
|
|
1302
|
-
scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1303
|
-
}
|
|
1304
|
-
else {
|
|
1305
|
-
pattern$3(value, scope, { kind, hoist, onlyBlock });
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
else {
|
|
1309
|
-
RestElement(property, scope, { kind, hoist, onlyBlock });
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
else if (property.type === 'Property') {
|
|
1314
|
-
let key;
|
|
1315
|
-
if (property.computed) {
|
|
1316
|
-
key = evaluate(property.key, scope);
|
|
1550
|
+
function FunctionDeclaration(node, scope) {
|
|
1551
|
+
scope.func(node.id.name, createFunc$1(node, scope));
|
|
1552
|
+
}
|
|
1553
|
+
function VariableDeclaration(node, scope, options = {}) {
|
|
1554
|
+
for (let i = 0; i < node.declarations.length; i++) {
|
|
1555
|
+
VariableDeclarator(node.declarations[i], scope, assign({ kind: node.kind }, options));
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
function VariableDeclarator(node, scope, options = {}) {
|
|
1559
|
+
const { kind = 'var', hoist = false, onlyBlock = false, feed } = options;
|
|
1560
|
+
if (hoist) {
|
|
1561
|
+
if (onlyBlock || kind === 'var') {
|
|
1562
|
+
if (node.id.type === 'Identifier') {
|
|
1563
|
+
scope[kind](node.id.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1317
1564
|
}
|
|
1318
1565
|
else {
|
|
1319
|
-
|
|
1566
|
+
pattern$3(node.id, scope, { kind, hoist, onlyBlock });
|
|
1320
1567
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
else {
|
|
1571
|
+
const hasFeed = 'feed' in options;
|
|
1572
|
+
const value = hasFeed ? feed : evaluate(node.init, scope);
|
|
1573
|
+
if (node.id.type === 'Identifier') {
|
|
1574
|
+
const name = node.id.name;
|
|
1575
|
+
if (kind === 'var' && !node.init && !hasFeed) {
|
|
1576
|
+
scope.var(name, NOINIT);
|
|
1325
1577
|
}
|
|
1326
1578
|
else {
|
|
1327
|
-
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
else {
|
|
1331
|
-
const rest = assign({}, feed);
|
|
1332
|
-
for (let i = 0; i < fedKeys.length; i++)
|
|
1333
|
-
delete rest[fedKeys[i]];
|
|
1334
|
-
RestElement(property, scope, { kind, feed: rest });
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
function ArrayPattern(node, scope, options = {}) {
|
|
1339
|
-
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
1340
|
-
const result = [];
|
|
1341
|
-
for (let i = 0; i < node.elements.length; i++) {
|
|
1342
|
-
const element = node.elements[i];
|
|
1343
|
-
if (!element)
|
|
1344
|
-
continue;
|
|
1345
|
-
if (hoist) {
|
|
1346
|
-
if (onlyBlock || kind === 'var') {
|
|
1347
|
-
if (element.type === 'Identifier') {
|
|
1348
|
-
scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1349
|
-
}
|
|
1350
|
-
else {
|
|
1351
|
-
pattern$3(element, scope, { kind, hoist, onlyBlock });
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
else if (element.type === 'Identifier') {
|
|
1356
|
-
if (kind) {
|
|
1357
|
-
scope[kind](element.name, feed[i]);
|
|
1358
|
-
}
|
|
1359
|
-
else {
|
|
1360
|
-
const variable = Identifier(element, scope, { getVar: true });
|
|
1361
|
-
variable.set(feed[i]);
|
|
1362
|
-
result.push(variable.get());
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
else if (element.type === 'RestElement') {
|
|
1366
|
-
RestElement(element, scope, { kind, feed: feed.slice(i) });
|
|
1367
|
-
}
|
|
1368
|
-
else {
|
|
1369
|
-
pattern$3(element, scope, { kind, feed: feed[i] });
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
if (result.length) {
|
|
1373
|
-
return result;
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
function RestElement(node, scope, options = {}) {
|
|
1377
|
-
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
1378
|
-
const arg = node.argument;
|
|
1379
|
-
if (hoist) {
|
|
1380
|
-
if (onlyBlock || kind === 'var') {
|
|
1381
|
-
if (arg.type === 'Identifier') {
|
|
1382
|
-
scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1383
|
-
}
|
|
1384
|
-
else {
|
|
1385
|
-
pattern$3(arg, scope, { kind, hoist, onlyBlock });
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
else if (arg.type === 'Identifier') {
|
|
1390
|
-
if (kind) {
|
|
1391
|
-
scope[kind](arg.name, feed);
|
|
1392
|
-
}
|
|
1393
|
-
else {
|
|
1394
|
-
const variable = Identifier(arg, scope, { getVar: true });
|
|
1395
|
-
variable.set(feed);
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
else {
|
|
1399
|
-
pattern$3(arg, scope, { kind, feed });
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
function AssignmentPattern(node, scope, options = {}) {
|
|
1403
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed = evaluate(node.right, scope) } = options;
|
|
1404
|
-
const left = node.left;
|
|
1405
|
-
if (hoist) {
|
|
1406
|
-
if (onlyBlock || kind === 'var') {
|
|
1407
|
-
if (left.type === 'Identifier') {
|
|
1408
|
-
scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1409
|
-
}
|
|
1410
|
-
else {
|
|
1411
|
-
pattern$3(left, scope, { kind, hoist, onlyBlock });
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
else if (left.type === 'Identifier') {
|
|
1416
|
-
scope[kind](left.name, feed);
|
|
1417
|
-
}
|
|
1418
|
-
else {
|
|
1419
|
-
pattern$3(left, scope, { kind, feed });
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1423
|
-
var pattern = /*#__PURE__*/Object.freeze({
|
|
1424
|
-
__proto__: null,
|
|
1425
|
-
ObjectPattern: ObjectPattern,
|
|
1426
|
-
ArrayPattern: ArrayPattern,
|
|
1427
|
-
RestElement: RestElement,
|
|
1428
|
-
AssignmentPattern: AssignmentPattern
|
|
1429
|
-
});
|
|
1430
|
-
|
|
1431
|
-
function Program(program, scope) {
|
|
1432
|
-
for (let i = 0; i < program.body.length; i++) {
|
|
1433
|
-
evaluate(program.body[i], scope);
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
|
-
var program = /*#__PURE__*/Object.freeze({
|
|
1438
|
-
__proto__: null,
|
|
1439
|
-
Program: Program
|
|
1440
|
-
});
|
|
1441
|
-
|
|
1442
|
-
let evaluateOps;
|
|
1443
|
-
function evaluate(node, scope) {
|
|
1444
|
-
if (!node)
|
|
1445
|
-
return;
|
|
1446
|
-
if (!evaluateOps) {
|
|
1447
|
-
evaluateOps = assign({}, declaration, expression, identifier, statement, literal, pattern, program);
|
|
1448
|
-
}
|
|
1449
|
-
const handler = evaluateOps[node.type];
|
|
1450
|
-
if (handler) {
|
|
1451
|
-
return handler(node, scope);
|
|
1452
|
-
}
|
|
1453
|
-
else {
|
|
1454
|
-
throw new Error(`${node.type} isn't implemented`);
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
function FunctionDeclaration(node, scope) {
|
|
1459
|
-
scope.func(node.id.name, createFunc$1(node, scope));
|
|
1460
|
-
}
|
|
1461
|
-
function VariableDeclaration(node, scope, options = {}) {
|
|
1462
|
-
for (let i = 0; i < node.declarations.length; i++) {
|
|
1463
|
-
VariableDeclarator(node.declarations[i], scope, assign({ kind: node.kind }, options));
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
function VariableDeclarator(node, scope, options = {}) {
|
|
1467
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed } = options;
|
|
1468
|
-
if (hoist) {
|
|
1469
|
-
if (onlyBlock || kind === 'var') {
|
|
1470
|
-
if (node.id.type === 'Identifier') {
|
|
1471
|
-
scope[kind](node.id.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1472
|
-
}
|
|
1473
|
-
else {
|
|
1474
|
-
pattern$3(node.id, scope, { kind, hoist, onlyBlock });
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
else {
|
|
1479
|
-
const hasFeed = 'feed' in options;
|
|
1480
|
-
const value = hasFeed ? feed : evaluate(node.init, scope);
|
|
1481
|
-
if (node.id.type === 'Identifier') {
|
|
1482
|
-
const name = node.id.name;
|
|
1483
|
-
if (kind === 'var' && !node.init && !hasFeed) {
|
|
1484
|
-
scope.var(name, NOINIT);
|
|
1485
|
-
}
|
|
1486
|
-
else {
|
|
1487
|
-
scope[kind](name, value);
|
|
1579
|
+
scope[kind](name, value);
|
|
1488
1580
|
}
|
|
1489
1581
|
if (node.init
|
|
1490
1582
|
&& ['ClassExpression', 'FunctionExpression', 'ArrowFunctionExpression']
|
|
@@ -1511,21 +1603,38 @@
|
|
|
1511
1603
|
if (def.type === 'MethodDefinition') {
|
|
1512
1604
|
MethodDefinition(def, scope, { klass, superClass });
|
|
1513
1605
|
}
|
|
1606
|
+
else if (def.type === 'PropertyDefinition' && def.static) {
|
|
1607
|
+
PropertyDefinition(def, scope, { klass, superClass });
|
|
1608
|
+
}
|
|
1609
|
+
else if (def.type === 'StaticBlock') {
|
|
1610
|
+
StaticBlock(def, scope, { klass, superClass });
|
|
1611
|
+
}
|
|
1514
1612
|
}
|
|
1515
1613
|
}
|
|
1516
1614
|
function MethodDefinition(node, scope, options = {}) {
|
|
1517
1615
|
const { klass, superClass } = options;
|
|
1518
1616
|
let key;
|
|
1617
|
+
let priv = false;
|
|
1519
1618
|
if (node.computed) {
|
|
1520
1619
|
key = evaluate(node.key, scope);
|
|
1521
1620
|
}
|
|
1522
1621
|
else if (node.key.type === 'Identifier') {
|
|
1523
1622
|
key = node.key.name;
|
|
1524
1623
|
}
|
|
1624
|
+
else if (node.key.type === 'PrivateIdentifier') {
|
|
1625
|
+
key = node.key.name;
|
|
1626
|
+
priv = true;
|
|
1627
|
+
}
|
|
1525
1628
|
else {
|
|
1526
1629
|
throw new SyntaxError('Unexpected token');
|
|
1527
1630
|
}
|
|
1528
|
-
|
|
1631
|
+
let obj = node.static ? klass : klass.prototype;
|
|
1632
|
+
if (priv) {
|
|
1633
|
+
if (!obj[PRIVATE]) {
|
|
1634
|
+
define(obj, PRIVATE, { value: {} });
|
|
1635
|
+
}
|
|
1636
|
+
obj = obj[PRIVATE];
|
|
1637
|
+
}
|
|
1529
1638
|
const value = createFunc$1(node.value, scope, { superClass });
|
|
1530
1639
|
switch (node.kind) {
|
|
1531
1640
|
case 'constructor':
|
|
@@ -1558,6 +1667,191 @@
|
|
|
1558
1667
|
default:
|
|
1559
1668
|
throw new SyntaxError('Unexpected token');
|
|
1560
1669
|
}
|
|
1670
|
+
}
|
|
1671
|
+
function PropertyDefinition(node, scope, options = {}) {
|
|
1672
|
+
const { klass, superClass } = options;
|
|
1673
|
+
let key;
|
|
1674
|
+
let priv = false;
|
|
1675
|
+
if (node.computed) {
|
|
1676
|
+
key = evaluate(node.key, scope);
|
|
1677
|
+
}
|
|
1678
|
+
else if (node.key.type === 'Identifier') {
|
|
1679
|
+
key = node.key.name;
|
|
1680
|
+
}
|
|
1681
|
+
else if (node.key.type === 'PrivateIdentifier') {
|
|
1682
|
+
key = node.key.name;
|
|
1683
|
+
priv = true;
|
|
1684
|
+
}
|
|
1685
|
+
else {
|
|
1686
|
+
throw new SyntaxError('Unexpected token');
|
|
1687
|
+
}
|
|
1688
|
+
const subScope = new Scope(scope, true);
|
|
1689
|
+
subScope.const('this', klass);
|
|
1690
|
+
let obj = klass;
|
|
1691
|
+
if (priv) {
|
|
1692
|
+
if (!obj[PRIVATE]) {
|
|
1693
|
+
define(obj, PRIVATE, { value: {} });
|
|
1694
|
+
}
|
|
1695
|
+
obj = obj[PRIVATE];
|
|
1696
|
+
}
|
|
1697
|
+
if (node.value.type === 'FunctionExpression' || node.value.type === 'ArrowFunctionExpression') {
|
|
1698
|
+
obj[key] = createFunc$1(node.value, subScope, { superClass });
|
|
1699
|
+
}
|
|
1700
|
+
else {
|
|
1701
|
+
obj[key] = evaluate(node.value, subScope);
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
function StaticBlock(node, scope, options = {}) {
|
|
1705
|
+
const { klass } = options;
|
|
1706
|
+
const subScope = new Scope(scope, true);
|
|
1707
|
+
subScope.const('this', klass);
|
|
1708
|
+
return BlockStatement(node, subScope, { invasived: true });
|
|
1709
|
+
}
|
|
1710
|
+
function ImportDeclaration(node, scope) {
|
|
1711
|
+
const globalScope = scope.global();
|
|
1712
|
+
const module = globalScope.find(IMPORT + node.source.value);
|
|
1713
|
+
let value;
|
|
1714
|
+
if (module) {
|
|
1715
|
+
const result = module.get();
|
|
1716
|
+
if (result) {
|
|
1717
|
+
if (typeof result === 'function') {
|
|
1718
|
+
value = result();
|
|
1719
|
+
}
|
|
1720
|
+
else if (typeof result === 'object') {
|
|
1721
|
+
value = result;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
if (!value || typeof value !== 'object') {
|
|
1726
|
+
throw new TypeError(`Failed to resolve module specifier "${node.source.value}"`);
|
|
1727
|
+
}
|
|
1728
|
+
for (let i = 0; i < node.specifiers.length; i++) {
|
|
1729
|
+
const spec = node.specifiers[i];
|
|
1730
|
+
let name;
|
|
1731
|
+
if (spec.type === 'ImportSpecifier') {
|
|
1732
|
+
name = spec.imported.type === 'Identifier'
|
|
1733
|
+
? spec.imported.name : spec.imported.value;
|
|
1734
|
+
}
|
|
1735
|
+
else if (spec.type === 'ImportDefaultSpecifier') {
|
|
1736
|
+
name = 'default';
|
|
1737
|
+
}
|
|
1738
|
+
else if (spec.type === 'ImportNamespaceSpecifier') {
|
|
1739
|
+
name = '*';
|
|
1740
|
+
}
|
|
1741
|
+
if (name !== '*' && !hasOwn(value, name)) {
|
|
1742
|
+
throw new SyntaxError(`The requested module "${node.source.value}" does not provide an export named "${name}"`);
|
|
1743
|
+
}
|
|
1744
|
+
scope.var(spec.local.name, name === '*' ? assign({}, value) : value[name]);
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
function ExportDefaultDeclaration(node, scope) {
|
|
1748
|
+
const globalScope = scope.global();
|
|
1749
|
+
let value;
|
|
1750
|
+
if (node.declaration.type === 'FunctionDeclaration') {
|
|
1751
|
+
value = createFunc$1(node.declaration, scope);
|
|
1752
|
+
scope.func(node.declaration.id.name, value);
|
|
1753
|
+
}
|
|
1754
|
+
else if (node.declaration.type === 'ClassDeclaration') {
|
|
1755
|
+
value = createClass$1(node.declaration, scope);
|
|
1756
|
+
scope.func(node.declaration.id.name, value);
|
|
1757
|
+
}
|
|
1758
|
+
else {
|
|
1759
|
+
value = evaluate(node.declaration, scope);
|
|
1760
|
+
}
|
|
1761
|
+
const variable = globalScope.find(EXPORTS);
|
|
1762
|
+
if (variable) {
|
|
1763
|
+
const exports = variable.get();
|
|
1764
|
+
if (exports && typeof exports === 'object') {
|
|
1765
|
+
exports.default = value;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
function ExportNamedDeclaration(node, scope) {
|
|
1770
|
+
const globalScope = scope.global();
|
|
1771
|
+
if (node.declaration) {
|
|
1772
|
+
if (node.declaration.type === 'FunctionDeclaration') {
|
|
1773
|
+
const value = createFunc$1(node.declaration, scope);
|
|
1774
|
+
scope.func(node.declaration.id.name, value);
|
|
1775
|
+
const variable = globalScope.find(EXPORTS);
|
|
1776
|
+
if (variable) {
|
|
1777
|
+
const exports = variable.get();
|
|
1778
|
+
if (exports && typeof exports === 'object') {
|
|
1779
|
+
exports[node.declaration.id.name] = value;
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
else if (node.declaration.type === 'ClassDeclaration') {
|
|
1784
|
+
const value = createClass$1(node.declaration, scope);
|
|
1785
|
+
scope.func(node.declaration.id.name, value);
|
|
1786
|
+
const variable = globalScope.find(EXPORTS);
|
|
1787
|
+
if (variable) {
|
|
1788
|
+
const exports = variable.get();
|
|
1789
|
+
if (exports && typeof exports === 'object') {
|
|
1790
|
+
exports[node.declaration.id.name] = value;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
else if (node.declaration.type === 'VariableDeclaration') {
|
|
1795
|
+
VariableDeclaration(node.declaration, scope);
|
|
1796
|
+
const variable = globalScope.find(EXPORTS);
|
|
1797
|
+
if (variable) {
|
|
1798
|
+
const exports = variable.get();
|
|
1799
|
+
if (exports && typeof exports === 'object') {
|
|
1800
|
+
for (let i = 0; i < node.declaration.declarations.length; i++) {
|
|
1801
|
+
const name = node.declaration.declarations[i].id.name;
|
|
1802
|
+
const item = scope.find(name);
|
|
1803
|
+
if (item) {
|
|
1804
|
+
exports[name] = item.get();
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
else if (node.specifiers) {
|
|
1812
|
+
const variable = globalScope.find(EXPORTS);
|
|
1813
|
+
if (variable) {
|
|
1814
|
+
const exports = variable.get();
|
|
1815
|
+
if (exports && typeof exports === 'object') {
|
|
1816
|
+
for (let i = 0; i < node.specifiers.length; i++) {
|
|
1817
|
+
const spec = node.specifiers[i];
|
|
1818
|
+
const name = spec.local.type === 'Identifier'
|
|
1819
|
+
? spec.local.name : spec.local.value;
|
|
1820
|
+
const item = scope.find(name);
|
|
1821
|
+
if (item) {
|
|
1822
|
+
exports[spec.exported.type === 'Identifier'
|
|
1823
|
+
? spec.exported.name : spec.exported.value] = item.get();
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
function ExportAllDeclaration(node, scope) {
|
|
1831
|
+
const globalScope = scope.global();
|
|
1832
|
+
const module = globalScope.find(IMPORT + node.source.value);
|
|
1833
|
+
let value;
|
|
1834
|
+
if (module) {
|
|
1835
|
+
const result = module.get();
|
|
1836
|
+
if (result) {
|
|
1837
|
+
if (typeof result === 'function') {
|
|
1838
|
+
value = result();
|
|
1839
|
+
}
|
|
1840
|
+
else if (typeof result === 'object') {
|
|
1841
|
+
value = result;
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
if (!value || typeof value !== 'object') {
|
|
1846
|
+
throw new TypeError(`Failed to resolve module specifier "${node.source.value}"`);
|
|
1847
|
+
}
|
|
1848
|
+
const variable = globalScope.find(EXPORTS);
|
|
1849
|
+
if (variable) {
|
|
1850
|
+
const exports = variable.get();
|
|
1851
|
+
if (exports && typeof exports === 'object') {
|
|
1852
|
+
assign(exports, value);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1561
1855
|
}
|
|
1562
1856
|
|
|
1563
1857
|
function* Identifier$1(node, scope, options = {}) {
|
|
@@ -1740,8 +2034,17 @@
|
|
|
1740
2034
|
}
|
|
1741
2035
|
}
|
|
1742
2036
|
function* BinaryExpression$1(node, scope) {
|
|
1743
|
-
|
|
1744
|
-
|
|
2037
|
+
let left;
|
|
2038
|
+
let right;
|
|
2039
|
+
if (node.left.type === 'PrivateIdentifier') {
|
|
2040
|
+
left = node.left.name;
|
|
2041
|
+
right = yield* evaluate$1(node.right, scope);
|
|
2042
|
+
right = right[PRIVATE];
|
|
2043
|
+
}
|
|
2044
|
+
else {
|
|
2045
|
+
left = yield* evaluate$1(node.left, scope);
|
|
2046
|
+
right = yield* evaluate$1(node.right, scope);
|
|
2047
|
+
}
|
|
1745
2048
|
switch (node.operator) {
|
|
1746
2049
|
case '==': return left == right;
|
|
1747
2050
|
case '!=': return left != right;
|
|
@@ -1864,12 +2167,20 @@
|
|
|
1864
2167
|
if (getObj)
|
|
1865
2168
|
return object;
|
|
1866
2169
|
let key;
|
|
2170
|
+
let priv = false;
|
|
1867
2171
|
if (node.computed) {
|
|
1868
2172
|
key = yield* evaluate$1(node.property, scope);
|
|
1869
2173
|
}
|
|
2174
|
+
else if (node.property.type === 'PrivateIdentifier') {
|
|
2175
|
+
key = node.property.name;
|
|
2176
|
+
priv = true;
|
|
2177
|
+
}
|
|
1870
2178
|
else {
|
|
1871
2179
|
key = node.property.name;
|
|
1872
2180
|
}
|
|
2181
|
+
if (priv) {
|
|
2182
|
+
object = object[PRIVATE];
|
|
2183
|
+
}
|
|
1873
2184
|
if (getVar) {
|
|
1874
2185
|
const setter = getSetter(object, key);
|
|
1875
2186
|
if (node.object.type === 'Super' && setter) {
|
|
@@ -1913,18 +2224,27 @@
|
|
|
1913
2224
|
return undefined;
|
|
1914
2225
|
}
|
|
1915
2226
|
let key;
|
|
2227
|
+
let priv = false;
|
|
1916
2228
|
if (node.callee.computed) {
|
|
1917
2229
|
key = yield* evaluate$1(node.callee.property, scope);
|
|
1918
2230
|
}
|
|
2231
|
+
else if (node.callee.property.type === 'PrivateIdentifier') {
|
|
2232
|
+
key = node.callee.property.name;
|
|
2233
|
+
priv = true;
|
|
2234
|
+
}
|
|
1919
2235
|
else {
|
|
1920
2236
|
key = node.callee.property.name;
|
|
1921
2237
|
}
|
|
2238
|
+
let obj = object;
|
|
2239
|
+
if (priv) {
|
|
2240
|
+
obj = obj[PRIVATE];
|
|
2241
|
+
}
|
|
1922
2242
|
if (node.callee.object.type === 'Super') {
|
|
1923
2243
|
const thisObject = scope.find('this').get();
|
|
1924
|
-
func =
|
|
2244
|
+
func = obj[key].bind(thisObject);
|
|
1925
2245
|
}
|
|
1926
2246
|
else {
|
|
1927
|
-
func =
|
|
2247
|
+
func = obj[key];
|
|
1928
2248
|
}
|
|
1929
2249
|
if (node.optional && func == null) {
|
|
1930
2250
|
return undefined;
|
|
@@ -2020,7 +2340,12 @@
|
|
|
2020
2340
|
return new constructor(...args);
|
|
2021
2341
|
}
|
|
2022
2342
|
function* MetaProperty$1(node, scope) {
|
|
2023
|
-
|
|
2343
|
+
if (node.meta.name === 'new' && node.property.name === 'target') {
|
|
2344
|
+
return scope.find(NEWTARGET).get();
|
|
2345
|
+
}
|
|
2346
|
+
else if (node.meta.name === 'import' && node.property.name === 'meta') {
|
|
2347
|
+
return { url: '' };
|
|
2348
|
+
}
|
|
2024
2349
|
}
|
|
2025
2350
|
function* SequenceExpression$1(node, scope) {
|
|
2026
2351
|
let result;
|
|
@@ -2089,6 +2414,27 @@
|
|
|
2089
2414
|
function* ChainExpression$1(node, scope) {
|
|
2090
2415
|
return yield* evaluate$1(node.expression, scope);
|
|
2091
2416
|
}
|
|
2417
|
+
function* ImportExpression$1(node, scope) {
|
|
2418
|
+
const globalScope = scope.global();
|
|
2419
|
+
const source = yield* evaluate$1(node.source, scope);
|
|
2420
|
+
const module = globalScope.find(IMPORT + source);
|
|
2421
|
+
let value;
|
|
2422
|
+
if (module) {
|
|
2423
|
+
const result = module.get();
|
|
2424
|
+
if (result) {
|
|
2425
|
+
if (typeof result === 'function') {
|
|
2426
|
+
value = result();
|
|
2427
|
+
}
|
|
2428
|
+
else if (typeof result === 'object') {
|
|
2429
|
+
value = result;
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
if (!value || typeof value !== 'object') {
|
|
2434
|
+
return Promise.reject(new TypeError(`Failed to resolve module specifier "${source}"`));
|
|
2435
|
+
}
|
|
2436
|
+
return Promise.resolve(value);
|
|
2437
|
+
}
|
|
2092
2438
|
function* YieldExpression(node, scope) {
|
|
2093
2439
|
const res = yield* evaluate$1(node.argument, scope);
|
|
2094
2440
|
return node.delegate ? yield* res : yield res;
|
|
@@ -2123,10 +2469,166 @@
|
|
|
2123
2469
|
Super: Super$1,
|
|
2124
2470
|
SpreadElement: SpreadElement$1,
|
|
2125
2471
|
ChainExpression: ChainExpression$1,
|
|
2472
|
+
ImportExpression: ImportExpression$1,
|
|
2126
2473
|
YieldExpression: YieldExpression,
|
|
2127
2474
|
AwaitExpression: AwaitExpression
|
|
2128
2475
|
});
|
|
2129
2476
|
|
|
2477
|
+
function* ObjectPattern$1(node, scope, options = {}) {
|
|
2478
|
+
const { kind = 'var', hoist = false, onlyBlock = false, feed = {} } = options;
|
|
2479
|
+
const fedKeys = [];
|
|
2480
|
+
for (let i = 0; i < node.properties.length; i++) {
|
|
2481
|
+
const property = node.properties[i];
|
|
2482
|
+
if (hoist) {
|
|
2483
|
+
if (onlyBlock || kind === 'var') {
|
|
2484
|
+
if (property.type === 'Property') {
|
|
2485
|
+
const value = property.value;
|
|
2486
|
+
if (value.type === 'Identifier') {
|
|
2487
|
+
scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2488
|
+
}
|
|
2489
|
+
else {
|
|
2490
|
+
yield* pattern$2(value, scope, { kind, hoist, onlyBlock });
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
else {
|
|
2494
|
+
yield* RestElement$1(property, scope, { kind, hoist, onlyBlock });
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
else if (property.type === 'Property') {
|
|
2499
|
+
let key;
|
|
2500
|
+
if (property.computed) {
|
|
2501
|
+
key = yield* evaluate$1(property.key, scope);
|
|
2502
|
+
}
|
|
2503
|
+
else {
|
|
2504
|
+
key = property.key.name;
|
|
2505
|
+
}
|
|
2506
|
+
fedKeys.push(key);
|
|
2507
|
+
const value = property.value;
|
|
2508
|
+
if (value.type === 'Identifier') {
|
|
2509
|
+
scope[kind](value.name, feed[key]);
|
|
2510
|
+
}
|
|
2511
|
+
else {
|
|
2512
|
+
yield* pattern$2(value, scope, { kind, feed: feed[key] });
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
else {
|
|
2516
|
+
const rest = assign({}, feed);
|
|
2517
|
+
for (let i = 0; i < fedKeys.length; i++)
|
|
2518
|
+
delete rest[fedKeys[i]];
|
|
2519
|
+
yield* RestElement$1(property, scope, { kind, feed: rest });
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
function* ArrayPattern$1(node, scope, options = {}) {
|
|
2524
|
+
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
2525
|
+
const result = [];
|
|
2526
|
+
for (let i = 0; i < node.elements.length; i++) {
|
|
2527
|
+
const element = node.elements[i];
|
|
2528
|
+
if (!element)
|
|
2529
|
+
continue;
|
|
2530
|
+
if (hoist) {
|
|
2531
|
+
if (onlyBlock || kind === 'var') {
|
|
2532
|
+
if (element.type === 'Identifier') {
|
|
2533
|
+
scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2534
|
+
}
|
|
2535
|
+
else {
|
|
2536
|
+
yield* pattern$2(element, scope, { kind, hoist, onlyBlock });
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
else if (element.type === 'Identifier') {
|
|
2541
|
+
if (kind) {
|
|
2542
|
+
scope[kind](element.name, feed[i]);
|
|
2543
|
+
}
|
|
2544
|
+
else {
|
|
2545
|
+
const variable = yield* Identifier$1(element, scope, { getVar: true });
|
|
2546
|
+
variable.set(feed[i]);
|
|
2547
|
+
result.push(variable.get());
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
else if (element.type === 'RestElement') {
|
|
2551
|
+
yield* RestElement$1(element, scope, { kind, feed: feed.slice(i) });
|
|
2552
|
+
}
|
|
2553
|
+
else {
|
|
2554
|
+
yield* pattern$2(element, scope, { kind, feed: feed[i] });
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
if (result.length) {
|
|
2558
|
+
return result;
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
function* RestElement$1(node, scope, options = {}) {
|
|
2562
|
+
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
2563
|
+
const arg = node.argument;
|
|
2564
|
+
if (hoist) {
|
|
2565
|
+
if (onlyBlock || kind === 'var') {
|
|
2566
|
+
if (arg.type === 'Identifier') {
|
|
2567
|
+
scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2568
|
+
}
|
|
2569
|
+
else {
|
|
2570
|
+
yield* pattern$2(arg, scope, { kind, hoist, onlyBlock });
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
else if (arg.type === 'Identifier') {
|
|
2575
|
+
if (kind) {
|
|
2576
|
+
scope[kind](arg.name, feed);
|
|
2577
|
+
}
|
|
2578
|
+
else {
|
|
2579
|
+
const variable = yield* Identifier$1(arg, scope, { getVar: true });
|
|
2580
|
+
variable.set(feed);
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
else {
|
|
2584
|
+
yield* pattern$2(arg, scope, { kind, feed });
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
function* AssignmentPattern$1(node, scope, options = {}) {
|
|
2588
|
+
const { kind = 'var', hoist = false, onlyBlock = false, feed = yield* evaluate$1(node.right, scope) } = options;
|
|
2589
|
+
const left = node.left;
|
|
2590
|
+
if (hoist) {
|
|
2591
|
+
if (onlyBlock || kind === 'var') {
|
|
2592
|
+
if (left.type === 'Identifier') {
|
|
2593
|
+
scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2594
|
+
}
|
|
2595
|
+
else {
|
|
2596
|
+
yield* pattern$2(left, scope, { kind, hoist, onlyBlock });
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
else if (left.type === 'Identifier') {
|
|
2601
|
+
scope[kind](left.name, feed);
|
|
2602
|
+
}
|
|
2603
|
+
else {
|
|
2604
|
+
yield* pattern$2(left, scope, { kind, feed });
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
var pattern$1 = /*#__PURE__*/Object.freeze({
|
|
2609
|
+
__proto__: null,
|
|
2610
|
+
ObjectPattern: ObjectPattern$1,
|
|
2611
|
+
ArrayPattern: ArrayPattern$1,
|
|
2612
|
+
RestElement: RestElement$1,
|
|
2613
|
+
AssignmentPattern: AssignmentPattern$1
|
|
2614
|
+
});
|
|
2615
|
+
|
|
2616
|
+
let evaluateOps$1;
|
|
2617
|
+
function* evaluate$1(node, scope) {
|
|
2618
|
+
if (!node)
|
|
2619
|
+
return;
|
|
2620
|
+
if (!evaluateOps$1) {
|
|
2621
|
+
evaluateOps$1 = assign({}, declaration$1, expression$1, identifier$1, statement$1, literal$1, pattern$1);
|
|
2622
|
+
}
|
|
2623
|
+
const handler = evaluateOps$1[node.type];
|
|
2624
|
+
if (handler) {
|
|
2625
|
+
return yield* handler(node, scope);
|
|
2626
|
+
}
|
|
2627
|
+
else {
|
|
2628
|
+
throw new Error(`${node.type} isn't implemented`);
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2130
2632
|
function* ExpressionStatement$1(node, scope) {
|
|
2131
2633
|
yield* evaluate$1(node.expression, scope);
|
|
2132
2634
|
}
|
|
@@ -2331,183 +2833,6 @@
|
|
|
2331
2833
|
}
|
|
2332
2834
|
}
|
|
2333
2835
|
|
|
2334
|
-
var statement$1 = /*#__PURE__*/Object.freeze({
|
|
2335
|
-
__proto__: null,
|
|
2336
|
-
ExpressionStatement: ExpressionStatement$1,
|
|
2337
|
-
BlockStatement: BlockStatement$1,
|
|
2338
|
-
EmptyStatement: EmptyStatement$1,
|
|
2339
|
-
DebuggerStatement: DebuggerStatement$1,
|
|
2340
|
-
ReturnStatement: ReturnStatement$1,
|
|
2341
|
-
BreakStatement: BreakStatement$1,
|
|
2342
|
-
ContinueStatement: ContinueStatement$1,
|
|
2343
|
-
IfStatement: IfStatement$1,
|
|
2344
|
-
SwitchStatement: SwitchStatement$1,
|
|
2345
|
-
SwitchCase: SwitchCase$1,
|
|
2346
|
-
ThrowStatement: ThrowStatement$1,
|
|
2347
|
-
TryStatement: TryStatement$1,
|
|
2348
|
-
CatchClause: CatchClause$1,
|
|
2349
|
-
WhileStatement: WhileStatement$1,
|
|
2350
|
-
DoWhileStatement: DoWhileStatement$1,
|
|
2351
|
-
ForStatement: ForStatement$1,
|
|
2352
|
-
ForInStatement: ForInStatement$1,
|
|
2353
|
-
ForOfStatement: ForOfStatement$1
|
|
2354
|
-
});
|
|
2355
|
-
|
|
2356
|
-
function* ObjectPattern$1(node, scope, options = {}) {
|
|
2357
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed = {} } = options;
|
|
2358
|
-
const fedKeys = [];
|
|
2359
|
-
for (let i = 0; i < node.properties.length; i++) {
|
|
2360
|
-
const property = node.properties[i];
|
|
2361
|
-
if (hoist) {
|
|
2362
|
-
if (onlyBlock || kind === 'var') {
|
|
2363
|
-
if (property.type === 'Property') {
|
|
2364
|
-
const value = property.value;
|
|
2365
|
-
if (value.type === 'Identifier') {
|
|
2366
|
-
scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2367
|
-
}
|
|
2368
|
-
else {
|
|
2369
|
-
yield* pattern$2(value, scope, { kind, hoist, onlyBlock });
|
|
2370
|
-
}
|
|
2371
|
-
}
|
|
2372
|
-
else {
|
|
2373
|
-
yield* RestElement$1(property, scope, { kind, hoist, onlyBlock });
|
|
2374
|
-
}
|
|
2375
|
-
}
|
|
2376
|
-
}
|
|
2377
|
-
else if (property.type === 'Property') {
|
|
2378
|
-
let key;
|
|
2379
|
-
if (property.computed) {
|
|
2380
|
-
key = yield* evaluate$1(property.key, scope);
|
|
2381
|
-
}
|
|
2382
|
-
else {
|
|
2383
|
-
key = property.key.name;
|
|
2384
|
-
}
|
|
2385
|
-
fedKeys.push(key);
|
|
2386
|
-
const value = property.value;
|
|
2387
|
-
if (value.type === 'Identifier') {
|
|
2388
|
-
scope[kind](value.name, feed[key]);
|
|
2389
|
-
}
|
|
2390
|
-
else {
|
|
2391
|
-
yield* pattern$2(value, scope, { kind, feed: feed[key] });
|
|
2392
|
-
}
|
|
2393
|
-
}
|
|
2394
|
-
else {
|
|
2395
|
-
const rest = assign({}, feed);
|
|
2396
|
-
for (let i = 0; i < fedKeys.length; i++)
|
|
2397
|
-
delete rest[fedKeys[i]];
|
|
2398
|
-
yield* RestElement$1(property, scope, { kind, feed: rest });
|
|
2399
|
-
}
|
|
2400
|
-
}
|
|
2401
|
-
}
|
|
2402
|
-
function* ArrayPattern$1(node, scope, options = {}) {
|
|
2403
|
-
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
2404
|
-
const result = [];
|
|
2405
|
-
for (let i = 0; i < node.elements.length; i++) {
|
|
2406
|
-
const element = node.elements[i];
|
|
2407
|
-
if (!element)
|
|
2408
|
-
continue;
|
|
2409
|
-
if (hoist) {
|
|
2410
|
-
if (onlyBlock || kind === 'var') {
|
|
2411
|
-
if (element.type === 'Identifier') {
|
|
2412
|
-
scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2413
|
-
}
|
|
2414
|
-
else {
|
|
2415
|
-
yield* pattern$2(element, scope, { kind, hoist, onlyBlock });
|
|
2416
|
-
}
|
|
2417
|
-
}
|
|
2418
|
-
}
|
|
2419
|
-
else if (element.type === 'Identifier') {
|
|
2420
|
-
if (kind) {
|
|
2421
|
-
scope[kind](element.name, feed[i]);
|
|
2422
|
-
}
|
|
2423
|
-
else {
|
|
2424
|
-
const variable = yield* Identifier$1(element, scope, { getVar: true });
|
|
2425
|
-
variable.set(feed[i]);
|
|
2426
|
-
result.push(variable.get());
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
|
-
else if (element.type === 'RestElement') {
|
|
2430
|
-
yield* RestElement$1(element, scope, { kind, feed: feed.slice(i) });
|
|
2431
|
-
}
|
|
2432
|
-
else {
|
|
2433
|
-
yield* pattern$2(element, scope, { kind, feed: feed[i] });
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
if (result.length) {
|
|
2437
|
-
return result;
|
|
2438
|
-
}
|
|
2439
|
-
}
|
|
2440
|
-
function* RestElement$1(node, scope, options = {}) {
|
|
2441
|
-
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
2442
|
-
const arg = node.argument;
|
|
2443
|
-
if (hoist) {
|
|
2444
|
-
if (onlyBlock || kind === 'var') {
|
|
2445
|
-
if (arg.type === 'Identifier') {
|
|
2446
|
-
scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2447
|
-
}
|
|
2448
|
-
else {
|
|
2449
|
-
yield* pattern$2(arg, scope, { kind, hoist, onlyBlock });
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
}
|
|
2453
|
-
else if (arg.type === 'Identifier') {
|
|
2454
|
-
if (kind) {
|
|
2455
|
-
scope[kind](arg.name, feed);
|
|
2456
|
-
}
|
|
2457
|
-
else {
|
|
2458
|
-
const variable = yield* Identifier$1(arg, scope, { getVar: true });
|
|
2459
|
-
variable.set(feed);
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
|
-
else {
|
|
2463
|
-
yield* pattern$2(arg, scope, { kind, feed });
|
|
2464
|
-
}
|
|
2465
|
-
}
|
|
2466
|
-
function* AssignmentPattern$1(node, scope, options = {}) {
|
|
2467
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed = yield* evaluate$1(node.right, scope) } = options;
|
|
2468
|
-
const left = node.left;
|
|
2469
|
-
if (hoist) {
|
|
2470
|
-
if (onlyBlock || kind === 'var') {
|
|
2471
|
-
if (left.type === 'Identifier') {
|
|
2472
|
-
scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2473
|
-
}
|
|
2474
|
-
else {
|
|
2475
|
-
yield* pattern$2(left, scope, { kind, hoist, onlyBlock });
|
|
2476
|
-
}
|
|
2477
|
-
}
|
|
2478
|
-
}
|
|
2479
|
-
else if (left.type === 'Identifier') {
|
|
2480
|
-
scope[kind](left.name, feed);
|
|
2481
|
-
}
|
|
2482
|
-
else {
|
|
2483
|
-
yield* pattern$2(left, scope, { kind, feed });
|
|
2484
|
-
}
|
|
2485
|
-
}
|
|
2486
|
-
|
|
2487
|
-
var pattern$1 = /*#__PURE__*/Object.freeze({
|
|
2488
|
-
__proto__: null,
|
|
2489
|
-
ObjectPattern: ObjectPattern$1,
|
|
2490
|
-
ArrayPattern: ArrayPattern$1,
|
|
2491
|
-
RestElement: RestElement$1,
|
|
2492
|
-
AssignmentPattern: AssignmentPattern$1
|
|
2493
|
-
});
|
|
2494
|
-
|
|
2495
|
-
let evaluateOps$1;
|
|
2496
|
-
function* evaluate$1(node, scope) {
|
|
2497
|
-
if (!node)
|
|
2498
|
-
return;
|
|
2499
|
-
if (!evaluateOps$1) {
|
|
2500
|
-
evaluateOps$1 = assign({}, declaration$1, expression$1, identifier$1, statement$1, literal$1, pattern$1);
|
|
2501
|
-
}
|
|
2502
|
-
const handler = evaluateOps$1[node.type];
|
|
2503
|
-
if (handler) {
|
|
2504
|
-
return yield* handler(node, scope);
|
|
2505
|
-
}
|
|
2506
|
-
else {
|
|
2507
|
-
throw new Error(`${node.type} isn't implemented`);
|
|
2508
|
-
}
|
|
2509
|
-
}
|
|
2510
|
-
|
|
2511
2836
|
function* FunctionDeclaration$1(node, scope) {
|
|
2512
2837
|
scope.func(node.id.name, createFunc(node, scope));
|
|
2513
2838
|
}
|
|
@@ -2564,21 +2889,38 @@
|
|
|
2564
2889
|
if (def.type === 'MethodDefinition') {
|
|
2565
2890
|
yield* MethodDefinition$1(def, scope, { klass, superClass });
|
|
2566
2891
|
}
|
|
2892
|
+
else if (def.type === 'PropertyDefinition' && def.static) {
|
|
2893
|
+
yield* PropertyDefinition$1(def, scope, { klass, superClass });
|
|
2894
|
+
}
|
|
2895
|
+
else if (def.type === 'StaticBlock') {
|
|
2896
|
+
yield* StaticBlock$1(def, scope, { klass, superClass });
|
|
2897
|
+
}
|
|
2567
2898
|
}
|
|
2568
2899
|
}
|
|
2569
2900
|
function* MethodDefinition$1(node, scope, options = {}) {
|
|
2570
2901
|
const { klass, superClass } = options;
|
|
2571
2902
|
let key;
|
|
2903
|
+
let priv = false;
|
|
2572
2904
|
if (node.computed) {
|
|
2573
2905
|
key = yield* evaluate$1(node.key, scope);
|
|
2574
2906
|
}
|
|
2575
2907
|
else if (node.key.type === 'Identifier') {
|
|
2576
2908
|
key = node.key.name;
|
|
2577
2909
|
}
|
|
2910
|
+
else if (node.key.type === 'PrivateIdentifier') {
|
|
2911
|
+
key = node.key.name;
|
|
2912
|
+
priv = true;
|
|
2913
|
+
}
|
|
2578
2914
|
else {
|
|
2579
2915
|
throw new SyntaxError('Unexpected token');
|
|
2580
2916
|
}
|
|
2581
|
-
|
|
2917
|
+
let obj = node.static ? klass : klass.prototype;
|
|
2918
|
+
if (priv) {
|
|
2919
|
+
if (!obj[PRIVATE]) {
|
|
2920
|
+
define(obj, PRIVATE, { value: {} });
|
|
2921
|
+
}
|
|
2922
|
+
obj = obj[PRIVATE];
|
|
2923
|
+
}
|
|
2582
2924
|
const value = createFunc(node.value, scope, { superClass });
|
|
2583
2925
|
switch (node.kind) {
|
|
2584
2926
|
case 'constructor':
|
|
@@ -2611,6 +2953,191 @@
|
|
|
2611
2953
|
default:
|
|
2612
2954
|
throw new SyntaxError('Unexpected token');
|
|
2613
2955
|
}
|
|
2956
|
+
}
|
|
2957
|
+
function* PropertyDefinition$1(node, scope, options = {}) {
|
|
2958
|
+
const { klass, superClass } = options;
|
|
2959
|
+
let key;
|
|
2960
|
+
let priv = false;
|
|
2961
|
+
if (node.computed) {
|
|
2962
|
+
key = yield* evaluate$1(node.key, scope);
|
|
2963
|
+
}
|
|
2964
|
+
else if (node.key.type === 'Identifier') {
|
|
2965
|
+
key = node.key.name;
|
|
2966
|
+
}
|
|
2967
|
+
else if (node.key.type === 'PrivateIdentifier') {
|
|
2968
|
+
key = node.key.name;
|
|
2969
|
+
priv = true;
|
|
2970
|
+
}
|
|
2971
|
+
else {
|
|
2972
|
+
throw new SyntaxError('Unexpected token');
|
|
2973
|
+
}
|
|
2974
|
+
const subScope = new Scope(scope, true);
|
|
2975
|
+
subScope.const('this', klass);
|
|
2976
|
+
let obj = klass;
|
|
2977
|
+
if (priv) {
|
|
2978
|
+
if (!obj[PRIVATE]) {
|
|
2979
|
+
define(obj, PRIVATE, { value: {} });
|
|
2980
|
+
}
|
|
2981
|
+
obj = obj[PRIVATE];
|
|
2982
|
+
}
|
|
2983
|
+
if (node.value.type === 'FunctionExpression' || node.value.type === 'ArrowFunctionExpression') {
|
|
2984
|
+
obj[key] = createFunc(node.value, subScope, { superClass });
|
|
2985
|
+
}
|
|
2986
|
+
else {
|
|
2987
|
+
obj[key] = yield* evaluate$1(node.value, subScope);
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
function* StaticBlock$1(node, scope, options = {}) {
|
|
2991
|
+
const { klass } = options;
|
|
2992
|
+
const subScope = new Scope(scope, true);
|
|
2993
|
+
subScope.const('this', klass);
|
|
2994
|
+
return yield* BlockStatement$1(node, subScope, { invasived: true });
|
|
2995
|
+
}
|
|
2996
|
+
function* ImportDeclaration$1(node, scope) {
|
|
2997
|
+
const globalScope = scope.global();
|
|
2998
|
+
const module = globalScope.find(IMPORT + node.source.value);
|
|
2999
|
+
let value;
|
|
3000
|
+
if (module) {
|
|
3001
|
+
const result = module.get();
|
|
3002
|
+
if (result) {
|
|
3003
|
+
if (typeof result === 'function') {
|
|
3004
|
+
value = result();
|
|
3005
|
+
}
|
|
3006
|
+
else if (typeof result === 'object') {
|
|
3007
|
+
value = result;
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
if (!value || typeof value !== 'object') {
|
|
3012
|
+
throw new TypeError(`Failed to resolve module specifier "${node.source.value}"`);
|
|
3013
|
+
}
|
|
3014
|
+
for (let i = 0; i < node.specifiers.length; i++) {
|
|
3015
|
+
const spec = node.specifiers[i];
|
|
3016
|
+
let name;
|
|
3017
|
+
if (spec.type === 'ImportSpecifier') {
|
|
3018
|
+
name = spec.imported.type === 'Identifier'
|
|
3019
|
+
? spec.imported.name : spec.imported.value;
|
|
3020
|
+
}
|
|
3021
|
+
else if (spec.type === 'ImportDefaultSpecifier') {
|
|
3022
|
+
name = 'default';
|
|
3023
|
+
}
|
|
3024
|
+
else if (spec.type === 'ImportNamespaceSpecifier') {
|
|
3025
|
+
name = '*';
|
|
3026
|
+
}
|
|
3027
|
+
if (name !== '*' && !hasOwn(value, name)) {
|
|
3028
|
+
throw new SyntaxError(`The requested module "${node.source.value}" does not provide an export named "${name}"`);
|
|
3029
|
+
}
|
|
3030
|
+
scope.var(spec.local.name, name === '*' ? assign({}, value) : value[name]);
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
function* ExportDefaultDeclaration$1(node, scope) {
|
|
3034
|
+
const globalScope = scope.global();
|
|
3035
|
+
let value;
|
|
3036
|
+
if (node.declaration.type === 'FunctionDeclaration') {
|
|
3037
|
+
value = createFunc(node.declaration, scope);
|
|
3038
|
+
scope.func(node.declaration.id.name, value);
|
|
3039
|
+
}
|
|
3040
|
+
else if (node.declaration.type === 'ClassDeclaration') {
|
|
3041
|
+
value = yield* createClass(node.declaration, scope);
|
|
3042
|
+
scope.func(node.declaration.id.name, value);
|
|
3043
|
+
}
|
|
3044
|
+
else {
|
|
3045
|
+
value = yield* evaluate$1(node.declaration, scope);
|
|
3046
|
+
}
|
|
3047
|
+
const variable = globalScope.find(EXPORTS);
|
|
3048
|
+
if (variable) {
|
|
3049
|
+
const exports = variable.get();
|
|
3050
|
+
if (exports && typeof exports === 'object') {
|
|
3051
|
+
exports.default = value;
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
function* ExportNamedDeclaration$1(node, scope) {
|
|
3056
|
+
const globalScope = scope.global();
|
|
3057
|
+
if (node.declaration) {
|
|
3058
|
+
if (node.declaration.type === 'FunctionDeclaration') {
|
|
3059
|
+
const value = createFunc(node.declaration, scope);
|
|
3060
|
+
scope.func(node.declaration.id.name, value);
|
|
3061
|
+
const variable = globalScope.find(EXPORTS);
|
|
3062
|
+
if (variable) {
|
|
3063
|
+
const exports = variable.get();
|
|
3064
|
+
if (exports && typeof exports === 'object') {
|
|
3065
|
+
exports[node.declaration.id.name] = value;
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
else if (node.declaration.type === 'ClassDeclaration') {
|
|
3070
|
+
const value = yield* createClass(node.declaration, scope);
|
|
3071
|
+
scope.func(node.declaration.id.name, value);
|
|
3072
|
+
const variable = globalScope.find(EXPORTS);
|
|
3073
|
+
if (variable) {
|
|
3074
|
+
const exports = variable.get();
|
|
3075
|
+
if (exports && typeof exports === 'object') {
|
|
3076
|
+
exports[node.declaration.id.name] = value;
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
else if (node.declaration.type === 'VariableDeclaration') {
|
|
3081
|
+
yield* VariableDeclaration$1(node.declaration, scope);
|
|
3082
|
+
const variable = globalScope.find(EXPORTS);
|
|
3083
|
+
if (variable) {
|
|
3084
|
+
const exports = variable.get();
|
|
3085
|
+
if (exports && typeof exports === 'object') {
|
|
3086
|
+
for (let i = 0; i < node.declaration.declarations.length; i++) {
|
|
3087
|
+
const name = node.declaration.declarations[i].id.name;
|
|
3088
|
+
const item = scope.find(name);
|
|
3089
|
+
if (item) {
|
|
3090
|
+
exports[name] = item.get();
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
else if (node.specifiers) {
|
|
3098
|
+
const variable = globalScope.find(EXPORTS);
|
|
3099
|
+
if (variable) {
|
|
3100
|
+
const exports = variable.get();
|
|
3101
|
+
if (exports && typeof exports === 'object') {
|
|
3102
|
+
for (let i = 0; i < node.specifiers.length; i++) {
|
|
3103
|
+
const spec = node.specifiers[i];
|
|
3104
|
+
const name = spec.local.type === 'Identifier'
|
|
3105
|
+
? spec.local.name : spec.local.value;
|
|
3106
|
+
const item = scope.find(name);
|
|
3107
|
+
if (item) {
|
|
3108
|
+
exports[spec.exported.type === 'Identifier'
|
|
3109
|
+
? spec.exported.name : spec.exported.value] = item.get();
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
function* ExportAllDeclaration$1(node, scope) {
|
|
3117
|
+
const globalScope = scope.global();
|
|
3118
|
+
const module = globalScope.find(IMPORT + node.source.value);
|
|
3119
|
+
let value;
|
|
3120
|
+
if (module) {
|
|
3121
|
+
const result = module.get();
|
|
3122
|
+
if (result) {
|
|
3123
|
+
if (typeof result === 'function') {
|
|
3124
|
+
value = result();
|
|
3125
|
+
}
|
|
3126
|
+
else if (typeof result === 'object') {
|
|
3127
|
+
value = result;
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
if (!value || typeof value !== 'object') {
|
|
3132
|
+
throw new TypeError(`Failed to resolve module specifier "${node.source.value}"`);
|
|
3133
|
+
}
|
|
3134
|
+
const variable = globalScope.find(EXPORTS);
|
|
3135
|
+
if (variable) {
|
|
3136
|
+
const exports = variable.get();
|
|
3137
|
+
if (exports && typeof exports === 'object') {
|
|
3138
|
+
assign(exports, value);
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
2614
3141
|
}
|
|
2615
3142
|
|
|
2616
3143
|
function runAsync(iterator, options = {}) {
|
|
@@ -2759,7 +3286,7 @@
|
|
|
2759
3286
|
if (!node.generator && !node.async) {
|
|
2760
3287
|
return createFunc$1(node, scope, options);
|
|
2761
3288
|
}
|
|
2762
|
-
const { superClass,
|
|
3289
|
+
const { superClass, construct } = options;
|
|
2763
3290
|
const params = node.params;
|
|
2764
3291
|
const tmpFunc = function* (...args) {
|
|
2765
3292
|
const subScope = new Scope(scope, true);
|
|
@@ -2767,9 +3294,12 @@
|
|
|
2767
3294
|
subScope.const('this', this);
|
|
2768
3295
|
subScope.let('arguments', arguments);
|
|
2769
3296
|
subScope.const(NEWTARGET, new.target);
|
|
3297
|
+
if (construct) {
|
|
3298
|
+
yield* construct(this);
|
|
3299
|
+
}
|
|
2770
3300
|
if (superClass) {
|
|
2771
3301
|
subScope.const(SUPER, superClass);
|
|
2772
|
-
if (
|
|
3302
|
+
if (construct)
|
|
2773
3303
|
subScope.let(SUPERCALL, false);
|
|
2774
3304
|
}
|
|
2775
3305
|
}
|
|
@@ -2850,16 +3380,25 @@
|
|
|
2850
3380
|
}
|
|
2851
3381
|
function* createClass(node, scope) {
|
|
2852
3382
|
const superClass = yield* evaluate$1(node.superClass, scope);
|
|
2853
|
-
|
|
3383
|
+
const methodBody = node.body.body;
|
|
3384
|
+
const construct = function* (object) {
|
|
3385
|
+
for (let i = 0; i < methodBody.length; i++) {
|
|
3386
|
+
const def = methodBody[i];
|
|
3387
|
+
if (def.type === 'PropertyDefinition' && !def.static) {
|
|
3388
|
+
yield* PropertyDefinition$1(def, scope, { klass: object, superClass });
|
|
3389
|
+
}
|
|
3390
|
+
}
|
|
3391
|
+
};
|
|
3392
|
+
let klass = function* () {
|
|
3393
|
+
yield* construct(this);
|
|
2854
3394
|
if (superClass) {
|
|
2855
3395
|
superClass.apply(this);
|
|
2856
3396
|
}
|
|
2857
3397
|
};
|
|
2858
|
-
const methodBody = node.body.body;
|
|
2859
3398
|
for (let i = 0; i < methodBody.length; i++) {
|
|
2860
3399
|
const method = methodBody[i];
|
|
2861
3400
|
if (method.type === 'MethodDefinition' && method.kind === 'constructor') {
|
|
2862
|
-
klass = createFunc(method.value, scope, { superClass,
|
|
3401
|
+
klass = createFunc(method.value, scope, { superClass, construct });
|
|
2863
3402
|
break;
|
|
2864
3403
|
}
|
|
2865
3404
|
}
|
|
@@ -2998,7 +3537,7 @@
|
|
|
2998
3537
|
if (node.generator || node.async) {
|
|
2999
3538
|
return createFunc(node, scope, options);
|
|
3000
3539
|
}
|
|
3001
|
-
const { superClass,
|
|
3540
|
+
const { superClass, construct } = options;
|
|
3002
3541
|
const params = node.params;
|
|
3003
3542
|
const tmpFunc = function (...args) {
|
|
3004
3543
|
const subScope = new Scope(scope, true);
|
|
@@ -3006,9 +3545,12 @@
|
|
|
3006
3545
|
subScope.const('this', this);
|
|
3007
3546
|
subScope.let('arguments', arguments);
|
|
3008
3547
|
subScope.const(NEWTARGET, new.target);
|
|
3548
|
+
if (construct) {
|
|
3549
|
+
construct(this);
|
|
3550
|
+
}
|
|
3009
3551
|
if (superClass) {
|
|
3010
3552
|
subScope.const(SUPER, superClass);
|
|
3011
|
-
if (
|
|
3553
|
+
if (construct)
|
|
3012
3554
|
subScope.let(SUPERCALL, false);
|
|
3013
3555
|
}
|
|
3014
3556
|
}
|
|
@@ -3061,16 +3603,25 @@
|
|
|
3061
3603
|
}
|
|
3062
3604
|
function createClass$1(node, scope) {
|
|
3063
3605
|
const superClass = evaluate(node.superClass, scope);
|
|
3606
|
+
const methodBody = node.body.body;
|
|
3607
|
+
const construct = function (object) {
|
|
3608
|
+
for (let i = 0; i < methodBody.length; i++) {
|
|
3609
|
+
const def = methodBody[i];
|
|
3610
|
+
if (def.type === 'PropertyDefinition' && !def.static) {
|
|
3611
|
+
PropertyDefinition(def, scope, { klass: object, superClass });
|
|
3612
|
+
}
|
|
3613
|
+
}
|
|
3614
|
+
};
|
|
3064
3615
|
let klass = function () {
|
|
3616
|
+
construct(this);
|
|
3065
3617
|
if (superClass) {
|
|
3066
3618
|
superClass.apply(this);
|
|
3067
3619
|
}
|
|
3068
3620
|
};
|
|
3069
|
-
const methodBody = node.body.body;
|
|
3070
3621
|
for (let i = 0; i < methodBody.length; i++) {
|
|
3071
3622
|
const method = methodBody[i];
|
|
3072
3623
|
if (method.type === 'MethodDefinition' && method.kind === 'constructor') {
|
|
3073
|
-
klass = createFunc$1(method.value, scope, { superClass,
|
|
3624
|
+
klass = createFunc$1(method.value, scope, { superClass, construct });
|
|
3074
3625
|
break;
|
|
3075
3626
|
}
|
|
3076
3627
|
}
|
|
@@ -3115,7 +3666,7 @@
|
|
|
3115
3666
|
this.options = { ecmaVersion: 'latest' };
|
|
3116
3667
|
this.scope = new Scope(null, true);
|
|
3117
3668
|
this.exports = {};
|
|
3118
|
-
let { ecmaVer = 'latest', sandBox = true } = options;
|
|
3669
|
+
let { ecmaVer = 'latest', sandBox = true, sourceType = 'script' } = options;
|
|
3119
3670
|
if (typeof ecmaVer === 'number') {
|
|
3120
3671
|
ecmaVer -= ecmaVer < 2015 ? 0 : 2009;
|
|
3121
3672
|
}
|
|
@@ -3123,16 +3674,19 @@
|
|
|
3123
3674
|
throw new Error(`unsupported ecmaVer`);
|
|
3124
3675
|
}
|
|
3125
3676
|
this.options.ecmaVersion = ecmaVer;
|
|
3677
|
+
this.options.sourceType = sourceType;
|
|
3126
3678
|
if (sandBox) {
|
|
3127
3679
|
const win = createSandBox();
|
|
3680
|
+
this.scope.let('globalThis', win);
|
|
3128
3681
|
this.scope.let('window', win);
|
|
3129
3682
|
this.scope.let('this', win);
|
|
3130
3683
|
}
|
|
3131
3684
|
else {
|
|
3685
|
+
this.scope.let('globalThis', globalObj);
|
|
3132
3686
|
this.scope.let('window', globalObj);
|
|
3133
3687
|
this.scope.let('this', globalObj);
|
|
3134
3688
|
}
|
|
3135
|
-
this.scope.const('exports', this.exports = {});
|
|
3689
|
+
this.scope.const(sourceType === 'module' ? EXPORTS : 'exports', this.exports = {});
|
|
3136
3690
|
}
|
|
3137
3691
|
import(nameOrModules, mod) {
|
|
3138
3692
|
if (typeof nameOrModules === 'string') {
|
|
@@ -3143,7 +3697,8 @@
|
|
|
3143
3697
|
const names = getOwnNames(nameOrModules);
|
|
3144
3698
|
for (let i = 0; i < names.length; i++) {
|
|
3145
3699
|
const name = names[i];
|
|
3146
|
-
this.
|
|
3700
|
+
const modName = this.options.sourceType === 'module' ? IMPORT + name : name;
|
|
3701
|
+
this.scope.var(modName, nameOrModules[name]);
|
|
3147
3702
|
}
|
|
3148
3703
|
}
|
|
3149
3704
|
parse(code, parser) {
|