Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

istanbul ignore hint misplaced when semi-colons are omitted after literal object #467

Closed
coreyfarrell opened this issue Sep 13, 2019 · 3 comments

Comments

@coreyfarrell
Copy link
Member

coreyfarrell commented Sep 13, 2019

const obj = {a: 'a'}

/* istanbul ignore if */
if ('b' in obj) {
  console.log('this should not be instrumented')
}

The output of nyc instrument --compact=false for this file is:

/* ...clipped... */
const obj = (cov_2oqccc38jn.s[0]++, {
  a: 'a'
  /* istanbul ignore if */

});
cov_2oqccc38jn.s[1]++;

if ('b' in obj) {
  cov_2oqccc38jn.b[0][0]++;
  cov_2oqccc38jn.s[2]++;
  console.log('this should not be instrumented');
} else {
  cov_2oqccc38jn.b[0][1]++;
}

Somehow the hint is getting moved up. I'm only able to reproduce this issue when the statement before the hint is a literal object assignment with at least one key and no semi-colons are used. Not sure yet if this is a bug in istanbul-lib-instrument or if babel is doing something unexpected.

@coreyfarrell
Copy link
Member Author

Additional detail, the above code results in the istanbul hint being seeing in node.trailingComments for node.type === 'VariableDeclaration'. Adding a semi-colon to the assignment const obj = {a: 'a'}; causes the comment to also be seen in node.leadingComments for node.type === 'IfStatement'.

This issue happens regardless of if the assignment is a variable declaration or not.

@coreyfarrell
Copy link
Member Author

Appears to be the result of a regression in @babel/parser, will be fixed by babel/babel#10445.

@coreyfarrell
Copy link
Member Author

Fixed in @babel/parser@7.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant