| | |
| | | const CovLine = require('./line') |
| | | const { sliceRange } = require('./range') |
| | | const { GREATEST_LOWER_BOUND, LEAST_UPPER_BOUND } = require('source-map').SourceMapConsumer |
| | | |
| | | module.exports = class CovSource { |
| | | constructor (sourceRaw, wrapperLength) { |
| | | sourceRaw = sourceRaw.trimEnd() |
| | | sourceRaw = sourceRaw ? sourceRaw.trimEnd() : '' |
| | | this.lines = [] |
| | | this.eof = sourceRaw.length |
| | | this.shebangLength = getShebangLength(sourceRaw) |
| | |
| | | // given a start column and end column in absolute offsets within |
| | | // a source file (0 - EOF), returns the relative line column positions. |
| | | offsetToOriginalRelative (sourceMap, startCol, endCol) { |
| | | const lines = this.lines.filter((line, i) => { |
| | | return startCol <= line.endCol && endCol >= line.startCol |
| | | }) |
| | | const lines = sliceRange(this.lines, startCol, endCol, true) |
| | | if (!lines.length) return {} |
| | | |
| | | const start = originalPositionTryBoth( |
| | |
| | | lines[0].line, |
| | | Math.max(0, startCol - lines[0].startCol) |
| | | ) |
| | | if (!(start && start.source)) { |
| | | return {} |
| | | } |
| | | |
| | | let end = originalEndPositionFor( |
| | | sourceMap, |
| | | lines[lines.length - 1].line, |
| | | endCol - lines[lines.length - 1].startCol |
| | | ) |
| | | |
| | | if (!(start && end)) { |
| | | return {} |
| | | } |
| | | |
| | | if (!(start.source && end.source)) { |
| | | if (!(end && end.source)) { |
| | | return {} |
| | | } |
| | | |