Module transform

Module transform 

Source
Expand description

TSX to JavaScript transformation logic

This module handles the transformation of TSX/JSX syntax to JavaScript using the Oxc compiler. It supports various JSX pragmas (engine, React-compatible) and handles component wrapping.

§Transformation Process

  1. Optionally wrap raw TSX in a component function
  2. Parse TSX into an AST using Oxc parser
  3. Build semantic information for better transformation
  4. Apply JSX transformations (convert to function calls)
  5. Generate JavaScript code with optional minification
  6. Clean up generated code (remove pure annotations)

§Error Handling

All transformation errors use MdxError for domain-specific error reporting.

Functions§

create_transform_options
Creates transformation options for JSX processing
transform_component_code
Intelligently transforms component code (detects if it’s raw JSX or a function)
transform_component_function
Transforms a full component function definition (already wrapped)
transform_tsx_to_js
Transforms TSX content to JavaScript using the default configuration
transform_tsx_to_js_for_output
Transforms TSX content to JavaScript for final output (uses h instead of engine.h)
transform_tsx_to_js_with_config
Transforms TSX content to JavaScript using the Oxc compiler
wrap_in_component
Wraps TSX content in a React component structure