Sourcemaps don't work in vm.Script scripts
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.3k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 283
Mô tả
Version
v21.7.1
Platform
Linux ecls 6.5.0-25-generic #25~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Feb 20 16:09:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
source_map
What steps will reproduce the bug?
This example is adapted from https://github.com/nodejs/node/issues/43047
import vm from 'node:vm';
const comment = '//#';
const code = `// Generated by CoffeeScript 2.7.0
(function() {
throw new Error('hello');
}).call(this);
${comment} sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2ltcGxlLmpzIiwic291cmNlUm9vdCI6IlxcIiwic291cmNlcyI6WyJzaW1wbGUuY29mZmVlIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTtFQUFBLE1BQU0sSUFBSSxLQUFKLENBQVUsT0FBVjtBQUFOIiwic291cmNlc0NvbnRlbnQiOlsidGhyb3cgbmV3IEVycm9yICdoZWxsbydcbiJdfQ==
${comment} sourceURL=simple.coffee
`;
// eval(code);
const script = new vm.Script(code, {filename: 'simple.js'})
console.log(script.sourceMapURL)
script.runInNewContext()
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior? Why is that the expected behavior?
The expected behavior is shown if I uncomment the eval call in foo.js and run the code:
$ node --enable-source-maps foo.js
/simple.coffee:1
throw new Error 'hello'
^
Error: hello
at eval (/simple.coffee:1:7)
at eval (/simple.coffee:1:1)
at file:///home/rrt/Software/ursa/foo.js:13:1
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Now, the traceback shows the error in the CoffeeScript code.
What do you see instead?
Running this code from file foo.js gives:
$ node --enable-source-maps foo.js
node --enable-source-maps foo.js
data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2ltcGxlLmpzIiwic291cmNlUm9vdCI6IlxcIiwic291cmNlcyI6WyJzaW1wbGUuY29mZmVlIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTtFQUFBLE1BQU0sSUFBSSxLQUFKLENBQVUsT0FBVjtBQUFOIiwic291cmNlc0NvbnRlbnQiOlsidGhyb3cgbmV3IEVycm9yICdoZWxsbydcbiJdfQ==
simple.coffee:3
throw new Error('hello');
^
Error: hello
at simple.coffee:3:9
at simple.coffee:5:4
at Script.runInContext (node:vm:133:12)
at Script.runInNewContext (node:vm:138:17)
at file:///home/rrt/Software/ursa/foo.js:17:8
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Note that the traceback shows the JavaScript source, not the CoffeeScript source.
Additional information
Note that the vm.Script module correctly parses the sourceMappingURL comment, and displays its contents. This led me to believe that the source map would be supported during execution!
I'm sorry if I have overlooked other issues in this area; I have only found the issue I referred to above about adding support for source maps to eval.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với ví dụ vm.Script trong foo.js và so sánh việc thực thi của nó với đường đi eval(code) dưới --enable-source-maps. Theo dõi cách sourceMappingURL được phân tích so với cách các stack trace được ánh xạ trong quá trình script.runInNewContext(); hoàn thành khi traceback của vm.Script trỏ đến mã nguồn CoffeeScript giống như traceback của eval.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, node.js
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 55/100