Skip to content

Commit 8c9b10e

Browse files
authored
Do not throw an error since broken prev map is popular issue (#20)
1 parent 45f7492 commit 8c9b10e

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

Diff for: lib/source-map-generator.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ SourceMapGenerator.prototype.addMapping =
107107
var name = util.getArg(aArgs, 'name', null);
108108

109109
if (!this._skipValidation) {
110-
this._validateMapping(generated, original, source, name);
110+
if (this._validateMapping(generated, original, source, name) === false) {
111+
return;
112+
}
111113
}
112114

113115
if (source != null) {
@@ -273,11 +275,14 @@ SourceMapGenerator.prototype._validateMapping =
273275
// specific error message to try to guide them the right way.
274276
// For example: https://github.com/Polymer/polymer-bundler/pull/519
275277
if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
276-
throw new Error(
278+
if (typeof console !== 'undefined' && console.warn) {
279+
console.warn(
277280
'original.line and original.column are not numbers -- you probably meant to omit ' +
278281
'the original mapping entirely and only map the generated position. If so, pass ' +
279282
'null for the original mapping instead of an object with empty or null values.'
280283
);
284+
}
285+
return false;
281286
}
282287

283288
if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
@@ -295,12 +300,15 @@ SourceMapGenerator.prototype._validateMapping =
295300
return;
296301
}
297302
else {
298-
throw new Error('Invalid mapping: ' + JSON.stringify({
299-
generated: aGenerated,
300-
source: aSource,
301-
original: aOriginal,
302-
name: aName
303-
}));
303+
if (typeof console !== 'undefined' && console.warn) {
304+
console.warn('Invalid mapping: ' + JSON.stringify({
305+
generated: aGenerated,
306+
source: aSource,
307+
original: aOriginal,
308+
name: aName
309+
}));
310+
}
311+
return false;
304312
}
305313
};
306314

Diff for: test/test-source-map-generator.js

-8
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ exports['test adding mappings (invalid)'] = function (assert) {
8585
assert.throws(function () {
8686
map.addMapping({});
8787
});
88-
89-
// Original file position, but no source.
90-
assert.throws(function () {
91-
map.addMapping({
92-
generated: { line: 1, column: 1 },
93-
original: { line: 1, column: 1 }
94-
});
95-
});
9688
};
9789

9890
exports['test adding mappings with skipValidation'] = function (assert) {

0 commit comments

Comments
 (0)