Skip to content

Commit 7cfbdd2

Browse files
committed
fix Prototype-polluting issue
1 parent d8d7351 commit 7cfbdd2

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

lib/generate.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const getReportGroup = (reports, lcov, dataType) => {
110110
}
111111

112112
// group v8 and istanbul
113-
const reportGroup = {};
113+
const groupMap = new Map();
114114
Object.keys(reportMap).forEach((k) => {
115115
const options = reportMap[k];
116116

@@ -120,24 +120,24 @@ const getReportGroup = (reports, lcov, dataType) => {
120120
type = options.type || 'v8';
121121
}
122122

123-
let group = reportGroup[type];
123+
let group = groupMap.get(type);
124124
if (!group) {
125-
group = {};
126-
reportGroup[type] = group;
125+
group = new Map();
126+
groupMap.set(type, group);
127127
}
128128

129-
group[k] = options;
129+
group.set(k, options);
130130

131131
});
132132

133133
// requires a default istanbul report if data is istanbul
134-
if (dataType === 'istanbul' && !reportGroup.istanbul) {
135-
reportGroup.istanbul = {
136-
html: {}
137-
};
134+
if (dataType === 'istanbul' && !groupMap.has('istanbul')) {
135+
const istanbulGroup = new Map();
136+
istanbulGroup.set('html', {});
137+
groupMap.set('istanbul', istanbulGroup);
138138
}
139139

140-
return reportGroup;
140+
return groupMap;
141141
};
142142

143143
// ========================================================================================================
@@ -146,7 +146,7 @@ const getReportGroup = (reports, lcov, dataType) => {
146146
const generateV8ListReports = async (v8list, coverageData, fileSources, options) => {
147147
let istanbulReportPath;
148148
// v8 to istanbul reports
149-
if (options.reportGroup.istanbul) {
149+
if (options.reportGroup.has('istanbul')) {
150150
const istanbulCoverageResults = await saveIstanbulReports(coverageData, fileSources, options);
151151
istanbulReportPath = istanbulCoverageResults.reportPath;
152152
}
@@ -200,11 +200,9 @@ const generateCoverageReports = async (dataList, sourceCache, options) => {
200200
// [ 'type', 'reportPath', 'name', 'watermarks', 'summary', 'files' ]
201201
// console.log(Object.keys(coverageResults));
202202

203-
const bothGroup = options.reportGroup.both;
204-
if (bothGroup) {
205-
const bothReports = Object.keys(bothGroup);
206-
for (const reportName of bothReports) {
207-
const reportOptions = bothGroup[reportName];
203+
if (options.reportGroup.has('both')) {
204+
const bothGroup = options.reportGroup.get('both');
205+
for (const [reportName, reportOptions] of bothGroup) {
208206
const builtInHandler = bothBuiltInReports[reportName];
209207
const t1 = Date.now();
210208
if (builtInHandler) {

lib/istanbul/istanbul.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,16 @@ const saveIstanbulReports = (coverageData, fileSources, options) => {
8787
// create a context for report generation
8888
const context = istanbulLibReport.createContext(contextOptions);
8989

90-
const istanbulGroup = options.reportGroup.istanbul;
91-
Object.keys(istanbulGroup).forEach((reportName) => {
92-
const t1 = Date.now();
93-
const reportOptions = istanbulGroup[reportName];
94-
const report = istanbulReports.create(reportName, reportOptions);
95-
report.execute(context);
96-
Util.logTime(`┌ [generate] saved report: ${reportName}`, t1);
97-
});
90+
const istanbulGroup = options.reportGroup.get('istanbul');
91+
// already has
92+
if (istanbulGroup) {
93+
for (const [reportName, reportOptions] of istanbulGroup) {
94+
const t1 = Date.now();
95+
const report = istanbulReports.create(reportName, reportOptions);
96+
report.execute(context);
97+
Util.logTime(`┌ [generate] saved report: ${reportName}`, t1);
98+
}
99+
}
98100

99101
// add watermarks and color
100102
const coverageReport = new IstanbulSummary();

lib/v8/v8.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,10 @@ const saveV8Report = async (v8list, options, istanbulReportPath) => {
405405
};
406406

407407
const outputs = {};
408-
const v8Group = options.reportGroup.v8;
408+
const v8Group = options.reportGroup.get('v8');
409409
// could be no v8 only reports, but have `both` data reports
410410
if (v8Group) {
411-
const v8Reports = Object.keys(v8Group);
412-
for (const reportName of v8Reports) {
413-
const reportOptions = v8Group[reportName];
411+
for (const [reportName, reportOptions] of v8Group) {
414412
const buildInHandler = buildInV8Reports[reportName];
415413
const t1 = Date.now();
416414
if (buildInHandler) {

0 commit comments

Comments
 (0)