Skip to content

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

@tmac4096

Description

@tmac4096

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions