Skip to content

Direct access to script setup variables where appropriate #3651

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

Closed
johnsoncodehk opened this issue Oct 11, 2023 · 2 comments
Closed

Direct access to script setup variables where appropriate #3651

johnsoncodehk opened this issue Oct 11, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@johnsoncodehk
Copy link
Member

johnsoncodehk commented Oct 11, 2023

The current virtual code always accesses variables through __VLS_ctx to obtain the unref type without breaking the template type narrowing.

The Vue SFC Compiler statically analyzes variables that are safe to access directly, but otherwise wrap unref. (We cannot use unref for virtual code because this breaks template type narrowing)

The way to reuse SFC Compiler analysis is to use require('@vue/compiler-sfc').compileScript.bindings, but this is not a suitable method for two reasons.

  1. compileScript does not support incremental updates. If you rely on this function, it will cause obvious delays in auto-complete on larger files.
  2. Introducing @vue/compiler-sfc will cause the package size to increase.

To solve it, we need to port SFC Compiler's analysis to our parseScriptSetupRanges(), but we don't need the complete logic (SFC Compiler thinks a lot to ensure runtime safety), just implement a simplified version.

This will resolve #2377 (comment), #3409

@johnsoncodehk
Copy link
Member Author

#2377 has been supported via 6943743.

@johnsoncodehk
Copy link
Member Author

#3409 has been supported via d0ed952.

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

Successfully merging a pull request may close this issue.

1 participant