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 extract and validate expression container attributes. The tool should parse JSX elements and identify attributes that use JavaScript expressions (e.g., onClick={handler}, style={styleObject}), then provide analysis about these expressions.
Provides JSX parsing capabilities for JavaScript code.
Your implementation should:
{})The input will be valid JavaScript code containing JSX elements.
Return a JSON object with the following structure:
{
"elements": [
{
"elementName": "Component",
"attributes": [
{
"name": "onClick",
"expressionType": "Identifier",
"expression": "handler"
}
]
}
]
}Input:
const element = <button onClick={handleClick} disabled={isDisabled}>Click me</button>;Expected output:
{
"elements": [
{
"elementName": "button",
"attributes": [
{
"name": "onClick",
"expressionType": "Identifier",
"expression": "handleClick"
},
{
"name": "disabled",
"expressionType": "Identifier",
"expression": "isDisabled"
}
]
}
]
}Input:
const component = <div style={theme.colors.primary} onClick={() => console.log('clicked')}>Content</div>;Expected output:
{
"elements": [
{
"elementName": "div",
"attributes": [
{
"name": "style",
"expressionType": "MemberExpression",
"expression": "theme.colors.primary"
},
{
"name": "onClick",
"expressionType": "ArrowFunctionExpression",
"expression": "() => console.log('clicked')"
}
]
}
]
}Input:
const element = <Component config={{enabled: true, count: 5}} />;Expected output:
{
"elements": [
{
"elementName": "Component",
"attributes": [
{
"name": "config",
"expressionType": "ObjectExpression",
"expression": "{enabled: true, count: 5}"
}
]
}
]
}Create a file parser.js that exports a function analyzeExpressionAttributes(code) which takes JSX code as a string and returns the analysis results as a JSON object.
Create a file parser.test.js that contains the test cases above.