Skip to content

Commit 98233c3

Browse files
committed
Debug: add warning if ReactComponent's render has no override
1 parent 4433389 commit 98233c3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/lib/react/ReactComponentMacro.hx

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class ReactComponentMacro {
1313
react.ReactTypeMacro.alterComponentSignatures,
1414
react.wrap.ReactWrapperMacro.buildComponent,
1515

16+
#if (debug && !react_ignore_empty_render)
17+
react.ReactTypeMacro.ensureRenderOverride,
18+
#end
19+
1620
#if (debug && react_render_warning)
1721
react.ReactDebugMacro.buildComponent,
1822
#end

src/lib/react/ReactTypeMacro.hx

+14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ class ReactTypeMacro
3535
return fields;
3636
}
3737

38+
public static function ensureRenderOverride(inClass:ClassType, fields:Array<Field>):Array<Field>
39+
{
40+
if (!inClass.isExtern)
41+
if (!Lambda.exists(fields, function(f) return f.name == 'render'))
42+
Context.warning(
43+
'Component ${inClass.name}: '
44+
+ 'No `render` method found: you may have forgotten to '
45+
+ 'override `render` from `ReactComponent`.',
46+
inClass.pos
47+
);
48+
49+
return fields;
50+
}
51+
3852
static function hasSetState(fields:Array<Field>) {
3953
for (field in fields)
4054
{

0 commit comments

Comments
 (0)