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

Compile module Text to another thing than $$Text

Open florentbarriol opened this issue 4 years ago • 2 comments

After posting on the forum, I create this issue to have a better compilation for module like "Text" or "String" or "Boolean" to better version than $$Text See more info here : https://forum.rescript-lang.org/t/why-text-is-compiled-to-text/2453

florentbarriol avatar Sep 29 '21 10:09 florentbarriol

This should only be about when you're looking to use the value from something other than ReScript, right? So the problem is at the export boundary when the intention is to use the code from JS/TS.

zth avatar Jul 16 '23 10:07 zth

It is indeed a problem only when we want to use the code with JS/TS, This snippet

module TextComponent = {
  let make = () => React.string("text")
};

let \"Text" = TextComponent.make

transpile to

// Generated by ReScript, PLEASE EDIT WITH CARE


function make(param) {
  return "text";
}

var TextComponent = {
  make: make
};

var $$Text = make;

export {
  TextComponent ,
  $$Text ,
}
/* No side effect */

A better output could be:

// Generated by ReScript, PLEASE EDIT WITH CARE


function make(param) {
  return "text";
}

var TextComponent = {
  make: make
};

var $$Text = make;

export {
  TextComponent ,
  Text: $$Text ,
}
/* No side effect */

WhyThat avatar Sep 05 '23 10:09 WhyThat