From d173de051a0022e311713587731b0698870822d8 Mon Sep 17 00:00:00 2001 From: k Date: Thu, 28 Jun 2018 09:48:56 +0200 Subject: [PATCH] Fix error position when using invalid nodes in jsx --- src/lib/react/ReactMacro.hx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib/react/ReactMacro.hx b/src/lib/react/ReactMacro.hx index 8067641..0d20872 100644 --- a/src/lib/react/ReactMacro.hx +++ b/src/lib/react/ReactMacro.hx @@ -78,6 +78,20 @@ class ReactMacro //TODO: consider giving warnings for isolated `&` return result; } + + static public function toFieldExpr(sl:Array, 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 }: []; @@ -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