CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-plugin-transform-react-display-name

Babel plugin that automatically adds displayName properties to React class components created with createClass

Overall
score

96%

Overview
Eval results
Files

task.mdevals/scenario-5/

Legacy React Display Name Injection

Create a tiny transform utility that ensures legacy createClass-style components gain a meaningful displayName derived from their surrounding identifiers.

Capabilities

Names from variables

  • When a component is created via a createClass helper and assigned to a variable (for example, const Fancy = createReactClass({ render() { return null; } });), the transformed output includes a displayName entry of "Fancy" inserted as the first property. @test

Names from member assignments

  • When a createClass call is assigned to a member expression (for example, Library.Widget = createReactClass({ render() { return null; } });), the transform injects displayName: "Library.Widget" as the first property within the component object. @test

Names from object keys

  • When a createClass call is nested inside an object literal property (for example, const registry = { Widget: createReactClass({ render() { return null; } }) };), the transform injects displayName: "Widget" as the first property inside that component object. @test

Respects existing names

  • If a component object already defines displayName, the transform leaves that value unchanged and does not add another entry. @test

Implementation

@generates

API

/**
 * 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);

Dependencies { .dependencies }

babel-plugin-transform-react-display-name { .dependency }

Provides display name injection for legacy React createClass patterns.

Install with Tessl CLI

npx tessl i tessl/npm-babel-plugin-transform-react-display-name

tile.json