@@ -84,7 +84,9 @@ const streamChunksOfCombinedSourceMap = (
84
84
const locationInChunk = originalColumn - innerGeneratedColumn ;
85
85
if ( locationInChunk > 0 ) {
86
86
let originalSourceLines =
87
- innerSourceContentLines [ innerSourceIndex ] ;
87
+ innerSourceIndex < innerSourceContentLines . length
88
+ ? innerSourceContentLines [ innerSourceIndex ]
89
+ : null ;
88
90
if ( originalSourceLines === undefined ) {
89
91
const originalSource = innerSourceContents [ innerSourceIndex ] ;
90
92
originalSourceLines = originalSource
@@ -110,11 +112,15 @@ const streamChunksOfCombinedSourceMap = (
110
112
// We have a inner mapping to original source
111
113
112
114
// emit source when needed and compute global source index
113
- let sourceIndex = innerSourceIndexMapping [ innerSourceIndex ] ;
114
- if ( sourceIndex < 0 ) {
115
- const [ source , sourceContent ] = innerSourceIndexValueMapping [
116
- innerSourceIndex
117
- ] ;
115
+ let sourceIndex =
116
+ innerSourceIndex < innerSourceIndexMapping . length
117
+ ? innerSourceIndexMapping [ innerSourceIndex ]
118
+ : - 2 ;
119
+ if ( sourceIndex === - 2 ) {
120
+ const [ source , sourceContent ] =
121
+ innerSourceIndex < innerSourceIndexValueMapping . length
122
+ ? innerSourceIndexValueMapping [ innerSourceIndex ]
123
+ : [ null , undefined ] ;
118
124
let globalIndex = sourceMapping . get ( source ) ;
119
125
if ( globalIndex === undefined ) {
120
126
sourceMapping . set ( source , ( globalIndex = sourceMapping . size ) ) ;
@@ -128,15 +134,25 @@ const streamChunksOfCombinedSourceMap = (
128
134
let finalNameIndex = - 1 ;
129
135
if ( innerNameIndex >= 0 ) {
130
136
// when we have a inner name
131
- finalNameIndex = innerNameIndexMapping [ innerNameIndex ] ;
132
- if ( finalNameIndex < 0 ) {
133
- const name = innerNameIndexValueMapping [ innerNameIndex ] ;
134
- let globalIndex = nameMapping . get ( name ) ;
135
- if ( globalIndex === undefined ) {
136
- nameMapping . set ( name , ( globalIndex = nameMapping . size ) ) ;
137
- onName ( globalIndex , name ) ;
137
+ finalNameIndex =
138
+ innerNameIndex < innerNameIndexMapping . length
139
+ ? innerNameIndexMapping [ innerNameIndex ]
140
+ : - 2 ;
141
+ if ( finalNameIndex === - 2 ) {
142
+ const name =
143
+ innerNameIndex < innerNameIndexValueMapping . length
144
+ ? innerNameIndexValueMapping [ innerNameIndex ]
145
+ : undefined ;
146
+ if ( name ) {
147
+ let globalIndex = nameMapping . get ( name ) ;
148
+ if ( globalIndex === undefined ) {
149
+ nameMapping . set ( name , ( globalIndex = nameMapping . size ) ) ;
150
+ onName ( globalIndex , name ) ;
151
+ }
152
+ finalNameIndex = globalIndex ;
153
+ } else {
154
+ finalNameIndex = - 1 ;
138
155
}
139
- finalNameIndex = globalIndex ;
140
156
innerNameIndexMapping [ innerNameIndex ] = finalNameIndex ;
141
157
}
142
158
} else if ( nameIndex >= 0 ) {
@@ -161,15 +177,22 @@ const streamChunksOfCombinedSourceMap = (
161
177
)
162
178
: "" ;
163
179
if ( name === originalName ) {
164
- finalNameIndex = nameIndexMapping [ nameIndex ] ;
165
- if ( finalNameIndex < 0 ) {
180
+ finalNameIndex =
181
+ nameIndex < nameIndexMapping . length
182
+ ? nameIndexMapping [ nameIndex ]
183
+ : - 2 ;
184
+ if ( finalNameIndex === - 2 ) {
166
185
const name = nameIndexValueMapping [ nameIndex ] ;
167
- let globalIndex = nameMapping . get ( name ) ;
168
- if ( globalIndex === undefined ) {
169
- nameMapping . set ( name , ( globalIndex = nameMapping . size ) ) ;
170
- onName ( globalIndex , name ) ;
186
+ if ( name ) {
187
+ let globalIndex = nameMapping . get ( name ) ;
188
+ if ( globalIndex === undefined ) {
189
+ nameMapping . set ( name , ( globalIndex = nameMapping . size ) ) ;
190
+ onName ( globalIndex , name ) ;
191
+ }
192
+ finalNameIndex = globalIndex ;
193
+ } else {
194
+ finalNameIndex = - 1 ;
171
195
}
172
- finalNameIndex = globalIndex ;
173
196
nameIndexMapping [ nameIndex ] = finalNameIndex ;
174
197
}
175
198
}
@@ -194,30 +217,39 @@ const streamChunksOfCombinedSourceMap = (
194
217
}
195
218
}
196
219
197
- // Pass through the chunk with mapping
198
- let finalNameIndex = - 1 ;
199
- if ( nameIndex >= 0 ) {
200
- finalNameIndex = nameIndexMapping [ nameIndex ] ;
201
- if ( finalNameIndex < 0 ) {
202
- const name = nameIndexValueMapping [ nameIndex ] ;
203
- let globalIndex = nameMapping . get ( name ) ;
204
- if ( globalIndex === undefined ) {
205
- nameMapping . set ( name , ( globalIndex = nameMapping . size ) ) ;
206
- onName ( globalIndex , name ) ;
220
+ const finalSourceIndex =
221
+ sourceIndex < 0 || sourceIndex >= sourceIndexMapping . length
222
+ ? - 1
223
+ : sourceIndexMapping [ sourceIndex ] ;
224
+ if ( finalSourceIndex < 0 ) {
225
+ // no source, so we make it a generated chunk
226
+ onChunk ( chunk , generatedLine , generatedColumn , - 1 , - 1 , - 1 , - 1 ) ;
227
+ } else {
228
+ // Pass through the chunk with mapping
229
+ let finalNameIndex = - 1 ;
230
+ if ( nameIndex >= 0 && nameIndex < nameIndexMapping . length ) {
231
+ finalNameIndex = nameIndexMapping [ nameIndex ] ;
232
+ if ( finalNameIndex === - 2 ) {
233
+ const name = nameIndexValueMapping [ nameIndex ] ;
234
+ let globalIndex = nameMapping . get ( name ) ;
235
+ if ( globalIndex === undefined ) {
236
+ nameMapping . set ( name , ( globalIndex = nameMapping . size ) ) ;
237
+ onName ( globalIndex , name ) ;
238
+ }
239
+ finalNameIndex = globalIndex ;
240
+ nameIndexMapping [ nameIndex ] = finalNameIndex ;
207
241
}
208
- finalNameIndex = globalIndex ;
209
- nameIndexMapping [ nameIndex ] = finalNameIndex ;
210
242
}
243
+ onChunk (
244
+ chunk ,
245
+ generatedLine ,
246
+ generatedColumn ,
247
+ finalSourceIndex ,
248
+ originalLine ,
249
+ originalColumn ,
250
+ finalNameIndex
251
+ ) ;
211
252
}
212
- onChunk (
213
- chunk ,
214
- generatedLine ,
215
- generatedColumn ,
216
- sourceIndex < 0 ? - 1 : sourceIndexMapping [ sourceIndex ] ,
217
- originalLine ,
218
- originalColumn ,
219
- nameIndex < 0 ? - 1 : nameIndexMapping [ nameIndex ]
220
- ) ;
221
253
} ,
222
254
( i , source , sourceContent ) => {
223
255
if ( source === innerSourceName ) {
@@ -254,11 +286,11 @@ const streamChunksOfCombinedSourceMap = (
254
286
( i , source , sourceContent ) => {
255
287
innerSourceContents [ i ] = sourceContent ;
256
288
innerSourceContentLines [ i ] = undefined ;
257
- innerSourceIndexMapping [ i ] = - 1 ;
289
+ innerSourceIndexMapping [ i ] = - 2 ;
258
290
innerSourceIndexValueMapping [ i ] = [ source , sourceContent ] ;
259
291
} ,
260
292
( i , name ) => {
261
- innerNameIndexMapping [ i ] = - 1 ;
293
+ innerNameIndexMapping [ i ] = - 2 ;
262
294
innerNameIndexValueMapping [ i ] = name ;
263
295
} ,
264
296
false ,
@@ -274,7 +306,7 @@ const streamChunksOfCombinedSourceMap = (
274
306
sourceIndexMapping [ i ] = globalIndex ;
275
307
} ,
276
308
( i , name ) => {
277
- nameIndexMapping [ i ] = - 1 ;
309
+ nameIndexMapping [ i ] = - 2 ;
278
310
nameIndexValueMapping [ i ] = name ;
279
311
} ,
280
312
finalSource ,
0 commit comments