@@ -65,12 +65,14 @@ void SourceMapBinding::addBufferMappings(const Napi::CallbackInfo &info) {
65
65
}
66
66
67
67
if (info.Length () > 1 && !info[1 ].IsNumber ()) {
68
- Napi::TypeError::New (env, " Expected a lineOffset of type integer for the second parameter" ).ThrowAsJavaScriptException ();
68
+ Napi::TypeError::New (env,
69
+ " Expected a lineOffset of type integer for the second parameter" ).ThrowAsJavaScriptException ();
69
70
return ;
70
71
}
71
72
72
73
if (info.Length () > 2 && !info[2 ].IsNumber ()) {
73
- Napi::TypeError::New (env, " Expected a columnOffset of type integer for the third parameter" ).ThrowAsJavaScriptException ();
74
+ Napi::TypeError::New (env,
75
+ " Expected a columnOffset of type integer for the third parameter" ).ThrowAsJavaScriptException ();
74
76
return ;
75
77
}
76
78
@@ -205,68 +207,24 @@ Napi::Value SourceMapBinding::getMap(const Napi::CallbackInfo &info) {
205
207
return obj;
206
208
}
207
209
208
- // addIndexedMappings(array<mapping>, lineOffset, columnOffset): uses numbers for source and name with the index specified in the sources/names map/array in SourceMap instance
209
- void SourceMapBinding::addIndexedMappings (const Napi::CallbackInfo &info) {
210
+ // addIndexedMapping(generatedLine, generatedColumn, originalLine, originalColumn, source, name)
211
+ void SourceMapBinding::addIndexedMapping (const Napi::CallbackInfo &info) {
210
212
Napi::Env env = info.Env ();
211
213
Napi::HandleScope scope (env);
212
214
213
- if (info.Length () < 1 ) {
214
- Napi::TypeError::New (env, " Expected 1-3 parameters" ).ThrowAsJavaScriptException ();
215
- return ;
216
- }
217
-
218
- if (!info[0 ].IsArray ()) {
219
- Napi::TypeError::New (env, " First parameter should be an array" ).ThrowAsJavaScriptException ();
220
- return ;
221
- }
222
-
223
- if (info.Length () > 1 && !info[1 ].IsNumber ()) {
224
- Napi::TypeError::New (env,
225
- " Second parameter should be a lineOffset of type integer" ).ThrowAsJavaScriptException ();
226
- return ;
227
- }
228
-
229
- if (info.Length () > 2 && !info[2 ].IsNumber ()) {
230
- Napi::TypeError::New (env,
231
- " Third parameter should be a lineOffset of type integer" ).ThrowAsJavaScriptException ();
215
+ if (info.Length () < 6 ) {
216
+ Napi::TypeError::New (env, " Expected 6 parameters" ).ThrowAsJavaScriptException ();
232
217
return ;
233
218
}
234
219
235
- const Napi::Array mappingsArray = info[0 ].As <Napi::Array>();
236
- int lineOffset = info.Length () > 1 ? info[1 ].As <Napi::Number>().Int32Value () : 0 ;
237
- int columnOffset = info.Length () > 2 ? info[2 ].As <Napi::Number>().Int32Value () : 0 ;
220
+ int generatedLine = info[0 ].As <Napi::Number>().Int32Value ();
221
+ int generatedColumn = info[1 ].As <Napi::Number>().Int32Value ();
222
+ int originalLine = info[2 ].As <Napi::Number>().Int32Value ();
223
+ int originalColumn = info[3 ].As <Napi::Number>().Int32Value ();
224
+ std::string source = info[4 ].As <Napi::String>().Utf8Value ();
225
+ std::string name = info[5 ].As <Napi::String>().Utf8Value ();
238
226
239
- unsigned int length = mappingsArray.Length ();
240
- for (unsigned int i = 0 ; i < length; ++i) {
241
- Napi::Value mapping = mappingsArray.Get (i);
242
- Napi::Object mappingObject = mapping.As <Napi::Object>();
243
-
244
- Napi::Object generated = mappingObject.Get (" generated" ).As <Napi::Object>();
245
- int generatedLine = generated.Get (" line" ).As <Napi::Number>().Int32Value () - 1 ;
246
- int generatedColumn = generated.Get (" column" ).As <Napi::Number>().Int32Value ();
247
- Position generatedPosition = Position{generatedLine + lineOffset, generatedColumn + columnOffset};
248
-
249
- Napi::Value originalPositionValue = mappingObject.Get (" original" );
250
- if (originalPositionValue.IsObject ()) {
251
- Napi::Object originalPositionObject = originalPositionValue.As <Napi::Object>();
252
- int originalLine = originalPositionObject.Get (" line" ).As <Napi::Number>().Int32Value () - 1 ;
253
- int originalColumn = originalPositionObject.Get (" column" ).As <Napi::Number>().Int32Value ();
254
- Position originalPosition = Position{originalLine, originalColumn};
255
-
256
- std::string sourceString = mappingObject.Get (" source" ).As <Napi::String>().Utf8Value ();
257
- int source = _mapping_container.addSource (sourceString);
258
-
259
- Napi::Value nameValue = mappingObject.Get (" name" );
260
- if (nameValue.IsString ()) {
261
- std::string nameString = nameValue.As <Napi::String>().Utf8Value ();
262
- _mapping_container.addMapping (generatedPosition, originalPosition, source, _mapping_container.addName (nameString));
263
- } else {
264
- _mapping_container.addMapping (generatedPosition, originalPosition, source);
265
- }
266
- } else {
267
- _mapping_container.addMapping (generatedPosition);
268
- }
269
- }
227
+ _mapping_container.addIndexedMapping (generatedLine, generatedColumn, originalLine, originalColumn, source, name);
270
228
}
271
229
272
230
Napi::Value SourceMapBinding::getSourceIndex (const Napi::CallbackInfo &info) {
@@ -368,7 +326,8 @@ void SourceMapBinding::addEmptyMap(const Napi::CallbackInfo &info) {
368
326
}
369
327
370
328
if (info.Length () == 3 && !info[2 ].IsNumber ()) {
371
- Napi::TypeError::New (env, " Expected third parameter to be a lineOffset of type Integer" ).ThrowAsJavaScriptException ();
329
+ Napi::TypeError::New (env,
330
+ " Expected third parameter to be a lineOffset of type Integer" ).ThrowAsJavaScriptException ();
372
331
return ;
373
332
}
374
333
@@ -387,8 +346,9 @@ Napi::Value SourceMapBinding::findClosestMapping(const Napi::CallbackInfo &info)
387
346
Napi::TypeError::New (env, " Expected 1 parameter of type buffer" ).ThrowAsJavaScriptException ();
388
347
return env.Null ();
389
348
}
390
-
391
- Mapping m = _mapping_container.findClosestMapping (info[0 ].As <Napi::Number>().Int32Value () - 1 , info[1 ].As <Napi::Number>().Int32Value ());
349
+
350
+ Mapping m = _mapping_container.findClosestMapping (info[0 ].As <Napi::Number>().Int32Value () - 1 ,
351
+ info[1 ].As <Napi::Number>().Int32Value ());
392
352
return _mappingToObject (env, m);
393
353
}
394
354
@@ -401,7 +361,7 @@ Napi::Object SourceMapBinding::Init(Napi::Env env, Napi::Object exports) {
401
361
InstanceMethod (" stringify" , &SourceMapBinding::stringify),
402
362
InstanceMethod (" toBuffer" , &SourceMapBinding::toBuffer),
403
363
InstanceMethod (" getMap" , &SourceMapBinding::getMap),
404
- InstanceMethod (" addIndexedMappings " , &SourceMapBinding::addIndexedMappings ),
364
+ InstanceMethod (" addIndexedMapping " , &SourceMapBinding::addIndexedMapping ),
405
365
InstanceMethod (" addNames" , &SourceMapBinding::addNames),
406
366
InstanceMethod (" addSources" , &SourceMapBinding::addSources),
407
367
InstanceMethod (" getSourceIndex" , &SourceMapBinding::getSourceIndex),
0 commit comments