Skip to content

RFC: Patterned Templates#823

Draft
ubugeeei wants to merge 1 commit intovuejs:masterfrom
ubugeeei-forks:patterned-template
Draft

RFC: Patterned Templates#823
ubugeeei wants to merge 1 commit intovuejs:masterfrom
ubugeeei-forks:patterned-template

Conversation

@ubugeeei
Copy link
Copy Markdown
Member

@ubugeeei ubugeeei commented Mar 5, 2026

WIP

@posva
Copy link
Copy Markdown
Member

posva commented Mar 5, 2026

I think this is useful and should come at no cost of learning if it follows closely the existing syntax of JS:

  • not mix switch, case, default with pattern matching
  • wait for pattern matching to be stage 3 and adopt v-match, v-when, etc

I remember this was proposed in the back in vuejs/vue, it might be worth checking the existing issues/discussions on it if you haven't already

@ubugeeei
Copy link
Copy Markdown
Member Author

ubugeeei commented Mar 5, 2026

tonaly agree!

@jods4
Copy link
Copy Markdown

jods4 commented Mar 5, 2026

It would be nice to lay out the interaction with other DOM-controlling directives, like v-for but mostly v-if.

Is it ok to put v-case and v-if on same element? If so I assume "case" has precedence and "if" applies next.
The general layout may become muddy, though, once v-else enters the room:

<!-- is this allowed? -->
<template v-match>
  <div v-case v-if />
  <div v-else>Still in first case?</div>
  <div v-case />
  <div v-case />
</template>

<!-- if not then this is they way I guess? -->
<template v-match>
  <template v-case>
      <div v-if />
      <div v-else>Still in first case?</div>
  </template>
  <div v-case />
  <div v-case />
</template>

I assume all tags inside the v-match MUST have a v-case and no text node is allowed?
Or can static content be mixed freely between cases?

@ubugeeei
Copy link
Copy Markdown
Member Author

ubugeeei commented Mar 5, 2026

no text node is allowed?

probably like:

<template v-case>Text</template>

@ubugeeei ubugeeei changed the title feat: patterned templates Patterned Templates Mar 7, 2026
@ubugeeei ubugeeei changed the title Patterned Templates RFC: Patterned Templates Mar 7, 2026
mizchi added a commit to mizchi/vapor-moon that referenced this pull request Mar 26, 2026
…dapted for MoonBit)

Implement patterned templates inspired by Vue RFC #823, generating native
MoonBit match expressions instead of equality comparisons.

Supports:
- String literal matching: v-case='"loading"'
- Enum pattern matching: v-case='Ok(data)' with variable binding
- Wildcard/default: v-case='_' or v-case.default
- Nested match expressions

Validation:
- v-case must be direct child of v-match element
- At most one v-case.default per v-match
- v-match must have at least one v-case child
- Non-v-case elements inside v-match are rejected

Codegen generates MoonBit match expressions for both client (DOM) and
server (SSR) targets.

Refs: vuejs/rfcs#823

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

3 participants