packages/ast/jsxScope
AST package: what a page component has in scope, and what a child component declares.
AST, v0.8. Source: packages/ast/jsxScope.mjs.
Functions#
collectComponentScopeNames()#
collectComponentScopeNames(
ast):string[]
Defined in: packages/ast/jsxScope.mjs:52
In-scope names of a page: every function's destructured/plain parameter names plus every
const [value, setValue] = useState(...) binding, in source order, de-duplicated.
Parameters#
ast
any
A parsed Program.
Returns#
string[]
The in-scope names, in source order, de-duplicated.
collectScopeDeclarations()#
collectScopeDeclarations(
ast):object[]
Defined in: packages/ast/jsxScope.mjs:246
Like collectComponentScopeNames, but keeps what each name is: {name, kind} with kind 'prop'
(a function parameter, destructured or plain), 'state' (a useState value) or 'setter' (its
setter). Same traversal order and de-duplication (first declaration wins) as the names-only variant.
Parameters#
ast
any
A parsed Program.
Returns#
object[]
What each in-scope name is.
declaredPropNames()#
declaredPropNames(
childSource,tagName,isDefault):any
Defined in: packages/ast/jsxScope.mjs:226
The declared prop names of the component tagName defined in childSource (imported by default or
by name): {closed, names, types}, or null when unknown (child doesn't parse, no matching export,
or its first parameter's shape isn't recognized) -- callers treat null as "don't filter". types is the same additive name -> type-text Map findTypeMembers returns, best-effort (empty
when no annotation is found on a plain destructured parameter).
Parameters#
childSource
string
Source of the child component's file.
tagName
string
Component name.
isDefault
boolean
Whether the component is the default export.
Returns#
any
{closed, names, types}: the declared props, or null when unknown.
findImportOfName()#
findImportOfName(
ast,localName):object
Defined in: packages/ast/jsxScope.mjs:76
How a module-level import binds localName: {source, isDefault}, or null if it isn't imported.
Parameters#
ast
any
A parsed Program.
localName
string
The local binding to look up.
Returns#
object
How it is imported, or null.
isDefault
isDefault:
boolean
source
source:
string
findTypeMembers()#
findTypeMembers(
source,typeName):any
Defined in: packages/ast/jsxScope.mjs:141
Member names of a TS interface / type-literal alias named typeName declared in source:
{closed: true, names, types}, {closed: false, names: empty, types: empty} if it has an index
signature (open -- can't enumerate), or null if not found. Uses the TypeScript compiler API, the
canonical parser for type syntax.
types is additive alongside names: a Map of member name -> its type annotation's exact
source text (e.g. 'string', '() => void'), present only for members that have one. Purely
syntactic (the annotation's own text, not a resolved/normalized type), deterministic, no LLM --
callers that only need names (the original, still-tested contract) can ignore it.
Parameters#
source
string
Source text containing the type.
typeName
string
Name of the interface or type alias.
Returns#
any
{closed, names, types}; closed: false for an open type; null when not found.