@@ -2,17 +2,17 @@ use std::borrow::Cow;
2
2
3
3
use crate :: { CowStr , MagicString , TextSize } ;
4
4
5
- struct ExcludeSet {
6
- exclude : Vec < [ TextSize ; 2 ] > ,
5
+ struct ExcludeSet < ' a > {
6
+ exclude : & ' a [ ( TextSize , TextSize ) ] ,
7
7
}
8
8
9
- impl ExcludeSet {
10
- fn new ( exclude : Vec < [ TextSize ; 2 ] > ) -> Self {
9
+ impl < ' a > ExcludeSet < ' a > {
10
+ fn new ( exclude : & ' a [ ( TextSize , TextSize ) ] ) -> Self {
11
11
Self { exclude }
12
12
}
13
13
14
14
fn contains ( & self , index : TextSize ) -> bool {
15
- self . exclude . iter ( ) . any ( |s| s[ 0 ] <= index && index <= s [ 1 ] )
15
+ self . exclude . iter ( ) . any ( |s| s. 0 <= index && index < s . 1 )
16
16
}
17
17
}
18
18
@@ -49,14 +49,14 @@ pub fn guess_indentor(source: &str) -> Option<String> {
49
49
}
50
50
51
51
#[ derive( Debug , Default ) ]
52
- pub struct IndentOptions < ' a > {
52
+ pub struct IndentOptions < ' a , ' b > {
53
53
/// MagicString will guess the `indentor`` from lines of the source if passed `None`.
54
54
pub indentor : Option < & ' a str > ,
55
55
56
56
/// The reason I use `[u32; 2]` instead of `(u32, u32)` to represent a range of text is that
57
57
/// I want to emphasize that the `[u32; 2]` is the closed interval, which means both the start
58
58
/// and the end are included in the range.
59
- pub exclude : Vec < [ TextSize ; 2 ] > ,
59
+ pub exclude : & ' b [ ( TextSize , TextSize ) ] ,
60
60
}
61
61
62
62
impl < ' text > MagicString < ' text > {
@@ -74,7 +74,7 @@ impl<'text> MagicString<'text> {
74
74
} )
75
75
}
76
76
77
- pub fn indent_with ( & mut self , opts : IndentOptions < ' _ > ) -> & mut Self {
77
+ pub fn indent_with ( & mut self , opts : IndentOptions ) -> & mut Self {
78
78
if opts. indentor . map_or ( false , |s| s. is_empty ( ) ) {
79
79
return self ;
80
80
}
@@ -83,11 +83,7 @@ impl<'text> MagicString<'text> {
83
83
indentor : String ,
84
84
}
85
85
86
-
87
- fn indent_frag < ' text > (
88
- frag : & mut CowStr < ' text > ,
89
- indent_replacer : & mut IndentReplacer ,
90
- ) {
86
+ fn indent_frag < ' text > ( frag : & mut CowStr < ' text > , indent_replacer : & mut IndentReplacer ) {
91
87
let mut indented = String :: new ( ) ;
92
88
for char in frag. chars ( ) {
93
89
if char == '\n' {
@@ -103,7 +99,6 @@ impl<'text> MagicString<'text> {
103
99
104
100
let indentor = opts. indentor . unwrap_or_else ( || self . guessed_indentor ( ) ) ;
105
101
106
-
107
102
let mut indent_replacer = IndentReplacer {
108
103
should_indent_next_char : true ,
109
104
indentor : indentor. to_string ( ) ,
@@ -114,7 +109,7 @@ impl<'text> MagicString<'text> {
114
109
}
115
110
116
111
let exclude_set = ExcludeSet :: new ( opts. exclude ) ;
117
-
112
+
118
113
let mut next_chunk_id = Some ( self . first_chunk_idx ) ;
119
114
let mut char_index = 0u32 ;
120
115
while let Some ( chunk_idx) = next_chunk_id {
@@ -123,7 +118,7 @@ impl<'text> MagicString<'text> {
123
118
next_chunk_id = self . chunks [ chunk_idx] . next ;
124
119
if let Some ( edited_content) = self . chunks [ chunk_idx] . edited_content . as_mut ( ) {
125
120
if !exclude_set. contains ( char_index) {
126
- indent_frag ( edited_content, & mut indent_replacer) ;
121
+ indent_frag ( edited_content, & mut indent_replacer) ;
127
122
}
128
123
} else {
129
124
let chunk = & self . chunks [ chunk_idx] ;
@@ -151,7 +146,7 @@ impl<'text> MagicString<'text> {
151
146
}
152
147
153
148
for frag in self . outro . iter_mut ( ) {
154
- indent_frag ( frag, & mut indent_replacer)
149
+ indent_frag ( frag, & mut indent_replacer)
155
150
}
156
151
157
152
self
0 commit comments