Skip to content

feat: add patterned template tooling (RFC 823) - #6207

Draft
ubugeeei wants to merge 5 commits into
vuejs:v3.4from
ubugeeei:feat/patterned-templates-reference
Draft

ubugeeei wants to merge 5 commits into
vuejs:v3.4from
ubugeeei:feat/patterned-templates-reference

Conversation

@ubugeeei

@ubugeeei ubugeeei commented Sep 16, 2026

Copy link
Copy Markdown
Member

Implement RFC 823 in template type checking, the language server and Vue syntax highlighting. Missing coverage is an error on the v-match subject and causes vue-tsc --noEmit to fail. Unreachable arms are warnings and do not change the CLI exit status.

The checker narrows each arm and subtracts the values covered by unguarded arms. It handles finite unions, nested object shapes, tuple combinations and array lengths. Optional property absence remains separate from present undefined; guards and union-typed runtime values do not prove coverage. Open or unresolved types require a catch-all. Bindings retain their narrowed types in guards, props, events and children.

Pattern helpers are ordinary TypeScript declarations under types/, referenced through the existing typesRoot mechanism only when a template uses v-match. They are checked with skipLibCheck: false. Generated templates contain pattern descriptors and helper references, without a copy of the type algorithm. Editor and CLI warnings reuse the active TypeScript Program.

Add hover, completion, definition, rename, directive completion, and TextMate scopes for patterns and guards.

This is a Draft reference implementation. The parser is mirrored until core #15531 is published. The CLI temporarily wraps Volar's program factory because it has no after-program hook; the wrapper is restored after runTsc. Companion documentation: docs #3465. This repository targets v3.4; the compiler PR targets minor.

Support v-match on the SFC top-level <template> with the same narrowing, coverage, and arm scopes. Header expressions retain their original locations for diagnostics, hover, completion, definition and rename. Header-only edits invalidate the template cache. Both default HTML and explicit lang="html" are tested. The top-level form in other template-language plugins remains unfinished.

Validation:

  • pnpm test: 360 passing tests, 4 existing skips across 52 files.
  • Build, lint and formatting checks.
  • Actual CLI subprocesses verify diagnostic locations and exit statuses; language-server tests verify hover, completion, definition, rename and diagnostics.
  • Type regressions cover imported generics, readonly rest bindings, optional properties, JavaScript inference, guards and missing tuple combinations.
  • 150 integration tests passed with the companion core compiler loaded.
  • Embedded grammar fixtures assert scopes and snapshots. Grammar URLs are pinned to the commit matching the existing checksums.

@ubugeeei ubugeeei changed the title feat: add RFC 823 patterned template reference tooling feat: add patterned template tooling (RFC 823) Sep 16, 2026
@ubugeeei

ubugeeei commented Sep 16, 2026

Copy link
Copy Markdown
Member Author

Draft reference implementation of RFC 823, paired with core #15531 and docs #3465.

At e68d41bfe, macOS, Windows and Linux CI pass. Locally, 360 tests pass with 4 existing skips; 150 companion-compiler tests pass.

Top-level SFC matches have the same narrowing, exhaustive coverage and lexical scopes as inner matches. Regressions cover default and explicit HTML, imported generics, mapped header diagnostics, hover/completion, definition/rename, and header-only edits. CLI tests still require missing coverage to fail and warnings alone to succeed. Other template-language plugins need follow-up integration for the top-level form.

Scope tests retain setup/prop/loop/slot shadowing, $event, duplicate declarations and navigation boundaries. Loop sources resolve before new loop bindings. The type algorithm remains an ordinary checked declaration in types/pattern-matching.d.ts, referenced through typesRoot; codegen/template/matchTypes.ts has been removed.

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.

1 participant