forked from webpack-contrib/istanbul-instrumenter-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (23 loc) · 896 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
var istanbulLibInstrument = require('istanbul-lib-instrument');
var loaderUtils = require('loader-utils');
var assign = require('object-assign');
var convert = require('convert-source-map');
module.exports = function(source, sourceMap) {
// use inline source map, if any
var inlineSourceMap = convert.fromSource(source);
if (!sourceMap && inlineSourceMap) {
sourceMap = inlineSourceMap.sourcemap;
}
var userOptions = loaderUtils.getOptions(this) || {};
var instrumenter = istanbulLibInstrument.createInstrumenter(
assign({ produceSourceMap: this.sourceMap }, userOptions)
);
if (this.cacheable) {
this.cacheable();
}
var that = this;
return instrumenter.instrument(source, this.resourcePath, function (error, source) {
that.callback(error, source, instrumenter.lastSourceMap());
}, sourceMap);
};