Closed as duplicate of#12790
Closed as duplicate of#12790
Description
Vue version
3.5.13
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-amw4dfwg
Steps to reproduce
<script setup lang="ts">
import { ref } from 'vue';
const { msg } = defineProps<{
msg: string;
}>();
console.log('FIRST LOG', msg);
const fun = () => {
const msg = null;
try {
console.log('');
} catch (e) {
console.log(e);
}
};
console.log('SECOND LOG', msg);
</script>
What is expected?
There should be no errors, and two log messages:
FIRST LOG HELLO WORLD!
SECOND LOG HELLO WORLD!
Note that shadowing the variable msg
in the function scope is valid JavaScript/TypeScript and should not affect the outer scope variable.
What is actually happening?
The first console.log
produces a log message as expected.
But the second one raises a ReferenceError, indicating that the variable msg
doesn't exist at all in the scope (not just undefined - the variable itself is missing):
HelloWorld.vue:17 Uncaught (in promise) ReferenceError: msg is not defined
at setup (HelloWorld.vue:17:36)
at callWithErrorHandling (vue.js?v=5b865bf9:2263:19)
at setupStatefulComponent (vue.js?v=5b865bf9:9983:25)
at setupComponent (vue.js?v=5b865bf9:9944:36)
at mountComponent (vue.js?v=5b865bf9:7300:7)
at processComponent (vue.js?v=5b865bf9:7266:9)
at patch (vue.js?v=5b865bf9:6782:11)
at ReactiveEffect.componentUpdateFn [as fn] (vue.js?v=5b865bf9:7490:9)
at ReactiveEffect.run (vue.js?v=5b865bf9:481:19)
at vue.js?v=5b865bf9:2591:25
Curiously, the error is not thrown if one removes the try/catch block in the function.
System Info
Any additional comments?
No response
Metadata
Metadata
Assignees
Labels
No labels