or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-5/

MDX Component Error Handler

Build a utility that evaluates MDX content and gracefully handles missing component references.

Requirements

Create a function that:

  1. Evaluates MDX source code with a given set of components
  2. Catches and reports errors when components are undefined
  3. Returns execution results or error information

Functionality

The evaluateMdx(source, components, options) function should:

  • Accept MDX source code as a string
  • Accept a components object containing available React components
  • Accept an options object with development (boolean) for enhanced error reporting
  • Return an object with:
    • success (boolean): Whether evaluation succeeded
    • error (string): Error message if a component is missing
    • result (object): The evaluated MDX module exports (on success)

Test Cases

  • Evaluating MDX with an undefined component <Alert /> returns an error indicating the missing component @test
  • Evaluating MDX with all required components provided returns the rendered result successfully @test
  • In development mode, errors include source location details @test
  • HTML elements like <div> work without being in the components object @test

Implementation

@generates

API

/**
 * Evaluates MDX content with provided components and handles errors
 *
 * @param {string} source - MDX source code to evaluate
 * @param {Object} components - Available React components
 * @param {Object} options - Evaluation options
 * @param {boolean} options.development - Enable development mode for enhanced errors
 * @returns {Promise<{success: boolean, error?: string, result?: Object}>}
 */
export async function evaluateMdx(source, components, options) {
  // Implementation here
}

Dependencies { .dependencies }

@mdx-js/mdx { .dependency }

Provides MDX compilation and component error handling support.