Skip to content

Commit

Permalink
Don't inline extern React components and allow to specify @:reactCont…
Browse files Browse the repository at this point in the history
…ext to explicitly prevent inlining
  • Loading branch information
Philippe Elsass committed May 21, 2016
1 parent ec3e242 commit 5c397e5
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/lib/api/react/ReactMacro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class ReactMacro
var children = parseChildren(xml, pos);

// inline declaration or createElement?
var useLiteral = canUseLiteral(ref);
var useLiteral = canUseLiteral(type, ref);
if (useLiteral)
{
if (children.length > 0) attrs.push({field:'children', expr:macro $a{children}});
Expand Down Expand Up @@ -229,11 +229,24 @@ class ReactMacro
return macro (untyped $obj : api.react.ReactComponent);
}

static function canUseLiteral(ref:Expr)
static function canUseLiteral(type:Expr, ref:Expr)
{
#if (debug || react_no_inline)
return false;
#end

// extern classes or classes requiring React context should not be inlined
var t = Context.typeof(type);
switch(t) {
case TType(_, _):
switch (Context.follow(t)) {
case TAnonymous(_.get() => {status: AClassStatics(_.get() => c)}):
if (c.isExtern || c.meta.has(':reactContext')) return false;
default:
}
default:
}

if (ref == null) return true;

// only refs as functions are allowed in literals, strings require the full createElement context
Expand Down Expand Up @@ -397,7 +410,7 @@ class ReactMacro
{
if (field.field == 'ref') {
ref = field.expr;
if (!canUseLiteral(ref)) {
if (!canUseLiteral(type, ref)) {
deopt = true;
break;
}
Expand Down

0 comments on commit 5c397e5

Please sign in to comment.