-
Notifications
You must be signed in to change notification settings - Fork 38
Clean up Js.t object parsing, printing and converting #291
Conversation
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.
src/res_printer.ml
Outdated
|
||
(* object printings *) | ||
| Ptyp_object (fields, openFlag) -> | ||
printBsObjectSugar ~inline:false fields openFlag cmtTbl |
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.
Should we improve the name of this function?
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.
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 |
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.
The line break is shady.
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.
I think before that, it went into a branch where it saw an attribute right before a type constructor ( Edit: wait no that's not true, master printed any constructor on a new lineJs.t
), so formatted that Js.t
on the same line as the attribute, which then triggered the type constructor + object <{
hugging branch.
But I've already discovered an existing error! @foo Js.t<{"bar": baz}>
printing removes the @foo
.
Let's maybe also add a test for |
The removal of this printer logic fixes a bug where `type a = @b Js.t<{"a": b}>`, when printed, loses the attribute
* Upgrade syntax repo to d9c44bb22 rescript-lang/syntax@d9c44bb * napkin: revert the rest of upstream PR#291 (#61) rescript-lang/syntax#291
…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
Fixes #277
Fixes #263
Now that rescript-lang/rescript#4967 has landed:
{"foo": int}
as ocaml{. foo: int}
. Previously it parsed into ocaml{. foo: int} Js.t
Js.t
.Js.t
objects. cc @rickyvetter @ryyppy for ppx4.Js.t
part.Js.t({..}) as 'a
into{..} as 'a
from naturally forgetting to special-case that path. Now this bug is convenientlymade into a featureobsolete.