diff --git a/packages/istanbul-lib-instrument/src/visitor.js b/packages/istanbul-lib-instrument/src/visitor.js index e3c207de..ad526e82 100644 --- a/packages/istanbul-lib-instrument/src/visitor.js +++ b/packages/istanbul-lib-instrument/src/visitor.js @@ -534,7 +534,8 @@ const globalTemplateVariable = template(` var global = GLOBAL_COVERAGE_SCOPE; `); // the template to insert at the top of the program. -const coverageTemplate = template(` +const coverageTemplate = template( + ` function COVERAGE_FUNCTION () { var path = PATH; var hash = HASH; @@ -547,13 +548,18 @@ const coverageTemplate = template(` } var actualCoverage = coverage[path]; - COVERAGE_FUNCTION = function () { - return actualCoverage; + { + // @ts-ignore + COVERAGE_FUNCTION = function () { + return actualCoverage; + } } return actualCoverage; } -`); +`, + { preserveComments: true } +); // the rewire plugin (and potentially other babel middleware) // may cause files to be instrumented twice, see: // https://github.com/istanbuljs/babel-plugin-istanbul/issues/94