gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 785 forks source link

Instrumentation breaks code when using inline arrow functions as parameters #891

Open bennidi opened 6 years ago

bennidi commented 6 years ago

I have just introduced the z pattern matching library into parts of my code base. Matchers are written as arrow functions which are passed as parameters to the match processor. Some common code looks like this

for(const operation in patch){
      match(operation)(
        (x = '$set') => this.$set(patch[operation], to),
        (x = '$unset') => this.$set(patch[operation], to),
        (x) => { throw new Error(`Unsupported operation ${x}`) })
    }

With istanbul enabled I have broken test cases with the following stack traces

ERROR 2018-06-29T13:08:28.530Z [][] SyntaxError: Unexpected token (
    at Parser.Object.<anonymous>.Parser.pushBuffer (/ext/development/workspaces/free2move/b2b-api-poc/node_modules/js-function-reflector/argument_parser.js:96:50)
    at Parser.Object.<anonymous>.Parser.parse (/ext/development/workspaces/free2move/b2b-api-poc/node_modules/js-function-reflector/argument_parser.js:61:14)
    at Object.<anonymous>.module.exports (/ext/development/workspaces/free2move/b2b-api-poc/node_modules/js-function-reflector/header_parser.js:10:21)
    at reflector (/ext/development/workspaces/free2move/b2b-api-poc/node_modules/js-function-reflector/index.js:34:30)
    at Object.<anonymous>.module.exports (/ext/development/workspaces/free2move/b2b-api-poc/node_modules/z/src/getMatchDetails.js:4:47)
 FAIL  test/fullstack/radars.ctrl.test.js (6.428s)kspaces/free2move/b2b-api-poc/node_modules/z/src/z.js:9:42)

This does not happen when running with disabled coverage. /*istanbul ignore next*/ helps but I don't want to start adding it everywhere I use pattern matching. I assume that instrumentation breaks code when encountering multiple inline arrow functions passed as parameters to another function