@next-core/brick-kit 2.202.0 → 2.203.0

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.
@@ -1446,11 +1446,22 @@
1446
1446
  for (var fn of functions) {
1447
1447
  registeredFunctions.set(fn.name, {
1448
1448
  source: fn.source,
1449
- typescript: fn.typescript
1449
+ typescript: fn.typescript,
1450
+ transformed: fn.transformed
1450
1451
  });
1451
1452
  }
1452
1453
  }
1453
1454
  }
1455
+ function getGlobalVariables(globals) {
1456
+ return supply(globals, getGeneralGlobals(globals, {
1457
+ collectCoverage,
1458
+ widgetId,
1459
+ widgetVersion,
1460
+ app: currentApp,
1461
+ storyboardFunctions,
1462
+ isStoryboardFunction: true
1463
+ }), !!collectCoverage);
1464
+ }
1454
1465
  function getStoryboardFunction(name) {
1455
1466
  var fn = registeredFunctions.get(name);
1456
1467
  if (!fn) {
@@ -1463,35 +1474,39 @@
1463
1474
  if (collectCoverage) {
1464
1475
  collector = collectCoverage.createCollector(name);
1465
1476
  }
1466
- var precooked = brickUtils.precookFunction(fn.source, {
1467
- cacheKey: fn,
1468
- typescript: fn.typescript,
1469
- hooks: collector && {
1470
- beforeVisit: collector.beforeVisit
1471
- }
1472
- });
1473
- fn.cooked = brickUtils.cook(precooked.function, fn.source, {
1474
- rules: {
1475
- noVar: true
1476
- },
1477
- globalVariables: supply(precooked.attemptToVisitGlobals, getGeneralGlobals(precooked.attemptToVisitGlobals, {
1478
- collectCoverage,
1479
- widgetId,
1480
- widgetVersion,
1481
- app: currentApp,
1482
- storyboardFunctions,
1483
- isStoryboardFunction: true
1484
- }), !!collectCoverage),
1485
- hooks: _objectSpread__default["default"]({
1486
- perfCall: needPerf ? duration => {
1487
- perf(name, fn.source, duration);
1488
- } : undefined
1489
- }, collector ? {
1490
- beforeEvaluate: collector.beforeEvaluate,
1491
- beforeCall: collector.beforeCall,
1492
- beforeBranch: collector.beforeBranch
1493
- } : null)
1494
- });
1477
+
1478
+ // Do not use transformed functions when collecting coverage.
1479
+ var transformed = !collector && fn.transformed;
1480
+ if (transformed) {
1481
+ var globalVariables = getGlobalVariables(transformed.globals);
1482
+ // Spread globals as params to prevent accessing forbidden globals.
1483
+ // NOTE: in native mode, forbidden globals are declared as `undefined`,
1484
+ // thus accessing them will not throw a ReferenceError.
1485
+ fn.cooked = new Function(...transformed.globals, "\"use strict\";return (".concat(transformed.source, ")"))(...transformed.globals.map(key => brickUtils.hasOwnProperty(globalVariables, key) ? globalVariables[key] : undefined));
1486
+ } else {
1487
+ var precooked = brickUtils.precookFunction(fn.source, {
1488
+ cacheKey: fn,
1489
+ typescript: fn.typescript,
1490
+ hooks: collector && {
1491
+ beforeVisit: collector.beforeVisit
1492
+ }
1493
+ });
1494
+ fn.cooked = brickUtils.cook(precooked.function, fn.source, {
1495
+ rules: {
1496
+ noVar: true
1497
+ },
1498
+ globalVariables: getGlobalVariables(precooked.attemptToVisitGlobals),
1499
+ hooks: _objectSpread__default["default"]({
1500
+ perfCall: needPerf ? duration => {
1501
+ perf(name, fn.source, duration);
1502
+ } : undefined
1503
+ }, collector ? {
1504
+ beforeEvaluate: collector.beforeEvaluate,
1505
+ beforeCall: collector.beforeCall,
1506
+ beforeBranch: collector.beforeBranch
1507
+ } : null)
1508
+ });
1509
+ }
1495
1510
  fn.processed = true;
1496
1511
  return fn.cooked;
1497
1512
  }
@@ -1501,7 +1516,8 @@
1501
1516
  updateStoryboardFunction(name, data) {
1502
1517
  registeredFunctions.set(name, {
1503
1518
  source: data.source,
1504
- typescript: data.typescript
1519
+ typescript: data.typescript,
1520
+ transformed: data.transformed
1505
1521
  });
1506
1522
  }
1507
1523
  };