Skip to content

Commit

Permalink
Fix error position when using invalid nodes in jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Jun 28, 2018
1 parent 98233c3 commit d173de0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lib/react/ReactMacro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ class ReactMacro
//TODO: consider giving warnings for isolated `&`
return result;
}

static public function toFieldExpr(sl:Array<String>, pos:Position = null):Expr {
if (pos == null) pos = Context.currentPos();
return Lambda.fold(
sl,
function(s, e) {
return e == null
? (macro @:pos(pos) $i{s})
: (macro @:pos(pos) $e.$s);
},
null
);
}

static function children(c:tink.hxx.Children) {
var exprs = switch c {
case null | { value: null }: [];
Expand Down Expand Up @@ -148,7 +162,7 @@ class ReactMacro
case [tag] if (tag.charAt(0) == tag.charAt(0).toLowerCase()):
macro @:pos(n.name.pos) $v{tag};
case parts:
macro @:pos(n.name.pos) $p{parts};
macro @:pos(n.name.pos) ${toFieldExpr(parts, n.name.pos)};
}

var isHtml = type.getString().isSuccess();//TODO: this is a little awkward
Expand Down

0 comments on commit d173de0

Please sign in to comment.