Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Clean up Js.t object parsing, printing and converting #291

Merged
merged 3 commits into from
Feb 27, 2021

Conversation

chenglou
Copy link
Member

Fixes #277
Fixes #263

Now that rescript-lang/rescript#4967 has landed:

  • Parse {"foo": int} as ocaml {. foo: int}. Previously it parsed into ocaml {. foo: int} Js.t
  • Remove a tiny printing optimizations for Js.t.
  • For React's PPX 3, generate objects directly instead of Js.t objects. cc @rickyvetter @ryyppy for ppx4.
  • The re->res converter automatically removes the Js.t part.
  • Said converter has a bug (Fix conversion of Js.t containing an alias core type #263) that converts Js.t({..}) as 'a into {..} as 'a from naturally forgetting to special-case that path. Now this bug is conveniently made into a feature obsolete.

Fixes rescript-lang#277
Fixes rescript-lang#263

Now that rescript-lang/rescript#4967 has landed:
- Parse `{"foo": int}` as ocaml `{. foo: int}`. Previously it parsed into ocaml `{. foo: int} Js.t`
- Remove a tiny printing optimizations for `Js.t`.
- For React's PPX 3, generate objects directly instead of `Js.t` objects. cc @rickyvetter @ryyppy for ppx4.
- The re->res converter automatically removes the `Js.t` part.
- Said converter has a bug (rescript-lang#263) that converts `Js.t({..}) as 'a` into `{..} as 'a` from naturally forgetting to special-case that path. Now this bug is conveniently ~~made into a feature~~ obsolete.

(* object printings *)
| Ptyp_object (fields, openFlag) ->
printBsObjectSugar ~inline:false fields openFlag cmtTbl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we improve the name of this function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking of unifying this with record printing, which we can discuss later. I'll do this now.

@@ -327,7 +327,8 @@ external test: (
foo,
bar,
baz,
) => @attr {..
) => @attr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line break is shady.

Copy link
Member Author

@chenglou chenglou Feb 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think before that, it went into a branch where it saw an attribute right before a type constructor (Js.t), so formatted that Js.t on the same line as the attribute, which then triggered the type constructor + object <{ hugging branch. Edit: wait no that's not true, master printed any constructor on a new line

But I've already discovered an existing error! @foo Js.t<{"bar": baz}> printing removes the @foo.

@IwanKaramazow
Copy link
Contributor

Let's maybe also add a test for Js.nullable(Js.t({..} as 'a)) conversion.

The removal of this printer logic fixes a bug where `type a = @b Js.t<{"a": b}>`, when printed, loses the attribute
@chenglou chenglou merged commit 7ff315d into rescript-lang:master Feb 27, 2021
@chenglou chenglou deleted the jst branch February 27, 2021 16:55
chenglou added a commit to chenglou/syntax that referenced this pull request Mar 8, 2021
chenglou added a commit that referenced this pull request Mar 8, 2021
anmonteiro added a commit to melange-re/melange that referenced this pull request Mar 25, 2021
anmonteiro added a commit to melange-re/melange that referenced this pull request Mar 26, 2021
anmonteiro added a commit to melange-re/melange that referenced this pull request Oct 30, 2021
anmonteiro added a commit to melange-re/melange that referenced this pull request Oct 30, 2021
* Upgrade syntax repo to d9c44bb22

rescript-lang/syntax@d9c44bb

* napkin: revert the rest of upstream PR#291 (#61)

rescript-lang/syntax#291
anmonteiro added a commit to melange-re/melange that referenced this pull request Feb 18, 2022
anmonteiro added a commit to melange-re/melange that referenced this pull request Feb 18, 2022
…69c73 (#241)

* Revert "Upgrade (ReScript) syntax repo to d9c44bb22 (#214)"

This reverts commit 7701ced.

* upgrade to b06dfa8fc6da202318bedaed66fb45a7fab69c73

* napkin: revert the rest of upstream PR#291 (#61)

rescript-lang/syntax#291

* Ignore some test files for now while we can't upgrade rescript
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clean up object types handling Fix conversion of Js.t containing an alias core type
2 participants