Skip to content

Commit

Permalink
Merge branch 'master' into instrument-include-exclude-option
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Finlay committed Apr 3, 2019
2 parents 17e4736 + 31817de commit 6852bbf
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 248 deletions.
23 changes: 11 additions & 12 deletions lib/source-maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const libSourceMaps = require('istanbul-lib-source-maps')
const fs = require('fs')
const path = require('path')

// TODO: write some unit tests for this class.
const sourceMapCache = libSourceMaps.createSourceMapStore()
function SourceMaps (opts) {
this.cache = opts.cache
this.cacheDirectory = opts.cacheDirectory
this.sourceMapCache = libSourceMaps.createSourceMapStore()
this.loadedMaps = {}
this._sourceMapCache = sourceMapCache
}

SourceMaps.prototype.extractAndRegister = function (code, filename, hash) {
Expand All @@ -19,36 +19,35 @@ SourceMaps.prototype.extractAndRegister = function (code, filename, hash) {
var mapPath = path.join(this.cacheDirectory, hash + '.map')
fs.writeFileSync(mapPath, sourceMap.toJSON())
} else {
this.sourceMapCache.registerMap(filename, sourceMap.sourcemap)
this._sourceMapCache.registerMap(filename, sourceMap.sourcemap)
}
}
return sourceMap
}

SourceMaps.prototype.remapCoverage = function (obj) {
var transformed = this.sourceMapCache.transformCoverage(
var transformed = this._sourceMapCache.transformCoverage(
libCoverage.createCoverageMap(obj)
)
return transformed.map.data
}

SourceMaps.prototype.reloadCachedSourceMaps = function (report) {
var _this = this
Object.keys(report).forEach(function (absFile) {
Object.keys(report).forEach((absFile) => {
var fileReport = report[absFile]
if (fileReport && fileReport.contentHash) {
var hash = fileReport.contentHash
if (!(hash in _this.loadedMaps)) {
if (!(hash in this.loadedMaps)) {
try {
var mapPath = path.join(_this.cacheDirectory, hash + '.map')
_this.loadedMaps[hash] = JSON.parse(fs.readFileSync(mapPath, 'utf8'))
var mapPath = path.join(this.cacheDirectory, hash + '.map')
this.loadedMaps[hash] = JSON.parse(fs.readFileSync(mapPath, 'utf8'))
} catch (e) {
// set to false to avoid repeatedly trying to load the map
_this.loadedMaps[hash] = false
this.loadedMaps[hash] = false
}
}
if (_this.loadedMaps[hash]) {
_this.sourceMapCache.registerMap(absFile, _this.loadedMaps[hash])
if (this.loadedMaps[hash]) {
this._sourceMapCache.registerMap(absFile, this.loadedMaps[hash])
}
}
})
Expand Down
Loading

0 comments on commit 6852bbf

Please sign in to comment.