Persistent comments in `@as` attribute payload
In the compiler v10, since the variant outputs were an integer and were not able to customized, we added the original name as a comment as a hint. e.g.
type t =
| A
| B
| Unknown
let test = (t) => switch t {
| "A" => A
| "B" => B
| _ => Unknown
}
generated
function test(t) {
switch (t) {
case "A" :
return /* A */0;
case "B" :
return /* B */1;
default:
return /* Unknown */2;
}
}
I liked those little comments when debugging the output directly. But starting from v11 we no longer print comments on there.
Sometimes, I still make some integer variants for (size and perf) optimization, but the presence or absence of comments greatly affects my debugging experience.
So I suggest that any comments explicitly entered by the user are copied as-is to the output, so:
type t =
| @as(/* leading comment and some space between */ 0) A
| @as(1/*also trailing comment*/) B
| Unknown
will produce:
function test(t) {
switch (t) {
case "A" :
return /* leading comment and some space between */ 0;
case "B" :
return 1/*leading comment and some space between*/;
default:
return "Unknown";
}
}
That means it can be truly "customizable" output
real-world usecases by myself
Let's do support sourcemaps then this would be not needed much