douglasduteil / isparta

:skull: A code coverage tool for ES6 (babel/6to5)
Do What The F*ck You Want To Public License
642 stars 47 forks source link

coverage report looks not good #116

Open mariodu opened 8 years ago

mariodu commented 8 years ago

image

It seems that can't deal with '||'.

yyx990803 commented 8 years ago

I spent some time digging into this issue and this is what I found:

Isparta extends Istanbul's Instrumenter class and overrides the input code with babel generated code, and patches the generated metrics (statementMap, fnMap, branchMap) using the source map generated by Babel, mapping the generated positions back to the original positions in the source code. However, Babel's source map isn't detailed enough to return the precise end position for any expression. For example, it returns a column number of 0 for the end position of expressions that are part of:

When Istanbul's HTML reporter is generating the HTML, it attempts to wrap the skipped branch, e.g. b with a <span>, however the end column is smaller than the starter column, so it fails to insert the closing </span>, causing the "skipped branch" span to include everything until the end of file.

I don't see a way to fix this other than asking Babel to provide source maps with better precision, but I also don't think it's going to be easy.