Valid legacy regex fragments are rejected before native compilation

Đã đóng
#3,035 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.

  • #3041 của @MathurAditya724 — đã đóng, không merge
  • #3112 của @ctate — đã 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
35/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, testing-qa

Hướng nghiên cứu

Start by saving the reduced example as fragment.mjs and comparing scriptc's diagnostic with Node 24.22.1. Trace the regex literal diagnostic path and the TypeScript diagnostic boundary mentioned in the issue; cover fragment composition, legacy escapes, capture references, replacements, and invalid Unicode patterns. Compare native output with Node, including sanitized execution; done means valid legacy fragments compile while invalid u and v patterns still reject. An open linked pull request (#3041) is already addressing this issue.

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

Mô tả

We are compiling the full Sentry CLI with scriptc, including its existing dependencies. highlight.js builds a Perl grammar by taking the source of a legacy regular-expression fragment and inserting it into a larger pattern. The fragment is valid JavaScript, but the build stops with SC0001 before it reaches the native regex runtime.

A reduced example is:

console.log(new RegExp("(a)" + /\1/.source).test("aa"));

Save this as fragment.mjs. Node 24.22.1 prints true. Building it with scriptc built from current main reports that the backreference refers to a group that does not exist (TypeScript TS1534). The related literal /(a)\2/ reaches TS1533 instead.

These non-Unicode literals have defined legacy semantics. Their source can also be reused in a pattern with enough capture groups, as in the example. The standalone literal and the final constructed pattern are different expressions and should each keep their JavaScript behavior.

Expected behavior is to compile valid legacy fragments and match Node. Regexes with u or v must still reject invalid backreferences. This should not be fixed by discarding all regex grammar diagnostics or changing the fragment's source text.

Regression coverage should include fragment composition, standalone octal and identity escapes, real capture references and replacement, invalid Unicode patterns, and the existing TypeScript diagnostic boundary. Native output needs to be compared with Node, including sanitized execution.

This removes one observed blocker from the CLI bundle; it does not establish that the whole CLI compiles. I rechecked open issues and PRs before filing this. The RegExp call handling in #2928 addresses a different lowering path, rather than these literal diagnostics.

Ngôn ngữ chính
TypeScript
Star
6.5k
Fork
212
Merge trung bình
13 giờ 6 phút
Pull request đã merge (30 ngày)
799

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

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 vercel-labs/scriptc

Tất cả issue của vercel-labs/scriptc

Issue tương tự

Thêm issue về TypeScript

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.