@@ -4,12 +4,12 @@ const libSourceMaps = require('istanbul-lib-source-maps')
4
4
const fs = require ( 'fs' )
5
5
const path = require ( 'path' )
6
6
7
- // TODO: write some unit tests for this class.
7
+ const sourceMapCache = libSourceMaps . createSourceMapStore ( )
8
8
function SourceMaps ( opts ) {
9
9
this . cache = opts . cache
10
10
this . cacheDirectory = opts . cacheDirectory
11
- this . sourceMapCache = libSourceMaps . createSourceMapStore ( )
12
11
this . loadedMaps = { }
12
+ this . _sourceMapCache = sourceMapCache
13
13
}
14
14
15
15
SourceMaps . prototype . extractAndRegister = function ( code , filename , hash ) {
@@ -19,36 +19,35 @@ SourceMaps.prototype.extractAndRegister = function (code, filename, hash) {
19
19
var mapPath = path . join ( this . cacheDirectory , hash + '.map' )
20
20
fs . writeFileSync ( mapPath , sourceMap . toJSON ( ) )
21
21
} else {
22
- this . sourceMapCache . registerMap ( filename , sourceMap . sourcemap )
22
+ this . _sourceMapCache . registerMap ( filename , sourceMap . sourcemap )
23
23
}
24
24
}
25
25
return sourceMap
26
26
}
27
27
28
28
SourceMaps . prototype . remapCoverage = function ( obj ) {
29
- var transformed = this . sourceMapCache . transformCoverage (
29
+ var transformed = this . _sourceMapCache . transformCoverage (
30
30
libCoverage . createCoverageMap ( obj )
31
31
)
32
32
return transformed . map . data
33
33
}
34
34
35
35
SourceMaps . prototype . reloadCachedSourceMaps = function ( report ) {
36
- var _this = this
37
- Object . keys ( report ) . forEach ( function ( absFile ) {
36
+ Object . keys ( report ) . forEach ( ( absFile ) => {
38
37
var fileReport = report [ absFile ]
39
38
if ( fileReport && fileReport . contentHash ) {
40
39
var hash = fileReport . contentHash
41
- if ( ! ( hash in _this . loadedMaps ) ) {
40
+ if ( ! ( hash in this . loadedMaps ) ) {
42
41
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' ) )
45
44
} catch ( e ) {
46
45
// set to false to avoid repeatedly trying to load the map
47
- _this . loadedMaps [ hash ] = false
46
+ this . loadedMaps [ hash ] = false
48
47
}
49
48
}
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 ] )
52
51
}
53
52
}
54
53
} )
0 commit comments