From 84ef8e8b09c816a88abf5abc0290d7b0776910b3 Mon Sep 17 00:00:00 2001 From: Jonny Gerig Meyer Date: Mon, 29 Feb 2016 14:41:02 -0500 Subject: [PATCH] Do not output "undefined" if more mappings than lines. --- lib/fromStringWithSourceMap.js | 1 + .../from-to-tests/mismatched-mappings.expected.map | 11 +++++++++++ .../from-to-tests/mismatched-mappings.generated.txt | 3 +++ .../from-to-tests/mismatched-mappings.input.map | 11 +++++++++++ 4 files changed, 26 insertions(+) create mode 100644 test/fixtures/from-to-tests/mismatched-mappings.expected.map create mode 100644 test/fixtures/from-to-tests/mismatched-mappings.generated.txt create mode 100644 test/fixtures/from-to-tests/mismatched-mappings.input.map diff --git a/lib/fromStringWithSourceMap.js b/lib/fromStringWithSourceMap.js index 2d75404..cbddf99 100644 --- a/lib/fromStringWithSourceMap.js +++ b/lib/fromStringWithSourceMap.js @@ -19,6 +19,7 @@ module.exports = function fromStringWithSourceMap(code, map) { var currentSourceNodeLine; mappings.forEach(function(mapping, idx) { var line = lines[idx]; + if(typeof line === 'undefined') return; if(idx !== lines.length - 1) line += "\n"; if(!mapping) return addCode(line); diff --git a/test/fixtures/from-to-tests/mismatched-mappings.expected.map b/test/fixtures/from-to-tests/mismatched-mappings.expected.map new file mode 100644 index 0000000..95bc6c8 --- /dev/null +++ b/test/fixtures/from-to-tests/mismatched-mappings.expected.map @@ -0,0 +1,11 @@ +{ + "version": 3, + "file": "mismatched-mappings.generated.txt", + "sources": [ + "hello-world.txt" + ], + "sourcesContent": [ + "function foobar() {\n return; // foo\n}" + ], + "mappings": "AAAA;AACA;AADA" +} diff --git a/test/fixtures/from-to-tests/mismatched-mappings.generated.txt b/test/fixtures/from-to-tests/mismatched-mappings.generated.txt new file mode 100644 index 0000000..3244fe7 --- /dev/null +++ b/test/fixtures/from-to-tests/mismatched-mappings.generated.txt @@ -0,0 +1,3 @@ +function foobar() { + return; // foo +} \ No newline at end of file diff --git a/test/fixtures/from-to-tests/mismatched-mappings.input.map b/test/fixtures/from-to-tests/mismatched-mappings.input.map new file mode 100644 index 0000000..b4cf362 --- /dev/null +++ b/test/fixtures/from-to-tests/mismatched-mappings.input.map @@ -0,0 +1,11 @@ +{ + "version": 3, + "file": "mismatched-mappings.generated.txt", + "sources": [ + "hello-world.txt" + ], + "sourcesContent": [ + "function foobar() {\n return; // foo\n}" + ], + "mappings": "AAAA,SAAS,MAAT,GAAmB;AACjB;CADF;AAAmB" +}