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

The end of line ($) in a regex, is replaced by <script setup> in a Vue 3 #306

Open
NNikulenkovSmapo opened this issue Aug 2, 2024 · 2 comments

Comments

@NNikulenkovSmapo
Copy link

Example:

<script setup>  
  const pattern = new RegExp(`/user/d+$`);  
</script>  
  
<template>  
  <div>{{pattern}}</div>  
</template>

After formatting, it becomes:

<script setup>  
  
  const pattern = new RegExp(`/user/d+<script setup>);  
</script>  
  
<template>  
  <div>{{ pattern }}</div>  
</template>

If I add $ to the end of the string separately:

const pattern = new RegExp(`/user/d+` + '$');  

When formatting, Prettier throws an error "SyntaxError: Unexpected closing tag 'script'. It may happen when the tag has already been closed by another tag." Without the plugin, all errors disappear.

.prettierrc

{  
  "plugins": ["@trivago/prettier-plugin-sort-imports"],  
  "importOrder": [],  
  "importOrderSeparation": true,  
  "importOrderSortSpecifiers": true  
}

Packages:

  • prettier: 3.3.3,
  • @trivago/prettier-plugin-sort-imports: 4.3.0
@adamDilger
Copy link

I think I have come across the same issue, PR here #283

@dongchengjie
Copy link

dongchengjie commented Oct 9, 2024

It seems to have nothing to do with regex and setup in Vue.

<script>
  import { clone } from "lodash-es";

  const foo = "$&";
</script>

It becomes:

<script>
  import { clone } from "lodash-es";


  const foo = "
    import { clone } from "lodash-es";

    const foo = "$&";
  ";
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants