mappings-from-map.js 833 B

123456789101112131415161718192021222324252627282930
  1. var SMConsumer = require('source-map').SourceMapConsumer;
  2. /**
  3. * @name mappingsFromMap
  4. * @function
  5. * @param map {Object} the JSON.parse()'ed map
  6. * @return {Array} array of mappings
  7. */
  8. module.exports = function (map) {
  9. var consumer = new SMConsumer(map);
  10. var mappings = [];
  11. consumer.eachMapping(function (mapping) {
  12. // only set source if we have original position to handle edgecase (see inline-source-map tests)
  13. mappings.push({
  14. original: mapping.originalColumn != null ? {
  15. column: mapping.originalColumn
  16. , line: mapping.originalLine
  17. } : undefined
  18. , generated: {
  19. column: mapping.generatedColumn
  20. , line: mapping.generatedLine
  21. }
  22. , source: mapping.originalColumn != null ? mapping.source : undefined
  23. , name: mapping.name
  24. });
  25. });
  26. return mappings;
  27. }