Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: istanbul-lib-source-maps to preserve implicit else when sourcemaps are used #706

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AriPerkkio
Copy link
Contributor

Tested the fix with reproduction case from downstream (vitest-dev/vitest#2239) by modifying ./node_modules/istanbul-lib-source-maps/lib/transformer.js on the fly.

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |     100 |       50 |     100 |     100 |                   
 cov.js   |     100 |       50 |     100 |     100 | 2                 
----------|---------|----------|---------|---------|-------------------

@AriPerkkio AriPerkkio changed the title fix: istanbul-lib-source-maps to preserve implicit else when sourceps are used fix: istanbul-lib-source-maps to preserve implicit else when sourceps are used Nov 4, 2022
Comment on lines +85 to +96
// Check if this is an implicit else
else if (
branchMeta.type === 'if' &&
i > 0 &&
loc.start.line === undefined &&
loc.start.end === undefined &&
loc.end.line === undefined &&
loc.end.end === undefined
) {
locs.push(loc);
mappedHits.push(hits[i]);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference:

- `locations[index].start` **[Object][1]** the branch component start location object. (`{}` for if branch without else)

- `locations[index].end` **[Object][1]** the branch component end location object. (`{}` for if branch without else)

// Check if the branch is a conditional if branch.
branchMeta[branchName].type === 'if' &&
// Check if the branch has an implicit else.
branchArray.length === 2 &&
// Check if the implicit else branch is unnacounted for.
metaArray.length === 1 &&
// Check if the implicit else branch is uncovered.
branchArray[1] === 0

@AriPerkkio AriPerkkio changed the title fix: istanbul-lib-source-maps to preserve implicit else when sourceps are used fix: istanbul-lib-source-maps to preserve implicit else when sourcemaps are used Nov 7, 2022
@adrian-burlacu-software
Copy link
Contributor

@AriPerkkio
Thank you, I appreciate this! Felt pretty embarrassed trying to find all the spots that needed to update downstream.

@carpie
Copy link

carpie commented Apr 24, 2023

Hello! Is there a timeline for this to be merged? We're hitting this issue as well with cypress code coverage on instrumented code with source maps. Thanks!

@AriPerkkio
Copy link
Contributor Author

Istanbul projects are not that active anymore so updates may take long time - if ever.

If you have access to coverageMap in your Cypress setup you can apply same work-around that Vitest uses to patch these implicit else's: https://github.com/vitest-dev/vitest/pull/2275/files#diff-a0a730c31ce78cf1c3cb20d55daa7167ff57fa8e062df213c6eeb918582d1cb5R244-R272

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

istanbul-lib-source-maps does not preserve implicit else
3 participants