-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use tink_hxx for parsing #95
Conversation
Legendary! Can I complain about the lack on code style consistency? You have a cool style but it's a bit out of place :) |
I don't mind your complaints, but what would help the most would be if you went ahead and squeezed it into the shape that pleases you the most. If I do it, neither of the both of us will be really happy with the result :D |
Now that's awesome 🎉 Would it be possible to handle Edit:
|
Sure. What's that supposed to do though? Maybe it'd be best to add a test for that. |
Those are the same in current jsx:
|
Ok. I'll have to alter the parser to accept that syntax. Out of curiosity: could you explain why it exists though? I get the point of |
Got it working for my current project; I had to:
Overall that's impressive that I had to change so few to make my project work with a complete jsx rewrite. Even more impressive is that most of it is due to the syntax I used, which -I guess- is not the most widely used since it's the less jsx-like one. I think the new syntax is better (closer to actual jsx, and that's a good thing if we want to convert some reactjs developers to haxe), but it's a breaking change for some. Maybe adding support for this syntax under a compilation flag (yeah, I know..) for those that used it would allow for more retro compatibility while defining the "default" syntax of haxe-react jsx as close as reactjs jsx as possible? Or just drop it and bump a major version with a breaking change :) This syntax came from standard haxe interpolation, which accepts both |
The point of the It'd be amazing to add support for it, but by all mean, you can enable it only with a compiler flag. (hum, that's what Rudy said with more words :)) |
Hi guys! It might be completely out of the current subject but do you think we could have conditional compilation instructions support right into jsx :p?
Yhea... My wishes have no limit ^^... |
Thinking about it, there is also this which is allowed in normal JSX (ES6) and which is quite useful:
Do you think we could/should do that ? |
@zabojad that particular syntax for conditional rendering won't work, because it requires the parser to be reentrant, which is really tricky. However, tink_hxx can parse if statements (although that's disabled in this PR), so you can write: <if {someCondition}>
<span>loading...</span>
</if> As for conditional compilation, it probably could be done too, but I'll have to think about it. |
@back2dos hey nice feedback! I was more expecting a "naaa, that won't be possible" ^^... Just for the sake of not moving too far away from the "original" JSX syntax, do you think we could keep the If not, it's not a big deal, I'm just trying to make the transition from ES6-react to haxe-react the smoother as it can be for new developers to come onboard... |
|
@kLabz agreed but that would easily translate to:
That's more a js vs haxe-js difference... |
Bringing JS truthiness to Haxe wouldn't be hard. As opposed to that, having tags within expressions requires parser reentrancy and I have tried for almost two weeks to get that right, and once it started working decently, I realized that there's no way to get completion. So for the time being, I don't see that happening. |
I'm not sure we need js truthiness in haxe... OK for the parser reentrancy issue. It's already nice if we can have if statements in the JSX. I was just worrying about Thanks for this very nice peace of work @back2dos ! |
Another change (for the best, imo) is that this allows attributes without values, such as |
@back2dos, is it possible to implement go to definition functionality without typing ' $' before component? It also would be great to have component auto import feature. |
@djaonourside I would think so, but there's nothing we can do about it from this libraries's side. The code the macro generates tracks positions accurately. It comes down to the IDE to support that. IntelliJ for example implements all Haxe support separately, so it will have to replicate all this logic. VSCode could support jumping to definition, but the plugin would have to understand that the opening tag is actually to be treated as expression (interestingly it even fails with |
Hmm, IIRC for the VS Code extension we just ask the position from the compiler without doing any magic, so in theory it should work as long as the expression under the cursor is sensible for "go-to definition" (e.g. a field, local var, |
@nadako |
var fields = [ | ||
{field: "@$__hx__$$typeof", expr: macro untyped __js__("$$tre")}, | ||
var fields:Array<ObjectField> = [ | ||
{field: #if (haxe_ver < 4) "@$__hx__$$typeof" #else "$$typeof", quotes: DoubleQuotes #end, expr: macro untyped __js__("$$tre")}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be quotes: Quoted
instead?
HaxeFoundation/haxe@b6e5d66
Please rebase - unit tests have been fixed (get latest munit), Travis CI set up. |
PS: what is about "FD doesn't play well with macros"? Things have improved on that front a little while go, like addition of compiler-based code navigation. |
Hey there! I just would like to revive this PR as it represents some very nice enhancement to the library... Is there any chance we'll get something merged soon :)? |
I'll go ahead and close this to keep my backlog small. It's on react-next and if the two projects are ever merged, I suppose that will also render this PR obsolete ;) |
This replaces the parser and AST by the counterparts from tink_hxx, to get accurate position tracking.
Among other things, this deals with mismatched tags more gracefully and allows for autocompletion without
$
:I also added some rudimentary props checking for components (both functions and classes) and warnings for unknown entities:
There's no checking for spreads, nor for missing props (this could be improved to some degree) nor for plain HTML tags. The default generator in
tink_hxx
does the former two, but it requires some quite heavy macros.I suppose the sane thing to do would be to extract the hxx generator from
coconut.react
into a standalone thing, so that you can just usejsx
orhxx
inreact
projects, depending on your preferences/needs.As for prop checking HTML tags, I want to extract the DOM spec from
js-virtual-dom
, so that it can be used everywhere. I just have to determine how to deal with all of React's idiosyncrasies (synthetic events, camel case handlers, alteredonChange
semantics).Anyway, let me know what you guys think ;)