Class: JsxRosetta::IR::Component

Inherits:
Data
  • Object
show all
Includes:
Node
Defined in:
lib/jsx_rosetta/ir/types.rb

Overview

A translated component definition. The root of a lowered IR tree.

name : String — component name as it appears in JSX (e.g. “Button”). props : [Prop] body : Node — usually an Element or Fragment. rest_prop_name : String | nil — name of a rest-destructured prop

(`function X({ a, ...rest })`). When non-nil, the
backend should generate a `**rest` initializer kwarg
and make it available via `@rest_prop_name`.

local_bindings : [LocalBinding] — non-JSX local ‘const` bindings inside

the component body. Backends typically render these as
a TODO comment block since arbitrary JS-to-Ruby
translation isn't attempted.

local_binding_names : [String] — flat list of all names bound by the

component body (destructure patterns, hook tuples,
ordinary const bindings). Backends pass this into the
ExpressionTranslator so an identifier reference like
`count` resolves to a `nil` placeholder instead of
a bare unresolved snake_case identifier that NameErrors
at render time. Includes hook destructures (e.g.
`open` and `setOpen` from `useState`) even though
those names don't appear in `local_bindings`.

stimulus_methods : [StimulusMethod] — event handlers extracted from

inline arrows / const-bound arrows used in onX={...}.
When non-empty, backends should emit a sibling
Stimulus controller file alongside the .rb/.erb pair.

react_hooks : [ReactHookCall] — every recognized hook invocation

in the component body, regardless of library.
Includes React's built-in hooks (useState, useEffect,
useRef, useContext, useMemo, useCallback, useReducer,
useImperativeHandle, useLayoutEffect), Apollo hooks
(useQuery, useMutation, useLazyQuery, useSubscription,
useApolloClient), and Next.js navigation hooks
(useRouter, usePathname, useSearchParams, useParams,
useSelectedLayoutSegment(s)). Each call carries a
`library` tag so backends can group them and emit a
library-specific TODO pointing at the right Rails
analog (Stimulus/server-render for React; controller
fetch for Apollo; request.path/params for Next.js).

module_bindings : [LocalBinding] — top-level ‘const`/`let` declarations

outside the component function that aren't themselves
components. Captured so backends can either translate
to Ruby constants (literal initializers) or surface
as a TODO comment block before the class definition.
Without this capture, references to module-level
constants from inside the JSX silently drop and
produce unbacked snake_case references at render time.

render_methods : [RenderMethod] — local arrow bindings that return JSX

and are invoked from the JSX body (`const renderHeader
= () => <div/>; ... {renderHeader()}`). Backends emit
each as a private method on the generated class and
reference it from a LocalRenderCall at the use site.

mode : Symbol — ‘:view` for a normal Phlex/ViewComponent component

whose body is rendered as JSX (the default); `:data_factory`
for column-descriptor / option-list modules whose top-level
export is a function returning an array of object literals.
When `:data_factory`, the backend emits a snake_case method
that returns the translated data, instead of `view_template`.
JSX inside object properties still extracts to private
methods on the class via the IR::Lambda path.

Instance Attribute Summary collapse

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



70
71
72
# File 'lib/jsx_rosetta/ir/types.rb', line 70

def body
  @body
end

#local_binding_namesObject (readonly)

Returns the value of attribute local_binding_names

Returns:

  • (Object)

    the current value of local_binding_names



70
71
72
# File 'lib/jsx_rosetta/ir/types.rb', line 70

def local_binding_names
  @local_binding_names
end

#local_bindingsObject (readonly)

Returns the value of attribute local_bindings

Returns:

  • (Object)

    the current value of local_bindings



70
71
72
# File 'lib/jsx_rosetta/ir/types.rb', line 70

def local_bindings
  @local_bindings
end

#modeObject (readonly)

Returns the value of attribute mode

Returns:

  • (Object)

    the current value of mode



70
71
72
# File 'lib/jsx_rosetta/ir/types.rb', line 70

def mode
  @mode
end

#module_bindingsObject (readonly)

Returns the value of attribute module_bindings

Returns:

  • (Object)

    the current value of module_bindings



70
71
72
# File 'lib/jsx_rosetta/ir/types.rb', line 70

def module_bindings
  @module_bindings
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



70
71
72
# File 'lib/jsx_rosetta/ir/types.rb', line 70

def name
  @name
end

#propsObject (readonly)

Returns the value of attribute props

Returns:

  • (Object)

    the current value of props



70
71
72
# File 'lib/jsx_rosetta/ir/types.rb', line 70

def props
  @props
end

#react_hooksObject (readonly)

Returns the value of attribute react_hooks

Returns:

  • (Object)

    the current value of react_hooks



70
71
72
# File 'lib/jsx_rosetta/ir/types.rb', line 70

def react_hooks
  @react_hooks
end

#render_methodsObject (readonly)

Returns the value of attribute render_methods

Returns:

  • (Object)

    the current value of render_methods



70
71
72
# File 'lib/jsx_rosetta/ir/types.rb', line 70

def render_methods
  @render_methods
end

#rest_prop_nameObject (readonly)

Returns the value of attribute rest_prop_name

Returns:

  • (Object)

    the current value of rest_prop_name



70
71
72
# File 'lib/jsx_rosetta/ir/types.rb', line 70

def rest_prop_name
  @rest_prop_name
end

#stimulus_methodsObject (readonly)

Returns the value of attribute stimulus_methods

Returns:

  • (Object)

    the current value of stimulus_methods



70
71
72
# File 'lib/jsx_rosetta/ir/types.rb', line 70

def stimulus_methods
  @stimulus_methods
end