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

"'error' is not defined" when using try/catch in event handler #3064

Closed
trbrc opened this issue Jun 20, 2019 · 2 comments · Fixed by #3098
Closed

"'error' is not defined" when using try/catch in event handler #3064

trbrc opened this issue Jun 20, 2019 · 2 comments · Fixed by #3098
Labels

Comments

@trbrc
Copy link
Contributor

trbrc commented Jun 20, 2019

The compiler does not appear to understand that in try {...} catch (error) {...}, error declares a new variable. Instead, it complains that 'error' is not defined.

https://svelte.dev/repl/b630939cfcc243ce8d46bfe1218dcfb4?version=3.5.3

In creating the above reproduction, I noticed it also doesn't recognise the global Error in this context.

trbrc added a commit to trbrc/svelte-inspect that referenced this issue Jun 21, 2019
@Conduitry Conduitry added the bug label Jun 21, 2019
@Conduitry
Copy link
Member

Adding Error as a known global would just be a matter of adding it to the list in src/compiler/utils/names.ts. Teaching it about the variable declared by catch would probably be a little trickier, but hopefully not too hard, as it already knows about the variables declared via for statements for example.

Rich-Harris added a commit that referenced this issue Jun 25, 2019
add Error to known globals, declare catch block parameter
Rich-Harris added a commit that referenced this issue Jun 25, 2019
@Rich-Harris
Copy link
Member

Both fixed in 3.6.0

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

Successfully merging a pull request may close this issue.

3 participants