Babel plugin that automatically adds displayName properties to React class components created with createClass
Overall
score
96%
Create a tiny transform utility that ensures legacy createClass-style components gain a meaningful displayName derived from their surrounding identifiers.
const Fancy = createReactClass({ render() { return null; } });), the transformed output includes a displayName entry of "Fancy" inserted as the first property. @testLibrary.Widget = createReactClass({ render() { return null; } });), the transform injects displayName: "Library.Widget" as the first property within the component object. @testconst registry = { Widget: createReactClass({ render() { return null; } }) };), the transform injects displayName: "Widget" as the first property inside that component object. @testdisplayName, the transform leaves that value unchanged and does not add another entry. @test@generates
/**
* Injects displayName into createClass-style React component definitions based on surrounding identifiers.
* @param {string} source JavaScript source containing createClass components.
* @param {string} [filename] Optional filename to support name inference for default exports.
* @returns {string} Transformed source with displayName added where missing.
*/
export function injectDisplayNames(source, filename);Provides display name injection for legacy React createClass patterns.
Install with Tessl CLI
npx tessl i tessl/npm-babel-plugin-transform-react-display-name