Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Error creating a SourceMapGenerator from a SourceMapConsumer of an index map (part 2)

Đang mở
#420 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đá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
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu trong lib/source-map-consumer.js, quanh phần triển khai sourceContentFor, và theo dõi cách lib/source-map-generator.js gọi nó từ fromSourceMap. Chạy trình tái hiện index-map được cung cấp và xác nhận rằng một mục sourcesContent rỗng được giữ nguyên thay vì bị coi là bị thiếu, mà không thay đổi hành vi đối với nội dung null hoặc undefined.

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

Mô tả

needs-triage
;(async () => {
  let mozilla = require('source-map')
  let map;

  map = {
    version: 3,
    sections: [
      {
        offset: { line: 0, column: 0 },
        map: {
          version: 3,
          sources: ['123', '456'],
          sourcesContent: ['a\nb\nc\n', ''],
          mappings: 'AAAA;AACA;AACA;'
        }
      }
    ]
  }

  // this map works for some reason
  /*map = {
    version: 3,
    sources: ['123', '456'],
    sourcesContent: ['a\nb\nc\n', ''],
    mappings: 'AAAA;AACA;AACA;'
  }*/

  let consumer = await new mozilla.SourceMapConsumer(map)
  consumer.sourceRoot = null; // https://github.com/mozilla/source-map/issues/345
  let generator = mozilla.SourceMapGenerator.fromSourceMap(consumer)
  console.log(generator.toJSON())

})().catch(console.log)

This errors out:

Error: "456" is not in the SourceMap.
    at IndexedSourceMapConsumer.sourceContentFor (/tmp/node_modules/source-map/lib/source-map-consumer.js:840:11)
    at /tmp/node_modules/source-map/lib/source-map-generator.js:82:42
    at Array.forEach (<anonymous>)
    at Function.fromSourceMap (/tmp/node_modules/source-map/lib/source-map-generator.js:72:32)
    at /tmp/123/test.js:29:46

The issue is in here somewhere:

https://github.com/mozilla/source-map/blob/7a263408de1b60e60b6220ca3e36d9b3e4aa047d/lib/source-map-consumer.js#L880

Content is empty - '' - but it is still in the sourcemap. I believe it should be if (content == null) { check, i.e. null or undefined, letting empty string pass along.

this may be related to https://github.com/mozilla/source-map/issues/345, so tagging it just in case

Ngôn ngữ chính
JavaScript
Star
3.7k
Fork
370
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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.