sval 0.4.9 → 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 +85 -30
- package/dist/sval.es6.js +1049 -419
- package/dist/sval.js +1439 -692
- package/dist/sval.min.js +1 -1
- package/package.json +3 -5
- package/types/index.d.ts +6 -9
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.4.9";
|
|
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;
|
|
@@ -733,7 +803,7 @@
|
|
|
733
803
|
}
|
|
734
804
|
}
|
|
735
805
|
function AssignmentExpression(node, scope) {
|
|
736
|
-
|
|
806
|
+
var _a;
|
|
737
807
|
const left = node.left;
|
|
738
808
|
let variable;
|
|
739
809
|
if (left.type === 'Identifier') {
|
|
@@ -747,8 +817,10 @@
|
|
|
747
817
|
variable = MemberExpression(left, scope, { getVar: true });
|
|
748
818
|
}
|
|
749
819
|
else {
|
|
820
|
+
const value = evaluate(node.right, scope);
|
|
750
821
|
return pattern$3(left, scope, { feed: value });
|
|
751
822
|
}
|
|
823
|
+
const value = evaluate(node.right, scope);
|
|
752
824
|
switch (node.operator) {
|
|
753
825
|
case '=':
|
|
754
826
|
variable.set(value);
|
|
@@ -789,15 +861,27 @@
|
|
|
789
861
|
case '&=':
|
|
790
862
|
variable.set(variable.get() & value);
|
|
791
863
|
return variable.get();
|
|
864
|
+
case '??=':
|
|
865
|
+
variable.set((_a = variable.get()) !== null && _a !== void 0 ? _a : value);
|
|
866
|
+
return variable.get();
|
|
867
|
+
case '&&=':
|
|
868
|
+
variable.set(variable.get() && value);
|
|
869
|
+
return variable.get();
|
|
870
|
+
case '||=':
|
|
871
|
+
variable.set(variable.get() || value);
|
|
872
|
+
return variable.get();
|
|
792
873
|
default: throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
793
874
|
}
|
|
794
875
|
}
|
|
795
876
|
function LogicalExpression(node, scope) {
|
|
877
|
+
var _a;
|
|
796
878
|
switch (node.operator) {
|
|
797
879
|
case '||':
|
|
798
880
|
return (evaluate(node.left, scope)) || (evaluate(node.right, scope));
|
|
799
881
|
case '&&':
|
|
800
882
|
return (evaluate(node.left, scope)) && (evaluate(node.right, scope));
|
|
883
|
+
case '??':
|
|
884
|
+
return (_a = (evaluate(node.left, scope))) !== null && _a !== void 0 ? _a : (evaluate(node.right, scope));
|
|
801
885
|
default:
|
|
802
886
|
throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
803
887
|
}
|
|
@@ -814,12 +898,20 @@
|
|
|
814
898
|
if (getObj)
|
|
815
899
|
return object;
|
|
816
900
|
let key;
|
|
901
|
+
let priv = false;
|
|
817
902
|
if (node.computed) {
|
|
818
903
|
key = evaluate(node.property, scope);
|
|
819
904
|
}
|
|
905
|
+
else if (node.property.type === 'PrivateIdentifier') {
|
|
906
|
+
key = node.property.name;
|
|
907
|
+
priv = true;
|
|
908
|
+
}
|
|
820
909
|
else {
|
|
821
910
|
key = node.property.name;
|
|
822
911
|
}
|
|
912
|
+
if (priv) {
|
|
913
|
+
object = object[PRIVATE];
|
|
914
|
+
}
|
|
823
915
|
if (getVar) {
|
|
824
916
|
const setter = getSetter(object, key);
|
|
825
917
|
if (node.object.type === 'Super' && setter) {
|
|
@@ -836,9 +928,15 @@
|
|
|
836
928
|
const getter = getGetter(object, key);
|
|
837
929
|
if (node.object.type === 'Super' && getter) {
|
|
838
930
|
const thisObject = scope.find('this').get();
|
|
931
|
+
if (node.optional && thisObject == null) {
|
|
932
|
+
return undefined;
|
|
933
|
+
}
|
|
839
934
|
return getter.call(thisObject);
|
|
840
935
|
}
|
|
841
936
|
else {
|
|
937
|
+
if (node.optional && object == null) {
|
|
938
|
+
return undefined;
|
|
939
|
+
}
|
|
842
940
|
return object[key];
|
|
843
941
|
}
|
|
844
942
|
}
|
|
@@ -853,19 +951,34 @@
|
|
|
853
951
|
let object;
|
|
854
952
|
if (node.callee.type === 'MemberExpression') {
|
|
855
953
|
object = MemberExpression(node.callee, scope, { getObj: true });
|
|
954
|
+
if (node.callee.optional && object == null) {
|
|
955
|
+
return undefined;
|
|
956
|
+
}
|
|
856
957
|
let key;
|
|
958
|
+
let priv = false;
|
|
857
959
|
if (node.callee.computed) {
|
|
858
960
|
key = evaluate(node.callee.property, scope);
|
|
859
961
|
}
|
|
962
|
+
else if (node.callee.property.type === 'PrivateIdentifier') {
|
|
963
|
+
key = node.callee.property.name;
|
|
964
|
+
priv = true;
|
|
965
|
+
}
|
|
860
966
|
else {
|
|
861
967
|
key = node.callee.property.name;
|
|
862
968
|
}
|
|
969
|
+
let obj = object;
|
|
970
|
+
if (priv) {
|
|
971
|
+
obj = obj[PRIVATE];
|
|
972
|
+
}
|
|
863
973
|
if (node.callee.object.type === 'Super') {
|
|
864
974
|
const thisObject = scope.find('this').get();
|
|
865
|
-
func =
|
|
975
|
+
func = obj[key].bind(thisObject);
|
|
866
976
|
}
|
|
867
977
|
else {
|
|
868
|
-
func =
|
|
978
|
+
func = obj[key];
|
|
979
|
+
}
|
|
980
|
+
if (node.optional && func == null) {
|
|
981
|
+
return undefined;
|
|
869
982
|
}
|
|
870
983
|
if (typeof func !== 'function') {
|
|
871
984
|
throw new TypeError(`${key} is not a function`);
|
|
@@ -877,6 +990,9 @@
|
|
|
877
990
|
else {
|
|
878
991
|
object = scope.find('this').get();
|
|
879
992
|
func = evaluate(node.callee, scope);
|
|
993
|
+
if (node.optional && func == null) {
|
|
994
|
+
return undefined;
|
|
995
|
+
}
|
|
880
996
|
if (typeof func !== 'function' || node.callee.type !== 'Super' && func[CLSCTOR]) {
|
|
881
997
|
let name;
|
|
882
998
|
if (node.callee.type === 'Identifier') {
|
|
@@ -955,7 +1071,12 @@
|
|
|
955
1071
|
return new constructor(...args);
|
|
956
1072
|
}
|
|
957
1073
|
function MetaProperty(node, scope) {
|
|
958
|
-
|
|
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
|
+
}
|
|
959
1080
|
}
|
|
960
1081
|
function SequenceExpression(node, scope) {
|
|
961
1082
|
let result;
|
|
@@ -1020,6 +1141,30 @@
|
|
|
1020
1141
|
}
|
|
1021
1142
|
function SpreadElement(node, scope) {
|
|
1022
1143
|
return evaluate(node.argument, scope);
|
|
1144
|
+
}
|
|
1145
|
+
function ChainExpression(node, scope) {
|
|
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);
|
|
1023
1168
|
}
|
|
1024
1169
|
|
|
1025
1170
|
var expression = /*#__PURE__*/Object.freeze({
|
|
@@ -1045,9 +1190,177 @@
|
|
|
1045
1190
|
TemplateElement: TemplateElement,
|
|
1046
1191
|
ClassExpression: ClassExpression,
|
|
1047
1192
|
Super: Super,
|
|
1048
|
-
SpreadElement: SpreadElement
|
|
1193
|
+
SpreadElement: SpreadElement,
|
|
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
|
|
1049
1346
|
});
|
|
1050
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
|
+
|
|
1051
1364
|
function ExpressionStatement(node, scope) {
|
|
1052
1365
|
evaluate(node.expression, scope);
|
|
1053
1366
|
}
|
|
@@ -1234,211 +1547,23 @@
|
|
|
1234
1547
|
}
|
|
1235
1548
|
}
|
|
1236
1549
|
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
CatchClause: CatchClause,
|
|
1252
|
-
WhileStatement: WhileStatement,
|
|
1253
|
-
DoWhileStatement: DoWhileStatement,
|
|
1254
|
-
ForStatement: ForStatement,
|
|
1255
|
-
ForInStatement: ForInStatement,
|
|
1256
|
-
ForOfStatement: ForOfStatement
|
|
1257
|
-
});
|
|
1258
|
-
|
|
1259
|
-
function ObjectPattern(node, scope, options = {}) {
|
|
1260
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed = {} } = options;
|
|
1261
|
-
const fedKeys = [];
|
|
1262
|
-
for (let i = 0; i < node.properties.length; i++) {
|
|
1263
|
-
const property = node.properties[i];
|
|
1264
|
-
if (hoist) {
|
|
1265
|
-
if (onlyBlock || kind === 'var') {
|
|
1266
|
-
if (property.type === 'Property') {
|
|
1267
|
-
const value = property.value;
|
|
1268
|
-
if (value.type === 'Identifier') {
|
|
1269
|
-
scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1270
|
-
}
|
|
1271
|
-
else {
|
|
1272
|
-
pattern$3(value, scope, { kind, hoist, onlyBlock });
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
else {
|
|
1276
|
-
RestElement(property, scope, { kind, hoist, onlyBlock });
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
else if (property.type === 'Property') {
|
|
1281
|
-
let key;
|
|
1282
|
-
if (property.computed) {
|
|
1283
|
-
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);
|
|
1284
1564
|
}
|
|
1285
1565
|
else {
|
|
1286
|
-
|
|
1287
|
-
}
|
|
1288
|
-
fedKeys.push(key);
|
|
1289
|
-
const value = property.value;
|
|
1290
|
-
if (value.type === 'Identifier') {
|
|
1291
|
-
scope[kind](value.name, feed[key]);
|
|
1292
|
-
}
|
|
1293
|
-
else {
|
|
1294
|
-
pattern$3(value, scope, { kind, feed: feed[key] });
|
|
1295
|
-
}
|
|
1296
|
-
}
|
|
1297
|
-
else {
|
|
1298
|
-
const rest = assign({}, feed);
|
|
1299
|
-
for (let i = 0; i < fedKeys.length; i++)
|
|
1300
|
-
delete rest[fedKeys[i]];
|
|
1301
|
-
RestElement(property, scope, { kind, feed: rest });
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
function ArrayPattern(node, scope, options = {}) {
|
|
1306
|
-
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
1307
|
-
const result = [];
|
|
1308
|
-
for (let i = 0; i < node.elements.length; i++) {
|
|
1309
|
-
const element = node.elements[i];
|
|
1310
|
-
if (!element)
|
|
1311
|
-
continue;
|
|
1312
|
-
if (hoist) {
|
|
1313
|
-
if (onlyBlock || kind === 'var') {
|
|
1314
|
-
if (element.type === 'Identifier') {
|
|
1315
|
-
scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1316
|
-
}
|
|
1317
|
-
else {
|
|
1318
|
-
pattern$3(element, scope, { kind, hoist, onlyBlock });
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
else if (element.type === 'Identifier') {
|
|
1323
|
-
if (kind) {
|
|
1324
|
-
scope[kind](element.name, feed[i]);
|
|
1325
|
-
}
|
|
1326
|
-
else {
|
|
1327
|
-
const variable = Identifier(element, scope, { getVar: true });
|
|
1328
|
-
variable.set(feed[i]);
|
|
1329
|
-
result.push(variable.get());
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
else if (element.type === 'RestElement') {
|
|
1333
|
-
RestElement(element, scope, { kind, feed: feed.slice(i) });
|
|
1334
|
-
}
|
|
1335
|
-
else {
|
|
1336
|
-
pattern$3(element, scope, { kind, feed: feed[i] });
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
if (result.length) {
|
|
1340
|
-
return result;
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
function RestElement(node, scope, options = {}) {
|
|
1344
|
-
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
1345
|
-
const arg = node.argument;
|
|
1346
|
-
if (hoist) {
|
|
1347
|
-
if (onlyBlock || kind === 'var') {
|
|
1348
|
-
if (arg.type === 'Identifier') {
|
|
1349
|
-
scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1350
|
-
}
|
|
1351
|
-
else {
|
|
1352
|
-
pattern$3(arg, scope, { kind, hoist, onlyBlock });
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
else if (arg.type === 'Identifier') {
|
|
1357
|
-
if (kind) {
|
|
1358
|
-
scope[kind](arg.name, feed);
|
|
1359
|
-
}
|
|
1360
|
-
else {
|
|
1361
|
-
const variable = Identifier(arg, scope, { getVar: true });
|
|
1362
|
-
variable.set(feed);
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
else {
|
|
1366
|
-
pattern$3(arg, scope, { kind, feed });
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
function AssignmentPattern(node, scope, options = {}) {
|
|
1370
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed = evaluate(node.right, scope) } = options;
|
|
1371
|
-
const left = node.left;
|
|
1372
|
-
if (hoist) {
|
|
1373
|
-
if (onlyBlock || kind === 'var') {
|
|
1374
|
-
if (left.type === 'Identifier') {
|
|
1375
|
-
scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1376
|
-
}
|
|
1377
|
-
else {
|
|
1378
|
-
pattern$3(left, scope, { kind, hoist, onlyBlock });
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
else if (left.type === 'Identifier') {
|
|
1383
|
-
scope[kind](left.name, feed);
|
|
1384
|
-
}
|
|
1385
|
-
else {
|
|
1386
|
-
pattern$3(left, scope, { kind, feed });
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
var pattern = /*#__PURE__*/Object.freeze({
|
|
1391
|
-
__proto__: null,
|
|
1392
|
-
ObjectPattern: ObjectPattern,
|
|
1393
|
-
ArrayPattern: ArrayPattern,
|
|
1394
|
-
RestElement: RestElement,
|
|
1395
|
-
AssignmentPattern: AssignmentPattern
|
|
1396
|
-
});
|
|
1397
|
-
|
|
1398
|
-
function Program(program, scope) {
|
|
1399
|
-
for (let i = 0; i < program.body.length; i++) {
|
|
1400
|
-
evaluate(program.body[i], scope);
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
var program = /*#__PURE__*/Object.freeze({
|
|
1405
|
-
__proto__: null,
|
|
1406
|
-
Program: Program
|
|
1407
|
-
});
|
|
1408
|
-
|
|
1409
|
-
let evaluateOps;
|
|
1410
|
-
function evaluate(node, scope) {
|
|
1411
|
-
if (!node)
|
|
1412
|
-
return;
|
|
1413
|
-
if (!evaluateOps) {
|
|
1414
|
-
evaluateOps = assign({}, declaration, expression, identifier, statement, literal, pattern, program);
|
|
1415
|
-
}
|
|
1416
|
-
const handler = evaluateOps[node.type];
|
|
1417
|
-
if (handler) {
|
|
1418
|
-
return handler(node, scope);
|
|
1419
|
-
}
|
|
1420
|
-
else {
|
|
1421
|
-
throw new Error(`${node.type} isn't implemented`);
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
function FunctionDeclaration(node, scope) {
|
|
1426
|
-
scope.func(node.id.name, createFunc$1(node, scope));
|
|
1427
|
-
}
|
|
1428
|
-
function VariableDeclaration(node, scope, options = {}) {
|
|
1429
|
-
for (let i = 0; i < node.declarations.length; i++) {
|
|
1430
|
-
VariableDeclarator(node.declarations[i], scope, assign({ kind: node.kind }, options));
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
function VariableDeclarator(node, scope, options = {}) {
|
|
1434
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed } = options;
|
|
1435
|
-
if (hoist) {
|
|
1436
|
-
if (onlyBlock || kind === 'var') {
|
|
1437
|
-
if (node.id.type === 'Identifier') {
|
|
1438
|
-
scope[kind](node.id.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
1439
|
-
}
|
|
1440
|
-
else {
|
|
1441
|
-
pattern$3(node.id, scope, { kind, hoist, onlyBlock });
|
|
1566
|
+
pattern$3(node.id, scope, { kind, hoist, onlyBlock });
|
|
1442
1567
|
}
|
|
1443
1568
|
}
|
|
1444
1569
|
}
|
|
@@ -1474,22 +1599,42 @@
|
|
|
1474
1599
|
function ClassBody(node, scope, options = {}) {
|
|
1475
1600
|
const { klass, superClass } = options;
|
|
1476
1601
|
for (let i = 0; i < node.body.length; i++) {
|
|
1477
|
-
|
|
1602
|
+
const def = node.body[i];
|
|
1603
|
+
if (def.type === 'MethodDefinition') {
|
|
1604
|
+
MethodDefinition(def, scope, { klass, superClass });
|
|
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
|
+
}
|
|
1478
1612
|
}
|
|
1479
1613
|
}
|
|
1480
1614
|
function MethodDefinition(node, scope, options = {}) {
|
|
1481
1615
|
const { klass, superClass } = options;
|
|
1482
1616
|
let key;
|
|
1617
|
+
let priv = false;
|
|
1483
1618
|
if (node.computed) {
|
|
1484
1619
|
key = evaluate(node.key, scope);
|
|
1485
1620
|
}
|
|
1486
1621
|
else if (node.key.type === 'Identifier') {
|
|
1487
1622
|
key = node.key.name;
|
|
1488
1623
|
}
|
|
1624
|
+
else if (node.key.type === 'PrivateIdentifier') {
|
|
1625
|
+
key = node.key.name;
|
|
1626
|
+
priv = true;
|
|
1627
|
+
}
|
|
1489
1628
|
else {
|
|
1490
1629
|
throw new SyntaxError('Unexpected token');
|
|
1491
1630
|
}
|
|
1492
|
-
|
|
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
|
+
}
|
|
1493
1638
|
const value = createFunc$1(node.value, scope, { superClass });
|
|
1494
1639
|
switch (node.kind) {
|
|
1495
1640
|
case 'constructor':
|
|
@@ -1522,6 +1667,191 @@
|
|
|
1522
1667
|
default:
|
|
1523
1668
|
throw new SyntaxError('Unexpected token');
|
|
1524
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
|
+
}
|
|
1525
1855
|
}
|
|
1526
1856
|
|
|
1527
1857
|
function* Identifier$1(node, scope, options = {}) {
|
|
@@ -1704,8 +2034,17 @@
|
|
|
1704
2034
|
}
|
|
1705
2035
|
}
|
|
1706
2036
|
function* BinaryExpression$1(node, scope) {
|
|
1707
|
-
|
|
1708
|
-
|
|
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
|
+
}
|
|
1709
2048
|
switch (node.operator) {
|
|
1710
2049
|
case '==': return left == right;
|
|
1711
2050
|
case '!=': return left != right;
|
|
@@ -1733,7 +2072,7 @@
|
|
|
1733
2072
|
}
|
|
1734
2073
|
}
|
|
1735
2074
|
function* AssignmentExpression$1(node, scope) {
|
|
1736
|
-
|
|
2075
|
+
var _a;
|
|
1737
2076
|
const left = node.left;
|
|
1738
2077
|
let variable;
|
|
1739
2078
|
if (left.type === 'Identifier') {
|
|
@@ -1747,8 +2086,10 @@
|
|
|
1747
2086
|
variable = yield* MemberExpression$1(left, scope, { getVar: true });
|
|
1748
2087
|
}
|
|
1749
2088
|
else {
|
|
2089
|
+
const value = yield* evaluate$1(node.right, scope);
|
|
1750
2090
|
return yield* pattern$2(left, scope, { feed: value });
|
|
1751
2091
|
}
|
|
2092
|
+
const value = yield* evaluate$1(node.right, scope);
|
|
1752
2093
|
switch (node.operator) {
|
|
1753
2094
|
case '=':
|
|
1754
2095
|
variable.set(value);
|
|
@@ -1789,15 +2130,27 @@
|
|
|
1789
2130
|
case '&=':
|
|
1790
2131
|
variable.set(variable.get() & value);
|
|
1791
2132
|
return variable.get();
|
|
2133
|
+
case '??=':
|
|
2134
|
+
variable.set((_a = variable.get()) !== null && _a !== void 0 ? _a : value);
|
|
2135
|
+
return variable.get();
|
|
2136
|
+
case '&&=':
|
|
2137
|
+
variable.set(variable.get() && value);
|
|
2138
|
+
return variable.get();
|
|
2139
|
+
case '||=':
|
|
2140
|
+
variable.set(variable.get() || value);
|
|
2141
|
+
return variable.get();
|
|
1792
2142
|
default: throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
1793
2143
|
}
|
|
1794
2144
|
}
|
|
1795
2145
|
function* LogicalExpression$1(node, scope) {
|
|
2146
|
+
var _a;
|
|
1796
2147
|
switch (node.operator) {
|
|
1797
2148
|
case '||':
|
|
1798
2149
|
return (yield* evaluate$1(node.left, scope)) || (yield* evaluate$1(node.right, scope));
|
|
1799
2150
|
case '&&':
|
|
1800
2151
|
return (yield* evaluate$1(node.left, scope)) && (yield* evaluate$1(node.right, scope));
|
|
2152
|
+
case '??':
|
|
2153
|
+
return (_a = (yield* evaluate$1(node.left, scope))) !== null && _a !== void 0 ? _a : (yield* evaluate$1(node.right, scope));
|
|
1801
2154
|
default:
|
|
1802
2155
|
throw new SyntaxError(`Unexpected token ${node.operator}`);
|
|
1803
2156
|
}
|
|
@@ -1814,12 +2167,20 @@
|
|
|
1814
2167
|
if (getObj)
|
|
1815
2168
|
return object;
|
|
1816
2169
|
let key;
|
|
2170
|
+
let priv = false;
|
|
1817
2171
|
if (node.computed) {
|
|
1818
2172
|
key = yield* evaluate$1(node.property, scope);
|
|
1819
2173
|
}
|
|
2174
|
+
else if (node.property.type === 'PrivateIdentifier') {
|
|
2175
|
+
key = node.property.name;
|
|
2176
|
+
priv = true;
|
|
2177
|
+
}
|
|
1820
2178
|
else {
|
|
1821
2179
|
key = node.property.name;
|
|
1822
2180
|
}
|
|
2181
|
+
if (priv) {
|
|
2182
|
+
object = object[PRIVATE];
|
|
2183
|
+
}
|
|
1823
2184
|
if (getVar) {
|
|
1824
2185
|
const setter = getSetter(object, key);
|
|
1825
2186
|
if (node.object.type === 'Super' && setter) {
|
|
@@ -1836,9 +2197,15 @@
|
|
|
1836
2197
|
const getter = getGetter(object, key);
|
|
1837
2198
|
if (node.object.type === 'Super' && getter) {
|
|
1838
2199
|
const thisObject = scope.find('this').get();
|
|
2200
|
+
if (node.optional && thisObject == null) {
|
|
2201
|
+
return undefined;
|
|
2202
|
+
}
|
|
1839
2203
|
return getter.call(thisObject);
|
|
1840
2204
|
}
|
|
1841
2205
|
else {
|
|
2206
|
+
if (node.optional && object == null) {
|
|
2207
|
+
return undefined;
|
|
2208
|
+
}
|
|
1842
2209
|
return object[key];
|
|
1843
2210
|
}
|
|
1844
2211
|
}
|
|
@@ -1853,19 +2220,34 @@
|
|
|
1853
2220
|
let object;
|
|
1854
2221
|
if (node.callee.type === 'MemberExpression') {
|
|
1855
2222
|
object = yield* MemberExpression$1(node.callee, scope, { getObj: true });
|
|
2223
|
+
if (node.callee.optional && object == null) {
|
|
2224
|
+
return undefined;
|
|
2225
|
+
}
|
|
1856
2226
|
let key;
|
|
2227
|
+
let priv = false;
|
|
1857
2228
|
if (node.callee.computed) {
|
|
1858
2229
|
key = yield* evaluate$1(node.callee.property, scope);
|
|
1859
2230
|
}
|
|
2231
|
+
else if (node.callee.property.type === 'PrivateIdentifier') {
|
|
2232
|
+
key = node.callee.property.name;
|
|
2233
|
+
priv = true;
|
|
2234
|
+
}
|
|
1860
2235
|
else {
|
|
1861
2236
|
key = node.callee.property.name;
|
|
1862
2237
|
}
|
|
2238
|
+
let obj = object;
|
|
2239
|
+
if (priv) {
|
|
2240
|
+
obj = obj[PRIVATE];
|
|
2241
|
+
}
|
|
1863
2242
|
if (node.callee.object.type === 'Super') {
|
|
1864
2243
|
const thisObject = scope.find('this').get();
|
|
1865
|
-
func =
|
|
2244
|
+
func = obj[key].bind(thisObject);
|
|
1866
2245
|
}
|
|
1867
2246
|
else {
|
|
1868
|
-
func =
|
|
2247
|
+
func = obj[key];
|
|
2248
|
+
}
|
|
2249
|
+
if (node.optional && func == null) {
|
|
2250
|
+
return undefined;
|
|
1869
2251
|
}
|
|
1870
2252
|
if (typeof func !== 'function') {
|
|
1871
2253
|
throw new TypeError(`${key} is not a function`);
|
|
@@ -1877,6 +2259,9 @@
|
|
|
1877
2259
|
else {
|
|
1878
2260
|
object = scope.find('this').get();
|
|
1879
2261
|
func = yield* evaluate$1(node.callee, scope);
|
|
2262
|
+
if (node.optional && func == null) {
|
|
2263
|
+
return undefined;
|
|
2264
|
+
}
|
|
1880
2265
|
if (typeof func !== 'function' || node.callee.type !== 'Super' && func[CLSCTOR]) {
|
|
1881
2266
|
let name;
|
|
1882
2267
|
if (node.callee.type === 'Identifier') {
|
|
@@ -1955,7 +2340,12 @@
|
|
|
1955
2340
|
return new constructor(...args);
|
|
1956
2341
|
}
|
|
1957
2342
|
function* MetaProperty$1(node, scope) {
|
|
1958
|
-
|
|
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
|
+
}
|
|
1959
2349
|
}
|
|
1960
2350
|
function* SequenceExpression$1(node, scope) {
|
|
1961
2351
|
let result;
|
|
@@ -2021,6 +2411,30 @@
|
|
|
2021
2411
|
function* SpreadElement$1(node, scope) {
|
|
2022
2412
|
return yield* evaluate$1(node.argument, scope);
|
|
2023
2413
|
}
|
|
2414
|
+
function* ChainExpression$1(node, scope) {
|
|
2415
|
+
return yield* evaluate$1(node.expression, scope);
|
|
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
|
+
}
|
|
2024
2438
|
function* YieldExpression(node, scope) {
|
|
2025
2439
|
const res = yield* evaluate$1(node.argument, scope);
|
|
2026
2440
|
return node.delegate ? yield* res : yield res;
|
|
@@ -2054,10 +2468,167 @@
|
|
|
2054
2468
|
ClassExpression: ClassExpression$1,
|
|
2055
2469
|
Super: Super$1,
|
|
2056
2470
|
SpreadElement: SpreadElement$1,
|
|
2471
|
+
ChainExpression: ChainExpression$1,
|
|
2472
|
+
ImportExpression: ImportExpression$1,
|
|
2057
2473
|
YieldExpression: YieldExpression,
|
|
2058
2474
|
AwaitExpression: AwaitExpression
|
|
2059
2475
|
});
|
|
2060
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
|
+
|
|
2061
2632
|
function* ExpressionStatement$1(node, scope) {
|
|
2062
2633
|
yield* evaluate$1(node.expression, scope);
|
|
2063
2634
|
}
|
|
@@ -2262,183 +2833,6 @@
|
|
|
2262
2833
|
}
|
|
2263
2834
|
}
|
|
2264
2835
|
|
|
2265
|
-
var statement$1 = /*#__PURE__*/Object.freeze({
|
|
2266
|
-
__proto__: null,
|
|
2267
|
-
ExpressionStatement: ExpressionStatement$1,
|
|
2268
|
-
BlockStatement: BlockStatement$1,
|
|
2269
|
-
EmptyStatement: EmptyStatement$1,
|
|
2270
|
-
DebuggerStatement: DebuggerStatement$1,
|
|
2271
|
-
ReturnStatement: ReturnStatement$1,
|
|
2272
|
-
BreakStatement: BreakStatement$1,
|
|
2273
|
-
ContinueStatement: ContinueStatement$1,
|
|
2274
|
-
IfStatement: IfStatement$1,
|
|
2275
|
-
SwitchStatement: SwitchStatement$1,
|
|
2276
|
-
SwitchCase: SwitchCase$1,
|
|
2277
|
-
ThrowStatement: ThrowStatement$1,
|
|
2278
|
-
TryStatement: TryStatement$1,
|
|
2279
|
-
CatchClause: CatchClause$1,
|
|
2280
|
-
WhileStatement: WhileStatement$1,
|
|
2281
|
-
DoWhileStatement: DoWhileStatement$1,
|
|
2282
|
-
ForStatement: ForStatement$1,
|
|
2283
|
-
ForInStatement: ForInStatement$1,
|
|
2284
|
-
ForOfStatement: ForOfStatement$1
|
|
2285
|
-
});
|
|
2286
|
-
|
|
2287
|
-
function* ObjectPattern$1(node, scope, options = {}) {
|
|
2288
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed = {} } = options;
|
|
2289
|
-
const fedKeys = [];
|
|
2290
|
-
for (let i = 0; i < node.properties.length; i++) {
|
|
2291
|
-
const property = node.properties[i];
|
|
2292
|
-
if (hoist) {
|
|
2293
|
-
if (onlyBlock || kind === 'var') {
|
|
2294
|
-
if (property.type === 'Property') {
|
|
2295
|
-
const value = property.value;
|
|
2296
|
-
if (value.type === 'Identifier') {
|
|
2297
|
-
scope[kind](value.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2298
|
-
}
|
|
2299
|
-
else {
|
|
2300
|
-
yield* pattern$2(value, scope, { kind, hoist, onlyBlock });
|
|
2301
|
-
}
|
|
2302
|
-
}
|
|
2303
|
-
else {
|
|
2304
|
-
yield* RestElement$1(property, scope, { kind, hoist, onlyBlock });
|
|
2305
|
-
}
|
|
2306
|
-
}
|
|
2307
|
-
}
|
|
2308
|
-
else if (property.type === 'Property') {
|
|
2309
|
-
let key;
|
|
2310
|
-
if (property.computed) {
|
|
2311
|
-
key = yield* evaluate$1(property.key, scope);
|
|
2312
|
-
}
|
|
2313
|
-
else {
|
|
2314
|
-
key = property.key.name;
|
|
2315
|
-
}
|
|
2316
|
-
fedKeys.push(key);
|
|
2317
|
-
const value = property.value;
|
|
2318
|
-
if (value.type === 'Identifier') {
|
|
2319
|
-
scope[kind](value.name, feed[key]);
|
|
2320
|
-
}
|
|
2321
|
-
else {
|
|
2322
|
-
yield* pattern$2(value, scope, { kind, feed: feed[key] });
|
|
2323
|
-
}
|
|
2324
|
-
}
|
|
2325
|
-
else {
|
|
2326
|
-
const rest = assign({}, feed);
|
|
2327
|
-
for (let i = 0; i < fedKeys.length; i++)
|
|
2328
|
-
delete rest[fedKeys[i]];
|
|
2329
|
-
yield* RestElement$1(property, scope, { kind, feed: rest });
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
}
|
|
2333
|
-
function* ArrayPattern$1(node, scope, options = {}) {
|
|
2334
|
-
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
2335
|
-
const result = [];
|
|
2336
|
-
for (let i = 0; i < node.elements.length; i++) {
|
|
2337
|
-
const element = node.elements[i];
|
|
2338
|
-
if (!element)
|
|
2339
|
-
continue;
|
|
2340
|
-
if (hoist) {
|
|
2341
|
-
if (onlyBlock || kind === 'var') {
|
|
2342
|
-
if (element.type === 'Identifier') {
|
|
2343
|
-
scope[kind](element.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2344
|
-
}
|
|
2345
|
-
else {
|
|
2346
|
-
yield* pattern$2(element, scope, { kind, hoist, onlyBlock });
|
|
2347
|
-
}
|
|
2348
|
-
}
|
|
2349
|
-
}
|
|
2350
|
-
else if (element.type === 'Identifier') {
|
|
2351
|
-
if (kind) {
|
|
2352
|
-
scope[kind](element.name, feed[i]);
|
|
2353
|
-
}
|
|
2354
|
-
else {
|
|
2355
|
-
const variable = yield* Identifier$1(element, scope, { getVar: true });
|
|
2356
|
-
variable.set(feed[i]);
|
|
2357
|
-
result.push(variable.get());
|
|
2358
|
-
}
|
|
2359
|
-
}
|
|
2360
|
-
else if (element.type === 'RestElement') {
|
|
2361
|
-
yield* RestElement$1(element, scope, { kind, feed: feed.slice(i) });
|
|
2362
|
-
}
|
|
2363
|
-
else {
|
|
2364
|
-
yield* pattern$2(element, scope, { kind, feed: feed[i] });
|
|
2365
|
-
}
|
|
2366
|
-
}
|
|
2367
|
-
if (result.length) {
|
|
2368
|
-
return result;
|
|
2369
|
-
}
|
|
2370
|
-
}
|
|
2371
|
-
function* RestElement$1(node, scope, options = {}) {
|
|
2372
|
-
const { kind, hoist = false, onlyBlock = false, feed = [] } = options;
|
|
2373
|
-
const arg = node.argument;
|
|
2374
|
-
if (hoist) {
|
|
2375
|
-
if (onlyBlock || kind === 'var') {
|
|
2376
|
-
if (arg.type === 'Identifier') {
|
|
2377
|
-
scope[kind](arg.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2378
|
-
}
|
|
2379
|
-
else {
|
|
2380
|
-
yield* pattern$2(arg, scope, { kind, hoist, onlyBlock });
|
|
2381
|
-
}
|
|
2382
|
-
}
|
|
2383
|
-
}
|
|
2384
|
-
else if (arg.type === 'Identifier') {
|
|
2385
|
-
if (kind) {
|
|
2386
|
-
scope[kind](arg.name, feed);
|
|
2387
|
-
}
|
|
2388
|
-
else {
|
|
2389
|
-
const variable = yield* Identifier$1(arg, scope, { getVar: true });
|
|
2390
|
-
variable.set(feed);
|
|
2391
|
-
}
|
|
2392
|
-
}
|
|
2393
|
-
else {
|
|
2394
|
-
yield* pattern$2(arg, scope, { kind, feed });
|
|
2395
|
-
}
|
|
2396
|
-
}
|
|
2397
|
-
function* AssignmentPattern$1(node, scope, options = {}) {
|
|
2398
|
-
const { kind = 'var', hoist = false, onlyBlock = false, feed = yield* evaluate$1(node.right, scope) } = options;
|
|
2399
|
-
const left = node.left;
|
|
2400
|
-
if (hoist) {
|
|
2401
|
-
if (onlyBlock || kind === 'var') {
|
|
2402
|
-
if (left.type === 'Identifier') {
|
|
2403
|
-
scope[kind](left.name, onlyBlock ? DEADZONE : kind === 'var' ? NOINIT : undefined);
|
|
2404
|
-
}
|
|
2405
|
-
else {
|
|
2406
|
-
yield* pattern$2(left, scope, { kind, hoist, onlyBlock });
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
|
-
else if (left.type === 'Identifier') {
|
|
2411
|
-
scope[kind](left.name, feed);
|
|
2412
|
-
}
|
|
2413
|
-
else {
|
|
2414
|
-
yield* pattern$2(left, scope, { kind, feed });
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
2417
|
-
|
|
2418
|
-
var pattern$1 = /*#__PURE__*/Object.freeze({
|
|
2419
|
-
__proto__: null,
|
|
2420
|
-
ObjectPattern: ObjectPattern$1,
|
|
2421
|
-
ArrayPattern: ArrayPattern$1,
|
|
2422
|
-
RestElement: RestElement$1,
|
|
2423
|
-
AssignmentPattern: AssignmentPattern$1
|
|
2424
|
-
});
|
|
2425
|
-
|
|
2426
|
-
let evaluateOps$1;
|
|
2427
|
-
function* evaluate$1(node, scope) {
|
|
2428
|
-
if (!node)
|
|
2429
|
-
return;
|
|
2430
|
-
if (!evaluateOps$1) {
|
|
2431
|
-
evaluateOps$1 = assign({}, declaration$1, expression$1, identifier$1, statement$1, literal$1, pattern$1);
|
|
2432
|
-
}
|
|
2433
|
-
const handler = evaluateOps$1[node.type];
|
|
2434
|
-
if (handler) {
|
|
2435
|
-
return yield* handler(node, scope);
|
|
2436
|
-
}
|
|
2437
|
-
else {
|
|
2438
|
-
throw new Error(`${node.type} isn't implemented`);
|
|
2439
|
-
}
|
|
2440
|
-
}
|
|
2441
|
-
|
|
2442
2836
|
function* FunctionDeclaration$1(node, scope) {
|
|
2443
2837
|
scope.func(node.id.name, createFunc(node, scope));
|
|
2444
2838
|
}
|
|
@@ -2491,22 +2885,42 @@
|
|
|
2491
2885
|
function* ClassBody$1(node, scope, options = {}) {
|
|
2492
2886
|
const { klass, superClass } = options;
|
|
2493
2887
|
for (let i = 0; i < node.body.length; i++) {
|
|
2494
|
-
|
|
2888
|
+
const def = node.body[i];
|
|
2889
|
+
if (def.type === 'MethodDefinition') {
|
|
2890
|
+
yield* MethodDefinition$1(def, scope, { klass, superClass });
|
|
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
|
+
}
|
|
2495
2898
|
}
|
|
2496
2899
|
}
|
|
2497
2900
|
function* MethodDefinition$1(node, scope, options = {}) {
|
|
2498
2901
|
const { klass, superClass } = options;
|
|
2499
2902
|
let key;
|
|
2903
|
+
let priv = false;
|
|
2500
2904
|
if (node.computed) {
|
|
2501
2905
|
key = yield* evaluate$1(node.key, scope);
|
|
2502
2906
|
}
|
|
2503
2907
|
else if (node.key.type === 'Identifier') {
|
|
2504
2908
|
key = node.key.name;
|
|
2505
2909
|
}
|
|
2910
|
+
else if (node.key.type === 'PrivateIdentifier') {
|
|
2911
|
+
key = node.key.name;
|
|
2912
|
+
priv = true;
|
|
2913
|
+
}
|
|
2506
2914
|
else {
|
|
2507
2915
|
throw new SyntaxError('Unexpected token');
|
|
2508
2916
|
}
|
|
2509
|
-
|
|
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
|
+
}
|
|
2510
2924
|
const value = createFunc(node.value, scope, { superClass });
|
|
2511
2925
|
switch (node.kind) {
|
|
2512
2926
|
case 'constructor':
|
|
@@ -2539,6 +2953,191 @@
|
|
|
2539
2953
|
default:
|
|
2540
2954
|
throw new SyntaxError('Unexpected token');
|
|
2541
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
|
+
}
|
|
2542
3141
|
}
|
|
2543
3142
|
|
|
2544
3143
|
function runAsync(iterator, options = {}) {
|
|
@@ -2687,7 +3286,7 @@
|
|
|
2687
3286
|
if (!node.generator && !node.async) {
|
|
2688
3287
|
return createFunc$1(node, scope, options);
|
|
2689
3288
|
}
|
|
2690
|
-
const { superClass,
|
|
3289
|
+
const { superClass, construct } = options;
|
|
2691
3290
|
const params = node.params;
|
|
2692
3291
|
const tmpFunc = function* (...args) {
|
|
2693
3292
|
const subScope = new Scope(scope, true);
|
|
@@ -2695,9 +3294,12 @@
|
|
|
2695
3294
|
subScope.const('this', this);
|
|
2696
3295
|
subScope.let('arguments', arguments);
|
|
2697
3296
|
subScope.const(NEWTARGET, new.target);
|
|
3297
|
+
if (construct) {
|
|
3298
|
+
yield* construct(this);
|
|
3299
|
+
}
|
|
2698
3300
|
if (superClass) {
|
|
2699
3301
|
subScope.const(SUPER, superClass);
|
|
2700
|
-
if (
|
|
3302
|
+
if (construct)
|
|
2701
3303
|
subScope.let(SUPERCALL, false);
|
|
2702
3304
|
}
|
|
2703
3305
|
}
|
|
@@ -2778,16 +3380,25 @@
|
|
|
2778
3380
|
}
|
|
2779
3381
|
function* createClass(node, scope) {
|
|
2780
3382
|
const superClass = yield* evaluate$1(node.superClass, scope);
|
|
2781
|
-
|
|
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);
|
|
2782
3394
|
if (superClass) {
|
|
2783
3395
|
superClass.apply(this);
|
|
2784
3396
|
}
|
|
2785
3397
|
};
|
|
2786
|
-
const methodBody = node.body.body;
|
|
2787
3398
|
for (let i = 0; i < methodBody.length; i++) {
|
|
2788
3399
|
const method = methodBody[i];
|
|
2789
|
-
if (method.kind === 'constructor') {
|
|
2790
|
-
klass = createFunc(method.value, scope, { superClass,
|
|
3400
|
+
if (method.type === 'MethodDefinition' && method.kind === 'constructor') {
|
|
3401
|
+
klass = createFunc(method.value, scope, { superClass, construct });
|
|
2791
3402
|
break;
|
|
2792
3403
|
}
|
|
2793
3404
|
}
|
|
@@ -2926,7 +3537,7 @@
|
|
|
2926
3537
|
if (node.generator || node.async) {
|
|
2927
3538
|
return createFunc(node, scope, options);
|
|
2928
3539
|
}
|
|
2929
|
-
const { superClass,
|
|
3540
|
+
const { superClass, construct } = options;
|
|
2930
3541
|
const params = node.params;
|
|
2931
3542
|
const tmpFunc = function (...args) {
|
|
2932
3543
|
const subScope = new Scope(scope, true);
|
|
@@ -2934,9 +3545,12 @@
|
|
|
2934
3545
|
subScope.const('this', this);
|
|
2935
3546
|
subScope.let('arguments', arguments);
|
|
2936
3547
|
subScope.const(NEWTARGET, new.target);
|
|
3548
|
+
if (construct) {
|
|
3549
|
+
construct(this);
|
|
3550
|
+
}
|
|
2937
3551
|
if (superClass) {
|
|
2938
3552
|
subScope.const(SUPER, superClass);
|
|
2939
|
-
if (
|
|
3553
|
+
if (construct)
|
|
2940
3554
|
subScope.let(SUPERCALL, false);
|
|
2941
3555
|
}
|
|
2942
3556
|
}
|
|
@@ -2989,16 +3603,25 @@
|
|
|
2989
3603
|
}
|
|
2990
3604
|
function createClass$1(node, scope) {
|
|
2991
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
|
+
};
|
|
2992
3615
|
let klass = function () {
|
|
3616
|
+
construct(this);
|
|
2993
3617
|
if (superClass) {
|
|
2994
3618
|
superClass.apply(this);
|
|
2995
3619
|
}
|
|
2996
3620
|
};
|
|
2997
|
-
const methodBody = node.body.body;
|
|
2998
3621
|
for (let i = 0; i < methodBody.length; i++) {
|
|
2999
3622
|
const method = methodBody[i];
|
|
3000
|
-
if (method.kind === 'constructor') {
|
|
3001
|
-
klass = createFunc$1(method.value, scope, { superClass,
|
|
3623
|
+
if (method.type === 'MethodDefinition' && method.kind === 'constructor') {
|
|
3624
|
+
klass = createFunc$1(method.value, scope, { superClass, construct });
|
|
3002
3625
|
break;
|
|
3003
3626
|
}
|
|
3004
3627
|
}
|
|
@@ -3037,27 +3660,33 @@
|
|
|
3037
3660
|
return result;
|
|
3038
3661
|
}
|
|
3039
3662
|
|
|
3663
|
+
const latestVer = 15;
|
|
3040
3664
|
class Sval {
|
|
3041
3665
|
constructor(options = {}) {
|
|
3042
|
-
this.options = {};
|
|
3666
|
+
this.options = { ecmaVersion: 'latest' };
|
|
3043
3667
|
this.scope = new Scope(null, true);
|
|
3044
3668
|
this.exports = {};
|
|
3045
|
-
let { ecmaVer =
|
|
3046
|
-
|
|
3047
|
-
|
|
3669
|
+
let { ecmaVer = 'latest', sandBox = true, sourceType = 'script' } = options;
|
|
3670
|
+
if (typeof ecmaVer === 'number') {
|
|
3671
|
+
ecmaVer -= ecmaVer < 2015 ? 0 : 2009;
|
|
3672
|
+
}
|
|
3673
|
+
if (ecmaVer !== 'latest' && ecmaVer !== 3 && (ecmaVer < 5 || ecmaVer > latestVer)) {
|
|
3048
3674
|
throw new Error(`unsupported ecmaVer`);
|
|
3049
3675
|
}
|
|
3050
3676
|
this.options.ecmaVersion = ecmaVer;
|
|
3677
|
+
this.options.sourceType = sourceType;
|
|
3051
3678
|
if (sandBox) {
|
|
3052
3679
|
const win = createSandBox();
|
|
3680
|
+
this.scope.let('globalThis', win);
|
|
3053
3681
|
this.scope.let('window', win);
|
|
3054
3682
|
this.scope.let('this', win);
|
|
3055
3683
|
}
|
|
3056
3684
|
else {
|
|
3685
|
+
this.scope.let('globalThis', globalObj);
|
|
3057
3686
|
this.scope.let('window', globalObj);
|
|
3058
3687
|
this.scope.let('this', globalObj);
|
|
3059
3688
|
}
|
|
3060
|
-
this.scope.const('exports', this.exports = {});
|
|
3689
|
+
this.scope.const(sourceType === 'module' ? EXPORTS : 'exports', this.exports = {});
|
|
3061
3690
|
}
|
|
3062
3691
|
import(nameOrModules, mod) {
|
|
3063
3692
|
if (typeof nameOrModules === 'string') {
|
|
@@ -3068,7 +3697,8 @@
|
|
|
3068
3697
|
const names = getOwnNames(nameOrModules);
|
|
3069
3698
|
for (let i = 0; i < names.length; i++) {
|
|
3070
3699
|
const name = names[i];
|
|
3071
|
-
this.
|
|
3700
|
+
const modName = this.options.sourceType === 'module' ? IMPORT + name : name;
|
|
3701
|
+
this.scope.var(modName, nameOrModules[name]);
|
|
3072
3702
|
}
|
|
3073
3703
|
}
|
|
3074
3704
|
parse(code, parser) {
|