Skip to content

Commit

Permalink
Fix dollar sign ($) issue in Vue SFC (#101)
Browse files Browse the repository at this point in the history
Fixes #100

When replacing a string if the provided replacement is a string it will
replace the original string using pattern matching. In the vue
preprocessor, the `$` in the code is seen as a regex pattern. Passing a
function as a replacement escapes that issue.
  • Loading branch information
istiak-tridip committed May 30, 2023
1 parent 8a4b651 commit e20a9fd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/preprocessors/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ function sortScript(

return code.replace(
content,
`\n${preprocessor(content, adjustedOptions)}\n`,
() => `\n${preprocessor(content, adjustedOptions)}\n`,
);
}
8 changes: 8 additions & 0 deletions tests/Vue/__snapshots__/ppsi.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ import { defineComponent } from 'vue'
function add(a,b) {
return a + b;
}
const number = 500;
const dollarSign = '$';
const dollarPrefixed =\`\\$\${number}\`;
</script>
<template>
Expand Down Expand Up @@ -179,6 +183,10 @@ import sameLevelRelativePath from "./sameLevelRelativePath";
function add(a, b) {
return a + b;
}
const number = 500;
const dollarSign = "$";
const dollarPrefixed = \`\\$\${number}\`;
</script>
<template>
Expand Down
4 changes: 4 additions & 0 deletions tests/Vue/setup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { defineComponent } from 'vue'
function add(a,b) {
return a + b;
}
const number = 500;
const dollarSign = '$';
const dollarPrefixed =`\$${number}`;
</script>

<template>
Expand Down

0 comments on commit e20a9fd

Please sign in to comment.