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.

transformer.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. Copyright 2015, Yahoo Inc.
  3. Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
  4. */
  5. 'use strict';
  6. const debug = require('debug')('istanbuljs');
  7. const libCoverage = require('istanbul-lib-coverage');
  8. const { MappedCoverage } = require('./mapped');
  9. const getMapping = require('./get-mapping');
  10. const { getUniqueKey, getOutput } = require('./transform-utils');
  11. class SourceMapTransformer {
  12. constructor(finder, opts = {}) {
  13. this.finder = finder;
  14. this.baseDir = opts.baseDir || process.cwd();
  15. }
  16. processFile(fc, sourceMap, coverageMapper) {
  17. let changes = 0;
  18. Object.entries(fc.statementMap).forEach(([s, loc]) => {
  19. const hits = fc.s[s];
  20. const mapping = getMapping(sourceMap, loc, fc.path);
  21. if (mapping) {
  22. changes += 1;
  23. const mappedCoverage = coverageMapper(mapping.source);
  24. mappedCoverage.addStatement(mapping.loc, hits);
  25. }
  26. });
  27. Object.entries(fc.fnMap).forEach(([f, fnMeta]) => {
  28. const hits = fc.f[f];
  29. const mapping = getMapping(sourceMap, fnMeta.decl, fc.path);
  30. const spanMapping = getMapping(sourceMap, fnMeta.loc, fc.path);
  31. if (
  32. mapping &&
  33. spanMapping &&
  34. mapping.source === spanMapping.source
  35. ) {
  36. changes += 1;
  37. const mappedCoverage = coverageMapper(mapping.source);
  38. mappedCoverage.addFunction(
  39. fnMeta.name,
  40. mapping.loc,
  41. spanMapping.loc,
  42. hits
  43. );
  44. }
  45. });
  46. Object.entries(fc.branchMap).forEach(([b, branchMeta]) => {
  47. const hits = fc.b[b];
  48. const locs = [];
  49. const mappedHits = [];
  50. let source;
  51. let skip;
  52. branchMeta.locations.forEach((loc, i) => {
  53. const mapping = getMapping(sourceMap, loc, fc.path);
  54. if (mapping) {
  55. if (!source) {
  56. source = mapping.source;
  57. }
  58. if (mapping.source !== source) {
  59. skip = true;
  60. }
  61. locs.push(mapping.loc);
  62. mappedHits.push(hits[i]);
  63. }
  64. });
  65. if (!skip && locs.length > 0) {
  66. changes += 1;
  67. const mappedCoverage = coverageMapper(source);
  68. mappedCoverage.addBranch(
  69. branchMeta.type,
  70. locs[0] /* XXX */,
  71. locs,
  72. mappedHits
  73. );
  74. }
  75. });
  76. return changes > 0;
  77. }
  78. async transform(coverageMap) {
  79. const uniqueFiles = {};
  80. const getMappedCoverage = file => {
  81. const key = getUniqueKey(file);
  82. if (!uniqueFiles[key]) {
  83. uniqueFiles[key] = {
  84. file,
  85. mappedCoverage: new MappedCoverage(file)
  86. };
  87. }
  88. return uniqueFiles[key].mappedCoverage;
  89. };
  90. for (const file of coverageMap.files()) {
  91. const fc = coverageMap.fileCoverageFor(file);
  92. const sourceMap = await this.finder(file, fc);
  93. if (sourceMap) {
  94. const changed = this.processFile(
  95. fc,
  96. sourceMap,
  97. getMappedCoverage
  98. );
  99. if (!changed) {
  100. debug(`File [${file}] ignored, nothing could be mapped`);
  101. }
  102. } else {
  103. uniqueFiles[getUniqueKey(file)] = {
  104. file,
  105. mappedCoverage: new MappedCoverage(fc)
  106. };
  107. }
  108. }
  109. return libCoverage.createCoverageMap(getOutput(uniqueFiles));
  110. }
  111. }
  112. module.exports = {
  113. SourceMapTransformer
  114. };