Skip to content
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

Add JSX API #254

Merged
merged 28 commits into from
Feb 8, 2020
Merged

Add JSX API #254

merged 28 commits into from
Feb 8, 2020

Conversation

Drup
Copy link
Member

@Drup Drup commented Jan 28, 2020

Follow up of #247

cc @Khady @jorisgio @ulrikstrid

@Drup Drup force-pushed the jsx branch 2 times, most recently from 02c4e18 to 8c0aa70 Compare January 31, 2020 10:21
@Drup
Copy link
Member Author

Drup commented Jan 31, 2020

Alright, the tests finally pass.

  • The JSX doesn't depend on markup anymore. The common part of JSX and PPX are isolated in the tyxml-syntax package, and the parser-specific part is only in tyxml-ppx.
  • The JSX supports namespaces ... reasonably. It's not perfect yet, but at least it tries to guess the correct one. On top, you can know specify a namespace by prefixing: <Svg.Line> .... </Svg.Line>. The first letter is turned lowercase (apparently, it's not syntactically valid to put a lowercase there ....).
  • The list operator <> ..... </> is now recognized and supported
  • Wrapping is supported

Current issues:

  • All antiquotations must be single elements, unlike the PPX were they accept lists. List can only be spliced through the spread operator ...{foo}. Unfortunately, the spread operator is super limited in where you can put it, which makes it impossible to write several things that the PPX would accept. For instance [%html "<p>bar" elt1 "foo" elt2 "baz</p>"] should translate to <p> "bar" ...{elt1} "foo" ...{elt2} "baz" </p> which isn't allowed
  • The code transformation is currently global. I will add an attribute to turn it on/off, and I'm also considering accepting <Tyxml.element /> to locally enable tyxml's jsx.

@Drup
Copy link
Member Author

Drup commented Feb 4, 2020

I added the toggle. The syntax is [@@@tyxml.jsx bool] in ocaml, and [@tyxml.jsx bool]; in reason.

@Khady I'm highly tempted to change the antiquotes so that in <foo> "bar" other </foo>, other must be a list of elements instead of a single one. A single element would be inserted by ([other]) (which is kinda verbose), and hopefully at some point, we can make reason accept [other] (without parens).
This would be much more consistent with the ppx, and more expressive.

@Khady
Copy link
Contributor

Khady commented Feb 5, 2020 via email

@ulrikstrid
Copy link
Contributor

I think keeping somewhat close to the react ppx would be preferable. I would rather have to spread a list than always wrap things with lists.

@Drup
Copy link
Member Author

Drup commented Feb 5, 2020

My issue is that the spread operator is only available if it's the only child. You can't write <> "foo" ...bar </>.

@Drup
Copy link
Member Author

Drup commented Feb 8, 2020

Everything's green, let's merge the current version! I kept the antiquotations as before.

@Khady @ulrikstrid I'll let you test this for a week. If someone's motivated to write a reason-inclined documentation, I would appreciate it as well ^^'

@Drup Drup merged commit 6d385e3 into master Feb 8, 2020
@Drup Drup deleted the jsx branch February 13, 2020 13:12
Drup added a commit to Drup/opam-repository that referenced this pull request Mar 6, 2020
CHANGES:

* Add support for Reason's JSX syntax with a new `tyxml-jsx` package
  (ocsigen/tyxml#254 by Joris Giovannangeli and Gabriel Radanne
   with help from Ulrik Strid and Louis Roché)
* Modernize the handling of toplevel printers for utop.
  (Gabriel Radanne)

## Elements and attributes

* Add `allowfullscreen`, `allowpaymentrequest`, `referrerpolicy` attributes
  (ocsigen/tyxml#242 by Thibault Suzanne)
* Allow `crossorigin` attribute for script element
  (ocsigen/tyxml#243 by Thibault Suzanne)
* Greatly improved support of whitespaces in the PPX
  (ocsigen/tyxml#225 by Jules Aguillon)
* Add preliminary support for ARIA attributes
  (ocsigen/tyxml#253 by Stéphane Legrand and Gabriel Radanne)
* Add `template` element
  (ocsigen/tyxml#239 Stéphane Legrand)

* Several bug fixes for types and PPX
Drup added a commit to Drup/opam-repository that referenced this pull request Mar 6, 2020
CHANGES:

* Add support for Reason's JSX syntax with a new `tyxml-jsx` package
  (ocsigen/tyxml#254 by Joris Giovannangeli and Gabriel Radanne
   with help from Ulrik Strid and Louis Roché)
* Modernize the handling of toplevel printers for utop.
  (Gabriel Radanne)

## Elements and attributes

* Add `allowfullscreen`, `allowpaymentrequest`, `referrerpolicy` attributes
  (ocsigen/tyxml#242 by Thibault Suzanne)
* Allow `crossorigin` attribute for script element
  (ocsigen/tyxml#243 by Thibault Suzanne)
* Greatly improved support of whitespaces in the PPX
  (ocsigen/tyxml#225 by Jules Aguillon)
* Add preliminary support for ARIA attributes
  (ocsigen/tyxml#253 by Stéphane Legrand and Gabriel Radanne)
* Add `template` element
  (ocsigen/tyxml#239 Stéphane Legrand)

* Several bug fixes for types and PPX
Drup added a commit to Drup/opam-repository that referenced this pull request Mar 6, 2020
CHANGES:

* Add support for Reason's JSX syntax with a new `tyxml-jsx` package
  (ocsigen/tyxml#254 by Joris Giovannangeli and Gabriel Radanne
   with help from Ulrik Strid and Louis Roché)
* Modernize the handling of toplevel printers for utop.
  (Gabriel Radanne)

## Elements and attributes

* Add `allowfullscreen`, `allowpaymentrequest`, `referrerpolicy` attributes
  (ocsigen/tyxml#242 by Thibault Suzanne)
* Allow `crossorigin` attribute for script element
  (ocsigen/tyxml#243 by Thibault Suzanne)
* Greatly improved support of whitespaces in the PPX
  (ocsigen/tyxml#225 by Jules Aguillon)
* Add preliminary support for ARIA attributes
  (ocsigen/tyxml#253 by Stéphane Legrand and Gabriel Radanne)
* Add `template` element
  (ocsigen/tyxml#239 Stéphane Legrand)

* Several bug fixes for types and PPX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants