feat(reactivity-transform): $$() escape for destructured prop bindings

This commit is contained in:
Evan You
2021-12-11 17:50:09 +08:00
parent 179fc05a84
commit 198ca14f19
4 changed files with 96 additions and 15 deletions

View File

@@ -145,6 +145,23 @@ describe('sfc props transform', () => {
})
})
test('$$() escape', () => {
const { content } = compile(`
<script setup>
const { foo, bar: baz } = defineProps(['foo'])
console.log($$(foo))
console.log($$(baz))
$$({ foo, baz })
</script>
`)
expect(content).toMatch(`const __props_foo = _toRef(__props, 'foo')`)
expect(content).toMatch(`const __props_bar = _toRef(__props, 'bar')`)
expect(content).toMatch(`console.log((__props_foo))`)
expect(content).toMatch(`console.log((__props_bar))`)
expect(content).toMatch(`({ foo: __props_foo, baz: __props_bar })`)
assertCode(content)
})
describe('errors', () => {
test('should error on deep destructure', () => {
expect(() =>