pax_global_header00006660000000000000000000000064126043122540014511gustar00rootroot0000000000000052 comment=ea108c3081334403d47c635942932cd6e8235fa1 inline-source-map-0.6.1/000077500000000000000000000000001260431225400150445ustar00rootroot00000000000000inline-source-map-0.6.1/.gitignore000066400000000000000000000001451260431225400170340ustar00rootroot00000000000000lib-cov *.seed *.log *.csv *.dat *.out *.pid *.gz pids logs results node_modules npm-debug.log tmp inline-source-map-0.6.1/.travis.yml000066400000000000000000000001701260431225400171530ustar00rootroot00000000000000sudo: false language: node_js node_js: - 0.8 - 0.10 - 0.12 - io.js before_install: - npm install --global npm inline-source-map-0.6.1/LICENSE000066400000000000000000000020661260431225400160550ustar00rootroot00000000000000Copyright 2013 Thorsten Lorenz. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. inline-source-map-0.6.1/README.md000066400000000000000000000055671260431225400163400ustar00rootroot00000000000000# inline-source-map [![build status](https://secure.travis-ci.org/thlorenz/inline-source-map.png)](http://travis-ci.org/thlorenz/inline-source-map) Adds source mappings and base64 encodes them, so they can be inlined in your generated file. ```js var generator = require('inline-source-map'); // default charset 'utf-8' is configurable var gen = generator({ charset: 'utf-8' }) .addMappings('foo.js', [{ original: { line: 2, column: 3 } , generated: { line: 5, column: 10 } }], { line: 5 }) .addGeneratedMappings('bar.js', 'var a = 2;\nconsole.log(a)', { line: 23, column: 22 }); console.log('base64 mapping:', gen.base64Encode()); console.log('inline mapping url:', gen.inlineMappingUrl()); ``` ``` base64 mapping: eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmb28uanMiLCJiYXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O1VBQ0c7Ozs7Ozs7Ozs7Ozs7O3NCQ0RIO3NCQUNBIn0= inline mapping url: //@ sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmb28uanMiLCJiYXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O1VBQ0c7Ozs7Ozs7Ozs7Ozs7O3NCQ0RIO3NCQUNBIn0= ``` ## API ### addMappings(sourceFile, mappings, offset) ``` /** * Adds the given mappings to the generator and offsets them if offset is given * * @name addMappings * @function * @param sourceFile {String} name of the source file * @param mappings {Array{{Object}} each object has the form { original: { line: _, column: _ }, generated: { line: _, column: _ } } * @param offset {Object} offset to apply to each mapping. Has the form { line: _, column: _ } * @return {Object} the generator to allow chaining */ ``` ### addGeneratedMappings(sourceFile, source, offset) ``` /** * Generates mappings for the given source and adds them, assuming that no translation from original to generated is necessary. * * @name addGeneratedMappings * @function * @param sourceFile {String} name of the source file * @param source {String} source of the file * @param offset {Object} offset to apply to each mapping. Has the form { line: _, column: _ } * @return {Object} the generator to allow chaining */ ``` ### addSourceContent(sourceFile, sourceContent) ``` /** * Adds source content for the given source file. * * @name addSourceContent * @function * @param sourceFile {String} The source file for which a mapping is included * @param sourceContent {String} The content of the source file * @return {Object} The generator to allow chaining */ ``` ### base64Encode() ``` /** * @name base64Encode * @function * @return {String} bas64 encoded representation of the added mappings */ ``` If source contents were added, this will be included in the encoded mappings. ### inlineMappingUrl() ``` /** * @name inlineMappingUrl * @function * @return {String} comment with base64 encoded representation of the added mappings. Can be inlined at the end of the generated file. */ ``` inline-source-map-0.6.1/example/000077500000000000000000000000001260431225400164775ustar00rootroot00000000000000inline-source-map-0.6.1/example/foo-bar.js000066400000000000000000000005631260431225400203660ustar00rootroot00000000000000var generator = require('..'); var gen = generator() .addMappings('foo.js', [{ original: { line: 2, column: 3 } , generated: { line: 5, column: 10 } }], { line: 5 }) .addGeneratedMappings('bar.js', 'var a = 2;\nconsole.log(a)', { line: 23, column: 22 }); console.log('base64 mapping', gen.base64Encode()); console.log('inline mapping url', gen.inlineMappingUrl()); inline-source-map-0.6.1/index.js000066400000000000000000000103021260431225400165050ustar00rootroot00000000000000'use strict'; var SourceMapGenerator = require('source-map').SourceMapGenerator; function offsetMapping(mapping, offset) { return { line: offset.line + mapping.line, column: offset.column + mapping.column }; } function newlinesIn(src) { if (!src) return 0; var newlines = src.match(/\n/g); return newlines ? newlines.length : 0; } function Generator(opts) { opts = opts || {}; this.generator = new SourceMapGenerator({ file: opts.file || '', sourceRoot: opts.sourceRoot || '' }); this.sourcesContent = undefined; this.opts = opts; } /** * Adds the given mappings to the generator and offsets them if offset is given * * @name addMappings * @function * @param sourceFile {String} name of the source file * @param mappings {Array{{Object}} each object has the form { original: { line: _, column: _ }, generated: { line: _, column: _ } } * @param offset {Object} offset to apply to each mapping. Has the form { line: _, column: _ } * @return {Object} the generator to allow chaining */ Generator.prototype.addMappings = function (sourceFile, mappings, offset) { var generator = this.generator; offset = offset || {}; offset.line = offset.hasOwnProperty('line') ? offset.line : 0; offset.column = offset.hasOwnProperty('column') ? offset.column : 0; mappings.forEach(function (m) { // only set source if we have original position to handle edgecase (see inline-source-map tests) generator.addMapping({ source : m.original ? sourceFile : undefined , original : m.original , generated : offsetMapping(m.generated, offset) }); }); return this; }; /** * Generates mappings for the given source, assuming that no translation from original to generated is necessary. * * @name addGeneratedMappings * @function * @param sourceFile {String} name of the source file * @param source {String} source of the file * @param offset {Object} offset to apply to each mapping. Has the form { line: _, column: _ } * @return {Object} the generator to allow chaining */ Generator.prototype.addGeneratedMappings = function (sourceFile, source, offset) { var mappings = [] , linesToGenerate = newlinesIn(source) + 1; for (var line = 1; line <= linesToGenerate; line++) { var location = { line: line, column: 0 }; mappings.push({ original: location, generated: location }); } return this.addMappings(sourceFile, mappings, offset); }; /** * Adds source content for the given source file. * * @name addSourceContent * @function * @param sourceFile {String} The source file for which a mapping is included * @param sourcesContent {String} The content of the source file * @return {Object} The generator to allow chaining */ Generator.prototype.addSourceContent = function (sourceFile, sourcesContent) { this.sourcesContent = this.sourcesContent || {}; this.sourcesContent[sourceFile] = sourcesContent; return this; }; /** * @name base64Encode * @function * @return {String} bas64 encoded representation of the added mappings */ Generator.prototype.base64Encode = function () { var map = this.toString(); return new Buffer(map).toString('base64'); }; /** * @name inlineMappingUrl * @function * @return {String} comment with base64 encoded representation of the added mappings. Can be inlined at the end of the generated file. */ Generator.prototype.inlineMappingUrl = function () { var charset = this.opts.charset || 'utf-8'; return '//# sourceMappingURL=data:application/json;charset=' + charset + ';base64,' + this.base64Encode(); }; Generator.prototype.toJSON = function () { var map = this.generator.toJSON(); if (!this.sourcesContent) return map; var toSourcesContent = (function (s) { if (typeof this.sourcesContent[s] === 'string') { return this.sourcesContent[s]; } else { return null; } }).bind(this); map.sourcesContent = map.sources.map(toSourcesContent); return map; }; Generator.prototype.toString = function () { return JSON.stringify(this); }; Generator.prototype._mappings = function () { return this.generator._mappings._array; }; Generator.prototype.gen = function () { return this.generator; }; module.exports = function (opts) { return new Generator(opts); }; module.exports.Generator = Generator; inline-source-map-0.6.1/package.json000066400000000000000000000022131260431225400173300ustar00rootroot00000000000000{ "name": "inline-source-map", "version": "0.6.1", "description": "Adds source mappings and base64 encodes them, so they can be inlined in your generated file.", "main": "index.js", "scripts": { "test-main": "tap test/*.js", "test-0.8": "nave use 0.8 npm run test-main", "test-0.10": "nave use 0.10 npm run test-main", "test-0.12": "nave use 0.12 npm run test-main", "test-all": "npm run test-main && npm run test-0.8 && npm run test-0.10 && npm run test-0.12", "test": "if [ -e $TRAVIS ]; then npm run test-all; else npm run test-main; fi" }, "repository": { "type": "git", "url": "git://github.com/thlorenz/inline-source-map.git" }, "homepage": "https://github.com/thlorenz/inline-source-map", "dependencies": { "source-map": "~0.4.0" }, "devDependencies": { "tap": "~0.7.0", "nave": "~0.5.0" }, "keywords": [ "source", "map", "inline", "base64", "bundle", "generate", "transpile" ], "author": { "name": "Thorsten Lorenz", "email": "thlorenz@gmx.de", "url": "http://thlorenz.com" }, "license": "MIT", "engine": { "node": ">=0.6" } } inline-source-map-0.6.1/test/000077500000000000000000000000001260431225400160235ustar00rootroot00000000000000inline-source-map-0.6.1/test/inline-source-map.js000066400000000000000000000260031260431225400217110ustar00rootroot00000000000000'use strict'; /*jshint asi: true*/ var test = require('tap').test var generator = require('..'); var foo = '' + function foo () { var hello = 'hello'; var world = 'world'; console.log('%s %s', hello, world); } var bar = '' + function bar () { console.log('yes?'); } function decode(base64) { return new Buffer(base64, 'base64').toString(); } function inspect(obj, depth) { console.error(require('util').inspect(obj, false, depth || 5, true)); } test('generated mappings', function (t) { t.test('one file no offset', function (t) { var gen = generator() .addGeneratedMappings('foo.js', foo) t.deepEqual( gen._mappings() , [ { generatedLine: 1, generatedColumn: 0, originalLine: 1, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 2, generatedColumn: 0, originalLine: 2, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 3, generatedColumn: 0, originalLine: 3, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 4, generatedColumn: 0, originalLine: 4, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 5, generatedColumn: 0, originalLine: 5, originalColumn: 0, source: 'foo.js', name: null } ] , 'generates correct mappings' ) t.deepEqual( JSON.parse(decode(gen.base64Encode())) , {"version":3,"file":"","sources":["foo.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA","sourceRoot":""} , 'encodes generated mappings' ) t.equal( gen.inlineMappingUrl() , '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIifQ==' , 'returns correct inline mapping url' ) t.end() }) t.test('two files no offset', function (t) { var gen = generator() .addGeneratedMappings('foo.js', foo) .addGeneratedMappings('bar.js', bar) t.deepEqual( gen._mappings() , [ { generatedLine: 1, generatedColumn: 0, originalLine: 1, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 2, generatedColumn: 0, originalLine: 2, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 3, generatedColumn: 0, originalLine: 3, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 4, generatedColumn: 0, originalLine: 4, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 5, generatedColumn: 0, originalLine: 5, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 1, generatedColumn: 0, originalLine: 1, originalColumn: 0, source: 'bar.js', name: null }, { generatedLine: 2, generatedColumn: 0, originalLine: 2, originalColumn: 0, source: 'bar.js', name: null }, { generatedLine: 3, generatedColumn: 0, originalLine: 3, originalColumn: 0, source: 'bar.js', name: null } ] , 'generates correct mappings' ) t.deepEqual( JSON.parse(decode(gen.base64Encode())) , {"version":3,"file":"","sources":["foo.js","bar.js"],"names":[],"mappings":"ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA","sourceRoot": ""} , 'encodes generated mappings' ) t.equal( gen.inlineMappingUrl() , '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyIsImJhci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUNBQSxBREFBO0FDQ0EsQURBQTtBQ0NBLEFEQUE7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIifQ==' , 'returns correct inline mapping url' ) t.end() }) t.test('one line source', function (t) { var gen = generator().addGeneratedMappings('one-liner.js', 'console.log("line one");') t.deepEqual( gen._mappings() , [ { generatedLine: 1, generatedColumn: 0, originalLine: 1, originalColumn: 0, source: 'one-liner.js', name: null } ] , 'generates correct mappings' ) t.end() }) t.test('with offset', function (t) { var gen = generator() .addGeneratedMappings('foo.js', foo, { line: 20 }) .addGeneratedMappings('bar.js', bar, { line: 23, column: 22 }) t.deepEqual( gen._mappings() , [ { generatedLine: 21, generatedColumn: 0, originalLine: 1, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 22, generatedColumn: 0, originalLine: 2, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 23, generatedColumn: 0, originalLine: 3, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 24, generatedColumn: 0, originalLine: 4, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 25, generatedColumn: 0, originalLine: 5, originalColumn: 0, source: 'foo.js', name: null }, { generatedLine: 24, generatedColumn: 22, originalLine: 1, originalColumn: 0, source: 'bar.js', name: null }, { generatedLine: 25, generatedColumn: 22, originalLine: 2, originalColumn: 0, source: 'bar.js', name: null }, { generatedLine: 26, generatedColumn: 22, originalLine: 3, originalColumn: 0, source: 'bar.js', name: null } ] , 'generates correct mappings' ) t.deepEqual( JSON.parse(decode(gen.base64Encode())) , {"version":3,"file":"","sources":["foo.js","bar.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA,sBCHA;ADIA,sBCHA;sBACA", "sourceRoot": ""} , 'encodes generated mappings with offset' ) t.end() }) }) test('given mappings, with one having no original', function (t) { t.test('no offset', function (t) { var gen = generator() .addMappings('foo.js', [{ original: { line: 2, column: 3 } , generated: { line: 5, column: 10 } }]) // This addresses an edgecase in which a transpiler generates mappings but doesn't include the original position. // If we set source to sourceFile (as usual) in that case, the mappings are considered invalid by the source-map module's // SourceMapGenerator. Keeping source undefined fixes this problem. // Raised issue: https://github.com/thlorenz/inline-source-map/issues/2 // Validate function: https://github.com/mozilla/source-map/blob/a3372ea78e662582087dd25ebda999c06424e047/lib/source-map/source-map-generator.js#L232 .addMappings('bar.js', [ { original: { line: 6, column: 0 } , generated: { line: 7, column: 20 } } , { generated: { line: 8, column: 30 } } ]) t.deepEqual( gen._mappings() , [ { generatedLine: 5, generatedColumn: 10, originalLine: 2, originalColumn: 3, source: 'foo.js', name: null }, { generatedLine: 7, generatedColumn: 20, originalLine: 6, originalColumn: 0, source: 'bar.js', name: null }, { generatedLine: 8, generatedColumn: 30, originalLine: false, originalColumn: false, source: undefined, name: null } ] , 'adds correct mappings' ) t.deepEqual( JSON.parse(decode(gen.base64Encode())) , {"version":3,"file":"","sources":["foo.js","bar.js"],"names":[],"mappings":";;;;UACG;;oBCIH;8B", sourceRoot: ""} , 'encodes generated mappings' ) t.equal( gen.inlineMappingUrl() , '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyIsImJhci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O1VBQ0c7O29CQ0lIOzhCIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIifQ==' , 'returns correct inline mapping url' ) t.end() }) t.test('with offset', function (t) { var gen = generator() .addMappings('foo.js', [{ original: { line: 2, column: 3 } , generated: { line: 5, column: 10 } }], { line: 5 }) .addMappings('bar.js', [{ original: { line: 6, column: 0 } , generated: { line: 7, column: 20 } }, { generated: { line: 8, column: 30 } }], { line: 9, column: 3 }) t.deepEqual( gen._mappings() , [ { generatedLine: 10, generatedColumn: 10, originalLine: 2, originalColumn: 3, source: 'foo.js', name: null }, { generatedLine: 16, generatedColumn: 23, originalLine: 6, originalColumn: 0, source: 'bar.js', name: null }, { generatedLine: 17, generatedColumn: 33, originalLine: false, originalColumn: false, source: undefined, name: null } ] , 'adds correct mappings' ) t.deepEqual( JSON.parse(decode(gen.base64Encode())) , {"version":3,"file":"","sources":["foo.js","bar.js"],"names":[],"mappings":";;;;;;;;;UACG;;;;;;uBCIH;iC", sourceRoot: ""} , 'encodes mappings with offset' ) t.end() }) }); test('inline mapping url with charset opt', function(t){ t.test('set inline mapping url charset to gbk', function(t){ var gen = generator({charset: 'gbk'}) .addGeneratedMappings('foo.js', foo); t.equal( gen.inlineMappingUrl(), '//# sourceMappingURL=data:application/json;charset=gbk;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIifQ==', 'charset set to gbk' ); t.end(); }); t.test('default charset should be utf-8', function(t){ var gen = generator() .addGeneratedMappings('foo.js', foo); t.equal( gen.inlineMappingUrl(), '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIifQ==', 'charset default to utf-8' ); t.end(); }); }); inline-source-map-0.6.1/test/source-content.js000066400000000000000000000130631260431225400213340ustar00rootroot00000000000000'use strict'; /*jshint asi: true*/ var test = require('tap').test var generator = require('..'); var foo = '' + function foo () { var hello = 'hello'; var world = 'world'; console.log('%s %s', hello, world); } var bar = '' + function bar () { console.log('yes?'); } function decode(base64) { return new Buffer(base64, 'base64').toString(); } function inspect(obj, depth) { console.log(require('util').inspect(obj, false, depth || 5, true)); } test('generated mappings', function (t) { t.test('one file with source content', function (t) { var gen = generator() .addGeneratedMappings('foo.js', foo) .addSourceContent('foo.js', foo) t.deepEqual( gen.toJSON() , { "version": 3, "file": "", "sources": [ "foo.js" ], "names": [], "mappings": "AAAA;AACA;AACA;AACA;AACA", "sourceRoot": "", "sourcesContent": [ "function foo() {\n var hello = 'hello';\n var world = 'world';\n console.log('%s %s', hello, world);\n}" ], } , 'includes source content' ) t.equal( decode(gen.base64Encode()) , '{"version":3,"sources":["foo.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA","file":"","sourceRoot":"","sourcesContent":["function foo() {\\n var hello = \'hello\';\\n var world = \'world\';\\n console.log(\'%s %s\', hello, world);\\n}"]}' , 'encodes generated mappings including source content' ) t.equal( gen.inlineMappingUrl() , '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyJmdW5jdGlvbiBmb28oKSB7XG4gIHZhciBoZWxsbyA9ICdoZWxsbyc7XG4gIHZhciB3b3JsZCA9ICd3b3JsZCc7XG4gIGNvbnNvbGUubG9nKCclcyAlcycsIGhlbGxvLCB3b3JsZCk7XG59Il19' , 'returns correct inline mapping url including source content' ) t.end() }) t.test('two files with source content', function (t) { var gen = generator() .addGeneratedMappings('foo.js', foo) .addSourceContent('foo.js', foo) .addGeneratedMappings('bar.js', bar) .addSourceContent('bar.js', bar) t.deepEqual( gen.toJSON() , { "version": 3, "file": "", "sources": [ "foo.js", "bar.js" ], "names": [], "mappings": "ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA", "sourceRoot": "", "sourcesContent": [ "function foo() {\n var hello = 'hello';\n var world = 'world';\n console.log('%s %s', hello, world);\n}", "function bar() {\n console.log('yes?');\n}" ], } , 'includes source content for both files' ) t.deepEqual( decode(gen.base64Encode()) , '{"version":3,"sources":["foo.js","bar.js"],"names":[],"mappings":"ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA","file":"","sourceRoot":"","sourcesContent":["function foo() {\\n var hello = \'hello\';\\n var world = \'world\';\\n console.log(\'%s %s\', hello, world);\\n}","function bar() {\\n console.log(\'yes?\');\\n}"]}' , 'encodes generated mappings including source content' ) t.equal( gen.inlineMappingUrl() , '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyIsImJhci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUNBQSxBREFBO0FDQ0EsQURBQTtBQ0NBLEFEQUE7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyJmdW5jdGlvbiBmb28oKSB7XG4gIHZhciBoZWxsbyA9ICdoZWxsbyc7XG4gIHZhciB3b3JsZCA9ICd3b3JsZCc7XG4gIGNvbnNvbGUubG9nKCclcyAlcycsIGhlbGxvLCB3b3JsZCk7XG59IiwiZnVuY3Rpb24gYmFyKCkge1xuICBjb25zb2xlLmxvZygneWVzPycpO1xufSJdfQ==' , 'returns correct inline mapping url including source content' ) t.end() }) t.test('two files, only one with source content', function (t) { var gen = generator() .addGeneratedMappings('foo.js', foo) .addGeneratedMappings('bar.js', bar) .addSourceContent('bar.js', bar) t.deepEqual( gen.toJSON() , { "version": 3, "file": "", "sources": [ "foo.js", "bar.js" ], "names": [], "mappings": "ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA", "sourcesContent": [ null, "function bar() {\n console.log('yes?');\n}" ], "sourceRoot": "" } , 'includes source content for the file with source content and [null] for the other file' ) t.deepEqual( decode(gen.base64Encode()) , '{"version":3,"sources":["foo.js","bar.js"],"names":[],"mappings":"ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA","file":"","sourceRoot":"","sourcesContent":[null,"function bar() {\\n console.log(\'yes?\');\\n}"]}' , 'encodes generated mappings including source content' ) t.equal( gen.inlineMappingUrl() , '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyIsImJhci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUNBQSxBREFBO0FDQ0EsQURBQTtBQ0NBLEFEQUE7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6W251bGwsImZ1bmN0aW9uIGJhcigpIHtcbiAgY29uc29sZS5sb2coJ3llcz8nKTtcbn0iXX0=' , 'returns correct inline mapping url including source content' ) t.end() }) t.test('one file with empty source', function (t) { var gen = generator() .addGeneratedMappings('empty.js', '') .addSourceContent('empty.js', '') t.deepEqual(gen.toJSON()["sourcesContent"], [""]) t.end() }); })