Skip to content

Commit

Permalink
Do not throw an error since broken prev map is popular issue (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Mar 17, 2024
1 parent 45f7492 commit 8c9b10e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
24 changes: 16 additions & 8 deletions lib/source-map-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ SourceMapGenerator.prototype.addMapping =
var name = util.getArg(aArgs, 'name', null);

if (!this._skipValidation) {
this._validateMapping(generated, original, source, name);
if (this._validateMapping(generated, original, source, name) === false) {
return;
}
}

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

if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
Expand All @@ -295,12 +300,15 @@ SourceMapGenerator.prototype._validateMapping =
return;
}
else {
throw new Error('Invalid mapping: ' + JSON.stringify({
generated: aGenerated,
source: aSource,
original: aOriginal,
name: aName
}));
if (typeof console !== 'undefined' && console.warn) {
console.warn('Invalid mapping: ' + JSON.stringify({
generated: aGenerated,
source: aSource,
original: aOriginal,
name: aName
}));
}
return false;
}
};

Expand Down
8 changes: 0 additions & 8 deletions test/test-source-map-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ exports['test adding mappings (invalid)'] = function (assert) {
assert.throws(function () {
map.addMapping({});
});

// Original file position, but no source.
assert.throws(function () {
map.addMapping({
generated: { line: 1, column: 1 },
original: { line: 1, column: 1 }
});
});
};

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

0 comments on commit 8c9b10e

Please sign in to comment.