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

Unnecessary removal of $$() when using Vue Reactivity Transform macros #247

Open
1 task
AnotiaWang opened this issue Aug 6, 2023 · 1 comment
Open
1 task

Comments

@AnotiaWang
Copy link

AnotiaWang commented Aug 6, 2023

Your Environment

  • Prettier version: 3.0.1
  • node version: 20.3.0
  • package manager: pnpm@8
  • IDE: VS Code

Describe the bug

I'm using Vue with the Reactivity Transform macros. There's a $$() macro to keep reactivity of refs when passing them to functions. However this plugin always tries to rename $$() to $(), which leads to Vue throwing an error $ can only be used as the initializer of a variable declaration.

To Reproduce

  1. Create a Vue 3 project. Please install the Reactivity Transform macros if you're using Vue 3.3+, or enable it in config if using Vue 3.2+.
  2. Write a component, and use it in another component. Specify a ref for the component.
<template>
  <some-component ref="componentRef" />
</template>

<script setup lang="ts">
import { provide } from 'vue'
import SomeComponent from '../path/to/component.vue'

const componentRef = $ref<InstanceType<typeof SomeComponent>>()

provide('any-key', $$(componentRef))
</script>
  1. Save the file. $$(componentRef) is changed to $(componentRef).
  2. Run the project

Expected behavior

The $$() macros shouldn't be changed.

Screenshots, code sample, etc

Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
.prettierrc.json

{
  "arrowParens": "avoid",
  "semi": false,
  "singleQuote": true,
  "trailingComma": "all",
  "printWidth": 100,
  "plugins": ["@trivago/prettier-plugin-sort-imports"],
  "importOrder": ["^@/(.*)$", "^[./]"],
  "importOrderSeparation": true,
  "importOrderSortSpecifiers": true
}

Error log

[plugin:commonjs] $ can only be used as the initializer of a variable declaration

Contribute to @trivago/prettier-plugin-sort-imports

  • I'm willing to fix this bug 🥇
@adamDilger
Copy link

I think this issue #276 is related, it's due to the $$ being a special replacement group in a call to "".replace(), which this plugin uses in pre-processing vue code.

I've submitted a fix PR which should address this issue

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

2 participants