@@ -170,60 +170,6 @@ Napi::Object SourceMapBinding::_mappingToObject(Napi::Env env, Mapping &mapping)
170170 return mappingObject;
171171}
172172
173- // returns the sorted and processed map with decoded vlqs and all other map data
174- Napi::Value SourceMapBinding::getMap (const Napi::CallbackInfo &info) {
175- Napi::Env env = info.Env ();
176- Napi::HandleScope scope (env);
177-
178- Napi::Object obj = Napi::Object::New (env);
179-
180- // Sort mappings
181- _mapping_container.sort ();
182-
183- auto sourcesVector = _mapping_container.getSourcesVector ();
184- int len = sourcesVector.size ();
185- Napi::Array sourcesArray = Napi::Array::New (env, len);
186- for (int i = 0 ; i < len; ++i) {
187- sourcesArray.Set (i, sourcesVector[i]);
188- }
189- obj.Set (" sources" , sourcesArray);
190-
191- auto sourcesContentVector = _mapping_container.getSourcesContentVector ();
192- len = sourcesContentVector.size ();
193- Napi::Array sourcesContentArray = Napi::Array::New (env, len);
194- for (int i = 0 ; i < len; ++i) {
195- sourcesContentArray.Set (i, sourcesContentVector[i]);
196- }
197- obj.Set (" sourcesContent" , sourcesContentArray);
198-
199- auto namesVector = _mapping_container.getNamesVector ();
200- len = namesVector.size ();
201- Napi::Array namesArray = Napi::Array::New (env, len);
202- for (int i = 0 ; i < len; ++i) {
203- namesArray.Set (i, namesVector[i]);
204- }
205- obj.Set (" names" , namesArray);
206-
207- auto mappingLinesVector = _mapping_container.getMappingLinesVector ();
208- Napi::Array mappingsArray = Napi::Array::New (env, _mapping_container.getTotalSegments ());
209- auto lineEnd = mappingLinesVector.end ();
210- int currentMapping = 0 ;
211- for (auto lineIterator = mappingLinesVector.begin (); lineIterator != lineEnd; ++lineIterator) {
212- auto &line = (*lineIterator);
213- auto &segments = line._segments ;
214- auto segmentsEnd = segments.end ();
215-
216- for (auto segmentIterator = segments.begin (); segmentIterator != segmentsEnd; ++segmentIterator) {
217- Mapping &mapping = *segmentIterator;
218- mappingsArray.Set (currentMapping, _mappingToObject (env, mapping));
219- ++currentMapping;
220- }
221- }
222- obj.Set (" mappings" , mappingsArray);
223-
224- return obj;
225- }
226-
227173void SourceMapBinding::addIndexedMappings (const Napi::CallbackInfo &info) {
228174 Napi::Env env = info.Env ();
229175 Napi::HandleScope scope (env);
@@ -269,7 +215,6 @@ Napi::Value SourceMapBinding::getSourceIndex(const Napi::CallbackInfo &info) {
269215 return Napi::Number::New (env, index);
270216}
271217
272-
273218Napi::Value SourceMapBinding::getSource (const Napi::CallbackInfo &info) {
274219 Napi::Env env = info.Env ();
275220 Napi::HandleScope scope (env);
@@ -283,6 +228,20 @@ Napi::Value SourceMapBinding::getSource(const Napi::CallbackInfo &info) {
283228 return Napi::String::New (env, _mapping_container.getSource (index));
284229}
285230
231+ Napi::Value SourceMapBinding::getSources (const Napi::CallbackInfo &info) {
232+ Napi::Env env = info.Env ();
233+ Napi::HandleScope scope (env);
234+
235+ auto sourcesVector = _mapping_container.getSourcesVector ();
236+ int len = sourcesVector.size ();
237+ Napi::Array sourcesArray = Napi::Array::New (env, len);
238+ for (int i = 0 ; i < len; ++i) {
239+ sourcesArray.Set (i, sourcesVector[i]);
240+ }
241+
242+ return sourcesArray;
243+ }
244+
286245Napi::Value SourceMapBinding::getNameIndex (const Napi::CallbackInfo &info) {
287246 Napi::Env env = info.Env ();
288247 Napi::HandleScope scope (env);
@@ -311,6 +270,20 @@ Napi::Value SourceMapBinding::getName(const Napi::CallbackInfo &info) {
311270 return Napi::String::New (env, _mapping_container.getName (index));
312271}
313272
273+ Napi::Value SourceMapBinding::getNames (const Napi::CallbackInfo &info) {
274+ Napi::Env env = info.Env ();
275+ Napi::HandleScope scope (env);
276+
277+ auto namesVector = _mapping_container.getNamesVector ();
278+ int len = namesVector.size ();
279+ Napi::Array namesArray = Napi::Array::New (env, len);
280+ for (int i = 0 ; i < len; ++i) {
281+ namesArray.Set (i, namesVector[i]);
282+ }
283+
284+ return namesArray;
285+ }
286+
314287std::vector<int > SourceMapBinding::_addNames (Napi::Array &namesArray) {
315288 std::vector<int > insertions;
316289 insertions.reserve (namesArray.Length ());
@@ -395,6 +368,47 @@ Napi::Value SourceMapBinding::getSourceContent(const Napi::CallbackInfo &info) {
395368 return Napi::String::New (env, _mapping_container.getSourceContent (_mapping_container.getSourceIndex (sourceName)));
396369}
397370
371+ Napi::Value SourceMapBinding::getSourcesContent (const Napi::CallbackInfo &info) {
372+ Napi::Env env = info.Env ();
373+ Napi::HandleScope scope (env);
374+
375+ auto sourcesContentVector = _mapping_container.getSourcesContentVector ();
376+ int len = sourcesContentVector.size ();
377+ Napi::Array sourcesContentArray = Napi::Array::New (env, len);
378+ for (int i = 0 ; i < len; ++i) {
379+ sourcesContentArray.Set (i, sourcesContentVector[i]);
380+ }
381+
382+ return sourcesContentArray;
383+ }
384+
385+ // returns the sorted and processed mappings with decoded vlqs
386+ Napi::Value SourceMapBinding::getMappings (const Napi::CallbackInfo &info) {
387+ Napi::Env env = info.Env ();
388+ Napi::HandleScope scope (env);
389+
390+ // Sort mappings
391+ _mapping_container.sort ();
392+
393+ auto mappingLinesVector = _mapping_container.getMappingLinesVector ();
394+ Napi::Array mappingsArray = Napi::Array::New (env, _mapping_container.getTotalSegments ());
395+ auto lineEnd = mappingLinesVector.end ();
396+ int currentMapping = 0 ;
397+ for (auto lineIterator = mappingLinesVector.begin (); lineIterator != lineEnd; ++lineIterator) {
398+ auto &line = (*lineIterator);
399+ auto &segments = line._segments ;
400+ auto segmentsEnd = segments.end ();
401+
402+ for (auto segmentIterator = segments.begin (); segmentIterator != segmentsEnd; ++segmentIterator) {
403+ Mapping &mapping = *segmentIterator;
404+ mappingsArray.Set (currentMapping, _mappingToObject (env, mapping));
405+ ++currentMapping;
406+ }
407+ }
408+
409+ return mappingsArray;
410+ }
411+
398412void SourceMapBinding::addEmptyMap (const Napi::CallbackInfo &info) {
399413 Napi::Env env = info.Env ();
400414 Napi::HandleScope scope (env);
@@ -464,16 +478,19 @@ Napi::Object SourceMapBinding::Init(Napi::Env env, Napi::Object exports) {
464478 InstanceMethod (" addBufferMappings" , &SourceMapBinding::addBufferMappings),
465479 InstanceMethod (" stringify" , &SourceMapBinding::stringify),
466480 InstanceMethod (" toBuffer" , &SourceMapBinding::toBuffer),
467- InstanceMethod (" getMap" , &SourceMapBinding::getMap),
468481 InstanceMethod (" addIndexedMappings" , &SourceMapBinding::addIndexedMappings),
469482 InstanceMethod (" addName" , &SourceMapBinding::addName),
470483 InstanceMethod (" addSource" , &SourceMapBinding::addSource),
471484 InstanceMethod (" setSourceContent" , &SourceMapBinding::setSourceContent),
472485 InstanceMethod (" getSourceContent" , &SourceMapBinding::getSourceContent),
486+ InstanceMethod (" getSourcesContent" , &SourceMapBinding::getSourcesContent),
473487 InstanceMethod (" getSourceIndex" , &SourceMapBinding::getSourceIndex),
474488 InstanceMethod (" getSource" , &SourceMapBinding::getSource),
489+ InstanceMethod (" getSources" , &SourceMapBinding::getSources),
475490 InstanceMethod (" getNameIndex" , &SourceMapBinding::getNameIndex),
476491 InstanceMethod (" getName" , &SourceMapBinding::getName),
492+ InstanceMethod (" getNames" , &SourceMapBinding::getNames),
493+ InstanceMethod (" getMappings" , &SourceMapBinding::getMappings),
477494 InstanceMethod (" extends" , &SourceMapBinding::extends),
478495 InstanceMethod (" addEmptyMap" , &SourceMapBinding::addEmptyMap),
479496 InstanceMethod (" findClosestMapping" , &SourceMapBinding::findClosestMapping),
0 commit comments