Better output for Tagged Variants with non-inline record

オープン
#8,280 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
javascript, ocaml
領域
compilers

調査の方向性

Issue には再帰的な tagged-variant の例と、現在の JavaScript 出力および望ましい JavaScript 出力が示されています。まずその例を再現し、tagged-variant レコードを出力するコンパイラーパスを追跡してください。適用される tag/フィールド名と単一レコードの制約を明らかにし、そのうえで、その例が _0 ラッパーなしのフラット化されたフィールドを生成することを確認してください。

索引モデルが issue の本文から書いたものです。

説明

Inline records in Variant provide good JS output, which is especially useful for bindings. When combined with tagged variants, they also provide a better DX.

However, it’s not always possible to inline records (or spread them in the case of recursive types), so I’m wondering if it would be possible to improve the JS output in the case of tagged variants.

One possible constraint would be to verify that the tag does not conflict with any of the record fields. We could also keep the same constraint as inline records: only one record.

@tag("nodeType")
type rec node =
  | @as(1) Element(element)
  | @as(3) Text(text)
  | @as(9) Document(document)
and element = {
  childNodes: array<node>,
  ownerDocument: null<document>,
}
and text = {
  nextElementSibling: null<element>,
}
and document = {
  children: array<element>,
}

let anElement = Element({
  childNodes: [Text({nextElementSibling: Null.null})],
  ownerDocument: Null.null,
})

Current output:

let anElement = {
  nodeType: 1,
  _0: {
    childNodes: [{
        nodeType: 3,
        _0: {
          nextElementSibling: null
        }
      }],
    ownerDocument: null
  }
};

Wanted output:

let anElement = {
  nodeType: 1,
  childNodes: [{
    nodeType: 3,
    nextElementSibling: null
  }],
  ownerDocument: null
};
主要言語
OCaml
スター
7.5k
フォーク
485
平均マージ
1日 2時間
マージ済み PR(30日)
55

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rescript-lang/rescript のほかの issue

rescript-lang/rescript の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。