JSX parsing plugin for the Acorn JavaScript parser that enables fast parsing of React JSX syntax
76
Build a tool that parses JSX code and reports statistics about the custom JSX token types encountered during parsing.
Your tool should accept JSX source code as input and analyze the token types generated by the parser. The output should provide counts of each JSX-specific token type.
Implement a function analyzeJsxTokens(sourceCode) that:
The return value should be an object with the following structure:
{
jsxName: <number>, // Count of JSX name tokens
jsxText: <number>, // Count of JSX text tokens
jsxTagStart: <number>, // Count of JSX tag start tokens
jsxTagEnd: <number> // Count of JSX tag end tokens
}<div>Hello</div>, the function returns { jsxName: 2, jsxText: 1, jsxTagStart: 2, jsxTagEnd: 2 } @test<Component attr="value" />, the function returns { jsxName: 2, jsxText: 0, jsxTagStart: 1, jsxTagEnd: 1 } @test<Parent><Child /></Parent>, the function returns { jsxName: 3, jsxText: 0, jsxTagStart: 3, jsxTagEnd: 3 } @test@generates
/**
* Analyzes JSX source code and returns counts of each JSX-specific token type.
*
* @param {string} sourceCode - The JSX source code to analyze
* @returns {Object} An object with counts for jsxName, jsxText, jsxTagStart, and jsxTagEnd tokens
*/
function analyzeJsxTokens(sourceCode) {
// IMPLEMENTATION HERE
}
module.exports = { analyzeJsxTokens };JavaScript parser that provides the base parsing functionality.
JSX parsing plugin for Acorn that provides JSX-specific token types.
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