@@ -4,12 +4,12 @@ const libSourceMaps = require('istanbul-lib-source-maps')
44const fs = require ( 'fs' )
55const path = require ( 'path' )
66
7- // TODO: write some unit tests for this class.
7+ const sourceMapCache = libSourceMaps . createSourceMapStore ( )
88function SourceMaps ( opts ) {
99 this . cache = opts . cache
1010 this . cacheDirectory = opts . cacheDirectory
11- this . sourceMapCache = libSourceMaps . createSourceMapStore ( )
1211 this . loadedMaps = { }
12+ this . _sourceMapCache = sourceMapCache
1313}
1414
1515SourceMaps . prototype . extractAndRegister = function ( code , filename , hash ) {
@@ -19,36 +19,35 @@ SourceMaps.prototype.extractAndRegister = function (code, filename, hash) {
1919 var mapPath = path . join ( this . cacheDirectory , hash + '.map' )
2020 fs . writeFileSync ( mapPath , sourceMap . toJSON ( ) )
2121 } else {
22- this . sourceMapCache . registerMap ( filename , sourceMap . sourcemap )
22+ this . _sourceMapCache . registerMap ( filename , sourceMap . sourcemap )
2323 }
2424 }
2525 return sourceMap
2626}
2727
2828SourceMaps . prototype . remapCoverage = function ( obj ) {
29- var transformed = this . sourceMapCache . transformCoverage (
29+ var transformed = this . _sourceMapCache . transformCoverage (
3030 libCoverage . createCoverageMap ( obj )
3131 )
3232 return transformed . map . data
3333}
3434
3535SourceMaps . prototype . reloadCachedSourceMaps = function ( report ) {
36- var _this = this
37- Object . keys ( report ) . forEach ( function ( absFile ) {
36+ Object . keys ( report ) . forEach ( ( absFile ) => {
3837 var fileReport = report [ absFile ]
3938 if ( fileReport && fileReport . contentHash ) {
4039 var hash = fileReport . contentHash
41- if ( ! ( hash in _this . loadedMaps ) ) {
40+ if ( ! ( hash in this . loadedMaps ) ) {
4241 try {
43- var mapPath = path . join ( _this . cacheDirectory , hash + '.map' )
44- _this . loadedMaps [ hash ] = JSON . parse ( fs . readFileSync ( mapPath , 'utf8' ) )
42+ var mapPath = path . join ( this . cacheDirectory , hash + '.map' )
43+ this . loadedMaps [ hash ] = JSON . parse ( fs . readFileSync ( mapPath , 'utf8' ) )
4544 } catch ( e ) {
4645 // set to false to avoid repeatedly trying to load the map
47- _this . loadedMaps [ hash ] = false
46+ this . loadedMaps [ hash ] = false
4847 }
4948 }
50- if ( _this . loadedMaps [ hash ] ) {
51- _this . sourceMapCache . registerMap ( absFile , _this . loadedMaps [ hash ] )
49+ if ( this . loadedMaps [ hash ] ) {
50+ this . _sourceMapCache . registerMap ( absFile , this . loadedMaps [ hash ] )
5251 }
5352 }
5453 } )
0 commit comments