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

`istanbul cover` hiding errors with octal literals #933

Open Jimbly opened 4 years ago

Jimbly commented 4 years ago

When running invalid Javascript through Istanbul, it is converting potentially unsupported numeric encodings (e.g. 0o1234 pre-ES2015) into decimal and hiding actual errors.

The npm module yazl has been passing it's Travis/Istanbul tests for years on Node v0.10.48, despite having ES2015-only octal literals in the code.

This line of code:

console.log(0o1234);

When run on Node v0.10.48 gives SyntaxError: Unexpected token ILLEGAL, but when sent through istanbul instrument I see this output:

__cov_iCMg9NRFTwMrHhpLiqgjqg.s['1']++;console.log(668);

Which suddenly has become valid Javascript, despite the original source not being such.

Pretty minor (I've recommended the YAZL author simply drop "support" for Node v0.10.48, since the module has not actually ran on that platform for many years), but was quite the head-scratcher to track down why an octal literal in the module was "ok" but was failing when used in the unit tests!