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

Regex doesn't match for inline code in coverage.json #149

Open
tmac4096 opened this issue Jun 20, 2017 · 1 comment
Open

Regex doesn't match for inline code in coverage.json #149

tmac4096 opened this issue Jun 20, 2017 · 1 comment

Comments

@tmac4096
Copy link

We may need to use a different sourceMapRegEx for inline code from the code reading through file path.
In Istanbul, if we instrument a file with option "embed-source:true", it will wrap the code with an immediate function. Like:
"(function() {
//original JS code....
/#sourceMappingURL=data:application/json;base64........
}());"

In this situation, the sourceMapRegEx cannot match the code, because it doesn't expect the code ending with some special characters like ')', and it couldn't resolve the sourceMap for this file.
I have tried to remove the $ from the sourceMapRegEx in CoverageTransformer.js line 66 and it can work.

var sourceMapRegEx = /(?:\/{2}[#@]{1,2}|\/\*)\s+sourceMappingURL\s*=\s*(data:(?:[^;]+;)+base64,)?(\S+)(?:\n\s*)?$/;
var sourceMapRegEx = /(?:\/{2}[#@]{1,2}|\/\*)\s+sourceMappingURL\s*=\s*(data:(?:[^;]+;)+base64,)?(\S+)(?:\n\s*)?/;

I'm not sure if we can simply use this change to fix, could you please help take a look?

@frenchu
Copy link

frenchu commented Jun 24, 2018

I faced the similar issue on Windows where the line ending is different than \n. I came up with this solution:

/(?:\/{2}[#@]{1,2}|\/\*)\s+sourceMappingURL\s*=\s*(data:(?:[^;]+;)+base64,)?(\S+)(?:(?:\n|\r|\r\n)\s*)?$/

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

No branches or pull requests

3 participants