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

Destructured props completely disappear (ReferenceError) after shadowing + try/catch in <script setup> #12938

Closed
arkandias opened this issue Feb 24, 2025 · 1 comment

Comments

@arkandias
Copy link

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

@edison1105
Copy link
Member

duplicate of #12790

@github-actions github-actions bot locked and limited conversation to collaborators Mar 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants