Skip to content

Commit

Permalink
create a separate file to detect bridges
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Apr 30, 2019
1 parent 5fb374e commit b1fb3fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 10 additions & 0 deletions lib/is-cjs-esm-bridge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = ({ functions }) => {
// https://github.com/nodejs/node/blob/v12.1.0/lib/internal/modules/esm/create_dynamic_module.js#L11-L19
return functions.length === 3 &&
functions[0].functionName === '' &&
functions[0].isBlockCoverage === true &&
functions[1].functionName === 'get' &&
functions[1].isBlockCoverage === false &&
functions[2].functionName === 'set' &&
functions[2].isBlockCoverage === true
}
12 changes: 2 additions & 10 deletions lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { isAbsolute, resolve } = require('path')
// TODO: switch back to @c88/v8-coverage once patch is landed.
const { mergeProcessCovs } = require('@bcoe/v8-coverage')
const v8toIstanbul = require('v8-to-istanbul')
const isCjsEsmBridgeCov = require('./is-cjs-esm-bridge')

class Report {
constructor ({
Expand Down Expand Up @@ -70,16 +71,7 @@ class Report {
resultCountPerPath.set(path, 0)
}

// https://github.com/nodejs/node/blob/v12.0.0/lib/internal/modules/esm/create_dynamic_module.js#L12-L20
if (
v8ScriptCov.functions.length === 3 &&
v8ScriptCov.functions[0].functionName === '' &&
v8ScriptCov.functions[0].isBlockCoverage === true &&
v8ScriptCov.functions[1].functionName === 'get' &&
v8ScriptCov.functions[1].isBlockCoverage === false &&
v8ScriptCov.functions[2].functionName === 'set' &&
v8ScriptCov.functions[2].isBlockCoverage === true
) {
if (isCjsEsmBridgeCov(v8ScriptCov)) {
possibleCjsEsmBridges.set(script, {
path,
functions: v8ScriptCov.functions
Expand Down

0 comments on commit b1fb3fc

Please sign in to comment.