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

Đã đóng
#9,142 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #9143 của @cknitt — đã merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
OCaml
Star
7.5k
Fork
484
Merge trung bình
17 giờ 2 phút
Pull request đã merge (30 ngày)
249

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rescript-lang/rescript

Tất cả issue của rescript-lang/rescript

Issue tương tự

Thêm issue về Compilers

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.