Prefer a map and a join as feel it's easier to understand, and I found a case in the wild where Array.prototype.reduce was overwritten (which admittedly is also a danger with map) (#52)

This commit is contained in:
Eoghan Murray
2026-04-01 12:00:00 +08:00
committed by GitHub
parent f9f9e9cecd
commit b005450c64

View File

@@ -35,10 +35,7 @@ function getCssRulesString(s: CSSStyleSheet): string | null {
try {
const rules = s.rules || s.cssRules;
return rules
? Array.from(rules).reduce(
(prev, cur) => prev + getCssRuleString(cur),
'',
)
? Array.from(rules).map(getCssRuleString).join('')
: null;
} catch (error) {
return null;