[feature](istanbul-lib-instrument): update ignore regex for "legal" comments #693
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #658.
This PR adds support for what
esbuild
calls "legal comments" (https://esbuild.github.io/api/#legal-comments).The issue being that
esbuild
strips comments when building, so any/* istanbul ignore (if | else | next) */
comments are ignored when using it (I recently ran into this exact issue trying to get test coverage with avite
project). However,esbuild
will leave "legal" comments in (ie, if the comment starts with/*!
or//!
).Caveats
According to the above-linked section in
esbuild
's docs, this only applies to "statement-level" "legal" comments:I interpret this to mean that the following example might not work:
However, I don't believe there is anything
istanbul
can do to solve this, so I'm only noting it here for completeness.Documentation (?)
Should we document this somewhere?
esbuild
is becoming a pretty popular tool and this issue may start to come up more often. I think a footnote inistanbul/nyc
'sREADME
would probably be enough?Side Note
I also discovered that there is inconsistent handling of RegEx matching between
/* istanbul ignore (if | else | next) */
and/* istanbul ignore file */
.When the
if | else | next
RegEx is tested, it usesv.match(COMMENT_RE)
. But whenfile
is tested, it usesCOMMENT_FILE_RE.test(c.value)
, which is less strict (I altered one of the tests so the comment read/* plz istanbul ignore file */
and it still passed). I don't know if this is intentional or not, but I noticed it while implementing this and thought I'd bring it up in case it was an oversight.Thanks for this rad library! Let me know if there is anything else I can do!