JavaScript: Add CaptureKind to template captures#7067
Draft
knutwannheden wants to merge 7 commits intomainfrom
Draft
JavaScript: Add CaptureKind to template captures#7067knutwannheden wants to merge 7 commits intomainfrom
CaptureKind to template captures#7067knutwannheden wants to merge 7 commits intomainfrom
Conversation
Add a CaptureKind enum (Expression, Identifier, TypeReference, Statement) and kind-specific factory functions (expr, ident, typeRef, stmt) as an alternative to the generic capture() function. Factory functions are also available as namespace-qualified methods on capture (e.g. capture.expr()). The existing capture() function defaults to CaptureKind.Expression for backwards compatibility. The kind is stored but not yet consumed by the engine — scaffold-aware placeholder generation will follow.
Replace generic capture() calls with expr(), ident(), and stmt() across all templating tests to document the semantic intent of each capture: - expr() for expression captures (operands, arguments, conditions) - ident() for identifier captures (function names, property names) - stmt() for statement captures (variadic statement bodies) Only basic.test.ts retains capture() since it tests the base function.
- Clarify namespace block is type-only declarations for TS augmentation - Eliminate duplicated logic in createKindCapture by delegating to capture() - Rename expr0 to parsed for consistency with other test files
CaptureKind to template captures
Remove CaptureKind from public exports and the kind option from CaptureOptions. The factory functions (expr, ident, typeRef, stmt) are the intended API for setting capture kinds; there is no need to expose the enum to callers.
Move the `type` option from CaptureOptions to a new ExprCaptureOptions interface only accepted by expr(). The template engine now skips preamble generation for non-expression captures (ident, typeRef, stmt), since type attribution declarations only make sense for expression placeholders.
Add non-variadic and variadic overload signatures to expr(), ident(),
typeRef(), and stmt() matching the existing capture() overloads. This
fixes TypeScript type inference for typed captures with constraints
(e.g. expr<J.Literal>({constraint: ...})) and variadic captures with
array operations (e.g. args[0], args.slice(1)).
npm run typecheck misses test file type errors because vitest types are not resolved by tsc alone. Note to prefer npm test as the final verification before pushing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CaptureKindenum (Expression,Identifier,TypeReference,Statement) to the JS templating engine, mirroring the C#CaptureKindadded in C#: AddCaptureKindto template captures for position-aware scaffolding #7059expr(),ident(),typeRef(),stmt()) as alternatives to the genericcapture(), available both as direct imports and namespace-qualified oncapture(e.g.capture.expr())capture()internally, so there is a single code path for name resolution and option handlingAPI
Note
The
CaptureKindmetadata is stored on captures but not yet consumed by the engine — scaffold-aware placeholder generation will follow once we have concrete recipes that need different scaffold wrapping.Test plan