source: trip-planner-front/node_modules/adjust-sourcemap-loader/lib/process/locate-root-with.js@ 6fe77af

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

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict';
2
3var getFieldAsFn = require('./get-field-as-fn'),
4 CustomError = require('./get-error');
5
6/**
7 * Locate the root for input sources using the given codec hash
8 * @throws Error Where the given codec is missing an encode function
9 * @this {object} A loader or compilation
10 * @param {{encode:function}} codec A single codec with an `encode` function
11 * @returns {function(string):string|Error} An encode function that takes an absolute path
12 */
13function locateRootWith(codec) {
14 /* jshint validthis:true */
15 var context = this,
16 root = getFieldAsFn('root')(codec);
17 if (!root) {
18 return new CustomError('Specified format does not support encoding (it lacks a "root" function)');
19 }
20 else {
21 return function locate() {
22
23 // call the root
24 var located;
25 try {
26 located = root.call(context);
27 }
28 catch (exception) {
29 return getNamedError(exception);
30 }
31 return located;
32
33 function getNamedError(details) {
34 var name = codec.name || '(unnamed)',
35 message = [
36 'Locating root with codec: ' + name,
37 details && (details.stack ? details.stack : details)
38 ]
39 .filter(Boolean)
40 .join('\n');
41 return new Error(message);
42 }
43 };
44 }
45}
46
47module.exports = locateRootWith;
Note: See TracBrowser for help on using the repository browser.