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] — calls to React hooks (useState,

useEffect, useRef, useContext, useMemo, useCallback,
useReducer, useImperativeHandle, useLayoutEffect).
Surfaced as a distinct TODO block so the human
reviewer knows to translate behavior to Stimulus
and state to server-side rendering.

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.

Instance Attribute Summary collapse

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



50
51
52
# File 'lib/jsx_rosetta/ir/types.rb', line 50

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



50
51
52
# File 'lib/jsx_rosetta/ir/types.rb', line 50

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



50
51
52
# File 'lib/jsx_rosetta/ir/types.rb', line 50

def local_bindings
  @local_bindings
end

#module_bindingsObject (readonly)

Returns the value of attribute module_bindings

Returns:

  • (Object)

    the current value of module_bindings



50
51
52
# File 'lib/jsx_rosetta/ir/types.rb', line 50

def module_bindings
  @module_bindings
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



50
51
52
# File 'lib/jsx_rosetta/ir/types.rb', line 50

def name
  @name
end

#propsObject (readonly)

Returns the value of attribute props

Returns:

  • (Object)

    the current value of props



50
51
52
# File 'lib/jsx_rosetta/ir/types.rb', line 50

def props
  @props
end

#react_hooksObject (readonly)

Returns the value of attribute react_hooks

Returns:

  • (Object)

    the current value of react_hooks



50
51
52
# File 'lib/jsx_rosetta/ir/types.rb', line 50

def react_hooks
  @react_hooks
end

#rest_prop_nameObject (readonly)

Returns the value of attribute rest_prop_name

Returns:

  • (Object)

    the current value of rest_prop_name



50
51
52
# File 'lib/jsx_rosetta/ir/types.rb', line 50

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



50
51
52
# File 'lib/jsx_rosetta/ir/types.rb', line 50

def stimulus_methods
  @stimulus_methods
end