Skip to content

Commit

Permalink
Merge bbed8c3 into 20dd0ef
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Apr 21, 2019
2 parents 20dd0ef + bbed8c3 commit d4e467a
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions lib/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ module.exports = class CovScript {
constructor (scriptPath, wrapperLength) {
assert(typeof scriptPath === 'string', 'scriptPath must be a string')
const path = parsePath(scriptPath)
const source = fs.readFileSync(path, 'utf8')
this.path = path
this.source = fs.readFileSync(path, 'utf8')
this.wrapperLength = wrapperLength === undefined ? cjsWrapperLength : wrapperLength
const shebangLength = getShebangLength(source)
const shebangLength = this._getShebangLength()
this.wrapperLength -= shebangLength
this.lines = []
this.branches = []
this.functions = []
this.eof = -1
this._buildLines(source, this.lines, shebangLength)
this._buildLines(this.lines, shebangLength)
}
_buildLines (source, lines, shebangLength) {
_buildLines (lines, shebangLength) {
let position = 0
for (const [i, lineStr] of source.trim().split(/(?<=\r?\n)/u).entries()) {
for (const [i, lineStr] of this.source.trim().split(/(?<=\r?\n)/u).entries()) {
const matchedNewLineChar = lineStr.match(/\r?\n$/u)
const newLineLength = matchedNewLineChar ? matchedNewLineChar[0].length : 0
this.eof = position + lineStr.length - newLineLength
Expand Down Expand Up @@ -137,16 +137,15 @@ module.exports = class CovScript {
})
return functions
}
}

function getShebangLength (source) {
if (source.indexOf('#!') === 0) {
const match = source.match(/(?<shebang>#!.*)/)
if (match) {
return match.groups.shebang.length
_getShebangLength () {
if (this.source.indexOf('#!') === 0) {
const match = this.source.match(/(?<shebang>#!.*)/)
if (match) {
return match.groups.shebang.length
}
} else {
return 0
}
} else {
return 0
}
}

Expand Down

0 comments on commit d4e467a

Please sign in to comment.