CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-acorn-jsx

JSX parsing plugin for the Acorn JavaScript parser that enables fast parsing of React JSX syntax

76

1.68x
Overview
Eval results
Files

task.mdevals/scenario-5/

JSX Parser Context Inspector

Build a tool that inspects the internal token contexts used by the JSX parser as it processes code.

Requirements

Create a function that:

  1. Accepts a string containing JSX code
  2. Parses the code using a JSX-capable parser
  3. Captures and reports the different token contexts used during parsing

Token contexts represent the internal state of the parser as it processes different syntactic elements. Your implementation should:

  • Access the parser's token context definitions
  • Track which contexts are active as parsing progresses
  • Report the names of contexts encountered (e.g., contexts for opening tags, closing tags, and element content)

Output Format

Return an array of objects with:

  • name: The identifier of the token context
  • description: A brief description of what the context is used for

Test Cases

Test: Identify available token contexts @test

When parsing JSX code "<Component />":

  • The tool should return an array of token context objects
  • The array should contain exactly 3 context definitions
  • Each context should have a name property (string) and a description property (string)

Test: Recognize all three context types @test

When parsing JSX code "<div>text</div>":

  • The returned array should include a context for opening tags
  • The returned array should include a context for closing tags
  • The returned array should include a context for content between tags
  • All three contexts should have distinct names

Implementation

@generates

API

/**
 * Inspects available token contexts from the JSX parser.
 *
 * @param {string} jsxCode - JSX code to trigger parser initialization
 * @returns {Array<{name: string, description: string}>} Array of token context definitions
 */
function getTokenContexts(jsxCode) {
  // IMPLEMENTATION HERE
}

module.exports = { getTokenContexts };

Dependencies { .dependencies }

acorn { .dependency }

Provides the core JavaScript parser.

acorn-jsx { .dependency }

Provides JSX parsing capabilities with token context management.

Install with Tessl CLI

npx tessl i tessl/npm-acorn-jsx

tile.json