Skip to content

Commit d173de0

Browse files
committed
Fix error position when using invalid nodes in jsx
1 parent 98233c3 commit d173de0

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/lib/react/ReactMacro.hx

+15-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ class ReactMacro
7878
//TODO: consider giving warnings for isolated `&`
7979
return result;
8080
}
81+
82+
static public function toFieldExpr(sl:Array<String>, pos:Position = null):Expr {
83+
if (pos == null) pos = Context.currentPos();
84+
return Lambda.fold(
85+
sl,
86+
function(s, e) {
87+
return e == null
88+
? (macro @:pos(pos) $i{s})
89+
: (macro @:pos(pos) $e.$s);
90+
},
91+
null
92+
);
93+
}
94+
8195
static function children(c:tink.hxx.Children) {
8296
var exprs = switch c {
8397
case null | { value: null }: [];
@@ -148,7 +162,7 @@ class ReactMacro
148162
case [tag] if (tag.charAt(0) == tag.charAt(0).toLowerCase()):
149163
macro @:pos(n.name.pos) $v{tag};
150164
case parts:
151-
macro @:pos(n.name.pos) $p{parts};
165+
macro @:pos(n.name.pos) ${toFieldExpr(parts, n.name.pos)};
152166
}
153167

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

0 commit comments

Comments
 (0)