line.js 1020 B

12345678910111213141516171819202122232425262728293031323334
  1. module.exports = class CovLine {
  2. constructor (line, startCol, lineStr) {
  3. this.line = line
  4. // note that startCol and endCol are absolute positions
  5. // within a file, not relative to the line.
  6. this.startCol = startCol
  7. // the line length itself does not include the newline characters,
  8. // these are however taken into account when enumerating absolute offset.
  9. const matchedNewLineChar = lineStr.match(/\r?\n$/u)
  10. const newLineLength = matchedNewLineChar ? matchedNewLineChar[0].length : 0
  11. this.endCol = startCol + lineStr.length - newLineLength
  12. // we start with all lines having been executed, and work
  13. // backwards zeroing out lines based on V8 output.
  14. this.count = 1
  15. // set by source.js during parsing, if /* c8 ignore next */ is found.
  16. this.ignore = false
  17. }
  18. toIstanbul () {
  19. return {
  20. start: {
  21. line: this.line,
  22. column: 0
  23. },
  24. end: {
  25. line: this.line,
  26. column: this.endCol - this.startCol
  27. }
  28. }
  29. }
  30. }