Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add SourceMapGenerator#toJSON #32

Merged
merged 1 commit into from

2 participants

@fgnass

This way JSON.stringify(map) will return the same external representation as map.toString() does.

@fgnass fgnass Added SourceMapGenerator#toJSON
This way `JSON.stringify(map)` will return the same representation as `map.toString()` does.
76cc0eb
@fitzgen fitzgen merged commit 78bcf01 into from
@fitzgen
Owner

Thanks!

I just published 0.1.7 on npm, which has this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 2, 2012
  1. @fgnass

    Added SourceMapGenerator#toJSON

    fgnass authored
    This way `JSON.stringify(map)` will return the same representation as `map.toString()` does.
This page is out of date. Refresh to see the latest.
View
16 lib/source-map/source-map-generator.js
@@ -172,10 +172,10 @@ define(function (require, exports, module) {
};
/**
- * Render the source map being generated to a string.
+ * Externalize the source map.
*/
- SourceMapGenerator.prototype.toString =
- function SourceMapGenerator_toString() {
+ SourceMapGenerator.prototype.toJSON =
+ function SourceMapGenerator_toJSON() {
var map = {
version: this._version,
file: this._file,
@@ -186,7 +186,15 @@ define(function (require, exports, module) {
if (this._sourceRoot) {
map.sourceRoot = this._sourceRoot;
}
- return JSON.stringify(map);
+ return map;
+ };
+
+ /**
+ * Render the source map being generated to a string.
+ */
+ SourceMapGenerator.prototype.toString =
+ function SourceMapGenerator_toString() {
+ return JSON.stringify(this);
};
exports.SourceMapGenerator = SourceMapGenerator;
View
8 test/source-map/test-source-map-generator.js
@@ -19,6 +19,14 @@ define(function (require, exports, module) {
assert.ok(true);
};
+ exports['test JSON serialization'] = function (assert, util) {
+ var map = new SourceMapGenerator({
+ file: 'foo.js',
+ sourceRoot: '.'
+ });
+ assert.equal(map.toString(), JSON.stringify(map));
+ };
+
exports['test adding mappings (case 1)'] = function (assert, util) {
var map = new SourceMapGenerator({
file: 'generated-foo.js',
Something went wrong with that request. Please try again.