Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not throw an error since broken prev map is popular issue #20

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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