Skip to content

Commit e6e9f6d

Browse files
committed
🐛 --ignore-sourcemap
1 parent 93dff29 commit e6e9f6d

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

src/runCoverage.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,29 @@ async function generateLcovStr (coverageOutput, supportedDeclarations) {
296296
const files = {} // key is filename, value is [{startLine, endLine, count}]
297297
const ret = [] // each line in the lcov file. Joined at the end of the function
298298

299-
function addCoverage (fileName, count, startLine, endLine) {
299+
function addCoverageRaw (fileName, count, startLine, endLine) {
300300
// add it to the files
301301
if (!files[fileName]) {
302302
files[fileName] = []
303303
}
304304
files[fileName].push({ startLine: startLine, endLine: endLine, count: count })
305305
}
306306

307+
function addCoverage (count, origStart, origEnd) {
308+
if (sourceMapConsumer) {
309+
// From https://github.com/mozilla/source-map#sourcemapconsumerprototypeoriginalpositionforgeneratedposition
310+
// Could have been {line: rule.position.start.line, column: rule.positoin.start.column}
311+
const startInfo = getStartInfo(origStart, origEnd)
312+
addCoverageRaw(startInfo.source, count, startInfo.line, startInfo.line)
313+
} else {
314+
// No sourceMap available
315+
const fileName = commander.css
316+
const startLine = origStart.line
317+
const endLine = startLine // Just do the selector (startLine)
318+
addCoverageRaw(fileName, count, startLine, endLine)
319+
}
320+
}
321+
307322
let i = -1
308323
cssTree.walkRules(ast, (rule, item, list) => {
309324
if (rule.type !== 'Rule') {
@@ -313,37 +328,20 @@ async function generateLcovStr (coverageOutput, supportedDeclarations) {
313328
i += 1
314329

315330
const count = coverageOutput[i][0]
316-
let fileName
317-
let startLine
318-
let endLine
319-
// Look up the source map (if available)
320-
if (sourceMapConsumer) {
321-
// From https://github.com/mozilla/source-map#sourcemapconsumerprototypeoriginalpositionforgeneratedposition
322-
// Could have been {line: rule.position.start.line, column: rule.positoin.start.column}
323-
const origStart = rule.loc.start
324-
const origEnd = rule.loc.end
325331

326-
const startInfo = getStartInfo(origStart, origEnd)
327-
addCoverage(startInfo.source, count, startInfo.line, startInfo.line)
328-
} else {
329-
// No sourceMap available
330-
fileName = commander.css
331-
startLine = rule.loc.start.line
332-
if (commander.coverDeclarations) {
333-
endLine = rule.loc.end.line
334-
} else {
335-
endLine = startLine // Just do the selector (startLine)
336-
}
337-
addCoverage(fileName, count, startLine, endLine)
338-
}
332+
// From https://github.com/mozilla/source-map#sourcemapconsumerprototypeoriginalpositionforgeneratedposition
333+
// Could have been {line: rule.position.start.line, column: rule.positoin.start.column}
334+
const origStart = rule.loc.start
335+
const origEnd = rule.loc.end
336+
337+
addCoverage(count, origStart, origEnd)
339338
})
340339

341340
// Mark all the unsupported declarations
342341
const unsupportedDeclarations = Object.keys(cssDeclarations).filter(decl => supportedDeclarations.indexOf(decl) < 0)
343342
for (const decl of unsupportedDeclarations) {
344343
for (const loc of cssDeclarations[decl]) {
345-
const startInfo = getStartInfo(loc.start)
346-
addCoverage(startInfo.source, 0, startInfo.line, startInfo.line)
344+
addCoverage(0, loc.start)
347345
}
348346
}
349347

0 commit comments

Comments
 (0)