|
1 |
| -if (v8ScriptCov.functions.every(({ functionName, ranges }) => { |
2 |
| - if (!script.source.includes(functionName)) { |
3 |
| - return false |
4 |
| - } |
| 1 | +const resultCountPerPath = new Map() |
| 2 | +const possibleCjsEsmBridges = new Map() |
| 3 | + |
| 4 | +for (const v8ScriptCov of v8ProcessCov.result) { |
| 5 | + try { |
| 6 | + const path = resolve(this.resolve, v8ScriptCov.url) |
| 7 | + const script = v8toIstanbul(path, this.wrapperLength) |
| 8 | + |
| 9 | + if (resultCountPerPath.has(path)) { |
| 10 | + resultCountPerPath.set(path, resultCountPerPath.get(path) + 1) |
| 11 | + } else { |
| 12 | + resultCountPerPath.set(path, 0) |
| 13 | + } |
5 | 14 |
|
6 |
| - for (const { endOffset } of ranges) { |
7 |
| - if (endOffset > script.source.length) { |
8 |
| - return false |
| 15 | + // https://github.com/nodejs/node/blob/v12.0.0/lib/internal/modules/esm/create_dynamic_module.js#L12-L20 |
| 16 | + if ( |
| 17 | + v8ScriptCov.functions.length === 3 && |
| 18 | + v8ScriptCov.functions[0].functionName === '' && |
| 19 | + v8ScriptCov.functions[0].isBlockCoverage === true && |
| 20 | + v8ScriptCov.functions[1].functionName === 'get' && |
| 21 | + v8ScriptCov.functions[1].isBlockCoverage === false && |
| 22 | + v8ScriptCov.functions[2].functionName === 'set' && |
| 23 | + v8ScriptCov.functions[2].isBlockCoverage === true |
| 24 | + ) { |
| 25 | + possibleCjsEsmBridges.set(script, { |
| 26 | + path, |
| 27 | + functions: v8ScriptCov.functions |
| 28 | + }) |
| 29 | + } else { |
| 30 | + script.applyCoverage(v8ScriptCov.functions) |
| 31 | + map.merge(script.toIstanbul()) |
9 | 32 | }
|
| 33 | + } catch (err) { |
| 34 | + console.warn(`file: ${v8ScriptCov.url} error: ${err.stack}`) |
10 | 35 | }
|
| 36 | +} |
11 | 37 |
|
12 |
| - return true |
13 |
| -})) { |
14 |
| - script.applyCoverage(v8ScriptCov.functions) |
15 |
| - map.merge(script.toIstanbul()) |
| 38 | +for (const [script, { path, functions }] of possibleCjsEsmBridges) { |
| 39 | + if (resultCountPerPath.get(path) <= 1) { |
| 40 | + script.applyCoverage(functions) |
| 41 | + map.merge(script.toIstanbul()) |
| 42 | + } |
16 | 43 | }
|
0 commit comments