Rescript-compiler: Refmt out of date? Removal of semicolon in ppx extension point nested in JSX

Created on 22 Feb 2019  路  6Comments  路  Source: rescript-lang/rescript-compiler

Since upgrading from 4.0.6 to the latest bs-platform (currently 4.0.18 installed), I'm seeing the following piece of code (which uses let-anything ppx), being formatted incorrectly with bsrefmt:

module Prop = {
  let let_ = (children, render) => children(render);
};

module Dummy = {
  type context = {locale: string};
  let use = children => <> {children({locale: "en-US"})} </>;
};

let component = ReasonReact.statelessComponent(__MODULE__);

let make = _children => {
  ...component,
  render: _ =>
    <div>
      {
        let%Prop {locale} = Dummy.use;

        <div> <p> {"Bob" |> ReasonReact.string} </p> </div>;
      }
    </div>,
};

Formattes into the following with syntax error due to missing semicolon after Dummy.use on line 16. Error: 1254: <syntax error> [18, 8]:

module Prop = {
  let let_ = (children, render) => children(render);
};

module Dummy = {
  type context = {locale: string};
  let use = children => <> {children({locale: "en-US"})} </>;
};

let component = ReasonReact.statelessComponent(__MODULE__);

let make = _children => {
  ...component,
  render: _ =>
    <div>
      {let%Prop {locale} = Dummy.use

       <div> <p> {"Bob" |> ReasonReact.string} </p> </div>}
    </div>,
};

I've checked out and built refmt from reason master (bspacks) and here it appears to format correctly.

Worth noting is that if render didn't have an outer react component, in this case <div> it would format correctly. So the issue is specifically within an expression of jsx.

HIGH

Most helpful comment

done in master

All 6 comments

cc @chenglou

Worth noting is that if render didn't have an outer react component, in this case <div> it would format correctly. So the issue is specifically within an expression of jsx.

There is also a case that can't be avoided by rearranging your code (at least I don't know how). It's when you using function-as-child:

let make = _children => {
  ...component,
  render: _self => {
    <Dummy>
      {state =>
         {
           let var = someFn(state);
           <div> var->ReasonReact.string </div>
         }
      }
    </Dummy>;
  },
};

Semicolon will be removed which will result in syntax error

AFAIK the fix landed in refmt master branch already, but there wasn't a release yet

hi @bloodyowl I am still waiting for reason folks to upstream. Will merge it as soon as a PR is sent

done in master

I just faced this issue with with bs-platform 5.0.1.

Is the jsx 2 version in this bs-platform release is synced correctly?
cc @rickyvetter

Edit: should be a refmt issue, not a reason-react or jsx thing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glennsl picture glennsl  路  3Comments

bobzhang picture bobzhang  路  3Comments

cknitt picture cknitt  路  5Comments

bobzhang picture bobzhang  路  4Comments

andares picture andares  路  5Comments