all files / src/ getMapping.js

84.62% Statements 11/13
84.62% Branches 11/13
100% Functions 2/2
84.62% Lines 11/13
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 1212×           606×       606×       606× 174×     432×       432×                                               432×                                
function normLocation(loc) {
  return {
    line: Math.max(loc.line, 1),
    column: Math.max(loc.column, 0),
  };
}
 
function getMapping(sourceMap, location) {
  const start = sourceMap.originalPositionFor(
    normLocation(location.start)
  );
 
  const end = sourceMap.originalPositionFor(
    normLocation(location.end)
  );
 
  if (!start.source || !end.source || start.source !== end.source) {
    return null;
  }
 
  Iif (start.line === null || start.column === null) {
    return null;
  }
 
  Iif (end.line === null || end.column === null) {
    return null;
  }
 
  // incorrect for case when using default parameters in function, transpiled via babel:
  //
  //     (url, state = null, title = null) => {
  //           window.history.pushState(state, title, url);
  //           next('push');
  //     }
  //
  // if (start.line === end.line && start.column === end.column) {
  //   const newEnd = sourceMap.originalPositionFor({
  //     line: location.end.line,
  //     column: location.end.column,
  //     bias: SourceMapConsumer.LEAST_UPPER_BOUND,
  //   });
  //
  //   if (newEnd.source && newEnd.line !== null && newEnd.column !== null) {
  //     end = newEnd;
  //     end.column = end.column - 1;
  //   }
  // }
 
  return {
    source: start.source,
    loc: {
      start: {
        line: start.line,
        column: start.column,
      },
      end: {
        line: end.line,
        column: end.column,
      },
      skip: location.skip,
    },
  };
}
 
module.exports = getMapping;