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-2/

React createClass Argument Validation

Create a small transform helper that processes JavaScript/TypeScript source strings containing React.createClass or createReactClass calls, injecting component displayName values only when the call receives exactly one object-literal argument.

Capabilities

Inject displayName for valid createClass

  • Given source containing const Widget = React.createClass({ render() { return null; } });, return code where the object literal starts with displayName: "Widget" while preserving the rest of the class definition. @test

Error on multiple arguments

  • When source contains a createClass call with more than one argument (e.g., React.createClass({}, {})), throw an error stating that the call must receive a single object-literal argument and include the filename in the message. @test

Error on non-object argument

  • When source contains a createClass call whose first argument is not an object literal (e.g., createReactClass(factoryFn())), throw an error explaining that the call must wrap a direct object literal. @test

Preserve declared displayName

  • If the class object already declares displayName, return code unchanged except for any formatting performed by the transform. @test

Implementation

@generates

API

export function transformCreateClass(sourceCode: string, filename?: string): string;

Dependencies { .dependencies }

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

Adds displayName support to createClass definitions and validates the argument shape.

Install with Tessl CLI

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

tile.json