JSX parsing plugin for the Acorn JavaScript parser that enables fast parsing of React JSX syntax
76
Build a utility that analyzes JSX code to extract and report on spread attributes usage.
Your task is to create a tool that parses JSX source code and identifies all spread attributes ({...expression}) used in JSX elements. The tool should extract the spread expressions and report their positions and the elements they appear in.
The tool should accept a string containing JSX source code.
The tool should return an array of objects, where each object contains:
elementName: The name of the JSX element containing the spread attribute (string)spreadExpression: The expression inside the spread (string, without the {...} wrapper)line: The line number where the spread attribute appears (number)<div {...props} />, it returns an array with one entry containing elementName "div", spreadExpression "props", and the line number @test<Component {...config} className="test" />, it correctly identifies the spread attribute before the regular attribute @test<div {...a} {...b} />, it returns two separate entries for both spread attributes @test<outer><inner {...props} /></outer>, it correctly identifies the spread in the inner element @test@generates
/**
* Analyzes JSX code to find all spread attributes
*
* @param {string} jsxCode - The JSX source code to analyze
* @returns {Array<{elementName: string, spreadExpression: string, line: number}>} Array of spread attribute information
*/
function analyzeSpreadAttributes(jsxCode) {
// Implementation here
}
module.exports = { analyzeSpreadAttributes };Provides JSX parsing support for generating ASTs from JSX code.
Install with Tessl CLI
npx tessl i tessl/npm-acorn-jsxdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10