diff --git a/packages/app/src/utils/coverage.js b/packages/app/src/utils/coverage.js index bf3a4942..eff33a72 100644 --- a/packages/app/src/utils/coverage.js +++ b/packages/app/src/utils/coverage.js @@ -280,6 +280,49 @@ class CoverageParser { } // ==================================================================================================== + fixRangeStart(locator, start, end) { + const comments = locator.lineParser.commentParser.comments; + const blankBlock = /\S/; + const len = end - start; + let text = locator.getSlice(start, end); + let offset = 0; + + while (offset < len) { + + const indent = text.search(blankBlock); + if (indent === 0) { + break; + } + + offset += indent; + + // skip comments + if (!comments.length) { + break; + } + + const nextPos = start + offset; + const comment = comments.find((it) => it.start === nextPos); + if (!comment) { + break; + } + + const commentLen = comment.end - comment.start; + + offset += commentLen; + + // next text + text = text.slice(indent + commentLen); + + } + + // It should never be possible to start with } + // if (text[0] === '}') { + // offset = 1; + // } + + return offset; + } // only for js, and count > 1 setExecutionCounts(range) { @@ -295,24 +338,8 @@ class CoverageParser { const formattedEnd = mappingParser.originalToFormatted(end); const locator = this.formattedLocator; - - // start in a comment, it does not make sense - // all comments range should be ignored, resolve it later - // if (locator.lineParser.commentParser.isComment(formattedStart, formattedEnd)) { - // return; - // } - // fix start indent - const text = locator.getSlice(formattedStart, formattedEnd); - const blankBlock = /\S/; - const indent = text.search(blankBlock); - let offset = indent; - - // It should never be possible to start with } - if (indent === 0 && text[0] === '}') { - offset = 1; - } - + const offset = this.fixRangeStart(locator, formattedStart, formattedEnd); const fixedStart = formattedStart + offset; // 1-base diff --git a/scripts/conf.cli.js b/scripts/conf.cli.js index f0aeaa0d..a721f253 100644 --- a/scripts/conf.cli.js +++ b/scripts/conf.cli.js @@ -14,7 +14,7 @@ const beforeApp = (item, Util) => { // const jsDataPath = path.resolve(__dirname, `../docs/minify/${dataFile}`); // typescript repo huge data example 8M - // const jsDataPath = path.resolve(__dirname, `../../../github/TypeScript/coverage-mcr/${dataFile}`); + // const jsDataPath = path.resolve(__dirname, `../../../github/TypeScript/coverage-reports/${dataFile}`); const jsPath = path.resolve(item.buildPath, dataFile); const distDir = path.dirname(jsPath);