@@ -206,25 +206,28 @@ function createCodegenContext(
206
206
context . push ( '\n' + ` ` . repeat ( n ) , NewlineType . Start )
207
207
}
208
208
209
- function addMapping ( loc : Position , name ?: string ) {
210
- context . map ! . addMapping ( {
211
- name,
212
- source : context . filename ,
213
- original : {
214
- line : loc . line ,
215
- column : loc . column - 1 // source-map column is 0 based
216
- } ,
217
- generated : {
218
- line : context . line ,
219
- column : context . column - 1
220
- }
209
+ function addMapping ( loc : Position , name : string | null = null ) {
210
+ // @ts -ignore we use the private property to directly add the mapping
211
+ // because the addMapping() implementation in source-map-js has a bunch of
212
+ // unnecessary arg and validation checks that are pure overhead in our case.
213
+ const { _names, _mappings } = context . map
214
+ if ( name !== null && ! _names . has ( name ) ) _names . add ( name )
215
+ _mappings . add ( {
216
+ originalLine : loc . line ,
217
+ originalColumn : loc . column - 1 , // source-map column is 0 based
218
+ generatedLine : context . line ,
219
+ generatedColumn : context . column - 1 ,
220
+ source : filename ,
221
+ name
221
222
} )
222
223
}
223
224
224
225
if ( ! __BROWSER__ && sourceMap ) {
225
226
// lazy require source-map implementation, only in non-browser builds
226
227
context . map = new SourceMapGenerator ( )
227
- context . map ! . setSourceContent ( filename , context . source )
228
+ context . map . setSourceContent ( filename , context . source )
229
+ // @ts -ignore
230
+ context . map . _sources . add ( filename )
228
231
}
229
232
230
233
return context
0 commit comments