Babel plugin that automatically adds displayName properties to React class components created with createClass
Overall
score
96%
Ensure default-exported React components receive a displayName derived from their file path.
displayName gains one matching the file stem (e.g., Card.js => "Card"). @testindex (e.g., components/index.jsx), the injected displayName matches the parent folder name. @testdisplayName, the transform leaves it unchanged even when the file or folder implies a different name. @test@generates
/**
* Adds displayName to default-exported React components based on the file path.
*
* @param {string} sourceCode - JavaScript/JSX source containing a default export.
* @param {string} filePath - Path to the source file (used to derive the displayName).
* @returns {string} Babel-transformed source with injected displayName when missing.
*/
export function addDisplayNamesForDefaultExport(sourceCode, filePath);Runs the transform pipeline for the provided source.
Injects React displayName values, including inferring a default export name from the file name and the parent directory when the file is named like index.js.
Install with Tessl CLI
npx tessl i tessl/npm-babel-plugin-transform-react-display-name