tessl install tessl/npm-acorn-jsx@5.3.0JSX parsing plugin for the Acorn JavaScript parser that enables fast parsing of React JSX syntax
Agent Success
Agent success rate when using this tile
76%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.69x
Baseline
Agent success rate without this tile
45%
Build a tool that analyzes JSX code to determine the maximum nesting depth of JSX elements within JavaScript expressions.
JSX allows JavaScript expressions to be embedded within elements using curly braces {...}, and those expressions can themselves contain JSX elements. This creates the possibility of deeply nested structures like:
<div>
{condition ? <span>{<Component />}</span> : null}
</div>Your task is to create a parser that can analyze JSX code and report the maximum depth of this kind of nesting.
Create a module that exports a function analyzeJSXNesting(code) which:
maxDepth: The maximum nesting depth found (integer)locations: An array of objects describing each deeply nested location, where each object contains:
depth: The nesting depth at this locationline: The line number where the nested JSX startselementName: The name of the JSX element (e.g., "div", "Component")<div>hello</div>, returns {maxDepth: 0, locations: []} @test<div>{<span>nested</span>}</div>, returns {maxDepth: 1, locations: [{depth: 1, line: 1, elementName: "span"}]} @test<div>{condition ? <span>yes</span> : <span>no</span>}</div>, returns {maxDepth: 1, locations: [{depth: 1, line: 1, elementName: "span"}, {depth: 1, line: 1, elementName: "span"}]} @test<div>{<span>{<em>deep</em>}</span>}</div>, returns {maxDepth: 2, locations: [{depth: 1, line: 1, elementName: "span"}, {depth: 2, line: 1, elementName: "em"}]} @test@generates
/**
* Analyzes JSX code to find the maximum nesting depth of JSX elements within expressions.
*
* @param {string} code - The JSX code to analyze
* @returns {Object} Analysis results with maxDepth and locations properties
*/
function analyzeJSXNesting(code) {
// Implementation here
}
module.exports = { analyzeJSXNesting };Provides JavaScript parsing functionality.
@satisfied-by
Extends Acorn parser with JSX parsing support.
@satisfied-by