monocart-coverage-reports
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -157,10 +157,2 @@ const { | ||
// not for css | ||
if (!item.js) { | ||
return { | ||
functions: [], | ||
branches: [] | ||
}; | ||
} | ||
const { source } = item; | ||
@@ -197,72 +189,114 @@ | ||
const addCssRules = (rules, coverageList, coveredRanges, locator) => { | ||
let hasCovered = false; | ||
// line and line is 1-base | ||
rules.forEach((rule) => { | ||
const addRule = (item, coverageList, coveredRanges, count = 0) => { | ||
const { type, position } = rule; | ||
const { source } = item; | ||
const { start, end } = source; | ||
const startOffset = start.offset; | ||
const endOffset = end.offset; | ||
if (type === 'comment') { | ||
return; | ||
if (!count) { | ||
const coveredRange = findInRanges(startOffset, endOffset, coveredRanges); | ||
if (coveredRange) { | ||
count = 1; | ||
} | ||
} | ||
const { start, end } = position; | ||
coverageList.push({ | ||
start: startOffset, | ||
end: endOffset, | ||
count | ||
}); | ||
// both 1-base | ||
// console.log(start, end); | ||
const startOffset = locator.locationToOffset({ | ||
line: start.line, | ||
column: start.column - 1 | ||
}); | ||
return count; | ||
const endOffset = locator.locationToOffset({ | ||
line: end.line, | ||
column: end.column - 1 | ||
}); | ||
}; | ||
// start should offset @media | ||
if (type === 'media') { | ||
// rules in media | ||
// console.log('media', rule.media, startOffset, endOffset); | ||
const childCoverageList = []; | ||
const hasChildCovered = addCssRules(rule.rules, childCoverageList, coveredRanges, locator); | ||
if (hasChildCovered) { | ||
childCoverageList.forEach((it) => { | ||
coverageList.push(it); | ||
}); | ||
return; | ||
} | ||
const addAtRule = (item, coverageList, coveredRanges) => { | ||
const { name, nodes } = item; | ||
// add whole media as uncovered | ||
if (['charset', 'import', 'namespace'].includes(name)) { | ||
addRule(item, coverageList, coveredRanges, 1); | ||
return; | ||
} | ||
if (['media', 'supports', 'container', 'layer'].includes(name)) { | ||
const childCoverageList = []; | ||
const count = addCssRules(nodes, childCoverageList, coveredRanges); | ||
if (count) { | ||
coverageList.push({ | ||
start: startOffset, | ||
end: endOffset, | ||
count: 0 | ||
start: item.source.start.offset, | ||
end: childCoverageList[0].start, | ||
count: 1 | ||
}); | ||
let end; | ||
childCoverageList.forEach((it) => { | ||
coverageList.push(it); | ||
end = it.end; | ||
}); | ||
coverageList.push({ | ||
start: end, | ||
end: item.source.end.offset, | ||
count: 1 | ||
}); | ||
return; | ||
} | ||
let count = 0; | ||
if (type === 'charset') { | ||
count = 1; | ||
} else { | ||
const coveredRange = findInRanges(startOffset, endOffset, coveredRanges); | ||
if (coveredRange) { | ||
count = 1; | ||
hasCovered = true; | ||
} | ||
} | ||
addRule(item, coverageList, coveredRanges); | ||
}; | ||
const addCssRules = (list, coverageList, coveredRanges) => { | ||
let count = 0; | ||
// line and line is 1-base | ||
list.forEach((item) => { | ||
const { type } = item; | ||
if (type === 'comment') { | ||
return; | ||
} | ||
coverageList.push({ | ||
start: startOffset, | ||
end: endOffset, | ||
count | ||
}); | ||
if (type === 'rule') { | ||
count += addRule(item, coverageList, coveredRanges); | ||
return; | ||
} | ||
// console.log('============================================================================='); | ||
// Object.keys(item).forEach((k) => { | ||
// if (k === 'parent') { | ||
// return; | ||
// } | ||
// if (k === 'raws') { | ||
// return; | ||
// } | ||
// if (k === 'nodes') { | ||
// console.log(k, item[k].length); | ||
// return; | ||
// } | ||
// if (k === 'source') { | ||
// console.log(k, item[k].start, item[k].end); | ||
// return; | ||
// } | ||
// console.log(k, item[k]); | ||
// }); | ||
if (type === 'atrule') { | ||
addAtRule(item, coverageList, coveredRanges); | ||
} | ||
}); | ||
return hasCovered; | ||
return count; | ||
}; | ||
const getCssAstInfo = (item, locator) => { | ||
const getCssAstInfo = (item, coverageList) => { | ||
@@ -275,2 +309,3 @@ const { | ||
ranges.sort((a, b) => a.start - b.start); | ||
// to offset covered ranges | ||
@@ -288,7 +323,9 @@ const coveredRanges = ranges.map((it) => { | ||
const coverageList = []; | ||
addCssRules(ast.rules, coverageList, coveredRanges, locator); | ||
// if (sourcePath.endsWith('style.css')) { | ||
addCssRules(ast.nodes, coverageList, coveredRanges); | ||
// } | ||
return { | ||
coverageList | ||
functions: [], | ||
branches: [] | ||
}; | ||
@@ -295,0 +332,0 @@ }; |
@@ -981,3 +981,3 @@ const path = require('path'); | ||
// move functions and ranges to coverageList | ||
let coverageList; | ||
let coverageList = []; | ||
let astInfo; | ||
@@ -992,7 +992,4 @@ if (js) { | ||
} else { | ||
astInfo = getCssAstInfo(item, locator); | ||
// convent css covered ranges to rules ranges and include uncovered ranges | ||
coverageList = astInfo.coverageList; | ||
// console.log(coverageList); | ||
astInfo = getCssAstInfo(item, coverageList); | ||
// remove original ranges | ||
@@ -999,0 +996,0 @@ if (Util.loggingType !== 'debug') { |
{ | ||
"name": "monocart-coverage-reports", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Monocart coverage reports", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
790446
5840
29
8