Skip to content

Commit 368c137

Browse files
authored
fix(coverage): remove work-around for implicit else (#6014)
1 parent d87bef9 commit 368c137

File tree

6 files changed

+18
-91
lines changed

6 files changed

+18
-91
lines changed

packages/coverage-istanbul/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"istanbul-lib-coverage": "^3.2.2",
5050
"istanbul-lib-instrument": "^6.0.3",
5151
"istanbul-lib-report": "^3.0.1",
52-
"istanbul-lib-source-maps": "^5.0.5",
52+
"istanbul-lib-source-maps": "^5.0.6",
5353
"istanbul-reports": "^3.1.7",
5454
"magicast": "^0.3.4",
5555
"picocolors": "^1.0.1",

packages/coverage-istanbul/src/provider.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,6 @@ export class IstanbulCoverageProvider
415415
}
416416

417417
async function transformCoverage(coverageMap: CoverageMap) {
418-
includeImplicitElseBranches(coverageMap)
419-
420418
const sourceMapStore = libSourceMaps.createSourceMapStore()
421419
return await sourceMapStore.transformCoverage(coverageMap)
422420
}
@@ -429,44 +427,3 @@ async function transformCoverage(coverageMap: CoverageMap) {
429427
function removeQueryParameters(filename: string) {
430428
return filename.split('?')[0]
431429
}
432-
433-
/**
434-
* Work-around for #1887 and #2239 while waiting for https://github.com/istanbuljs/istanbuljs/pull/706
435-
*
436-
* Goes through all files in the coverage map and checks if branchMap's have
437-
* if-statements with implicit else. When finds one, copies source location of
438-
* the if-statement into the else statement.
439-
*/
440-
function includeImplicitElseBranches(coverageMap: CoverageMap) {
441-
for (const file of coverageMap.files()) {
442-
const fileCoverage = coverageMap.fileCoverageFor(file)
443-
444-
for (const branchMap of Object.values(fileCoverage.branchMap)) {
445-
if (branchMap.type === 'if') {
446-
const lastIndex = branchMap.locations.length - 1
447-
448-
if (lastIndex > 0) {
449-
const elseLocation = branchMap.locations[lastIndex]
450-
451-
if (elseLocation && isEmptyCoverageRange(elseLocation)) {
452-
const ifLocation = branchMap.locations[0]
453-
454-
elseLocation.start = { ...ifLocation.start }
455-
elseLocation.end = { ...ifLocation.end }
456-
}
457-
}
458-
}
459-
}
460-
}
461-
}
462-
463-
function isEmptyCoverageRange(range: libCoverage.Range) {
464-
return (
465-
range.start === undefined
466-
|| range.start.line === undefined
467-
|| range.start.column === undefined
468-
|| range.end === undefined
469-
|| range.end.line === undefined
470-
|| range.end.column === undefined
471-
)
472-
}

packages/coverage-v8/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"debug": "^4.3.5",
5050
"istanbul-lib-coverage": "^3.2.2",
5151
"istanbul-lib-report": "^3.0.1",
52-
"istanbul-lib-source-maps": "^5.0.5",
52+
"istanbul-lib-source-maps": "^5.0.6",
5353
"istanbul-reports": "^3.1.7",
5454
"magic-string": "^0.30.10",
5555
"magicast": "^0.3.4",

pnpm-lock.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/coverage-test/test/__snapshots__/pre-transpiled-istanbul.snapshot.json

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,8 @@
156156
}
157157
},
158158
{
159-
"start": {
160-
"line": 2,
161-
"column": 2
162-
},
163-
"end": {
164-
"line": 5,
165-
"column": 3
166-
}
159+
"start": {},
160+
"end": {}
167161
}
168162
]
169163
},
@@ -191,14 +185,8 @@
191185
}
192186
},
193187
{
194-
"start": {
195-
"line": 10,
196-
"column": 2
197-
},
198-
"end": {
199-
"line": 13,
200-
"column": 3
201-
}
188+
"start": {},
189+
"end": {}
202190
}
203191
]
204192
},
@@ -226,14 +214,8 @@
226214
}
227215
},
228216
{
229-
"start": {
230-
"line": 15,
231-
"column": 2
232-
},
233-
"end": {
234-
"line": 18,
235-
"column": 3
236-
}
217+
"start": {},
218+
"end": {}
237219
}
238220
]
239221
}

test/coverage-test/test/__snapshots__/results-istanbul.snapshot.json

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,8 @@
438438
}
439439
},
440440
{
441-
"start": {
442-
"line": 33,
443-
"column": 2
444-
},
445-
"end": {
446-
"line": 36,
447-
"column": null
448-
}
441+
"start": {},
442+
"end": {}
449443
}
450444
]
451445
},
@@ -473,14 +467,8 @@
473467
}
474468
},
475469
{
476-
"start": {
477-
"line": 39,
478-
"column": 2
479-
},
480-
"end": {
481-
"line": 42,
482-
"column": null
483-
}
470+
"start": {},
471+
"end": {}
484472
}
485473
]
486474
}

0 commit comments

Comments
 (0)