sval 0.5.3 → 0.5.5

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.js CHANGED
@@ -13,6 +13,8 @@
13
13
  get ReturnStatement () { return ReturnStatement$1; },
14
14
  get BreakStatement () { return BreakStatement$1; },
15
15
  get ContinueStatement () { return ContinueStatement$1; },
16
+ get LabeledStatement () { return LabeledStatement$1; },
17
+ get WithStatement () { return WithStatement$1; },
16
18
  get IfStatement () { return IfStatement$1; },
17
19
  get SwitchStatement () { return SwitchStatement$1; },
18
20
  get SwitchCase () { return SwitchCase$1; },
@@ -49,6 +51,8 @@
49
51
  get ReturnStatement () { return ReturnStatement; },
50
52
  get BreakStatement () { return BreakStatement; },
51
53
  get ContinueStatement () { return ContinueStatement; },
54
+ get LabeledStatement () { return LabeledStatement; },
55
+ get WithStatement () { return WithStatement; },
52
56
  get IfStatement () { return IfStatement; },
53
57
  get SwitchStatement () { return SwitchStatement; },
54
58
  get SwitchCase () { return SwitchCase; },
@@ -395,6 +399,10 @@
395
399
  globalObj.crypto = crypto;
396
400
  }
397
401
  catch (err) { }
402
+ try {
403
+ globalObj.URL = URL;
404
+ }
405
+ catch (err) { }
398
406
  names = getOwnNames(globalObj);
399
407
  }
400
408
  }
@@ -444,8 +452,8 @@
444
452
 
445
453
  var AWAIT = { RES: undefined };
446
454
  var RETURN = { RES: undefined };
447
- var CONTINUE = createSymbol('continue');
448
- var BREAK = createSymbol('break');
455
+ var CONTINUE = { LABEL: undefined };
456
+ var BREAK = { LABEL: undefined };
449
457
  var SUPER = createSymbol('super');
450
458
  var SUPERCALL = createSymbol('supercall');
451
459
  var NOCTOR = createSymbol('noctor');
@@ -457,7 +465,7 @@
457
465
  var IMPORT = createSymbol('import');
458
466
  var EXPORTS = createSymbol('exports');
459
467
 
460
- var version = "0.5.3";
468
+ var version = "0.5.5";
461
469
 
462
470
  var Var = (function () {
463
471
  function Var(kind, value) {
@@ -500,6 +508,7 @@
500
508
  if (parent === void 0) { parent = null; }
501
509
  if (isolated === void 0) { isolated = false; }
502
510
  this.context = create(null);
511
+ this.withContext = create(null);
503
512
  this.parent = parent;
504
513
  this.isolated = isolated;
505
514
  }
@@ -510,18 +519,13 @@
510
519
  }
511
520
  return scope;
512
521
  };
513
- Scope.prototype.clone = function () {
514
- var cloneScope = new Scope(this.parent, this.isolated);
515
- for (var name_1 in this.context) {
516
- var variable = this.context[name_1];
517
- cloneScope[variable.kind](name_1, variable.get());
518
- }
519
- return cloneScope;
520
- };
521
522
  Scope.prototype.find = function (name) {
522
523
  if (this.context[name]) {
523
524
  return this.context[name];
524
525
  }
526
+ else if (name in this.withContext) {
527
+ return new Prop(this.withContext, name);
528
+ }
525
529
  else if (this.parent) {
526
530
  return this.parent.find(name);
527
531
  }
@@ -588,6 +592,11 @@
588
592
  throw new SyntaxError("Identifier '" + name + "' has already been declared");
589
593
  }
590
594
  };
595
+ Scope.prototype.with = function (value) {
596
+ if (Object.keys(value)) {
597
+ this.withContext = value;
598
+ }
599
+ };
591
600
  return Scope;
592
601
  }());
593
602
 
@@ -1473,7 +1482,13 @@
1473
1482
  }
1474
1483
  for (var i = 0; i < block.body.length; i++) {
1475
1484
  var result = evaluate$1(block.body[i], subScope);
1476
- if (result === BREAK || result === CONTINUE || result === RETURN) {
1485
+ if (result === BREAK) {
1486
+ if (result.LABEL && result.LABEL === options.label) {
1487
+ break;
1488
+ }
1489
+ return result;
1490
+ }
1491
+ if (result === CONTINUE || result === RETURN) {
1477
1492
  return result;
1478
1493
  }
1479
1494
  }
@@ -1487,21 +1502,86 @@
1487
1502
  RETURN.RES = node.argument ? (evaluate$1(node.argument, scope)) : undefined;
1488
1503
  return RETURN;
1489
1504
  }
