Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: drop special shebang handling (#125)
As of Node 13, the shebang is parsed by v8.
  • Loading branch information
bcoe committed Oct 24, 2020
1 parent d375ee3 commit 0d3b57f
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .nycrc
Expand Up @@ -7,6 +7,6 @@
"text"
],
"lines": 99.5,
"branches": "94",
"branches": "92",
"statements": "99.5"
}
}
4 changes: 3 additions & 1 deletion lib/source.js
Expand Up @@ -206,8 +206,10 @@ function originalPositionTryBoth (sourceMap, line, column) {
return original
}

// Not required since Node 13, see: https://github.com/nodejs/node/pull/27375
const isPrerNode13 = /^v1[0-2]\./u.test(process.version)
function getShebangLength (source) {
if (source.indexOf('#!') === 0) {
if (isPrerNode13 && source.indexOf('#!') === 0) {
const match = source.match(/(?<shebang>#!.*)/)
if (match) {
return match.groups.shebang.length
Expand Down
62 changes: 59 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -32,6 +32,7 @@
"devDependencies": {
"@types/node": "^12.7.11",
"c8": "^7.2.1",
"semver": "^7.3.2",
"should": "13.2.3",
"standard": "^14.3.1",
"tap": "^14.10.8"
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/shebang.js
@@ -1,5 +1,6 @@
module.exports = {
describe: 'shebang',
maxNodeVersion: 'v13.0.0',
coverageV8: {
"scriptId": "56",
"url": "./test/fixtures/scripts/shebang.js",
Expand Down
6 changes: 6 additions & 0 deletions test/utils/run-fixture.js
Expand Up @@ -2,13 +2,19 @@

const toIstanbul = require('../../')
const t = require('tap')
const semver = require('semver')

t.mochaGlobals()
require('should')

module.exports = async (fixture) => {
const script = toIstanbul(fixture.coverageV8.url)
await script.load()
if (fixture.maxNodeVersion && !semver.lt(process.version, fixture.maxNodeVersion)) {
console.info(`skipping "${fixture.describe}" fixture maxNodeVersion = ${fixture.maxNodeVersion}`)
return
}

script.applyCoverage(fixture.coverageV8.functions)

let coverageIstanbul = script.toIstanbul()
Expand Down

0 comments on commit 0d3b57f

Please sign in to comment.