Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

read-coverage.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = readInitialCoverage;
  6. var _core = require("@babel/core");
  7. var _schema = require("@istanbuljs/schema");
  8. var _constants = require("./constants");
  9. function getAst(code) {
  10. if (typeof code === 'object' && typeof code.type === 'string') {
  11. // Assume code is already a babel ast.
  12. return code;
  13. }
  14. if (typeof code !== 'string') {
  15. throw new Error('Code must be a string');
  16. } // Parse as leniently as possible
  17. return (0, _core.parseSync)(code, {
  18. babelrc: false,
  19. configFile: false,
  20. parserOpts: {
  21. allowImportExportEverywhere: true,
  22. allowReturnOutsideFunction: true,
  23. allowSuperOutsideMethod: true,
  24. sourceType: 'script',
  25. plugins: _schema.defaults.instrumenter.parserPlugins
  26. }
  27. });
  28. }
  29. function readInitialCoverage(code) {
  30. const ast = getAst(code);
  31. let covScope;
  32. (0, _core.traverse)(ast, {
  33. ObjectProperty(path) {
  34. const {
  35. node
  36. } = path;
  37. if (!node.computed && path.get('key').isIdentifier() && node.key.name === _constants.MAGIC_KEY) {
  38. const magicValue = path.get('value').evaluate();
  39. if (!magicValue.confident || magicValue.value !== _constants.MAGIC_VALUE) {
  40. return;
  41. }
  42. covScope = path.scope.getFunctionParent() || path.scope.getProgramParent();
  43. path.stop();
  44. }
  45. }
  46. });
  47. if (!covScope) {
  48. return null;
  49. }
  50. const result = {};
  51. for (const key of ['path', 'hash', 'gcv', 'coverageData']) {
  52. const binding = covScope.getOwnBinding(key);
  53. if (!binding) {
  54. return null;
  55. }
  56. const valuePath = binding.path.get('init');
  57. const value = valuePath.evaluate();
  58. if (!value.confident) {
  59. return null;
  60. }
  61. result[key] = value.value;
  62. }
  63. delete result.coverageData[_constants.MAGIC_KEY];
  64. delete result.coverageData.hash;
  65. return result;
  66. }