Indexed source maps: lastColumn is not clamped to the next section when the section does not start on line 1

Đang mở Phù hợp với người mới
#542 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 5 ngày

@sebxt đang làm issue này rồi.

Từ ngày 18/10/2026.

  • #543 của @sebxt — đang mở
  • #551 của @user-Param — đang mở
  • #562 của @user-Param — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript
Lĩnh vực
devtools

Hướng nghiên cứu

Đọc IndexedSourceMapConsumer và kiểm tra các phép so sánh của generatedPositionFor, allGeneratedPositionsFor và eachMapping với dòng được tạo của section tiếp theo. Tái hiện vấn đề bằng source map gồm ba section được cung cấp, rồi chạy các bài kiểm thử source map liên quan. Công việc hoàn tất khi cả ba API giới hạn cột cuối cùng của section ở ranh giới section tiếp theo nếu section bắt đầu sau dòng 1.

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

Mô tả

After computeColumnSpans(), IndexedSourceMapConsumer is supposed to clamp a mapping's lastColumn (or lastGeneratedColumn) so it ends where the next section begins on the same generated line. This only works for the first section, or more precisely for sections whose offset line is 0. For any later section the clamp is skipped, and in some layouts it is applied to the wrong line.

Repro:

const { SourceMapConsumer } = require("source-map");

const section = source => ({ version: 3, sources: [source], names: [], mappings: "AAAA" });

const map = await new SourceMapConsumer({
  version: 3,
  sections: [
    { offset: { line: 0, column: 0 }, map: section("a.js") },
    { offset: { line: 2, column: 0 }, map: section("b.js") },
    { offset: { line: 2, column: 10 }, map: section("c.js") },
  ],
});
map.computeColumnSpans();

map.generatedPositionFor({ source: "b.js", line: 1, column: 0 });
// actual:   { line: 3, column: 0, lastColumn: Infinity }
// expected: { line: 3, column: 0, lastColumn: 9 }

allGeneratedPositionsFor and eachMapping (lastGeneratedColumn) return the same wrong value.

Root cause: in generatedPositionFor, allGeneratedPositionsFor and eachMapping of IndexedSourceMapConsumer, the comparison line === nextSection.generatedOffset.generatedLine runs before lineShift is added, so a section relative line is compared with an absolute line from the next section's offset. It only lines up when lineShift is 0. Adding the shift before the comparison fixes it.

Ngôn ngữ chính
JavaScript
Star
3.7k
Fork
392
Merge trung bình
4 ngày 18 giờ
Pull request đã merge (30 ngày)
1

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 mozilla/source-map

Tất cả issue của mozilla/source-map

Issue tương tự

Thêm issue về JavaScript

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.