@@ -20,24 +20,9 @@ export default function(this: loader.LoaderContext, source: string, sourceMap?:
20
20
options = Object . assign ( defaultOptions , options ) ;
21
21
validateOptions ( optionsSchema , options , "Coverage Istanbul Loader" ) ;
22
22
23
- try {
24
- if ( ! sourceMap ) {
25
- // Check for an inline source map
26
- const inlineSourceMap = convert . fromSource ( source )
27
- || convert . fromMapFileSource ( source , path . dirname ( this . resourcePath ) ) ;
28
-
29
- if ( inlineSourceMap ) {
30
- // Use the inline source map
31
- sourceMap = inlineSourceMap . sourcemap as RawSourceMap ;
32
- }
33
- }
34
- } catch ( e ) {
35
- // Exception is thrown by fromMapFileSource when there is no source map file
36
- if ( e instanceof Error && e . message . includes ( "An error occurred while trying to read the map file at" ) ) {
37
- this . emitWarning ( e ) ;
38
- } else {
39
- throw e ;
40
- }
23
+ // If there's no external sourceMap file, then check for an inline sourceMap
24
+ if ( ! sourceMap ) {
25
+ sourceMap = getInlineSourceMap . call ( this , source ) ;
41
26
}
42
27
43
28
// Instrument the code
@@ -56,3 +41,28 @@ export default function(this: loader.LoaderContext, source: string, sourceMap?:
56
41
this . callback ( error , instrumentedSource , instrumentedSourceMap ) ;
57
42
}
58
43
}
44
+
45
+ /**
46
+ * If the source code has an inline base64-encoded source map,
47
+ * then this function decodes it, parses it, and returns it.
48
+ */
49
+ function getInlineSourceMap ( this : loader . LoaderContext , source : string ) : RawSourceMap | undefined {
50
+ try {
51
+ // Check for an inline source map
52
+ const inlineSourceMap = convert . fromSource ( source )
53
+ || convert . fromMapFileSource ( source , path . dirname ( this . resourcePath ) ) ;
54
+
55
+ if ( inlineSourceMap ) {
56
+ // Use the inline source map
57
+ return inlineSourceMap . sourcemap as RawSourceMap ;
58
+ }
59
+ }
60
+ catch ( e ) {
61
+ // Exception is thrown by fromMapFileSource when there is no source map file
62
+ if ( e instanceof Error && e . message . includes ( "An error occurred while trying to read the map file at" ) ) {
63
+ this . emitWarning ( e ) ;
64
+ } else {
65
+ throw e ;
66
+ }
67
+ }
68
+ }
0 commit comments