Skip to content

Commit

Permalink
fix: add regex for vue SFC to prevent instrumenting style and templates
Browse files Browse the repository at this point in the history
Single file Components no longer have their html or css instrumented instead of their script

Closes #96 #178 #89
  • Loading branch information
hugo-daclon committed Feb 14, 2024
1 parent 0a70378 commit 268d4b5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ export default function istanbulPlugin(opts: IstanbulPluginOptions = {}): Plugin
return;
}

// for vue single-file components, check if the src code is the script and not the html or style
const isVueSFC = /[?&]vue\b(?=&|$)/.test(id);
const isVueSFCScript = /[?&]type=script\b(?=&|$)/.test(id);
if (isVueSFC && !isVueSFCScript) {
return;
}

const filename = resolveFilename(id);

if (testExclude.shouldInstrument(filename)) {
Expand Down

0 comments on commit 268d4b5

Please sign in to comment.