Skip to content

feat(rsc): expose server function metadata - #1258

Closed
james-elicx wants to merge 2 commits into
vitejs:mainfrom
james-elicx:codex/rsc-transform-function-metadata
Closed

feat(rsc): expose server function metadata#1258
james-elicx wants to merge 2 commits into
vitejs:mainfrom
james-elicx:codex/rsc-transform-function-metadata

Conversation

@james-elicx

Copy link
Copy Markdown
Contributor

Extracted from #1246.

Transform runtimes currently receive directive/export metadata but cannot tell whether an inline function captures bound values or inspect the declared parameter shape without reparsing source.

This adds hasBoundArgs and { count, hasRest } metadata for inline functions, plus parameter metadata for named, variable, local re-export, and default module exports. Focused tests cover closure captures and all supported export forms.

@hi-ogawa

hi-ogawa commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

The "runtime meta" now provides corresponding function ast node, so this should allow custom transform to make use of it instead of specific metadata hasBoundArgs/count/hasRest. Please check out the example here:

? transformWrapExport(code, ast, {
runtime: (value, name, meta) =>
runtime(value, name, getCacheWrapperOptions(meta)),

function getCacheWrapperOptions(
meta: Pick<ModuleExportMeta, 'valueNode'>,
): CacheWrapperOptions {
const node = meta.valueNode
if (
node?.type !== 'FunctionDeclaration' &&
node?.type !== 'FunctionExpression' &&
node?.type !== 'ArrowFunctionExpression'
) {
return {}
}
return node.params.at(-1)?.type === 'RestElement'
? {}
: { argumentCount: node.params.length }
}

Please let me know if something still requires from transform utility side.

@hi-ogawa hi-ogawa closed this Aug 6, 2026
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