diff --git a/src/preprocessors/vue-preprocessor.ts b/src/preprocessors/vue-preprocessor.ts index b29bbc44..ddbe2b6f 100644 --- a/src/preprocessors/vue-preprocessor.ts +++ b/src/preprocessors/vue-preprocessor.ts @@ -10,5 +10,9 @@ export function vuePreprocessor(code: string, options: PrettierOptions) { return code; } - return code.replace(content, `\n${preprocessor(content, options)}\n`); + // 'replacer' is a function so it returns the preprocessed code as-is. + // If it were passed as just a string and the string contained special groups (like $&, $`, $', $n, $, etc.) this would produce invalid results + const replacer = () => `\n${preprocessor(content, options)}\n`; + + return code.replace(content, replacer); } diff --git a/tests/Vue/__snapshots__/ppsi.spec.js.snap b/tests/Vue/__snapshots__/ppsi.spec.js.snap index 065c444f..b4fe3e32 100644 --- a/tests/Vue/__snapshots__/ppsi.spec.js.snap +++ b/tests/Vue/__snapshots__/ppsi.spec.js.snap @@ -137,6 +137,25 @@ div { `; +exports[`sfcWithSpecialReplacerGroups.vue - vue-verify: sfcWithSpecialReplacerGroups.vue 1`] = ` + + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + +`; + exports[`ts.vue - vue-verify: ts.vue 1`] = ` +