sval 0.6.1 → 0.6.3
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/dist/sval.es6.js +49 -29
- package/dist/sval.js +64 -41
- package/dist/sval.min.js +1 -1
- package/package.json +1 -1
package/dist/sval.es6.js
CHANGED
|
@@ -129,6 +129,16 @@
|
|
|
129
129
|
}
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
|
+
function callSuper(target, superClass, args = []) {
|
|
133
|
+
let supportReflect = false;
|
|
134
|
+
try {
|
|
135
|
+
supportReflect = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () { }));
|
|
136
|
+
}
|
|
137
|
+
catch (err) { }
|
|
138
|
+
return supportReflect
|
|
139
|
+
? Reflect.construct(superClass, args, getProto(target).constructor)
|
|
140
|
+
: superClass.apply(target, args);
|
|
141
|
+
}
|
|
132
142
|
function _assign(target) {
|
|
133
143
|
for (let i = 1; i < arguments.length; ++i) {
|
|
134
144
|
const source = arguments[i];
|
|
@@ -475,7 +485,7 @@
|
|
|
475
485
|
const IMPORT = createSymbol('import');
|
|
476
486
|
const EXPORTS = createSymbol('exports');
|
|
477
487
|
|
|
478
|
-
var version = "0.6.
|
|
488
|
+
var version = "0.6.3";
|
|
479
489
|
|
|
480
490
|
class Var {
|
|
481
491
|
constructor(kind, value) {
|
|
@@ -695,7 +705,7 @@
|
|
|
695
705
|
|
|
696
706
|
function* ThisExpression$1(node, scope) {
|
|
697
707
|
const superCall = scope.find(SUPERCALL);
|
|
698
|
-
if (superCall &&
|
|
708
|
+
if (superCall && superCall.get() !== true) {
|
|
699
709
|
throw new ReferenceError('Must call super constructor in derived class '
|
|
700
710
|
+ 'before accessing \'this\' or returning from derived constructor');
|
|
701
711
|
}
|
|
@@ -1092,12 +1102,15 @@
|
|
|
1092
1102
|
}
|
|
1093
1103
|
if (node.callee.type === 'Super') {
|
|
1094
1104
|
const superCall = scope.find(SUPERCALL);
|
|
1095
|
-
|
|
1105
|
+
const construct = superCall.get();
|
|
1106
|
+
if (construct === true) {
|
|
1096
1107
|
throw new ReferenceError('Super constructor may only be called once');
|
|
1097
1108
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1109
|
+
const inst = callSuper(object, func, args);
|
|
1110
|
+
yield* construct(inst);
|
|
1111
|
+
scope.find('this').set(inst);
|
|
1112
|
+
scope.find(SUPERCALL).set(true);
|
|
1113
|
+
return inst;
|
|
1101
1114
|
}
|
|
1102
1115
|
try {
|
|
1103
1116
|
return func.apply(object, args);
|
|
@@ -2125,7 +2138,7 @@
|
|
|
2125
2138
|
|
|
2126
2139
|
function ThisExpression(node, scope) {
|
|
2127
2140
|
const superCall = scope.find(SUPERCALL);
|
|
2128
|
-
if (superCall &&
|
|
2141
|
+
if (superCall && superCall.get() !== true) {
|
|
2129
2142
|
throw new ReferenceError('Must call super constructor in derived class '
|
|
2130
2143
|
+ 'before accessing \'this\' or returning from derived constructor');
|
|
2131
2144
|
}
|
|
@@ -2522,12 +2535,15 @@
|
|
|
2522
2535
|
}
|
|
2523
2536
|
if (node.callee.type === 'Super') {
|
|
2524
2537
|
const superCall = scope.find(SUPERCALL);
|
|
2525
|
-
|
|
2538
|
+
const construct = superCall.get();
|
|
2539
|
+
if (construct === true) {
|
|
2526
2540
|
throw new ReferenceError('Super constructor may only be called once');
|
|
2527
2541
|
}
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2542
|
+
const inst = callSuper(object, func, args);
|
|
2543
|
+
construct(inst);
|
|
2544
|
+
scope.find('this').set(inst);
|
|
2545
|
+
scope.find(SUPERCALL).set(true);
|
|
2546
|
+
return inst;
|
|
2531
2547
|
}
|
|
2532
2548
|
try {
|
|
2533
2549
|
return func.apply(object, args);
|
|
@@ -3583,16 +3599,16 @@
|
|
|
3583
3599
|
const tmpFunc = function (...args) {
|
|
3584
3600
|
const subScope = new Scope(scope, true);
|
|
3585
3601
|
if (node.type !== 'ArrowFunctionExpression') {
|
|
3586
|
-
subScope.
|
|
3602
|
+
subScope.let('this', this);
|
|
3587
3603
|
subScope.let('arguments', arguments);
|
|
3588
3604
|
subScope.const(NEWTARGET, new.target);
|
|
3589
|
-
if (construct) {
|
|
3590
|
-
construct(this);
|
|
3591
|
-
}
|
|
3592
3605
|
if (superClass) {
|
|
3593
3606
|
subScope.const(SUPER, superClass);
|
|
3594
3607
|
if (construct)
|
|
3595
|
-
subScope.let(SUPERCALL,
|
|
3608
|
+
subScope.let(SUPERCALL, construct);
|
|
3609
|
+
}
|
|
3610
|
+
else if (construct) {
|
|
3611
|
+
construct(this);
|
|
3596
3612
|
}
|
|
3597
3613
|
}
|
|
3598
3614
|
for (let i = 0; i < params.length; i++) {
|
|
@@ -3625,6 +3641,9 @@
|
|
|
3625
3641
|
if (result === RETURN) {
|
|
3626
3642
|
return result.RES;
|
|
3627
3643
|
}
|
|
3644
|
+
else if (new.target) {
|
|
3645
|
+
return subScope.find('this').get();
|
|
3646
|
+
}
|
|
3628
3647
|
};
|
|
3629
3648
|
let func = tmpFunc;
|
|
3630
3649
|
if (node.type === 'ArrowFunctionExpression') {
|
|
@@ -3661,10 +3680,9 @@
|
|
|
3661
3680
|
}
|
|
3662
3681
|
};
|
|
3663
3682
|
let klass = function () {
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
}
|
|
3683
|
+
const inst = superClass ? callSuper(this, superClass) : this;
|
|
3684
|
+
construct(inst);
|
|
3685
|
+
return inst;
|
|
3668
3686
|
};
|
|
3669
3687
|
for (let i = 0; i < methodBody.length; i++) {
|
|
3670
3688
|
const method = methodBody[i];
|
|
@@ -3814,16 +3832,16 @@
|
|
|
3814
3832
|
const tmpFunc = function* (...args) {
|
|
3815
3833
|
const subScope = new Scope(scope, true);
|
|
3816
3834
|
if (node.type !== 'ArrowFunctionExpression') {
|
|
3817
|
-
subScope.
|
|
3835
|
+
subScope.let('this', this);
|
|
3818
3836
|
subScope.let('arguments', arguments);
|
|
3819
3837
|
subScope.const(NEWTARGET, new.target);
|
|
3820
|
-
if (construct) {
|
|
3821
|
-
yield* construct(this);
|
|
3822
|
-
}
|
|
3823
3838
|
if (superClass) {
|
|
3824
3839
|
subScope.const(SUPER, superClass);
|
|
3825
3840
|
if (construct)
|
|
3826
|
-
subScope.let(SUPERCALL,
|
|
3841
|
+
subScope.let(SUPERCALL, construct);
|
|
3842
|
+
}
|
|
3843
|
+
else if (construct) {
|
|
3844
|
+
yield* construct(this);
|
|
3827
3845
|
}
|
|
3828
3846
|
}
|
|
3829
3847
|
for (let i = 0; i < params.length; i++) {
|
|
@@ -3856,6 +3874,9 @@
|
|
|
3856
3874
|
if (result === RETURN) {
|
|
3857
3875
|
return result.RES;
|
|
3858
3876
|
}
|
|
3877
|
+
else if (new.target) {
|
|
3878
|
+
return subScope.find('this').get();
|
|
3879
|
+
}
|
|
3859
3880
|
};
|
|
3860
3881
|
let func;
|
|
3861
3882
|
if (node.async && node.generator) {
|
|
@@ -3920,10 +3941,9 @@
|
|
|
3920
3941
|
}
|
|
3921
3942
|
};
|
|
3922
3943
|
let klass = function* () {
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
}
|
|
3944
|
+
const inst = superClass ? callSuper(this, superClass) : this;
|
|
3945
|
+
yield* construct(inst);
|
|
3946
|
+
return inst;
|
|
3927
3947
|
};
|
|
3928
3948
|
for (let i = 0; i < methodBody.length; i++) {
|
|
3929
3949
|
const method = methodBody[i];
|
package/dist/sval.js
CHANGED
|
@@ -206,6 +206,17 @@
|
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
208
|
}
|
|
209
|
+
function callSuper(target, superClass, args) {
|
|
210
|
+
if (args === void 0) { args = []; }
|
|
211
|
+
var supportReflect = false;
|
|
212
|
+
try {
|
|
213
|
+
supportReflect = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () { }));
|
|
214
|
+
}
|
|
215
|
+
catch (err) { }
|
|
216
|
+
return supportReflect
|
|
217
|
+
? Reflect.construct(superClass, args, getProto(target).constructor)
|
|
218
|
+
: superClass.apply(target, args);
|
|
219
|
+
}
|
|
209
220
|
function _assign(target) {
|
|
210
221
|
for (var i = 1; i < arguments.length; ++i) {
|
|
211
222
|
var source = arguments[i];
|
|
@@ -553,7 +564,7 @@
|
|
|
553
564
|
var IMPORT = createSymbol('import');
|
|
554
565
|
var EXPORTS = createSymbol('exports');
|
|
555
566
|
|
|
556
|
-
var version = "0.6.
|
|
567
|
+
var version = "0.6.3";
|
|
557
568
|
|
|
558
569
|
var Var = (function () {
|
|
559
570
|
function Var(kind, value) {
|
|
@@ -787,7 +798,7 @@
|
|
|
787
798
|
var superCall;
|
|
788
799
|
return __generator(this, function (_a) {
|
|
789
800
|
superCall = scope.find(SUPERCALL);
|
|
790
|
-
if (superCall &&
|
|
801
|
+
if (superCall && superCall.get() !== true) {
|
|
791
802
|
throw new ReferenceError('Must call super constructor in derived class '
|
|
792
803
|
+ 'before accessing \'this\' or returning from derived constructor');
|
|
793
804
|
}
|
|
@@ -1259,7 +1270,7 @@
|
|
|
1259
1270
|
});
|
|
1260
1271
|
}
|
|
1261
1272
|
function CallExpression$1(node, scope) {
|
|
1262
|
-
var func, object, key, priv, obj, thisObject, name_1, args, i, arg, _a, _b, _c, _d, superCall, win;
|
|
1273
|
+
var func, object, key, priv, obj, thisObject, name_1, args, i, arg, _a, _b, _c, _d, superCall, construct, inst, win;
|
|
1263
1274
|
return __generator(this, function (_e) {
|
|
1264
1275
|
switch (_e.label) {
|
|
1265
1276
|
case 0:
|
|
@@ -1359,15 +1370,20 @@
|
|
|
1359
1370
|
i++;
|
|
1360
1371
|
return [3, 8];
|
|
1361
1372
|
case 13:
|
|
1362
|
-
if (node.callee.type === 'Super')
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1373
|
+
if (!(node.callee.type === 'Super')) return [3, 15];
|
|
1374
|
+
superCall = scope.find(SUPERCALL);
|
|
1375
|
+
construct = superCall.get();
|
|
1376
|
+
if (construct === true) {
|
|
1377
|
+
throw new ReferenceError('Super constructor may only be called once');
|
|
1378
|
+
}
|
|
1379
|
+
inst = callSuper(object, func, args);
|
|
1380
|
+
return [5, __values(construct(inst))];
|
|
1381
|
+
case 14:
|
|
1382
|
+
_e.sent();
|
|
1383
|
+
scope.find('this').set(inst);
|
|
1384
|
+
scope.find(SUPERCALL).set(true);
|
|
1385
|
+
return [2, inst];
|
|
1386
|
+
case 15:
|
|
1371
1387
|
try {
|
|
1372
1388
|
return [2, func.apply(object, args)];
|
|
1373
1389
|
}
|
|
@@ -3020,7 +3036,7 @@
|
|
|
3020
3036
|
|
|
3021
3037
|
function ThisExpression(node, scope) {
|
|
3022
3038
|
var superCall = scope.find(SUPERCALL);
|
|
3023
|
-
if (superCall &&
|
|
3039
|
+
if (superCall && superCall.get() !== true) {
|
|
3024
3040
|
throw new ReferenceError('Must call super constructor in derived class '
|
|
3025
3041
|
+ 'before accessing \'this\' or returning from derived constructor');
|
|
3026
3042
|
}
|
|
@@ -3418,12 +3434,15 @@
|
|
|
3418
3434
|
}
|
|
3419
3435
|
if (node.callee.type === 'Super') {
|
|
3420
3436
|
var superCall = scope.find(SUPERCALL);
|
|
3421
|
-
|
|
3437
|
+
var construct = superCall.get();
|
|
3438
|
+
if (construct === true) {
|
|
3422
3439
|
throw new ReferenceError('Super constructor may only be called once');
|
|
3423
3440
|
}
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3441
|
+
var inst = callSuper(object, func, args);
|
|
3442
|
+
construct(inst);
|
|
3443
|
+
scope.find('this').set(inst);
|
|
3444
|
+
scope.find(SUPERCALL).set(true);
|
|
3445
|
+
return inst;
|
|
3427
3446
|
}
|
|
3428
3447
|
try {
|
|
3429
3448
|
return func.apply(object, args);
|
|
@@ -4520,16 +4539,16 @@
|
|
|
4520
4539
|
}
|
|
4521
4540
|
var subScope = new Scope(scope, true);
|
|
4522
4541
|
if (node.type !== 'ArrowFunctionExpression') {
|
|
4523
|
-
subScope.
|
|
4542
|
+
subScope.let('this', this);
|
|
4524
4543
|
subScope.let('arguments', arguments);
|
|
4525
4544
|
subScope.const(NEWTARGET, _newTarget);
|
|
4526
|
-
if (construct) {
|
|
4527
|
-
construct(this);
|
|
4528
|
-
}
|
|
4529
4545
|
if (superClass) {
|
|
4530
4546
|
subScope.const(SUPER, superClass);
|
|
4531
4547
|
if (construct)
|
|
4532
|
-
subScope.let(SUPERCALL,
|
|
4548
|
+
subScope.let(SUPERCALL, construct);
|
|
4549
|
+
}
|
|
4550
|
+
else if (construct) {
|
|
4551
|
+
construct(this);
|
|
4533
4552
|
}
|
|
4534
4553
|
}
|
|
4535
4554
|
for (var i = 0; i < params.length; i++) {
|
|
@@ -4562,6 +4581,9 @@
|
|
|
4562
4581
|
if (result === RETURN) {
|
|
4563
4582
|
return result.RES;
|
|
4564
4583
|
}
|
|
4584
|
+
else if (_newTarget) {
|
|
4585
|
+
return subScope.find('this').get();
|
|
4586
|
+
}
|
|
4565
4587
|
};
|
|
4566
4588
|
var func = tmpFunc;
|
|
4567
4589
|
if (node.type === 'ArrowFunctionExpression') {
|
|
@@ -4598,10 +4620,9 @@
|
|
|
4598
4620
|
}
|
|
4599
4621
|
};
|
|
4600
4622
|
var klass = function () {
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
}
|
|
4623
|
+
var inst = superClass ? callSuper(this, superClass) : this;
|
|
4624
|
+
construct(inst);
|
|
4625
|
+
return inst;
|
|
4605
4626
|
};
|
|
4606
4627
|
for (var i = 0; i < methodBody.length; i++) {
|
|
4607
4628
|
var method = methodBody[i];
|
|
@@ -4863,20 +4884,19 @@
|
|
|
4863
4884
|
case 0:
|
|
4864
4885
|
subScope = new Scope(scope, true);
|
|
4865
4886
|
if (!(node.type !== 'ArrowFunctionExpression')) return [3, 3];
|
|
4866
|
-
subScope.
|
|
4887
|
+
subScope.let('this', this);
|
|
4867
4888
|
subScope.let('arguments', arguments);
|
|
4868
4889
|
subScope.const(NEWTARGET, _newTarget);
|
|
4869
|
-
if (!
|
|
4870
|
-
|
|
4890
|
+
if (!superClass) return [3, 1];
|
|
4891
|
+
subScope.const(SUPER, superClass);
|
|
4892
|
+
if (construct)
|
|
4893
|
+
subScope.let(SUPERCALL, construct);
|
|
4894
|
+
return [3, 3];
|
|
4871
4895
|
case 1:
|
|
4872
|
-
|
|
4873
|
-
|
|
4896
|
+
if (!construct) return [3, 3];
|
|
4897
|
+
return [5, __values(construct(this))];
|
|
4874
4898
|
case 2:
|
|
4875
|
-
|
|
4876
|
-
subScope.const(SUPER, superClass);
|
|
4877
|
-
if (construct)
|
|
4878
|
-
subScope.let(SUPERCALL, false);
|
|
4879
|
-
}
|
|
4899
|
+
_a.sent();
|
|
4880
4900
|
_a.label = 3;
|
|
4881
4901
|
case 3:
|
|
4882
4902
|
i = 0;
|
|
@@ -4924,6 +4944,9 @@
|
|
|
4924
4944
|
if (result === RETURN) {
|
|
4925
4945
|
return [2, result.RES];
|
|
4926
4946
|
}
|
|
4947
|
+
else if (_newTarget) {
|
|
4948
|
+
return [2, subScope.find('this').get()];
|
|
4949
|
+
}
|
|
4927
4950
|
return [2];
|
|
4928
4951
|
}
|
|
4929
4952
|
});
|
|
@@ -5012,15 +5035,15 @@
|
|
|
5012
5035
|
});
|
|
5013
5036
|
};
|
|
5014
5037
|
klass = function () {
|
|
5038
|
+
var inst;
|
|
5015
5039
|
return __generator(this, function (_a) {
|
|
5016
5040
|
switch (_a.label) {
|
|
5017
|
-
case 0:
|
|
5041
|
+
case 0:
|
|
5042
|
+
inst = superClass ? callSuper(this, superClass) : this;
|
|
5043
|
+
return [5, __values(construct(inst))];
|
|
5018
5044
|
case 1:
|
|
5019
5045
|
_a.sent();
|
|
5020
|
-
|
|
5021
|
-
superClass.apply(this);
|
|
5022
|
-
}
|
|
5023
|
-
return [2];
|
|
5046
|
+
return [2, inst];
|
|
5024
5047
|
}
|
|
5025
5048
|
});
|
|
5026
5049
|
};
|