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

<script setup> variables declared with destructure #24

Closed
yyx990803 opened this issue Nov 19, 2020 · 4 comments
Closed

<script setup> variables declared with destructure #24

yyx990803 opened this issue Nov 19, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@yyx990803
Copy link
Member

yyx990803 commented Nov 19, 2020

It seems <script setup> binding analysis is not accounting destructure patterns. This works:

<script setup>
const link = useEditLink()
const url = link.url
const text = link.text
</script>

This doesn't:

<script setup>
const { url, text } = useEditLink()
</script>
@johnsoncodehk
Copy link
Member

Thanks for the report! Fixed in 0.15.10. And also fix the array binding case:

<script setup>
const [item1, item2] = useArr()
</script>

<template>{{ item1 }} {{ item2 }}</template>

@yyx990803
Copy link
Member Author

That was fast! However, looking at the commit, not sure if the commit handles more complex destructure patterns:

const { url, text = 1, foo: [bar, ...baz], ...qux } = useEditLink()

Some relevant test cases in @vue/compiler-sfc that might help: https://github.com/vuejs/vue-next/blob/master/packages/compiler-sfc/__tests__/compileScript.spec.ts#L585-L658

@johnsoncodehk
Copy link
Member

I completely forgot about this...Thank you for the use case, very useful! I will fix it tomorrow.

@johnsoncodehk
Copy link
Member

fixed in 0.15.11, and now has been support type-only declarations for defineOptions().

@johnsoncodehk johnsoncodehk added the bug Something isn't working label Nov 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants