@@ -19,9 +19,9 @@ type ArcStr = Arc<str>;
19
19
type InnerSourceContentLine =
20
20
RefCell < HashMap < i64 , Option < Rc < Vec < WithIndices < ArcStr > > > > > > ;
21
21
22
- pub fn get_map < S : StreamChunks > (
23
- stream : & S ,
24
- options : & MapOptions ,
22
+ pub fn get_map < ' a , S : StreamChunks < ' a > > (
23
+ stream : & ' a S ,
24
+ options : & ' a MapOptions ,
25
25
) -> Option < SourceMap > {
26
26
let mut mappings = Vec :: new ( ) ;
27
27
let mut sources: Vec < Cow < ' static , str > > = Vec :: new ( ) ;
@@ -65,13 +65,13 @@ pub fn get_map<S: StreamChunks>(
65
65
}
66
66
67
67
/// [StreamChunks] abstraction, see [webpack-sources source.streamChunks](https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/helpers/streamChunks.js#L13).
68
- pub trait StreamChunks {
68
+ pub trait StreamChunks < ' a > {
69
69
/// [StreamChunks] abstraction
70
70
fn stream_chunks (
71
- & self ,
71
+ & ' a self ,
72
72
options : & MapOptions ,
73
73
on_chunk : OnChunk ,
74
- on_source : OnSource ,
74
+ on_source : OnSource < ' _ , ' a > ,
75
75
on_name : OnName ,
76
76
) -> GeneratedInfo ;
77
77
}
@@ -80,7 +80,7 @@ pub trait StreamChunks {
80
80
pub type OnChunk < ' a > = & ' a mut dyn FnMut ( Option < & str > , Mapping ) ;
81
81
82
82
/// [OnSource] abstraction, see [webpack-sources onSource](https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/helpers/streamChunks.js#L13).
83
- pub type OnSource < ' a > = & ' a mut dyn FnMut ( u32 , & str , Option < & str > ) ;
83
+ pub type OnSource < ' a , ' b > = & ' a mut dyn FnMut ( u32 , & str , Option < & ' b str > ) ;
84
84
85
85
/// [OnName] abstraction, see [webpack-sources onName](https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/helpers/streamChunks.js#L13).
86
86
pub type OnName < ' a > = & ' a mut dyn FnMut ( u32 , & str ) ;
@@ -94,11 +94,14 @@ pub fn stream_chunks_default<S: Source>(
94
94
on_name : OnName ,
95
95
) -> GeneratedInfo {
96
96
if let Some ( map) = source. map ( options) {
97
+ let s = source. source ( ) ;
97
98
stream_chunks_of_source_map (
98
- & source . source ( ) ,
99
+ & s ,
99
100
& map,
100
101
on_chunk,
101
- on_source,
102
+ & mut |a, b, c| {
103
+
104
+ } ,
102
105
on_name,
103
106
options,
104
107
)
@@ -556,11 +559,11 @@ pub fn stream_chunks_of_raw_source(
556
559
}
557
560
}
558
561
559
- pub fn stream_chunks_of_source_map (
560
- source : & str ,
561
- source_map : & SourceMap ,
562
+ pub fn stream_chunks_of_source_map < ' a > (
563
+ source : & ' a str ,
564
+ source_map : & ' a SourceMap ,
562
565
on_chunk : OnChunk ,
563
- on_source : OnSource ,
566
+ on_source : OnSource < ' _ , ' a > ,
564
567
on_name : OnName ,
565
568
options : & MapOptions ,
566
569
) -> GeneratedInfo {
@@ -602,11 +605,11 @@ fn get_source(source_map: &SourceMap, source: &str) -> String {
602
605
}
603
606
}
604
607
605
- fn stream_chunks_of_source_map_final (
606
- source : & str ,
607
- source_map : & SourceMap ,
608
+ fn stream_chunks_of_source_map_final < ' a > (
609
+ source : & ' a str ,
610
+ source_map : & ' a SourceMap ,
608
611
on_chunk : OnChunk ,
609
- on_source : OnSource ,
612
+ on_source : OnSource < ' _ , ' a > ,
610
613
on_name : OnName ,
611
614
) -> GeneratedInfo {
612
615
let result = get_generated_source_info ( source) ;
@@ -658,11 +661,11 @@ fn stream_chunks_of_source_map_final(
658
661
result
659
662
}
660
663
661
- fn stream_chunks_of_source_map_full (
662
- source : & str ,
663
- source_map : & SourceMap ,
664
+ fn stream_chunks_of_source_map_full < ' a > (
665
+ source : & ' a str ,
666
+ source_map : & ' a SourceMap ,
664
667
on_chunk : OnChunk ,
665
- on_source : OnSource ,
668
+ on_source : OnSource < ' _ , ' a > ,
666
669
on_name : OnName ,
667
670
) -> GeneratedInfo {
668
671
for ( i, source) in source_map. sources ( ) . iter ( ) . enumerate ( ) {
@@ -759,11 +762,11 @@ fn stream_chunks_of_source_map_full(
759
762
}
760
763
}
761
764
762
- fn stream_chunks_of_source_map_lines_final (
763
- source : & str ,
764
- source_map : & SourceMap ,
765
+ fn stream_chunks_of_source_map_lines_final < ' a > (
766
+ source : & ' a str ,
767
+ source_map : & ' a SourceMap ,
765
768
on_chunk : OnChunk ,
766
- on_source : OnSource ,
769
+ on_source : OnSource < ' _ , ' a > ,
767
770
_on_name : OnName ,
768
771
) -> GeneratedInfo {
769
772
let result = get_generated_source_info ( source) ;
@@ -814,11 +817,11 @@ fn stream_chunks_of_source_map_lines_final(
814
817
result
815
818
}
816
819
817
- fn stream_chunks_of_source_map_lines_full (
818
- source : & str ,
819
- source_map : & SourceMap ,
820
+ fn stream_chunks_of_source_map_lines_full < ' a > (
821
+ source : & ' a str ,
822
+ source_map : & ' a SourceMap ,
820
823
on_chunk : OnChunk ,
821
- on_source : OnSource ,
824
+ on_source : OnSource < ' _ , ' a > ,
822
825
_on_name : OnName ,
823
826
) -> GeneratedInfo {
824
827
let lines: Vec < & str > = split_into_lines ( source) . collect ( ) ;
@@ -933,21 +936,21 @@ impl SourceMapLineChunk {
933
936
}
934
937
935
938
#[ allow( clippy:: too_many_arguments) ]
936
- pub fn stream_chunks_of_combined_source_map (
937
- source : & str ,
938
- source_map : & SourceMap ,
939
- inner_source_name : & str ,
940
- inner_source : Option < & str > ,
941
- inner_source_map : & SourceMap ,
939
+ pub fn stream_chunks_of_combined_source_map < ' a > (
940
+ source : & ' a str ,
941
+ source_map : & ' a SourceMap ,
942
+ inner_source_name : & ' a str ,
943
+ inner_source : Option < & ' a str > ,
944
+ inner_source_map : & ' a SourceMap ,
942
945
remove_inner_source : bool ,
943
946
on_chunk : OnChunk ,
944
- on_source : OnSource ,
947
+ on_source : OnSource < ' _ , ' a > ,
945
948
on_name : OnName ,
946
949
options : & MapOptions ,
947
950
) -> GeneratedInfo {
948
951
let on_source = RefCell :: new ( on_source) ;
949
- let inner_source: RefCell < Option < ArcStr > > =
950
- RefCell :: new ( inner_source. map ( Into :: into ) ) ;
952
+ let inner_source: RefCell < Option < & ' a str > > =
953
+ RefCell :: new ( inner_source) ;
951
954
let source_mapping: RefCell < HashMap < ArcStr , u32 > > =
952
955
RefCell :: new ( HashMap :: default ( ) ) ;
953
956
let mut name_mapping: HashMap < ArcStr , u32 > = HashMap :: default ( ) ;
@@ -961,7 +964,7 @@ pub fn stream_chunks_of_combined_source_map(
961
964
let inner_source_index_mapping: RefCell < HashMap < i64 , i64 > > =
962
965
RefCell :: new ( HashMap :: default ( ) ) ;
963
966
let inner_source_index_value_mapping: RefCell <
964
- HashMap < i64 , ( ArcStr , Option < ArcStr > ) > ,
967
+ HashMap < i64 , ( ArcStr , Option < & ' a str > ) > ,
965
968
> = RefCell :: new ( HashMap :: default ( ) ) ;
966
969
let inner_source_contents: RefCell < HashMap < i64 , Option < ArcStr > > > =
967
970
RefCell :: new ( HashMap :: default ( ) ) ;
@@ -1098,7 +1101,7 @@ pub fn stream_chunks_of_combined_source_map(
1098
1101
if global_index. is_none ( ) {
1099
1102
let len = source_mapping. len ( ) as u32 ;
1100
1103
source_mapping. insert ( source. clone ( ) , len) ;
1101
- on_source. borrow_mut ( ) ( len, & source, source_content. as_deref ( ) ) ;
1104
+ on_source. borrow_mut ( ) ( len, & source, source_content) ;
1102
1105
global_index = Some ( len) ;
1103
1106
}
1104
1107
source_index = global_index. unwrap ( ) as i64 ;
@@ -1240,7 +1243,7 @@ pub fn stream_chunks_of_combined_source_map(
1240
1243
on_source. borrow_mut ( ) (
1241
1244
len,
1242
1245
inner_source_name,
1243
- inner_source. borrow ( ) . as_deref ( ) ,
1246
+ * inner_source. borrow ( ) ,
1244
1247
) ;
1245
1248
global_index = Some ( len) ;
1246
1249
}
@@ -1299,14 +1302,13 @@ pub fn stream_chunks_of_combined_source_map(
1299
1302
) ;
1300
1303
}
1301
1304
} ,
1302
- & mut |i, source, source_content| {
1305
+ & mut |i, source, mut source_content| {
1303
1306
let i = i as i64 ;
1304
- let mut source_content: Option < ArcStr > = source_content. map ( Into :: into) ;
1305
1307
if source == inner_source_name {
1306
1308
* inner_source_index. borrow_mut ( ) = i;
1307
1309
let mut inner_source = inner_source. borrow_mut ( ) ;
1308
1310
if let Some ( inner_source) = inner_source. as_ref ( ) {
1309
- source_content = Some ( inner_source. clone ( ) ) ;
1311
+ source_content = Some ( inner_source) ;
1310
1312
} else {
1311
1313
* inner_source = source_content. clone ( ) ;
1312
1314
}
@@ -1395,7 +1397,7 @@ pub fn stream_chunks_of_combined_source_map(
1395
1397
if global_index. is_none ( ) {
1396
1398
let len = source_mapping. len ( ) as u32 ;
1397
1399
source_mapping. insert ( source. into ( ) , len) ;
1398
- on_source. borrow_mut ( ) ( len, source, source_content. as_deref ( ) ) ;
1400
+ on_source. borrow_mut ( ) ( len, source, source_content) ;
1399
1401
global_index = Some ( len) ;
1400
1402
}
1401
1403
source_index_mapping
@@ -1412,11 +1414,11 @@ pub fn stream_chunks_of_combined_source_map(
1412
1414
)
1413
1415
}
1414
1416
1415
- pub fn stream_and_get_source_and_map < S : StreamChunks > (
1416
- input_source : & S ,
1417
- options : & MapOptions ,
1417
+ pub fn stream_and_get_source_and_map < ' a , S : StreamChunks < ' a > > (
1418
+ input_source : & ' a S ,
1419
+ options : & ' a MapOptions ,
1418
1420
on_chunk : OnChunk ,
1419
- on_source : OnSource ,
1421
+ on_source : OnSource < ' _ , ' a > ,
1420
1422
on_name : OnName ,
1421
1423
) -> ( GeneratedInfo , Option < SourceMap > ) {
1422
1424
let mut mappings = Vec :: new ( ) ;
0 commit comments