@@ -10,8 +10,8 @@ class GeneratedFragmentMapper {
10
10
}
11
11
12
12
get_position_relative_to_fragment ( positionRelativeToFile ) {
13
- const fragment_offset = this . offset_in_fragment ( offset_at ( positionRelativeToFile , this . generated_code ) ) ;
14
- return position_at ( fragment_offset , this . tag_info . generated_content ) ;
13
+ const fragment_offset = this . offset_in_fragment ( offset_at ( positionRelativeToFile , this . generated_code ) ) ;
14
+ return position_at ( fragment_offset , this . tag_info . generated_content ) ;
15
15
}
16
16
17
17
offset_in_fragment ( offset ) {
@@ -72,7 +72,7 @@ class SourceMapper {
72
72
return { line : - 1 , column : - 1 } ;
73
73
}
74
74
75
- const column_match = line_match . find ( ( col , idx ) =>
75
+ const column_match = line_match . find ( ( col , idx ) =>
76
76
idx + 1 === line_match . length ||
77
77
( col [ 0 ] <= column && line_match [ idx + 1 ] [ 0 ] > column )
78
78
) ;
@@ -101,33 +101,33 @@ export class DocumentMapper {
101
101
} ) ;
102
102
}
103
103
104
- get_original_position ( generated_position ) {
104
+ get_original_position ( generated_position ) {
105
105
generated_position = { line : generated_position . line - 1 , column : generated_position . column } ;
106
- const offset = offset_at ( generated_position , this . generated_code ) ;
107
- let original_offset = offset ;
108
- for ( const mapper of this . mappers ) {
106
+ const offset = offset_at ( generated_position , this . generated_code ) ;
107
+ let original_offset = offset ;
108
+ for ( const mapper of this . mappers ) {
109
109
if ( offset >= mapper . start && offset <= mapper . end ) {
110
110
return this . map ( mapper , generated_position ) ;
111
111
}
112
- if ( offset > mapper . end ) {
113
- original_offset -= mapper . diff ;
114
- }
115
- }
116
- const original_position = position_at ( original_offset , this . original_code ) ;
112
+ if ( offset > mapper . end ) {
113
+ original_offset -= mapper . diff ;
114
+ }
115
+ }
116
+ const original_position = position_at ( original_offset , this . original_code ) ;
117
117
return this . to_ESLint_position ( original_position ) ;
118
- }
118
+ }
119
119
120
120
map ( mapper , generatedPosition ) {
121
- // Map the position to be relative to the transpiled fragment
122
- const position_in_transpiled_fragment = mapper . generated_fragment_mapper . get_position_relative_to_fragment (
123
- generatedPosition
124
- ) ;
125
- // Map the position, using the sourcemap, to the original position in the source fragment
126
- const position_in_original_fragment = mapper . source_mapper . getOriginalPosition (
127
- position_in_transpiled_fragment
128
- ) ;
129
- // Map the position to be in the original fragment's parent
130
- const original_position = mapper . original_fragment_mapper . get_position_relative_to_file ( position_in_original_fragment ) ;
121
+ // Map the position to be relative to the transpiled fragment
122
+ const position_in_transpiled_fragment = mapper . generated_fragment_mapper . get_position_relative_to_fragment (
123
+ generatedPosition
124
+ ) ;
125
+ // Map the position, using the sourcemap, to the original position in the source fragment
126
+ const position_in_original_fragment = mapper . source_mapper . getOriginalPosition (
127
+ position_in_transpiled_fragment
128
+ ) ;
129
+ // Map the position to be in the original fragment's parent
130
+ const original_position = mapper . original_fragment_mapper . get_position_relative_to_file ( position_in_original_fragment ) ;
131
131
return this . to_ESLint_position ( original_position ) ;
132
132
}
133
133
@@ -144,69 +144,69 @@ export class DocumentMapper {
144
144
* @param text The text for which the offset should be retrived
145
145
*/
146
146
function offset_at ( position , text ) {
147
- const line_offsets = get_line_offsets ( text ) ;
147
+ const line_offsets = get_line_offsets ( text ) ;
148
148
149
- if ( position . line >= line_offsets . length ) {
150
- return text . length ;
151
- } else if ( position . line < 0 ) {
152
- return 0 ;
153
- }
149
+ if ( position . line >= line_offsets . length ) {
150
+ return text . length ;
151
+ } else if ( position . line < 0 ) {
152
+ return 0 ;
153
+ }
154
154
155
- const line_offset = line_offsets [ position . line ] ;
156
- const next_line_offset =
157
- position . line + 1 < line_offsets . length ? line_offsets [ position . line + 1 ] : text . length ;
155
+ const line_offset = line_offsets [ position . line ] ;
156
+ const next_line_offset =
157
+ position . line + 1 < line_offsets . length ? line_offsets [ position . line + 1 ] : text . length ;
158
158
159
- return clamp ( next_line_offset , line_offset , line_offset + position . column ) ;
159
+ return clamp ( next_line_offset , line_offset , line_offset + position . column ) ;
160
160
}
161
161
162
162
function position_at ( offset , text ) {
163
- offset = clamp ( offset , 0 , text . length ) ;
164
-
165
- const line_offsets = get_line_offsets ( text ) ;
166
- let low = 0 ;
167
- let high = line_offsets . length ;
168
- if ( high === 0 ) {
169
- return { line : 0 , column : offset } ;
170
- }
171
-
172
- while ( low < high ) {
173
- const mid = Math . floor ( ( low + high ) / 2 ) ;
174
- if ( line_offsets [ mid ] > offset ) {
175
- high = mid ;
176
- } else {
177
- low = mid + 1 ;
178
- }
179
- }
180
-
181
- // low is the least x for which the line offset is larger than the current offset
182
- // or array.length if no line offset is larger than the current offset
183
- const line = low - 1 ;
184
- return { line, column : offset - line_offsets [ line ] } ;
163
+ offset = clamp ( offset , 0 , text . length ) ;
164
+
165
+ const line_offsets = get_line_offsets ( text ) ;
166
+ let low = 0 ;
167
+ let high = line_offsets . length ;
168
+ if ( high === 0 ) {
169
+ return { line : 0 , column : offset } ;
170
+ }
171
+
172
+ while ( low < high ) {
173
+ const mid = Math . floor ( ( low + high ) / 2 ) ;
174
+ if ( line_offsets [ mid ] > offset ) {
175
+ high = mid ;
176
+ } else {
177
+ low = mid + 1 ;
178
+ }
179
+ }
180
+
181
+ // low is the least x for which the line offset is larger than the current offset
182
+ // or array.length if no line offset is larger than the current offset
183
+ const line = low - 1 ;
184
+ return { line, column : offset - line_offsets [ line ] } ;
185
185
}
186
186
187
187
function get_line_offsets ( text ) {
188
- const line_offsets = [ ] ;
189
- let is_line_start = true ;
190
-
191
- for ( let i = 0 ; i < text . length ; i ++ ) {
192
- if ( is_line_start ) {
193
- line_offsets . push ( i ) ;
194
- is_line_start = false ;
195
- }
196
- const ch = text . charAt ( i ) ;
197
- is_line_start = ch === '\r' || ch === '\n' ;
198
- if ( ch === '\r' && i + 1 < text . length && text . charAt ( i + 1 ) === '\n' ) {
199
- i ++ ;
200
- }
201
- }
202
-
203
- if ( is_line_start && text . length > 0 ) {
204
- line_offsets . push ( text . length ) ;
205
- }
206
-
207
- return line_offsets ;
188
+ const line_offsets = [ ] ;
189
+ let is_line_start = true ;
190
+
191
+ for ( let i = 0 ; i < text . length ; i ++ ) {
192
+ if ( is_line_start ) {
193
+ line_offsets . push ( i ) ;
194
+ is_line_start = false ;
195
+ }
196
+ const ch = text . charAt ( i ) ;
197
+ is_line_start = ch === '\r' || ch === '\n' ;
198
+ if ( ch === '\r' && i + 1 < text . length && text . charAt ( i + 1 ) === '\n' ) {
199
+ i ++ ;
200
+ }
201
+ }
202
+
203
+ if ( is_line_start && text . length > 0 ) {
204
+ line_offsets . push ( text . length ) ;
205
+ }
206
+
207
+ return line_offsets ;
208
208
}
209
209
210
210
function clamp ( num , min , max ) {
211
- return Math . max ( min , Math . min ( max , num ) ) ;
211
+ return Math . max ( min , Math . min ( max , num ) ) ;
212
212
}
0 commit comments