{"action":"opened","issue":{"url":"https://api.github.com/repos/mozilla/source-map/issues/156","labels_url":"https://api.github.com/repos/mozilla/source-map/issues/156/labels{/name}","comments_url":"https://api.github.com/repos/mozilla/source-map/issues/156/comments","events_url":"https://api.github.com/repos/mozilla/source-map/issues/156/events","html_url":"https://github.com/mozilla/source-map/issues/156","id":56468049,"number":156,"title":"`generator.toString()` versus `JSON.stringify(generator.toJSON())`","user":{"login":"brycecr","id":1319512,"avatar_url":"https://avatars.githubusercontent.com/u/1319512?v=3","gravatar_id":"","url":"https://api.github.com/users/brycecr","html_url":"https://github.com/brycecr","followers_url":"https://api.github.com/users/brycecr/followers","following_url":"https://api.github.com/users/brycecr/following{/other_user}","gists_url":"https://api.github.com/users/brycecr/gists{/gist_id}","starred_url":"https://api.github.com/users/brycecr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brycecr/subscriptions","organizations_url":"https://api.github.com/users/brycecr/orgs","repos_url":"https://api.github.com/users/brycecr/repos","events_url":"https://api.github.com/users/brycecr/events{/privacy}","received_events_url":"https://api.github.com/users/brycecr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-04T01:42:43Z","updated_at":"2015-02-04T01:42:43Z","closed_at":null,"body":"The instructions in the readme for Generating a Source Map using the low level api state that a client should create a generator, call `addMapping` as needed, and then call `toString()` to get the map out follows:\r\n\r\n```\r\nconsole.log(map.toString());\r\n// '{\"version\":3,\"file\":\"source-mapped.js\",\"sources\":[\"foo.js\"],\"names\":[\"christopher\"],\"mappings\":\";;;;;;;;;mCAgCEA\"}'\r\n```\r\n\r\nHowever, the generator toString is defined as:\r\n```\r\n    function SourceMapGenerator_toString() {\r\n      return JSON.stringify(this);\r\n    };\r\n```\r\n\r\nWhich does not generate the form in the comment below the console log, it generates something like:\r\n```\r\n{ _file: 'sourcemap.js.map',\r\n  _sourceRoot: null,\r\n  _sources: { _array: [ 'fixture.js' ], _set: { '$fixture.js': 0 } },\r\n  _names: { _array: [ 'map', 'v' ], _set: { '$map': 0, '$v': 1 } },\r\n  _mappings: \r\n   [ { generatedLine: 1,\r\n       generatedColumn: 0,\r\n       originalLine: 1,\r\n       originalColumn: 0,\r\n       source: 'fixture.js',\r\n       name: null },\r\n     { generatedLine: 1,\r\n       generatedColumn: 3,\r\n       originalLine: 1,\r\n       originalColumn: 3,\r\n       source: 'fixture.js',\r\n       name: 'map' }, ],\r\n  _sourcesContents: { '$fixture.js': '[].map(v => v + 1)' } }\r\n```\r\n\r\nSo, as far as I can tell, either the readme needs to change to instruct clients to call `JSON.stringify(map.toJSON())`, or the definition of `generator.toString` needs to change to return the correct source map format.\r\n\r\nI am happy to submit either patch, but I wanted to raise this as an issue in case I'm missing something here, and/or to ask which approach is preferable. Personally, I think the definition of toString should change as that seems to be what was intended in the first place, but I only have a pony in this race."}}