1490
- function BreakStatement$1() {
1505
+ function BreakStatement$1(node) {
1506
+ var _a;
1507
+ BREAK.LABEL = (_a = node.label) === null || _a === void 0 ? void 0 : _a.name;
1491
1508
  return BREAK;
1492
1509
  }
1493
- function ContinueStatement$1() {
1510
+ function ContinueStatement$1(node) {
1511
+ var _a;
1512
+ CONTINUE.LABEL = (_a = node.label) === null || _a === void 0 ? void 0 : _a.name;
1494
1513
  return CONTINUE;
1495
1514
  }
1496
- function IfStatement$1(node, scope) {
1515
+ function LabeledStatement$1(node, scope) {
1516
+ var label = node.label.name;
1517
+ if (node.body.type === 'WhileStatement') {
1518
+ return WhileStatement$1(node.body, scope, { label: label });
1519
+ }
1520
+ if (node.body.type === 'DoWhileStatement') {
1521
+ return DoWhileStatement$1(node.body, scope, { label: label });
1522
+ }
1523
+ if (node.body.type === 'ForStatement') {
1524
+ return ForStatement$1(node.body, scope, { label: label });
1525
+ }
1526
+ if (node.body.type === 'ForInStatement') {
1527
+ return ForInStatement$1(node.body, scope, { label: label });
1528
+ }
1529
+ if (node.body.type === 'ForOfStatement') {
1530
+ return ForOfStatement$1(node.body, scope, { label: label });
1531
+ }
1532
+ if (node.body.type === 'BlockStatement') {
1533
+ return BlockStatement$1(node.body, scope, { label: label });
1534
+ }
1535
+ if (node.body.type === 'WithStatement') {
1536
+ return WithStatement$1(node.body, scope, { label: label });
1537
+ }
1538
+ if (node.body.type === 'IfStatement') {
1539
+ return IfStatement$1(node.body, scope, { label: label });
1540
+ }
1541
+ if (node.body.type === 'SwitchStatement') {
1542
+ return SwitchStatement$1(node.body, scope, { label: label });
1543
+ }
1544
+ if (node.body.type === 'TryStatement') {
1545
+ return TryStatement$1(node.body, scope, { label: label });
1546
+ }
1547
+ throw new SyntaxError(node.body.type + " cannot be labeled");
1548
+ }
1549
+ function WithStatement$1(node, scope, options) {
1550
+ if (options === void 0) { options = {}; }
1551
+ var withScope = new Scope(scope);
1552
+ withScope.with(evaluate$1(node.object, scope));
1553
+ var result = evaluate$1(node.body, withScope);
1554
+ if (result === BREAK) {
1555
+ if (result.LABEL && result.LABEL === options.label) {
1556
+ return;
1557
+ }
1558
+ return result;
1559
+ }
1560
+ if (result === CONTINUE || result === RETURN) {
1561
+ return result;
1562
+ }
1563
+ }
1564
+ function IfStatement$1(node, scope, options) {
1565
+ if (options === void 0) { options = {}; }
1566
+ var result;
1497
1567
  if (evaluate$1(node.test, scope)) {
1498
- return evaluate$1(node.consequent, scope);
1568
+ result = evaluate$1(node.consequent, scope);
1499
1569
  }
1500
1570
  else {
1501
- return evaluate$1(node.alternate, scope);
1571
+ result = evaluate$1(node.alternate, scope);
1572
+ }
1573
+ if (result === BREAK) {
1574
+ if (result.LABEL && result.LABEL === options.label) {
1575
+ return;
1576
+ }
1577
+ return result;
1578
+ }
1579
+ if (result === CONTINUE || result === RETURN) {
1580
+ return result;
1502
1581
  }
1503
1582
  }
1504
- function SwitchStatement$1(node, scope) {
1583
+ function SwitchStatement$1(node, scope, options) {
1584
+ if (options === void 0) { options = {}; }
1505
1585
  var discriminant = evaluate$1(node.discriminant, scope);
1506
1586
  var matched = false;
1507
1587
  for (var i = 0; i < node.cases.length; i++) {
@@ -1514,7 +1594,10 @@
1514
1594
  if (matched) {
1515
1595
  var result = SwitchCase$1(eachCase, scope);
1516
1596
  if (result === BREAK) {
1517
- break;
1597
+ if (result.LABEL === options.label) {
1598
+ break;
1599
+ }
1600
+ return result;
1518
1601
  }
1519
1602
  if (result === CONTINUE || result === RETURN) {
1520
1603
  return result;
@@ -1533,9 +1616,11 @@
1533
1616
  function ThrowStatement$1(node, scope) {
1534
1617
  throw evaluate$1(node.argument, scope);
1535
1618
  }
1536
- function TryStatement$1(node, scope) {
1619
+ function TryStatement$1(node, scope, options) {
1620
+ if (options === void 0) { options = {}; }
1621
+ var result;
1537
1622
  try {
1538
- return BlockStatement$1(node.block, scope);
1623
+ result = BlockStatement$1(node.block, scope);
1539
1624
  }
1540
1625
  catch (err) {
1541
1626
  if (node.handler) {
@@ -1550,7 +1635,7 @@
1550
1635
  pattern(param, scope, { feed: err });
1551
1636
  }
1552
1637
  }
1553
- return CatchClause$1(node.handler, subScope);
1638
+ result = CatchClause$1(node.handler, subScope);
1554
1639
  }
1555
1640
  else {
1556
1641
  throw err;
@@ -1558,45 +1643,66 @@
1558
1643
  }
1559
1644
  finally {
1560
1645
  if (node.finalizer) {
1561
- var result = BlockStatement$1(node.finalizer, scope);
1562
- if (result === BREAK || result === CONTINUE || result === RETURN) {
1563
- return result;
1564
- }
1646
+ result = BlockStatement$1(node.finalizer, scope);
1565
1647
  }
1566
1648
  }
1649
+ if (result === BREAK) {
1650
+ if (result.LABEL && result.LABEL === options.label) {
1651
+ return;
1652
+ }
1653
+ return result;
1654
+ }
1655
+ if (result === CONTINUE || result === RETURN) {
1656
+ return result;
1657
+ }
1567
1658
  }
1568
1659
  function CatchClause$1(node, scope) {
1569
1660
  return BlockStatement$1(node.body, scope, { invasived: true });
1570
1661
  }
1571
- function WhileStatement$1(node, scope) {
1662
+ function WhileStatement$1(node, scope, options) {
1663
+ if (options === void 0) { options = {}; }
1572
1664
  while (evaluate$1(node.test, scope)) {
1573
1665
  var result = evaluate$1(node.body, scope);
1574
1666
  if (result === BREAK) {
1575
- break;
1667
+ if (result.LABEL === options.label) {
1668
+ break;
1669
+ }
1670
+ return result;
1576
1671
  }
1577
1672
  else if (result === CONTINUE) {
1578
- continue;
1673
+ if (result.LABEL === options.label) {
1674
+ continue;
1675
+ }
1676
+ return result;
1579
1677
  }
1580
1678
  else if (result === RETURN) {
1581
1679
  return result;
1582
1680
  }
1583
1681
  }
1584
1682
  }
1585
- function DoWhileStatement$1(node, scope) {
1683
+ function DoWhileStatement$1(node, scope, options) {
1684
+ if (options === void 0) { options = {}; }
1586
1685
  do {
1587
1686
  var result = evaluate$1(node.body, scope);
1588
1687
  if (result === BREAK) {
1589
- break;
1688
+ if (result.LABEL === options.label) {
1689
+ break;
1690
+ }
1691
+ return result;
1590
1692
  }
1591
1693
  else if (result === CONTINUE) {
1592
- continue;
1694
+ if (result.LABEL === options.label) {
1695
+ continue;
1696
+ }
1697
+ return result;
1593
1698
  }
1594
1699
  else if (result === RETURN) {
1595
1700
  return result;
1596
1701
  }
1597
1702
  } while (evaluate$1(node.test, scope));
1598
1703
  }
1599
- function ForStatement$1(node, scope) {
1704
+ function ForStatement$1(node, scope, options) {
1705
+ if (options === void 0) { options = {}; }
1600
1706
  var forScope = new Scope(scope);
1601
1707
  for (evaluate$1(node.init, forScope); node.test ? (evaluate$1(node.test, forScope)) : true; evaluate$1(node.update, forScope)) {
1602
1708
  var subScope = new Scope(forScope);
@@ -1608,42 +1714,62 @@
1608
1714
  result = evaluate$1(node.body, subScope);
1609
1715
  }
1610
1716
  if (result === BREAK) {
1611
- break;
1717
+ if (result.LABEL === options.label) {
1718
+ break;
1719
+ }
1720
+ return result;
1612
1721
  }
1613
1722
  else if (result === CONTINUE) {
1614
- continue;
1723
+ if (result.LABEL === options.label) {
1724
+ continue;
1725
+ }
1726
+ return result;
1615
1727
  }
1616
1728
  else if (result === RETURN) {
1617
1729
  return result;
1618
1730
  }
1619
1731
  }
1620
1732
  }
1621
- function ForInStatement$1(node, scope) {
1733
+ function ForInStatement$1(node, scope, options) {
1734
+ if (options === void 0) { options = {}; }
1622
1735
  for (var value in evaluate$1(node.right, scope)) {
1623
1736
  var result = ForXHandler(node, scope, { value: value });
1624
1737
  if (result === BREAK) {
1625
- break;
1738
+ if (result.LABEL === options.label) {
1739
+ break;
1740
+ }
1741
+ return result;
1626
1742
  }
1627
1743
  else if (result === CONTINUE) {
1628
- continue;
1744
+ if (result.LABEL === options.label) {
1745
+ continue;
1746
+ }
1747
+ return result;
1629
1748
  }
1630
1749
  else if (result === RETURN) {
1631
1750
  return result;
1632
1751
  }
1633
1752
  }
1634
1753
  }
1635
- function ForOfStatement$1(node, scope) {
1754
+ function ForOfStatement$1(node, scope, options) {
1636
1755
  var e_1, _a;
1756
+ if (options === void 0) { options = {}; }
1637
1757
  var right = evaluate$1(node.right, scope);
1638
1758
  try {
1639
1759
  for (var right_1 = __values(right), right_1_1 = right_1.next(); !right_1_1.done; right_1_1 = right_1.next()) {
1640
1760
  var value = right_1_1.value;
1641
1761
  var result = ForXHandler(node, scope, { value: value });
1642
1762
  if (result === BREAK) {
1643
- break;
1763
+ if (result.LABEL === options.label) {
1764
+ break;
1765
+ }
1766
+ return result;
1644
1767
  }
1645
1768
  else if (result === CONTINUE) {
1646
- continue;
1769
+ if (result.LABEL === options.label) {
1770
+ continue;
1771
+ }
1772
+ return result;
1647
1773
  }
1648
1774
  else if (result === RETURN) {
1649
1775
  return result;
@@ -3171,7 +3297,13 @@
3171
3297
  return [5, __values(evaluate(block.body[i], subScope))];
3172
3298
  case 4:
3173
3299
  result = _c.sent();
3174
- if (result === BREAK || result === CONTINUE || result === RETURN) {
3300
+ if (result === BREAK) {
3301
+ if (result.LABEL && result.LABEL === options.label) {
3302
+ return [3, 6];
3303
+ }
3304
+ return [2, result];
3305
+ }
3306
+ if (result === CONTINUE || result === RETURN) {
3175
3307
  return [2, result];
3176
3308
  }
3177
3309
  _c.label = 5;
@@ -3213,31 +3345,129 @@
3213
3345
  }
3214
3346
  });
3215
3347
  }
3216
- function BreakStatement() {
3217
- return __generator(this, function (_a) {
3348
+ function BreakStatement(node) {
3349
+ var _a;
3350
+ return __generator(this, function (_b) {
3351
+ BREAK.LABEL = (_a = node.label) === null || _a === void 0 ? void 0 : _a.name;
3218
3352
  return [2, BREAK];
3219
3353
  });
3220
3354
  }
3221
- function ContinueStatement() {
3222
- return __generator(this, function (_a) {
3355
+ function ContinueStatement(node) {
3356
+ var _a;
3357
+ return __generator(this, function (_b) {
3358
+ CONTINUE.LABEL = (_a = node.label) === null || _a === void 0 ? void 0 : _a.name;
3223
3359
  return [2, CONTINUE];
3224
3360
  });
3225
3361
  }
3226
- function IfStatement(node, scope) {
3362
+ function LabeledStatement(node, scope) {
3363
+ var label;
3364
+ return __generator(this, function (_a) {
3365
+ switch (_a.label) {
3366
+ case 0:
3367
+ label = node.label.name;
3368
+ if (!(node.body.type === 'WhileStatement')) return [3, 2];
3369
+ return [5, __values(WhileStatement(node.body, scope, { label: label }))];
3370
+ case 1: return [2, _a.sent()];
3371
+ case 2:
3372
+ if (!(node.body.type === 'DoWhileStatement')) return [3, 4];
3373
+ return [5, __values(DoWhileStatement(node.body, scope, { label: label }))];
3374
+ case 3: return [2, _a.sent()];
3375
+ case 4:
3376
+ if (!(node.body.type === 'ForStatement')) return [3, 6];
3377
+ return [5, __values(ForStatement(node.body, scope, { label: label }))];
3378
+ case 5: return [2, _a.sent()];
3379
+ case 6:
3380
+ if (!(node.body.type === 'ForInStatement')) return [3, 8];
3381
+ return [5, __values(ForInStatement(node.body, scope, { label: label }))];
3382
+ case 7: return [2, _a.sent()];
3383
+ case 8:
3384
+ if (!(node.body.type === 'ForOfStatement')) return [3, 10];
3385
+ return [5, __values(ForOfStatement(node.body, scope, { label: label }))];
3386
+ case 9: return [2, _a.sent()];
3387
+ case 10:
3388
+ if (!(node.body.type === 'BlockStatement')) return [3, 12];
3389
+ return [5, __values(BlockStatement(node.body, scope, { label: label }))];
3390
+ case 11: return [2, _a.sent()];
3391
+ case 12:
3392
+ if (!(node.body.type === 'WithStatement')) return [3, 14];
3393
+ return [5, __values(WithStatement(node.body, scope, { label: label }))];
3394
+ case 13: return [2, _a.sent()];
3395
+ case 14:
3396
+ if (!(node.body.type === 'IfStatement')) return [3, 16];
3397
+ return [5, __values(IfStatement(node.body, scope, { label: label }))];
3398
+ case 15: return [2, _a.sent()];
3399
+ case 16:
3400
+ if (!(node.body.type === 'SwitchStatement')) return [3, 18];
3401
+ return [5, __values(SwitchStatement(node.body, scope, { label: label }))];
3402
+ case 17: return [2, _a.sent()];
3403
+ case 18:
3404
+ if (!(node.body.type === 'TryStatement')) return [3, 20];
3405
+ return [5, __values(TryStatement(node.body, scope, { label: label }))];
3406
+ case 19: return [2, _a.sent()];
3407
+ case 20: throw new SyntaxError(node.body.type + " cannot be labeled");
3408
+ }
3409
+ });
3410
+ }
3411
+ function WithStatement(node, scope, options) {
3412
+ var withScope, _a, _b, result;
3413
+ if (options === void 0) { options = {}; }
3414
+ return __generator(this, function (_c) {
3415
+ switch (_c.label) {
3416
+ case 0:
3417
+ withScope = new Scope(scope);
3418
+ _b = (_a = withScope).with;
3419
+ return [5, __values(evaluate(node.object, scope))];
3420
+ case 1:
3421
+ _b.apply(_a, [_c.sent()]);
3422
+ return [5, __values(evaluate(node.body, withScope))];
3423
+ case 2:
3424
+ result = _c.sent();
3425
+ if (result === BREAK) {
3426
+ if (result.LABEL && result.LABEL === options.label) {
3427
+ return [2];
3428
+ }
3429
+ return [2, result];
3430
+ }
3431
+ if (result === CONTINUE || result === RETURN) {
3432
+ return [2, result];
3433
+ }
3434
+ return [2];
3435
+ }
3436
+ });
3437
+ }
3438
+ function IfStatement(node, scope, options) {
3439
+ var result;
3440
+ if (options === void 0) { options = {}; }
3227
3441
  return __generator(this, function (_a) {
3228
3442
  switch (_a.label) {
3229
3443
  case 0: return [5, __values(evaluate(node.test, scope))];
3230
3444
  case 1:
3231
3445
  if (!_a.sent()) return [3, 3];
3232
3446
  return [5, __values(evaluate(node.consequent, scope))];
3233
- case 2: return [2, _a.sent()];
3447
+ case 2:
3448
+ result = _a.sent();
3449
+ return [3, 5];
3234
3450
  case 3: return [5, __values(evaluate(node.alternate, scope))];
3235
- case 4: return [2, _a.sent()];
3451
+ case 4:
3452
+ result = _a.sent();
3453
+ _a.label = 5;
3454
+ case 5:
3455
+ if (result === BREAK) {
3456
+ if (result.LABEL && result.LABEL === options.label) {
3457
+ return [2];
3458
+ }
3459
+ return [2, result];
3460
+ }
3461
+ if (result === CONTINUE || result === RETURN) {
3462
+ return [2, result];
3463
+ }
3464
+ return [2];
3236
3465
  }
3237
3466
  });
3238
3467
  }
3239
- function SwitchStatement(node, scope) {
3468
+ function SwitchStatement(node, scope, options) {
3240
3469
  var discriminant, matched, i, eachCase, _a, _b, result;
3470
+ if (options === void 0) { options = {}; }
3241
3471
  return __generator(this, function (_c) {
3242
3472
  switch (_c.label) {
3243
3473
  case 0: return [5, __values(evaluate(node.discriminant, scope))];
@@ -3269,7 +3499,10 @@
3269
3499
  case 6:
3270
3500
  result = _c.sent();
3271
3501
  if (result === BREAK) {
3272
- return [3, 8];
3502
+ if (result.LABEL === options.label) {
3503
+ return [3, 8];
3504
+ }
3505
+ return [2, result];
3273
3506
  }
3274
3507
  if (result === CONTINUE || result === RETURN) {
3275
3508
  return [2, result];
@@ -3313,14 +3546,17 @@
3313
3546
  }
3314
3547
  });
3315
3548
  }
3316
- function TryStatement(node, scope) {
3317
- var err_1, subScope, param, name_1, result;
3549
+ function TryStatement(node, scope, options) {
3550
+ var result, err_1, subScope, param, name_1;
3551
+ if (options === void 0) { options = {}; }
3318
3552
  return __generator(this, function (_a) {
3319
3553
  switch (_a.label) {
3320
3554
  case 0:
3321
3555
  _a.trys.push([0, 2, 9, 12]);
3322
3556
  return [5, __values(BlockStatement(node.block, scope))];
3323
- case 1: return [2, _a.sent()];
3557
+ case 1:
3558
+ result = _a.sent();
3559
+ return [3, 12];
3324
3560
  case 2:
3325
3561
  err_1 = _a.sent();
3326
3562
  if (!node.handler) return [3, 7];
@@ -3336,7 +3572,9 @@
3336
3572
  _a.sent();
3337
3573
  _a.label = 5;
3338
3574
  case 5: return [5, __values(CatchClause(node.handler, subScope))];
3339
- case 6: return [2, _a.sent()];
3575
+ case 6:
3576
+ result = _a.sent();
3577
+ return [3, 8];
3340
3578
  case 7: throw err_1;
3341
3579
  case 8: return [3, 12];
3342
3580
  case 9:
@@ -3344,12 +3582,19 @@
3344
3582
  return [5, __values(BlockStatement(node.finalizer, scope))];
3345
3583
  case 10:
3346
3584
  result = _a.sent();
3347
- if (result === BREAK || result === CONTINUE || result === RETURN) {
3348
- return [2, result];
3349
- }
3350
3585
  _a.label = 11;
3351
3586
  case 11: return [7];
3352
- case 12: return [2];
3587
+ case 12:
3588
+ if (result === BREAK) {
3589
+ if (result.LABEL && result.LABEL === options.label) {
3590
+ return [2];
3591
+ }
3592
+ return [2, result];
3593
+ }
3594
+ if (result === CONTINUE || result === RETURN) {
3595
+ return [2, result];
3596
+ }
3597
+ return [2];
3353
3598
  }
3354
3599
  });
3355
3600
  }
@@ -3361,8 +3606,9 @@
3361
3606
  }
3362
3607
  });
3363
3608
  }
3364
- function WhileStatement(node, scope) {
3609
+ function WhileStatement(node, scope, options) {
3365
3610
  var result;
3611
+ if (options === void 0) { options = {}; }
3366
3612
  return __generator(this, function (_a) {
3367
3613
  switch (_a.label) {
3368
3614
  case 0: return [5, __values(evaluate(node.test, scope))];
@@ -3372,10 +3618,16 @@
3372
3618
  case 2:
3373
3619
  result = _a.sent();
3374
3620
  if (result === BREAK) {
3375
- return [3, 3];
3621
+ if (result.LABEL === options.label) {
3622
+ return [3, 3];
3623
+ }
3624
+ return [2, result];
3376
3625
  }
3377
3626
  else if (result === CONTINUE) {
3378
- return [3, 0];
3627
+ if (result.LABEL === options.label) {
3628
+ return [3, 0];
3629
+ }
3630
+ return [2, result];
3379
3631
  }
3380
3632
  else if (result === RETURN) {
3381
3633
  return [2, result];
@@ -3385,18 +3637,25 @@
3385
3637
  }
3386
3638
  });
3387
3639
  }
3388
- function DoWhileStatement(node, scope) {
3640
+ function DoWhileStatement(node, scope, options) {
3389
3641
  var result;
3642
+ if (options === void 0) { options = {}; }
3390
3643
  return __generator(this, function (_a) {
3391
3644
  switch (_a.label) {
3392
3645
  case 0: return [5, __values(evaluate(node.body, scope))];
3393
3646
  case 1:
3394
3647
  result = _a.sent();
3395
3648
  if (result === BREAK) {
3396
- return [3, 4];
3649
+ if (result.LABEL === options.label) {
3650
+ return [3, 4];
3651
+ }
3652
+ return [2, result];
3397
3653
  }
3398
3654
  else if (result === CONTINUE) {
3399
- return [3, 2];
3655
+ if (result.LABEL === options.label) {
3656
+ return [3, 2];
3657
+ }
3658
+ return [2, result];
3400
3659
  }
3401
3660
  else if (result === RETURN) {
3402
3661
  return [2, result];
@@ -3410,8 +3669,9 @@
3410
3669
  }
3411
3670
  });
3412
3671
  }
3413
- function ForStatement(node, scope) {
3672
+ function ForStatement(node, scope, options) {
3414
3673
  var forScope, _a, subScope, result;
3674
+ if (options === void 0) { options = {}; }
3415
3675
  return __generator(this, function (_b) {
3416
3676
  switch (_b.label) {
3417
3677
  case 0:
@@ -3444,10 +3704,16 @@
3444
3704
  _b.label = 9;
3445
3705
  case 9:
3446
3706
  if (result === BREAK) {
3447
- return [3, 12];
3707
+ if (result.LABEL === options.label) {
3708
+ return [3, 12];
3709
+ }
3710
+ return [2, result];
3448
3711
  }
3449
3712
  else if (result === CONTINUE) {
3450
- return [3, 10];
3713
+ if (result.LABEL === options.label) {
3714
+ return [3, 10];
3715
+ }
3716
+ return [2, result];
3451
3717
  }
3452
3718
  else if (result === RETURN) {
3453
3719
  return [2, result];
@@ -3461,8 +3727,9 @@
3461
3727
  }
3462
3728
  });
3463
3729
  }
3464
- function ForInStatement(node, scope) {
3730
+ function ForInStatement(node, scope, options) {
3465
3731
  var _a, _b, _i, value, result;
3732
+ if (options === void 0) { options = {}; }
3466
3733
  return __generator(this, function (_c) {
3467
3734
  switch (_c.label) {
3468
3735
  case 0:
@@ -3480,10 +3747,16 @@
3480
3747
  case 3:
3481
3748
  result = _c.sent();
3482
3749
  if (result === BREAK) {
3483
- return [3, 5];
3750
+ if (result.LABEL === options.label) {
3751
+ return [3, 5];
3752
+ }
3753
+ return [2, result];
3484
3754
  }
3485
3755
  else if (result === CONTINUE) {
3486
- return [3, 4];
3756
+ if (result.LABEL === options.label) {
3757
+ return [3, 4];
3758
+ }
3759
+ return [2, result];
3487
3760
  }
3488
3761
  else if (result === RETURN) {
3489
3762
  return [2, result];
@@ -3496,9 +3769,10 @@
3496
3769
  }
3497
3770
  });
3498
3771
  }
3499
- function ForOfStatement(node, scope) {
3772
+ function ForOfStatement(node, scope, options) {
3500
3773
  var right, iterator, ret, result, right_1, right_1_1, value, result, e_1_1;
3501
3774
  var e_1, _a;
3775
+ if (options === void 0) { options = {}; }
3502
3776
  return __generator(this, function (_b) {
3503
3777
  switch (_b.label) {
3504
3778
  case 0: return [5, __values(evaluate(node.right, scope))];
@@ -3518,10 +3792,16 @@
3518
3792
  case 4:
3519
3793
  result = _b.sent();
3520
3794
  if (result === BREAK) {
3521
- return [3, 7];
3795
+ if (result.LABEL === options.label) {
3796
+ return [3, 7];
3797
+ }
3798
+ return [2, result];
3522
3799
  }
3523
3800
  else if (result === CONTINUE) {
3524
- return [3, 5];
3801
+ if (result.LABEL === options.label) {
3802
+ return [3, 5];
3803
+ }
3804
+ return [2, result];
3525
3805
  }
3526
3806
  else if (result === RETURN) {
3527
3807
  return [2, result];
@@ -3545,10 +3825,16 @@
3545
3825
  case 10:
3546
3826
  result = _b.sent();
3547
3827
  if (result === BREAK) {
3548
- return [3, 12];
3828
+ if (result.LABEL === options.label) {
3829
+ return [3, 12];
3830
+ }
3831
+ return [2, result];
3549
3832
  }
3550
3833
  else if (result === CONTINUE) {
3551
- return [3, 11];
3834
+ if (result.LABEL === options.label) {
3835
+ return [3, 11];
3836
+ }
3837
+ return [2, result];
3552
3838
  }
3553
3839
  else if (result === RETURN) {
3554
3840
  return [2, result];
@@ -4261,15 +4547,16 @@
4261
4547
  });
4262
4548
  }
4263
4549
  function createFunc$1(node, scope, options) {
4550
+ var _a;
4264
4551
  if (options === void 0) { options = {}; }
4265
4552
  if (!node.generator && !node.async) {
4266
4553
  return createFunc(node, scope, options);
4267
4554
  }
4268
4555
  var superClass = options.superClass, construct = options.construct;
4269
4556
  var params = node.params;
4270
- var tmpFunc = function _a() {
4557
+ var tmpFunc = function _b() {
4271
4558
  var _i, subScope, i, param, result;
4272
- var _newTarget = this && this instanceof _a ? this.constructor : void 0;
4559
+ var _newTarget = this && this instanceof _b ? this.constructor : void 0;
4273
4560
  var args = [];
4274
4561
  for (_i = 0; _i < arguments.length; _i++) {
4275
4562
  args[_i] = arguments[_i];
@@ -4388,6 +4675,13 @@
4388
4675
  value: params.length,
4389
4676
  configurable: true
4390
4677
  });
4678
+ var source = (_a = node.loc) === null || _a === void 0 ? void 0 : _a.source;
4679
+ if (source) {
4680
+ define(func, 'toString', {
4681
+ value: function () { return source.substring(node.start, node.end); },
4682
+ configurable: true
4683
+ });
4684
+ }
4391
4685
  return func;
4392
4686
  }
4393
4687
  function createClass$1(node, scope) {
@@ -4593,14 +4887,15 @@
4593
4887
  }
4594
4888
  }
4595
4889
  function createFunc(node, scope, options) {
4890
+ var _a;
4596
4891
  if (options === void 0) { options = {}; }
4597
4892
  if (node.generator || node.async) {
4598
4893
  return createFunc$1(node, scope, options);
4599
4894
  }
4600
4895
  var superClass = options.superClass, construct = options.construct;
4601
4896
  var params = node.params;
4602
- var tmpFunc = function _a() {
4603
- var _newTarget = this && this instanceof _a ? this.constructor : void 0;
4897
+ var tmpFunc = function _b() {
4898
+ var _newTarget = this && this instanceof _b ? this.constructor : void 0;
4604
4899
  var args = [];
4605
4900
  for (var _i = 0; _i < arguments.length; _i++) {
4606
4901
  args[_i] = arguments[_i];
@@ -4664,6 +4959,13 @@
4664
4959
  value: params.length,
4665
4960
  configurable: true
4666
4961
  });
4962
+ var source = (_a = node.loc) === null || _a === void 0 ? void 0 : _a.source;
4963
+ if (source) {
4964
+ define(func, 'toString', {
4965
+ value: function () { return source.substring(node.start, node.end); },
4966
+ configurable: true
4967
+ });
4968
+ }
4667
4969
  return func;
4668
4970
  }
4669
4971
  function createClass(node, scope) {