source: trip-planner-front/node_modules/@jsdevtools/coverage-istanbul-loader/lib/index.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.6 KB
Line 
1"use strict";
2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 if (k2 === undefined) k2 = k;
4 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5}) : (function(o, m, k, k2) {
6 if (k2 === undefined) k2 = k;
7 o[k2] = m[k];
8}));
9var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10 Object.defineProperty(o, "default", { enumerable: true, value: v });
11}) : function(o, v) {
12 o["default"] = v;
13});
14var __importStar = (this && this.__importStar) || function (mod) {
15 if (mod && mod.__esModule) return mod;
16 var result = {};
17 if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18 __setModuleDefault(result, mod);
19 return result;
20};
21var __importDefault = (this && this.__importDefault) || function (mod) {
22 return (mod && mod.__esModule) ? mod : { "default": mod };
23};
24Object.defineProperty(exports, "__esModule", { value: true });
25const convert = __importStar(require("convert-source-map"));
26const istanbul_lib_instrument_1 = require("istanbul-lib-instrument");
27const loaderUtils = __importStar(require("loader-utils"));
28const merge_source_map_1 = __importDefault(require("merge-source-map"));
29const path = __importStar(require("path"));
30const schema_utils_1 = __importDefault(require("schema-utils"));
31const optionsSchema = __importStar(require("./options-schema.json"));
32const options_js_1 = require("./options.js");
33/**
34 * Adds code coverage instrumentation using Istanbul.
35 *
36 * If the source code has an existing source map, then it is used to re-map the instrumented
37 * code back to the original source.
38 */
39function default_1(source, sourceMap) {
40 let options = loaderUtils.getOptions(this);
41 options = Object.assign(options_js_1.defaultOptions, options);
42 schema_utils_1.default(optionsSchema, options, "Coverage Istanbul Loader");
43 // If there's no external sourceMap file, then check for an inline sourceMap
44 if (!sourceMap) {
45 sourceMap = getInlineSourceMap.call(this, source);
46 }
47 // Instrument the code
48 let instrumenter = istanbul_lib_instrument_1.createInstrumenter(options);
49 instrumenter.instrument(source, this.resourcePath, done.bind(this), sourceMap);
50 function done(error, instrumentedSource) {
51 // Get the source map for the instrumented code
52 let instrumentedSourceMap = instrumenter.lastSourceMap();
53 if (sourceMap && instrumentedSourceMap) {
54 // Re-map the source map to the original source code
55 instrumentedSourceMap = merge_source_map_1.default(sourceMap, instrumentedSourceMap);
56 }
57 this.callback(error, instrumentedSource, instrumentedSourceMap);
58 }
59}
60exports.default = default_1;
61/**
62 * If the source code has an inline base64-encoded source map,
63 * then this function decodes it, parses it, and returns it.
64 */
65function getInlineSourceMap(source) {
66 try {
67 // Check for an inline source map
68 const inlineSourceMap = convert.fromSource(source)
69 || convert.fromMapFileSource(source, path.dirname(this.resourcePath));
70 if (inlineSourceMap) {
71 // Use the inline source map
72 return inlineSourceMap.sourcemap;
73 }
74 }
75 catch (e) {
76 // Exception is thrown by fromMapFileSource when there is no source map file
77 if (e instanceof Error && e.message.includes("An error occurred while trying to read the map file at")) {
78 this.emitWarning(e);
79 }
80 else {
81 throw e;
82 }
83 }
84}
85//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.