| 25 | |
| 26 | impl MagicString<'_> { |
| 27 | pub fn source_map(&self, opts: SourceMapOptions) -> oxc_sourcemap::SourceMap<'static> { |
| 28 | let mut source_builder = SourcemapBuilder::new(opts.hires); |
| 29 | |
| 30 | source_builder.set_source_and_content(&opts.source, &self.source); |
| 31 | |
| 32 | let locator = Locator::new(&self.source); |
| 33 | |
| 34 | self.intro.iter().for_each(|frag| { |
| 35 | source_builder.advance(frag); |
| 36 | }); |
| 37 | |
| 38 | let utf16_index_map = |
| 39 | precompute_utf16_index_map(&self.source, self.iter_chunks().map(|chunk| chunk.start())); |
| 40 | |
| 41 | self.iter_chunks().for_each(|chunk| { |
| 42 | chunk.intro.iter().for_each(|frag| { |
| 43 | source_builder.advance(frag); |
| 44 | }); |
| 45 | let name = |
| 46 | (chunk.keep_in_mappings && chunk.is_edited()).then(|| chunk.span.text(&self.source)); |
| 47 | |
| 48 | source_builder.add_chunk( |
| 49 | chunk, |
| 50 | utf16_index_map[&chunk.start()], |
| 51 | &locator, |
| 52 | &self.source, |
| 53 | name, |
| 54 | ); |
| 55 | |
| 56 | chunk.outro.iter().for_each(|frag| { |
| 57 | source_builder.advance(frag); |
| 58 | }); |
| 59 | }); |
| 60 | |
| 61 | let mut source_map = source_builder.into_source_map(); |
| 62 | |
| 63 | if self.ignore_list { |
| 64 | // The source is always at index 0 for a single MagicString instance. |
| 65 | source_map.set_x_google_ignore_list(vec![0]); |
| 66 | } |
| 67 | |
| 68 | source_map |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | fn precompute_utf16_index_map( |