Class: JsxRosetta::IR::ModuleShapeClassifier
- Inherits:
-
Object
- Object
- JsxRosetta::IR::ModuleShapeClassifier
- Defined in:
- lib/jsx_rosetta/ir/module_shape_classifier.rb
Overview
Heuristic classifier that labels a module whose top-level shape isn’t a function component. Used by Lowering::no_component_error to produce triage-friendly messages explaining why a file didn’t translate. Pure function: program in, label symbol out — no mutable state, no relationship to the rest of the lowering pipeline.
Labels (in priority order — more specific shapes win):
:class_component `class X extends React.Component { ... }`
:hoc_wrapped `const X = React.memo(...)` etc.
:columns_data top-level array literal export
:hooks_only every export is a `use*` hook
:utils_only every export is a lowercase non-hook helper
:mixed_exports mixes hooks + non-hook lowercase exports
:side_effects_only top-level expression statements, no exports
:types_only types/constants only, no functions
:unknown no signal — caller emits the bare error
Constant Summary collapse
- EXPORT_TYPES =
%w[ExportNamedDeclaration ExportDefaultDeclaration].freeze
- HOC_NAMES =
%w[memo forwardRef lazy observer].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #classify ⇒ Object
-
#initialize(program) ⇒ ModuleShapeClassifier
constructor
A new instance of ModuleShapeClassifier.
Constructor Details
#initialize(program) ⇒ ModuleShapeClassifier
Returns a new instance of ModuleShapeClassifier.
32 33 34 |
# File 'lib/jsx_rosetta/ir/module_shape_classifier.rb', line 32 def initialize(program) @program = program end |
Class Method Details
.classify(program) ⇒ Object
28 29 30 |
# File 'lib/jsx_rosetta/ir/module_shape_classifier.rb', line 28 def self.classify(program) new(program).classify end |
Instance Method Details
#classify ⇒ Object
36 37 38 39 40 41 |
# File 'lib/jsx_rosetta/ir/module_shape_classifier.rb', line 36 def classify ast_shape = classify_ast_shape return ast_shape if ast_shape classify_by_export_names(top_level_export_names) end |