Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape dollars in Vue preprocessor replacement. #217

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

### v4.1.2
#### New features
- Fix dollars being interpolated in vue SFC [#217](https://github.com/trivago/prettier-plugin-sort-imports/pull/217) by [mefyl](https://github.com/mefyl)

---
### v4.1.1
Expand Down
4 changes: 2 additions & 2 deletions src/preprocessors/vue-preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export function vuePreprocessor(code: string, options: PrettierOptions) {
if (!content) {
return code;
}

return code.replace(content, `\n${preprocessor(content, options)}\n`);
const replacement = preprocessor(content, options).replace(/\$/g, '$$$$');
return code.replace(content, `\n${replacement}\n`);
}
19 changes: 19 additions & 0 deletions tests/Vue/__snapshots__/ppsi.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`dollar-escaping.vue - vue-verify: dollar-escaping.vue 1`] = `
<template>
<div></div>
</template>

<script lang="ts">
const x = new RegExp(\`\${x}$\`);
</script>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<template>
<div></div>
</template>

<script lang="ts">
const x = new RegExp(\`\${x}$\`);
</script>

`;

exports[`setup.vue - vue-verify: setup.vue 1`] = `
<script setup>
// I am top level comment in this file.
Expand Down
7 changes: 7 additions & 0 deletions tests/Vue/dollar-escaping.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div></div>
</template>

<script lang="ts">
const x = new RegExp(`${x}$`);
</script>