1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! Convert V8 byte-range coverage into Istanbul `FileCoverage`.
//!
//! Thin orchestrator that combines this crate's AST-traversal pass
//! ([`crate::instrument::collect_for_v8_to_istanbul`]) with
//! `oxc_coverage_v8::apply_v8_coverage` for the V8-range intersection and
//! `oxc_coverage_v8`'s source-map extraction helpers for the inline /
//! external `//# sourceMappingURL=` trailer.
//!
//! For the user-facing description of the V8-to-Istanbul mapping, the CJS
//! wrapper offset semantics, and the per-arm `body_byte_span` resolution, see
//! the `oxc_coverage_v8` crate documentation.
pub use ;
use cratecollect_for_v8_to_istanbul;
use FileCoverage;
use ;
/// Errors produced by the V8-to-Istanbul conversion.
/// Convert V8 function coverage into Istanbul `FileCoverage`.
///
/// `wrapper_length` accounts for Node's CJS module wrapper prefix
/// (`(function(exports,require,module,__filename,__dirname){`). Pass 0 for ESM.
///
/// Statement, function, and branch counts are each populated from the smallest
/// V8 range containing the corresponding location. When the source carries an
/// inline `//# sourceMappingURL=data:application/json;base64,...` comment, the
/// embedded map is decoded and attached as `inputSourceMap` so the result
/// chains cleanly into [`crate::remap_coverage`].
///
/// To resolve an external `//# sourceMappingURL=foo.js.map` reference rather
/// than the inline data-URL form, use [`v8_to_istanbul_with_loader`] and
/// supply a loader that reads the map JSON from disk (or fetches it).
/// Like [`v8_to_istanbul`], but with a loader for external `sourceMappingURL`
/// references.
///
/// When the source carries a `//# sourceMappingURL=` trailer that is not an
/// inline `data:application/json` URL, the loader is called with the URL as
/// reported by the trailer (e.g. `foo.js.map`, `https://cdn.example/x.js.map`).
/// Returning `Some(json)` attaches the parsed map as `inputSourceMap` on the
/// result so a subsequent [`crate::remap_coverage`] resolves
/// positions back to the original source in one chained call. Returning
/// `None` leaves `inputSourceMap` unset.
///
/// The loader is sync and infallible: side channels (disk I/O errors, HTTP
/// failures) collapse to `None`. Caller-side URL resolution (relative paths,
/// http schemes, file:// URIs) is intentionally not handled here.
///
/// # Example
///
/// ```
/// use oxc_coverage_instrument::{V8CoverageRange, V8FunctionCoverage, v8_to_istanbul_with_loader};
///
/// let source = "const x = 1;\n//# sourceMappingURL=app.js.map\n";
/// let functions = vec![V8FunctionCoverage {
/// function_name: String::new(),
/// ranges: vec![V8CoverageRange { start_offset: 0, end_offset: source.len() as u32, count: 1 }],
/// is_block_coverage: false,
/// }];
///
/// // Loader keyed on the trailer URL; here we just keep one map in-memory,
/// // but a real caller would read from disk relative to `filename`.
/// let map_json = r#"{"version":3,"sources":["src/app.ts"],"mappings":"AAAA","names":[]}"#;
/// let fc = v8_to_istanbul_with_loader(source, "app.js", &functions, 0, |url| {
/// if url == "app.js.map" { Some(map_json.to_string()) } else { None }
/// })
/// .unwrap();
///
/// // The loader-supplied map is attached and can be chained into remap_coverage.
/// assert!(fc.input_source_map.is_some());
/// ```