rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Make usage of `_` in object keys consistent between external and JSX

Open alex35mil opened this issue 5 years ago • 5 comments

JSX:

<button type_="button" />

Compiles to:

var React = require("react");

React.createElement("button", {
      type: "button"
    });

external:

type t;

[@bs.obj] external make: (~_type: string) => t = "";

let x = make(~_type="x");

Compiles to:

var x = {
  type: "x"
};

But when bindings to React components meet external, it's required to use prefix form:

module X = {
  [@react.component] [@bs.module "x"]
  external make: (~_type: string) => React.element = "X";
};

So on the call site it's:

<button type_="button" />
<X _type="x" />

alex35mil avatar May 05 '20 11:05 alex35mil

Is this your desired behavior or current behavior? It is a bit strange to me where such name mangling happens

JSX:

<button type_="button" />

Compiles to:

var React = require("react");

React.createElement("button", {
      type: "button"
    });

bobzhang avatar May 05 '20 14:05 bobzhang

This is the current behavior.

The desired one is:

type t;

[@bs.obj] external make: (~type_: string) => t = "";

let x = make(~type_="x");

Would compile to:

var x = {
  type: "x"
};

alex35mil avatar May 05 '20 14:05 alex35mil

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 26 '22 02:04 stale[bot]

Not stale.

alex35mil avatar Apr 26 '22 06:04 alex35mil

The issue is solved.

DZakh avatar Aug 19 '23 07:08 DZakh