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

Lexical declarations as JSX code children #1387

Merged
merged 1 commit into from
Aug 31, 2024
Merged

Lexical declarations as JSX code children #1387

merged 1 commit into from
Aug 31, 2024

Conversation

edemaine
Copy link
Collaborator

One more idea from #561: This PR allows for lexical declarations as JSX code children (as braced expressions, > expressions, or automatic code children). In particular, this example now works:

<div>
  user := getUser()
  if user?
    {name} := user
    <h1> `Welcome ${name}!`
  <h2>Posts</h2>
  for post of posts
    <div .post> post.jsx()

Somewhat unusual for Civet is that the declaration is not treated as an expression, as that would cause it to render in the JSX, which seems rarely desired. Instead we automatically add ,void 0 at the end to prevent rendering and just do the assignment. The declaration itself gets lifted (though there's no way to preserve const semantics here).

@edemaine edemaine merged commit c5381bf into main Aug 31, 2024
4 checks passed
@edemaine edemaine deleted the jsx-declaration branch August 31, 2024 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants