feat(reactivity-transform): use toRef() for $() destructure codegen
- now supports destructuring reactive objects - no longer supports rest elements
This commit is contained in:
@@ -55,13 +55,12 @@ exports[`accessing ref binding 1`] = `
|
||||
`;
|
||||
|
||||
exports[`array destructure 1`] = `
|
||||
"import { ref as _ref, shallowRef as _shallowRef } from 'vue'
|
||||
"import { ref as _ref, toRef as _toRef } from 'vue'
|
||||
|
||||
let n = _ref(1), [__a, __b = 1, ...__c] = (useFoo())
|
||||
const a = _shallowRef(__a);
|
||||
const b = _shallowRef(__b);
|
||||
const c = _shallowRef(__c);
|
||||
console.log(n.value, a.value, b.value, c.value)
|
||||
let n = _ref(1), __$temp_1 = (useFoo()),
|
||||
a = _toRef(__$temp_1, 0),
|
||||
b = _toRef(__$temp_1, 1, 1)
|
||||
console.log(n.value, a.value, b.value)
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -114,13 +113,13 @@ exports[`mutating ref binding 1`] = `
|
||||
`;
|
||||
|
||||
exports[`nested destructure 1`] = `
|
||||
"import { shallowRef as _shallowRef } from 'vue'
|
||||
"import { toRef as _toRef } from 'vue'
|
||||
|
||||
let [{ a: { b: __b }}] = (useFoo())
|
||||
const b = _shallowRef(__b);
|
||||
let { c: [__d, __e] } = (useBar())
|
||||
const d = _shallowRef(__d);
|
||||
const e = _shallowRef(__e);
|
||||
let __$temp_1 = (useFoo()),
|
||||
b = _toRef(__$temp_1[0].a, 'b')
|
||||
let __$temp_2 = (useBar()),
|
||||
d = _toRef(__$temp_2.c, 0),
|
||||
e = _toRef(__$temp_2.c, 1)
|
||||
console.log(b.value, d.value, e.value)
|
||||
"
|
||||
`;
|
||||
@@ -163,20 +162,29 @@ exports[`nested scopes 1`] = `
|
||||
`;
|
||||
|
||||
exports[`object destructure 1`] = `
|
||||
"import { ref as _ref, shallowRef as _shallowRef } from 'vue'
|
||||
"import { ref as _ref, toRef as _toRef } from 'vue'
|
||||
|
||||
let n = _ref(1), { a: __a, b: __c, d: __d = 1, e: __f = 2, ...__g } = (useFoo())
|
||||
const a = _shallowRef(__a);
|
||||
const c = _shallowRef(__c);
|
||||
const d = _shallowRef(__d);
|
||||
const f = _shallowRef(__f);
|
||||
const g = _shallowRef(__g);
|
||||
let { foo: __foo } = (useSomthing(() => 1));
|
||||
const foo = _shallowRef(__foo);
|
||||
console.log(n.value, a.value, c.value, d.value, f.value, g.value, foo.value)
|
||||
let n = _ref(1), __$temp_1 = (useFoo()),
|
||||
a = _toRef(__$temp_1, 'a'),
|
||||
c = _toRef(__$temp_1, 'b'),
|
||||
d = _toRef(__$temp_1, 'd', 1),
|
||||
f = _toRef(__$temp_1, 'e', 2),
|
||||
h = _toRef(__$temp_1, g)
|
||||
let __$temp_2 = (useSomthing(() => 1)),
|
||||
foo = _toRef(__$temp_2, 'foo');
|
||||
console.log(n.value, a.value, c.value, d.value, f.value, h.value, foo.value)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`object destructure w/ mid-path default values 1`] = `
|
||||
"import { toRef as _toRef } from 'vue'
|
||||
|
||||
const __$temp_1 = (useFoo()),
|
||||
b = _toRef((__$temp_1.a || { b: 123 }), 'b')
|
||||
console.log(b.value)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`should not rewrite scope variable 1`] = `
|
||||
"import { ref as _ref } from 'vue'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user