babel-jsx-utils (v1.1.0) is a utility library for resolving JSX attribute values at compile time using Babel. It statically evaluates attribute expressions in the local scope, handling variables, literals, and simple expressions but not function calls or props passed from parent components. This is primarily used in custom Babel plugins for static analysis or code transformations. Released infrequently, it is a lightweight alternative to more complex AST utilities. Key differentiator: focuses specifically on JSX attribute resolution with a simple API (getAttributeValues, getAttributeValue) and built-in error handling for unresolvable attributes.
npm install babel-jsx-utilsVerified import paths — ran on the pinned version, not inferred.
Shows how to parse JSX, traverse AST, and resolve attribute values using getAttributeValues.
Ensure attribute values are local literals, variables, or simple expressions (e.g., a + b). For dynamic props, consider runtime evaluation or a different approach.
Do not rely on spread attributes being included in the result; handle them separately.
Check for `true` explicitly or use TypeScript to handle the union type `T | true`.
Ensure the variable is defined in the same function scope and is a literal or simple expression. Alternatively, pass a custom onError callback to handle unresolved attributes.
Use correct named import: import { getAttributeValues } from 'babel-jsx-utils'Check import statement: use import { getAttributeValues } from 'babel-jsx-utils'No dependency data recorded yet.