core icon indicating copy to clipboard operation
core copied to clipboard

[Reactivity Transform] `$$` breaks the original semantics

Open sxzz opened this issue 3 years ago • 1 comments

Vue version

v3.2.37

Link to minimal reproduction

https://sfc.vuejs.org/#eNo9TjsOwjAMvUpkdQAJErFWoRIbh8hSKpe2aj6yXRiq3p2kICb7ffz8VrilpF8LQg2WOxqTKEZZUuOCC10MLIrUVVWE/eFydKGqDpSHNV/zbrOCPs2tYEZK2eHS3HGeozV5K9a/DCcYfYokZ98mPXEM+e1ajtxPYAe12pnC5V4FOxhEEtfGcN+VshPrSE+TN01LkNGjRvbnB8U3I+VgByVic2GD7QP4UU0C

Steps to reproduce

Open the reproduction link, there's an error on SFC playground. Cannot access 'r' before initialization

The code

const r = $ref(1)
$$(r)

is transformed to

const r = _ref(1)
(r)

We can see that $$ is removed, and only brackets remain. It will break the original semantics. It's actually only one line code: const r = _ref(1)(r).

What is expected?

const r = _ref(1)
r

// ⬇️ formatted to
const r = _ref(1);
r;

What is actually happening?

const r = _ref(1)
(r)

// ⬇️ formatted to
const r = _ref(1)(r);

System Info

N/A

Any additional comments?

IMHO, the brackets should be removed to avoid changing the semantics when using $$ function.

sxzz avatar Jul 19 '22 23:07 sxzz

The problem still exists

https://sfc.vuejs.org/#eNotjsEOgjAQRH+l2XAAIyVyJMTEm3/gZS+KFSHtbtMteiD8u616253JvJkVTt7r12Kgg16GMPmoxMTFH5EGJmFrtOWxRDgba1ldONg7QoVUFOWhrdROtUh984umEOxhcp5DrN3V61mYEnlFUgr/hiB06qtkLVXnH+EZo5euaeQx5D2zaA5jky4dFoqTM9qIq2+B32JCAiNkxIa0wfYBpvRCtg==

/cc @yyx990803 @tuchg

sxzz avatar Dec 10 '22 18:12 sxzz

I've closed my PR. If you decide the best solution is to remove the brackets when transforming $$, I can try to make a PR for that and include the tests from my previous PR.

taye avatar Jan 12 '23 11:01 taye

Unfortunately, Reactivity Transform has been dropped officially now, so I closed this issue/PR. If you want to keep using it, please consider the community version Vue Macros.

sxzz avatar Jan 26 '23 08:01 sxzz