Class: JsxRosetta::IR::Component
- Inherits:
-
Data
- Object
- Data
- JsxRosetta::IR::Component
- 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.
module_imports : [ModuleImport] — top-level ‘import` declarations.
Backends thread the imported names into the
ExpressionTranslator so any expression-context
reference to an import (e.g. `styles.listContainer`
from `import styles from "./X.module.css"`, or
`AlertStatusEnum.Pending` from a TS enum import)
bails out to a TODO instead of snake-casing to a
bare identifier that NameErrors 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.
server_data_source : ServerDataSource | nil — capture of a
Next.js `getServerSideProps` / `getStaticProps`
export from the same source file as this component.
Body preserved verbatim so the Phlex backend can
emit it as a TODO comment block above the class
(the matching Rails controller action is where the
user ports the data-loading logic). Attached only
to the first component when a file contains
multiple — Next.js page files have exactly one
default-export component, so collisions are rare.
hoc_wrappers : [String] — Higher-Order Component wrapper names
that the lowering peeled off when finding this
component (e.g. `memo`, `forwardRef`, `observer`,
`connect`, `withRouter`). Recorded in
outside-in order so a `memo(forwardRef(...))`
emits as ["memo", "forwardRef"]. Backends surface
these as a TODO comment block above the class
explaining each wrapper's Rails analog (or
lack of one). Empty for components without
wrappers — the common case.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#hoc_wrappers ⇒ Object
readonly
Returns the value of attribute hoc_wrappers.
-
#local_binding_names ⇒ Object
readonly
Returns the value of attribute local_binding_names.
-
#local_bindings ⇒ Object
readonly
Returns the value of attribute local_bindings.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#module_bindings ⇒ Object
readonly
Returns the value of attribute module_bindings.
-
#module_imports ⇒ Object
readonly
Returns the value of attribute module_imports.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#props ⇒ Object
readonly
Returns the value of attribute props.
-
#react_hooks ⇒ Object
readonly
Returns the value of attribute react_hooks.
-
#render_methods ⇒ Object
readonly
Returns the value of attribute render_methods.
-
#rest_prop_name ⇒ Object
readonly
Returns the value of attribute rest_prop_name.
-
#server_data_source ⇒ Object
readonly
Returns the value of attribute server_data_source.
-
#stimulus_methods ⇒ Object
readonly
Returns the value of attribute stimulus_methods.
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def body @body end |
#hoc_wrappers ⇒ Object (readonly)
Returns the value of attribute hoc_wrappers
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def hoc_wrappers @hoc_wrappers end |
#local_binding_names ⇒ Object (readonly)
Returns the value of attribute local_binding_names
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def local_binding_names @local_binding_names end |
#local_bindings ⇒ Object (readonly)
Returns the value of attribute local_bindings
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def local_bindings @local_bindings end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def mode @mode end |
#module_bindings ⇒ Object (readonly)
Returns the value of attribute module_bindings
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def module_bindings @module_bindings end |
#module_imports ⇒ Object (readonly)
Returns the value of attribute module_imports
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def module_imports @module_imports end |
#name ⇒ Object (readonly)
Returns the value of attribute name
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def name @name end |
#props ⇒ Object (readonly)
Returns the value of attribute props
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def props @props end |
#react_hooks ⇒ Object (readonly)
Returns the value of attribute react_hooks
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def react_hooks @react_hooks end |
#render_methods ⇒ Object (readonly)
Returns the value of attribute render_methods
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def render_methods @render_methods end |
#rest_prop_name ⇒ Object (readonly)
Returns the value of attribute rest_prop_name
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def rest_prop_name @rest_prop_name end |
#server_data_source ⇒ Object (readonly)
Returns the value of attribute server_data_source
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def server_data_source @server_data_source end |
#stimulus_methods ⇒ Object (readonly)
Returns the value of attribute stimulus_methods
98 99 100 |
# File 'lib/jsx_rosetta/ir/types.rb', line 98 def stimulus_methods @stimulus_methods end |