Printed @as names of fields and constructors turn non-ASCII letters into other characters

クローズ
#9,142 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #9143 @cknitt による — マージ済み

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
領域
compilers

調査の方向性

Start with Printtyp.tree_of_constructor and Res_outcome_printer, the two printer locations named in the issue, and compare their escaping with String_literal.encode_js_string, which is used for @tag names. Check how non-ASCII @as names appear in printed interfaces, errors, and hover; done means they preserve the original runtime names when read back. Linked pull request #9143 is already open.

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

説明

When a type declaration is printed (error messages, hover, createInterface), the @as names of record fields and variant constructors are escaped the OCaml way (%S in Printtyp.tree_of_constructor, String.escaped in Res_outcome_printer). Non-ASCII bytes become decimal escapes like \195\169, which ReScript reads back as different characters.

module Make = (X: {type t}) => {
  type record = {@as("prénom") name: X.t}
  type variant = | @as("é") E | @as("a\"b") Q
}

module Applied = Make({
  type t = string
})

createInterface prints the types of Applied through this printer:

module Applied: {
  type record = {@as("pr\195\169nom") name: string}
  type variant = @as("\195\169") E | @as("a\"b") Q
}

Read back, @as("pr\195\169nom") names the field prénom:

type record = {@as("pr\195\169nom") name: string}
let r = {name: "x"}

compiles to

let r = {
  "prénom": "x"
};

so a generated interface gives the fields and constructors other runtime names than the implementation. Error messages and hover show the escapes too.

The @tag name of a declaration is printed with String_literal.encode_js_string since #9136, which keeps non-ASCII letters and escapes only what a string literal needs.

主要言語
OCaml
スター
7.5k
フォーク
484
平均マージ
20時間 50分
マージ済み PR(30日)
266

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

rescript-lang/rescript のほかの issue

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

似ている issue

Compilers の issue をもっと見る

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

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