Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Code coverage for conditional operator with comma operator isn't handled correctly #555
Version: Lab 10.3.0 with code coverage turned on,
This expression is not correctly annotated so when the code is run it produces invalid result
true ? ('no', 'yes') : 'nope'
Expected value: 'yes'
The reason is it's being annotated like this:
(global.__$$labCov._statement('/Users/2921/code/_3rd/lab/test/coverage/conditional2.js',1,1,true) ? global.__$$labCov._statement('/Users/2921/code/_3rd/lab/test/coverage/conditional2.js',2,1,'no', 'yes') : global.__$$labCov._statement('/Users/2921/code/_3rd/lab/test/coverage/conditional2.js',3,1,'nope'))
This excerpt shows that consequent expression is missing it's parentheses:
It should have been annotated as:
The consequent code is rendered using
node.set('(' + node.test.source() + '? global.__$$labCov._statement(\'' + filename + '\',' + consequent + ',' + line + ',' + node.consequent.source() + ') : global.__$$labCov._statement(\'' + filename + '\',' + alternate + ',' + line + ',' + node.alternate.source() + '))');
I see three possible solutions:
I think the easiest and safest is alternative 2. There shouldn't be any problems with adding extra parentheses around the consequent and alternate nodes. It's already being done around the entire ternary expression.
If you're ok with alternative 2 I can submit a PR with the fix and a test.