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 786 forks source link

Unexpected token with node magic syntax #827

Closed edpop closed 7 years ago

edpop commented 7 years ago

Reproducing

  1. Files
    
    // test/test.js
    const assert = require('assert');

let {a:b = null} = {a: 'hello'};

console.log('Here is OK'); assert(b === 'hello');

require('../modules/module');


```js
// modules/module.js
console.log('Here is FAIL');
let {a:b = null} = {a: 'hello'};
  1. npm scripts
    {
    "coverage": "istanbul cover _mocha -- -R spec",
    "test": "mocha"
    }

npm test works fine, but npm run coverage fails with

SyntaxError: Unexpected token :
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions.(anonymous function) [as .js] (/home/%USERNAME%/mocha_test/node_modules/istanbul/lib/hook.js:107:24)
......

If I comment let {a:b = null} = {a: 'hello'}; in module.js, then it will be OK.

I hate this syntax, but it works in real life outside of istanbul.

ENV

node: 6.9.1 npm: 3.10.8 istanbul: 0.4.5 mocha: 3.4.2

edpop commented 7 years ago

Fixed in nyc