-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Regression: Variables exposed from <script> can't be used in defineProps #4644
Comments
According to: https://github.com/vuejs/rfcs/blob/master/active-rfcs/0040-script-setup.md
it seems to be a known behavior. |
The RFC specifies setup scope. My variables are defined in a regular script block so they're in module scope. (And as mentioned it used to work fine) |
<script>
export const bar = 14;
//const bar = 14;
export default {};
</script>
<script setup>
defineProps({
foo: {
type: Number,
default: _bar,
}
});
</script>
<template>
<h1>{{ foo }}</h1>
</template> would have worked and compiled to this without the compiler error./* Analyzed bindings: {
"foo": "props",
"bar": "setup-const"
} */
import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
export const bar = 14;
//const bar = 14;
const __default__ = {};
function setup(__props) {
return (_ctx, _cache) => {
return (_openBlock(), _createElementBlock("h1", null, _toDisplayString(__props.foo), 1 /* TEXT */))
}
}
const __sfc__ = /*#__PURE__*/ Object.assign(__default__, {
props: {
foo: {
type: Number,
default: bar,
}
},
setup
})
__sfc__.__file = "App.vue"
export default __sfc__ |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Version
3.2.12
Reproduction link
sfc.vuejs.org/
Steps to reproduce
Open the reproduction and observe the error. Switch to v3.2.11 and observe that it works. Then comment the exported variable and uncomment the non-exported variable. Observe that you now get an error in v3.2.11. Switch to v3.2.4 and observe that it works.
What is expected?
Variables defined in <script> should be usable in defineProps. They used to be.
What is actually happening?
You get an error. The error in the playground isn't actually that helpful, but when I reproduce this locally I get this error in the overlay:
"
defineProps()
in <script setup> cannot reference locally declared variables because it will be hoisted outside of the setup() function. If your component options requires initialization in the module scope, use a separate normal <script> to export the options instead."I believe these to be regressions from 872b3f7 and 8055445, as the non-exported variable works in defineProps until 3.2.5 and the exported one works until 3.2.12, which matches up perfectly with these fixes.
The text was updated successfully, but these errors were encountered: