Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent comments in @as attribute payload #6734

Open
cometkim opened this issue Apr 19, 2024 · 1 comment
Open

Persistent comments in @as attribute payload #6734

cometkim opened this issue Apr 19, 2024 · 1 comment

Comments

@cometkim
Copy link
Contributor

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

@cometkim
Copy link
Contributor Author

real-world usecases by myself

image

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant