prettier-plugin-sort-imports icon indicating copy to clipboard operation
prettier-plugin-sort-imports copied to clipboard

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

Open NNikulenkovSmapo opened this issue 1 year ago • 2 comments

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

NNikulenkovSmapo avatar Aug 02 '24 20:08 NNikulenkovSmapo

I think I have come across the same issue, PR here https://github.com/trivago/prettier-plugin-sort-imports/pull/283

adamDilger avatar Oct 01 '24 01:10 adamDilger

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>

dongchengjie avatar Oct 09 '24 06:10 dongchengjie