Comments (5)
Could you describe what the the [@JSX]
rewriting does? Just so that I understand whether it is something that would make sense to support in ppxlib. I think I see what it does, however if my understanding is correct then there might be performance implications.
from ppxlib.
For example ppx-tea-jsx rewrites this:
([@JSX] div ~class_:"a b" ~children:[
([@JSX] span ~style:[("text-weight", "bold")] ~children:["foo"] ());
([@JSX] br ~children:[] ());
] ())
Into this:
div [class "a b"] [
span [style "text-weight" "bold"] [text "foo"];
br [];
]
My ppx rewrites this:
([@JSX] div ~class_:["a"; "b"] ~children:[
([@JSX] span ~style:"text-weight: bold" ~children:["foo"] ())
] ())
Into this:
div ~a:[a_class ["a"; "b"]] [
span ~a:[a_style "text-weight: bold"] [txt "foo"]
]
from ppxlib.
...Now that I think about it, it's not like this would net me a huge reduction in code size, since setting that up with Ast_traverse
is pretty easy. If you think there would be performance implications then maybe it doesn't make a lot of sense to support this.
from ppxlib.
The performance implication could be manageable actually. However, this code is a bit tedious and adding this feature wouldn't be super fun :/
Looking at the rewriting, it seems to me that a more idiomatic one would be to rewrite expressions of the form:
[%JSX div ~class_:"a b" ~children:[
span ~style:[("text-weight", "bold")] ~children:["foo"];
br ~children:[];
]
Indeed, while you are free to rewrite the input how you wish with a ppx rewriter, the generally accepted convention is that extension points are the right choice for interpreting DSLs.
Such rewritings are well supported by ppxlib.
from ppxlib.
I agree that using extension points would be better and more idiomatic; I don't really have a choice since the Reason parser only emits the attributes.
The original Reason code actually looks like this:
<div class="a b">
<span style=[("text-weight", "bold")]> "foo" </span>
<br />
</div>
Which is arguably nicer to read (if you're used to JSX from ReactJS) and plays nicer with Reason's formatter and all the tooling.
Yeah, now that I think about this isn't a great idea. Reason already does it but it's probably better to encourage people to use extension points for DSLs instead of this.
As for Reason in particular it would be easier to fix it upstream or make a wrapper library for JSX rewriters to remove all the boilerplate.
from ppxlib.
Related Issues (20)
- Performance analysis
- Server mode
- Reduce the number of AST traversals
- Reserving an attribute namespace with a dot has unexpected semantics
- Ppxlib’s behaviour in case of raised exception. HOT 2
- trunk-support does't build with ocaml-trunk HOT 10
- Fixpoint and monadic combinators for `Ast_pattern` HOT 1
- Attributes in `Ast_builder.Default` and `Ast_pattern` HOT 3
- The tests fail when using OCaml 5.1.1 HOT 7
- Add a driver mode with no output if there is no rewriting to do HOT 4
- Binary mode when writing to stdout on Windows HOT 7
- Unused-type declaration warning and bisect_ppx coverage points HOT 19
- ocaml.ppx.context's local_path format changes in OCaml 5.2 HOT 1
- Compiler error with OCaml 5.2.0 and an identity ppx HOT 3
- Remove Ppxlib's label exposed HOT 1
- Allow generation of type definitions using expression nodes HOT 1
- BUG: generating invalid ocaml syntax. HOT 2
- Generating recursive definitions with metaquot HOT 1
- Exp.fun_ appears to be unbound using ocaml 5.2 and ppxlib 0.32.1 HOT 5
- ppxlib and ocamlfind: looks like code_path is broken ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ppxlib.