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

Update vue/no-expose-after-await rule to support <script setup> #1885

Merged
merged 7 commits into from May 12, 2022

Conversation

ota-meshi
Copy link
Member

close #1872

Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but very complicated 😲

I have two very minor suggestions.

lib/rules/no-expose-after-await.js Outdated Show resolved Hide resolved
lib/rules/no-expose-after-await.js Outdated Show resolved Hide resolved
ota-meshi and others added 4 commits May 12, 2022 06:41
Co-authored-by: Flo Edelmann <florian-edelmann@online.de>
Co-authored-by: Flo Edelmann <florian-edelmann@online.de>
@ota-meshi
Copy link
Member Author

Thank you for your review! I have merged your suggestions.
I also updated eslintrc to use arrow-body-style rule.
https://eslint.org/docs/rules/arrow-body-style

Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks for fixing the other rules, too :)

@ota-meshi ota-meshi merged commit 52accc9 into master May 12, 2022
@ota-meshi ota-meshi deleted the no-expose-after-await branch May 12, 2022 11:58
@cjpearson
Copy link
Contributor

Could a similar change be applied to no-lifecycle-after-await so it also supports script setup?

@FloEdelmann
Copy link
Member

Sounds like a valid improvement. Could you please open an issue for that? And maybe you'd like to implement that change? It should be quite similar to this PR.

@ota-meshi
Copy link
Member Author

No. Since the changes in Vue 3.2, there is no problem in doing it after await in script setup.

@cjpearson
Copy link
Contributor

@FloEdelmann Added #2291

@ota-meshi I'm using vue@3.3.4, but I still get the console warning Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement. at runtime when using onMounted after await. Is that something different?

@ota-meshi
Copy link
Member Author

ota-meshi commented Oct 5, 2023

You can check it on SFC Playground. You can see that the compilation result of await doSomething() looks like this:

;(
  ([__temp,__restore] = _withAsyncContext(() => doSomething())),
  await __temp,
  __restore()
)

__restore() should now allow you to use lifecycle methods and others then defineExpose. If it doesn't work, I think it's a bug in Vue.

SFC Playground:

https://play.vuejs.org/#eNqNUk1rwkAQ/SvLXkxAotabpEJbPLTQVqrHvYRkjGuT3WU/VJD8984kmlaopadk5r03vHmzJ/5gTLIPwGc8dbmVxjMHPpi5ULI22nr2pGvDNlbXbJCMqCD6QKh01PGRiYWH2lSZB6wYS1fBGVAO5ikJ5mmrw0/fJ3kv4UPuXa7VRpbJzmmFXk40RvAcZbIC+2681MoJPmMtQlhWVfrw0va8DTC89PMt5J+/9HfuSD3BlxYc2D0I3mM+syX4Dl6s3uCI/z1Y6yJUyP4D/ACnq0AeO9pjUAXa/sFr3T63iUpVrt3i6DGIy1JklJhNyxccE6bEbq3+bXeaTFudUA2meLnO7WOemFavOigPBWvOV+3OKVSPRFHM7ufIxZvgXpBUuowG9Vk2GcSsiUmQHTLpWaFXuga/xbWitv3POXf9nE1QOS15PQp1Fs1bxRQc2BKtSgcR3o5m4lprWYMOnjpDNhmPx3GMMdx8lZTN1asjAm++AK0DBNA=

@ota-meshi
Copy link
Member Author

Note that your own implementation of async setup(props) will not do this. This only applies to <script setup>.

@cjpearson
Copy link
Contributor

Ok, that's interesting. The warning I saw must be caused by something else then. Thank you for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disallow top-level await before defineExpose
3 participants