react / wstein / node_modules / browserify / node_modules / browser-pack / node_modules / combine-source-map / node_modules / source-map / dist / test / test_source_map_consumer.js
80559 views/*1* WARNING!2*3* Do not edit this file directly, it is built from the sources at4* https://github.com/mozilla/source-map/5*/67Components.utils.import('resource://test/Utils.jsm');8/* -*- Mode: js; js-indent-level: 2; -*- */9/*10* Copyright 2011 Mozilla Foundation and contributors11* Licensed under the New BSD license. See LICENSE or:12* http://opensource.org/licenses/BSD-3-Clause13*/14define("test/source-map/test-source-map-consumer", ["require", "exports", "module"], function (require, exports, module) {1516var SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer;17var IndexedSourceMapConsumer = require('source-map/source-map-consumer').IndexedSourceMapConsumer;18var BasicSourceMapConsumer = require('source-map/source-map-consumer').BasicSourceMapConsumer;19var SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;2021exports['test that we can instantiate with a string or an object'] = function (assert, util) {22assert.doesNotThrow(function () {23var map = new SourceMapConsumer(util.testMap);24});25assert.doesNotThrow(function () {26var map = new SourceMapConsumer(JSON.stringify(util.testMap));27});28};2930exports['test that the object returned from new SourceMapConsumer inherits from SourceMapConsumer'] = function (assert, util) {31assert.ok(new SourceMapConsumer(util.testMap) instanceof SourceMapConsumer);32}3334exports['test that a BasicSourceMapConsumer is returned for sourcemaps without sections'] = function(assert, util) {35assert.ok(new SourceMapConsumer(util.testMap) instanceof BasicSourceMapConsumer);36};3738exports['test that an IndexedSourceMapConsumer is returned for sourcemaps with sections'] = function(assert, util) {39assert.ok(new SourceMapConsumer(util.indexedTestMap) instanceof IndexedSourceMapConsumer);40};4142exports['test that the `sources` field has the original sources'] = function (assert, util) {43var map;44var sources;4546map = new SourceMapConsumer(util.testMap);47sources = map.sources;48assert.equal(sources[0], '/the/root/one.js');49assert.equal(sources[1], '/the/root/two.js');50assert.equal(sources.length, 2);5152map = new SourceMapConsumer(util.indexedTestMap);53sources = map.sources;54assert.equal(sources[0], '/the/root/one.js');55assert.equal(sources[1], '/the/root/two.js');56assert.equal(sources.length, 2);5758map = new SourceMapConsumer(util.indexedTestMapDifferentSourceRoots);59sources = map.sources;60assert.equal(sources[0], '/the/root/one.js');61assert.equal(sources[1], '/different/root/two.js');62assert.equal(sources.length, 2);6364map = new SourceMapConsumer(util.testMapNoSourceRoot);65sources = map.sources;66assert.equal(sources[0], 'one.js');67assert.equal(sources[1], 'two.js');68assert.equal(sources.length, 2);6970map = new SourceMapConsumer(util.testMapEmptySourceRoot);71sources = map.sources;72assert.equal(sources[0], 'one.js');73assert.equal(sources[1], 'two.js');74assert.equal(sources.length, 2);75};7677exports['test that the source root is reflected in a mapping\'s source field'] = function (assert, util) {78var map;79var mapping;8081map = new SourceMapConsumer(util.testMap);8283mapping = map.originalPositionFor({84line: 2,85column: 186});87assert.equal(mapping.source, '/the/root/two.js');8889mapping = map.originalPositionFor({90line: 1,91column: 192});93assert.equal(mapping.source, '/the/root/one.js');949596map = new SourceMapConsumer(util.testMapNoSourceRoot);9798mapping = map.originalPositionFor({99line: 2,100column: 1101});102assert.equal(mapping.source, 'two.js');103104mapping = map.originalPositionFor({105line: 1,106column: 1107});108assert.equal(mapping.source, 'one.js');109110111map = new SourceMapConsumer(util.testMapEmptySourceRoot);112113mapping = map.originalPositionFor({114line: 2,115column: 1116});117assert.equal(mapping.source, 'two.js');118119mapping = map.originalPositionFor({120line: 1,121column: 1122});123assert.equal(mapping.source, 'one.js');124};125126exports['test mapping tokens back exactly'] = function (assert, util) {127var map = new SourceMapConsumer(util.testMap);128129util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, map, assert);130util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, map, assert);131util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, map, assert);132util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', map, assert);133util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, map, assert);134util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert);135util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', map, assert);136137util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, map, assert);138util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, map, assert);139util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, map, assert);140util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', map, assert);141util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, map, assert);142util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', map, assert);143};144145exports['test mapping tokens back exactly in indexed source map'] = function (assert, util) {146var map = new SourceMapConsumer(util.indexedTestMap);147148util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, map, assert);149util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, map, assert);150util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, map, assert);151util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', map, assert);152util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, map, assert);153util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert);154util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', map, assert);155156util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, map, assert);157util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, map, assert);158util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, map, assert);159util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', map, assert);160util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, map, assert);161util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', map, assert);162};163164165exports['test mapping tokens back exactly'] = function (assert, util) {166var map = new SourceMapConsumer(util.testMap);167168util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, map, assert);169util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, map, assert);170util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, map, assert);171util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', map, assert);172util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, map, assert);173util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert);174util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', map, assert);175176util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, map, assert);177util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, map, assert);178util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, map, assert);179util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', map, assert);180util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, map, assert);181util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', map, assert);182};183184exports['test mapping tokens fuzzy'] = function (assert, util) {185var map = new SourceMapConsumer(util.testMap);186187// Finding original positions188util.assertMapping(1, 16, '/the/root/one.js', 1, 21, 'bar', map, assert, true);189util.assertMapping(1, 26, '/the/root/one.js', 2, 10, 'baz', map, assert, true);190util.assertMapping(2, 6, '/the/root/two.js', 1, 11, null, map, assert, true);191192// Finding generated positions193util.assertMapping(1, 18, '/the/root/one.js', 1, 20, 'bar', map, assert, null, true);194util.assertMapping(1, 28, '/the/root/one.js', 2, 7, 'baz', map, assert, null, true);195util.assertMapping(2, 9, '/the/root/two.js', 1, 6, null, map, assert, null, true);196};197198exports['test mapping tokens fuzzy in indexed source map'] = function (assert, util) {199var map = new SourceMapConsumer(util.indexedTestMap);200201// Finding original positions202util.assertMapping(1, 16, '/the/root/one.js', 1, 21, 'bar', map, assert, true);203util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert, true);204util.assertMapping(2, 6, '/the/root/two.js', 1, 11, null, map, assert, true);205206// Finding generated positions207util.assertMapping(1, 18, '/the/root/one.js', 1, 20, 'bar', map, assert, null, true);208util.assertMapping(1, 28, '/the/root/one.js', 2, 7, 'baz', map, assert, null, true);209util.assertMapping(2, 9, '/the/root/two.js', 1, 6, null, map, assert, null, true);210};211212exports['test mappings and end of lines'] = function (assert, util) {213var smg = new SourceMapGenerator({214file: 'foo.js'215});216smg.addMapping({217original: { line: 1, column: 1 },218generated: { line: 1, column: 1 },219source: 'bar.js'220});221smg.addMapping({222original: { line: 2, column: 2 },223generated: { line: 2, column: 2 },224source: 'bar.js'225});226227var map = SourceMapConsumer.fromSourceMap(smg);228229// When finding original positions, mappings end at the end of the line.230util.assertMapping(2, 3, null, null, null, null, map, assert, true)231232// When finding generated positions, mappings do not end at the end of the line.233util.assertMapping(2, 2, 'bar.js', 1, 2, null, map, assert, null, true);234};235236exports['test creating source map consumers with )]}\' prefix'] = function (assert, util) {237assert.doesNotThrow(function () {238var map = new SourceMapConsumer(")]}'" + JSON.stringify(util.testMap));239});240};241242exports['test eachMapping'] = function (assert, util) {243var map;244245map = new SourceMapConsumer(util.testMap);246var previousLine = -Infinity;247var previousColumn = -Infinity;248map.eachMapping(function (mapping) {249assert.ok(mapping.generatedLine >= previousLine);250251assert.ok(mapping.source === '/the/root/one.js' || mapping.source === '/the/root/two.js');252253if (mapping.generatedLine === previousLine) {254assert.ok(mapping.generatedColumn >= previousColumn);255previousColumn = mapping.generatedColumn;256}257else {258previousLine = mapping.generatedLine;259previousColumn = -Infinity;260}261});262263map = new SourceMapConsumer(util.testMapNoSourceRoot);264map.eachMapping(function (mapping) {265assert.ok(mapping.source === 'one.js' || mapping.source === 'two.js');266});267268map = new SourceMapConsumer(util.testMapEmptySourceRoot);269map.eachMapping(function (mapping) {270assert.ok(mapping.source === 'one.js' || mapping.source === 'two.js');271});272};273274exports['test eachMapping for indexed source maps'] = function(assert, util) {275var map = new SourceMapConsumer(util.indexedTestMap);276var previousLine = -Infinity;277var previousColumn = -Infinity;278map.eachMapping(function (mapping) {279assert.ok(mapping.generatedLine >= previousLine);280281if (mapping.source) {282assert.equal(mapping.source.indexOf(util.testMap.sourceRoot), 0);283}284285if (mapping.generatedLine === previousLine) {286assert.ok(mapping.generatedColumn >= previousColumn);287previousColumn = mapping.generatedColumn;288}289else {290previousLine = mapping.generatedLine;291previousColumn = -Infinity;292}293});294};295296297exports['test iterating over mappings in a different order'] = function (assert, util) {298var map = new SourceMapConsumer(util.testMap);299var previousLine = -Infinity;300var previousColumn = -Infinity;301var previousSource = "";302map.eachMapping(function (mapping) {303assert.ok(mapping.source >= previousSource);304305if (mapping.source === previousSource) {306assert.ok(mapping.originalLine >= previousLine);307308if (mapping.originalLine === previousLine) {309assert.ok(mapping.originalColumn >= previousColumn);310previousColumn = mapping.originalColumn;311}312else {313previousLine = mapping.originalLine;314previousColumn = -Infinity;315}316}317else {318previousSource = mapping.source;319previousLine = -Infinity;320previousColumn = -Infinity;321}322}, null, SourceMapConsumer.ORIGINAL_ORDER);323};324325exports['test iterating over mappings in a different order in indexed source maps'] = function (assert, util) {326var map = new SourceMapConsumer(util.indexedTestMap);327var previousLine = -Infinity;328var previousColumn = -Infinity;329var previousSource = "";330map.eachMapping(function (mapping) {331assert.ok(mapping.source >= previousSource);332333if (mapping.source === previousSource) {334assert.ok(mapping.originalLine >= previousLine);335336if (mapping.originalLine === previousLine) {337assert.ok(mapping.originalColumn >= previousColumn);338previousColumn = mapping.originalColumn;339}340else {341previousLine = mapping.originalLine;342previousColumn = -Infinity;343}344}345else {346previousSource = mapping.source;347previousLine = -Infinity;348previousColumn = -Infinity;349}350}, null, SourceMapConsumer.ORIGINAL_ORDER);351};352353exports['test that we can set the context for `this` in eachMapping'] = function (assert, util) {354var map = new SourceMapConsumer(util.testMap);355var context = {};356map.eachMapping(function () {357assert.equal(this, context);358}, context);359};360361exports['test that we can set the context for `this` in eachMapping in indexed source maps'] = function (assert, util) {362var map = new SourceMapConsumer(util.indexedTestMap);363var context = {};364map.eachMapping(function () {365assert.equal(this, context);366}, context);367};368369exports['test that the `sourcesContent` field has the original sources'] = function (assert, util) {370var map = new SourceMapConsumer(util.testMapWithSourcesContent);371var sourcesContent = map.sourcesContent;372373assert.equal(sourcesContent[0], ' ONE.foo = function (bar) {\n return baz(bar);\n };');374assert.equal(sourcesContent[1], ' TWO.inc = function (n) {\n return n + 1;\n };');375assert.equal(sourcesContent.length, 2);376};377378exports['test that we can get the original sources for the sources'] = function (assert, util) {379var map = new SourceMapConsumer(util.testMapWithSourcesContent);380var sources = map.sources;381382assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };');383assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };');384assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };');385assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };');386assert.throws(function () {387map.sourceContentFor("");388}, Error);389assert.throws(function () {390map.sourceContentFor("/the/root/three.js");391}, Error);392assert.throws(function () {393map.sourceContentFor("three.js");394}, Error);395};396397exports['test that we can get the original source content with relative source paths'] = function (assert, util) {398var map = new SourceMapConsumer(util.testMapRelativeSources);399var sources = map.sources;400401assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };');402assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };');403assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };');404assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };');405assert.throws(function () {406map.sourceContentFor("");407}, Error);408assert.throws(function () {409map.sourceContentFor("/the/root/three.js");410}, Error);411assert.throws(function () {412map.sourceContentFor("three.js");413}, Error);414};415416exports['test that we can get the original source content for the sources on an indexed source map'] = function (assert, util) {417var map = new SourceMapConsumer(util.indexedTestMap);418var sources = map.sources;419420assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };');421assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };');422assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };');423assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };');424assert.throws(function () {425map.sourceContentFor("");426}, Error);427assert.throws(function () {428map.sourceContentFor("/the/root/three.js");429}, Error);430assert.throws(function () {431map.sourceContentFor("three.js");432}, Error);433};434435436exports['test sourceRoot + generatedPositionFor'] = function (assert, util) {437var map = new SourceMapGenerator({438sourceRoot: 'foo/bar',439file: 'baz.js'440});441map.addMapping({442original: { line: 1, column: 1 },443generated: { line: 2, column: 2 },444source: 'bang.coffee'445});446map.addMapping({447original: { line: 5, column: 5 },448generated: { line: 6, column: 6 },449source: 'bang.coffee'450});451map = new SourceMapConsumer(map.toString());452453// Should handle without sourceRoot.454var pos = map.generatedPositionFor({455line: 1,456column: 1,457source: 'bang.coffee'458});459460assert.equal(pos.line, 2);461assert.equal(pos.column, 2);462463// Should handle with sourceRoot.464var pos = map.generatedPositionFor({465line: 1,466column: 1,467source: 'foo/bar/bang.coffee'468});469470assert.equal(pos.line, 2);471assert.equal(pos.column, 2);472};473474exports['test allGeneratedPositionsFor'] = function (assert, util) {475var map = new SourceMapGenerator({476file: 'generated.js'477});478map.addMapping({479original: { line: 1, column: 1 },480generated: { line: 2, column: 2 },481source: 'foo.coffee'482});483map.addMapping({484original: { line: 1, column: 1 },485generated: { line: 2, column: 2 },486source: 'bar.coffee'487});488map.addMapping({489original: { line: 2, column: 1 },490generated: { line: 3, column: 2 },491source: 'bar.coffee'492});493map.addMapping({494original: { line: 2, column: 2 },495generated: { line: 3, column: 3 },496source: 'bar.coffee'497});498map.addMapping({499original: { line: 3, column: 1 },500generated: { line: 4, column: 2 },501source: 'bar.coffee'502});503map = new SourceMapConsumer(map.toString());504505var mappings = map.allGeneratedPositionsFor({506line: 2,507source: 'bar.coffee'508});509510assert.equal(mappings.length, 2);511assert.equal(mappings[0].line, 3);512assert.equal(mappings[0].column, 2);513assert.equal(mappings[1].line, 3);514assert.equal(mappings[1].column, 3);515};516517exports['test allGeneratedPositionsFor for line with no mappings'] = function (assert, util) {518var map = new SourceMapGenerator({519file: 'generated.js'520});521map.addMapping({522original: { line: 1, column: 1 },523generated: { line: 2, column: 2 },524source: 'foo.coffee'525});526map.addMapping({527original: { line: 1, column: 1 },528generated: { line: 2, column: 2 },529source: 'bar.coffee'530});531map.addMapping({532original: { line: 3, column: 1 },533generated: { line: 4, column: 2 },534source: 'bar.coffee'535});536map = new SourceMapConsumer(map.toString());537538var mappings = map.allGeneratedPositionsFor({539line: 2,540source: 'bar.coffee'541});542543assert.equal(mappings.length, 0);544};545546exports['test allGeneratedPositionsFor source map with no mappings'] = function (assert, util) {547var map = new SourceMapGenerator({548file: 'generated.js'549});550map = new SourceMapConsumer(map.toString());551552var mappings = map.allGeneratedPositionsFor({553line: 2,554source: 'bar.coffee'555});556557assert.equal(mappings.length, 0);558};559560exports['test computeColumnSpans'] = function (assert, util) {561var map = new SourceMapGenerator({562file: 'generated.js'563});564map.addMapping({565original: { line: 1, column: 1 },566generated: { line: 1, column: 1 },567source: 'foo.coffee'568});569map.addMapping({570original: { line: 2, column: 1 },571generated: { line: 2, column: 1 },572source: 'foo.coffee'573});574map.addMapping({575original: { line: 2, column: 2 },576generated: { line: 2, column: 10 },577source: 'foo.coffee'578});579map.addMapping({580original: { line: 2, column: 3 },581generated: { line: 2, column: 20 },582source: 'foo.coffee'583});584map.addMapping({585original: { line: 3, column: 1 },586generated: { line: 3, column: 1 },587source: 'foo.coffee'588});589map.addMapping({590original: { line: 3, column: 2 },591generated: { line: 3, column: 2 },592source: 'foo.coffee'593});594map = new SourceMapConsumer(map.toString());595596map.computeColumnSpans();597598var mappings = map.allGeneratedPositionsFor({599line: 1,600source: 'foo.coffee'601});602603assert.equal(mappings.length, 1);604// assert.equal(mappings[0].lastColumn, Infinity);605606var mappings = map.allGeneratedPositionsFor({607line: 2,608source: 'foo.coffee'609});610611assert.equal(mappings.length, 3);612assert.equal(mappings[0].lastColumn, 9);613assert.equal(mappings[1].lastColumn, 19);614assert.equal(mappings[2].lastColumn, Infinity);615616var mappings = map.allGeneratedPositionsFor({617line: 3,618source: 'foo.coffee'619});620621assert.equal(mappings.length, 2);622assert.equal(mappings[0].lastColumn, 1);623assert.equal(mappings[1].lastColumn, Infinity);624};625626exports['test sourceRoot + originalPositionFor'] = function (assert, util) {627var map = new SourceMapGenerator({628sourceRoot: 'foo/bar',629file: 'baz.js'630});631map.addMapping({632original: { line: 1, column: 1 },633generated: { line: 2, column: 2 },634source: 'bang.coffee'635});636map = new SourceMapConsumer(map.toString());637638var pos = map.originalPositionFor({639line: 2,640column: 2,641});642643// Should always have the prepended source root644assert.equal(pos.source, 'foo/bar/bang.coffee');645assert.equal(pos.line, 1);646assert.equal(pos.column, 1);647};648649exports['test github issue #56'] = function (assert, util) {650var map = new SourceMapGenerator({651sourceRoot: 'http://',652file: 'www.example.com/foo.js'653});654map.addMapping({655original: { line: 1, column: 1 },656generated: { line: 2, column: 2 },657source: 'www.example.com/original.js'658});659map = new SourceMapConsumer(map.toString());660661var sources = map.sources;662assert.equal(sources.length, 1);663assert.equal(sources[0], 'http://www.example.com/original.js');664};665666exports['test github issue #43'] = function (assert, util) {667var map = new SourceMapGenerator({668sourceRoot: 'http://example.com',669file: 'foo.js'670});671map.addMapping({672original: { line: 1, column: 1 },673generated: { line: 2, column: 2 },674source: 'http://cdn.example.com/original.js'675});676map = new SourceMapConsumer(map.toString());677678var sources = map.sources;679assert.equal(sources.length, 1,680'Should only be one source.');681assert.equal(sources[0], 'http://cdn.example.com/original.js',682'Should not be joined with the sourceRoot.');683};684685exports['test absolute path, but same host sources'] = function (assert, util) {686var map = new SourceMapGenerator({687sourceRoot: 'http://example.com/foo/bar',688file: 'foo.js'689});690map.addMapping({691original: { line: 1, column: 1 },692generated: { line: 2, column: 2 },693source: '/original.js'694});695map = new SourceMapConsumer(map.toString());696697var sources = map.sources;698assert.equal(sources.length, 1,699'Should only be one source.');700assert.equal(sources[0], 'http://example.com/original.js',701'Source should be relative the host of the source root.');702};703704exports['test indexed source map errors when sections are out of order by line'] = function(assert, util) {705// Make a deep copy of the indexedTestMap706var misorderedIndexedTestMap = JSON.parse(JSON.stringify(util.indexedTestMap));707708misorderedIndexedTestMap.sections[0].offset = {709line: 2,710column: 0711};712713assert.throws(function() {714new SourceMapConsumer(misorderedIndexedTestMap);715}, Error);716};717718exports['test github issue #64'] = function (assert, util) {719var map = new SourceMapConsumer({720"version": 3,721"file": "foo.js",722"sourceRoot": "http://example.com/",723"sources": ["/a"],724"names": [],725"mappings": "AACA",726"sourcesContent": ["foo"]727});728729assert.equal(map.sourceContentFor("a"), "foo");730assert.equal(map.sourceContentFor("/a"), "foo");731};732733exports['test bug 885597'] = function (assert, util) {734var map = new SourceMapConsumer({735"version": 3,736"file": "foo.js",737"sourceRoot": "file:///Users/AlGore/Invented/The/Internet/",738"sources": ["/a"],739"names": [],740"mappings": "AACA",741"sourcesContent": ["foo"]742});743744var s = map.sources[0];745assert.equal(map.sourceContentFor(s), "foo");746};747748exports['test github issue #72, duplicate sources'] = function (assert, util) {749var map = new SourceMapConsumer({750"version": 3,751"file": "foo.js",752"sources": ["source1.js", "source1.js", "source3.js"],753"names": [],754"mappings": ";EAAC;;IAEE;;MEEE",755"sourceRoot": "http://example.com"756});757758var pos = map.originalPositionFor({759line: 2,760column: 2761});762assert.equal(pos.source, 'http://example.com/source1.js');763assert.equal(pos.line, 1);764assert.equal(pos.column, 1);765766var pos = map.originalPositionFor({767line: 4,768column: 4769});770assert.equal(pos.source, 'http://example.com/source1.js');771assert.equal(pos.line, 3);772assert.equal(pos.column, 3);773774var pos = map.originalPositionFor({775line: 6,776column: 6777});778assert.equal(pos.source, 'http://example.com/source3.js');779assert.equal(pos.line, 5);780assert.equal(pos.column, 5);781};782783exports['test github issue #72, duplicate names'] = function (assert, util) {784var map = new SourceMapConsumer({785"version": 3,786"file": "foo.js",787"sources": ["source.js"],788"names": ["name1", "name1", "name3"],789"mappings": ";EAACA;;IAEEA;;MAEEE",790"sourceRoot": "http://example.com"791});792793var pos = map.originalPositionFor({794line: 2,795column: 2796});797assert.equal(pos.name, 'name1');798assert.equal(pos.line, 1);799assert.equal(pos.column, 1);800801var pos = map.originalPositionFor({802line: 4,803column: 4804});805assert.equal(pos.name, 'name1');806assert.equal(pos.line, 3);807assert.equal(pos.column, 3);808809var pos = map.originalPositionFor({810line: 6,811column: 6812});813assert.equal(pos.name, 'name3');814assert.equal(pos.line, 5);815assert.equal(pos.column, 5);816};817818exports['test SourceMapConsumer.fromSourceMap'] = function (assert, util) {819var smg = new SourceMapGenerator({820sourceRoot: 'http://example.com/',821file: 'foo.js'822});823smg.addMapping({824original: { line: 1, column: 1 },825generated: { line: 2, column: 2 },826source: 'bar.js'827});828smg.addMapping({829original: { line: 2, column: 2 },830generated: { line: 4, column: 4 },831source: 'baz.js',832name: 'dirtMcGirt'833});834smg.setSourceContent('baz.js', 'baz.js content');835836var smc = SourceMapConsumer.fromSourceMap(smg);837assert.equal(smc.file, 'foo.js');838assert.equal(smc.sourceRoot, 'http://example.com/');839assert.equal(smc.sources.length, 2);840assert.equal(smc.sources[0], 'http://example.com/bar.js');841assert.equal(smc.sources[1], 'http://example.com/baz.js');842assert.equal(smc.sourceContentFor('baz.js'), 'baz.js content');843844var pos = smc.originalPositionFor({845line: 2,846column: 2847});848assert.equal(pos.line, 1);849assert.equal(pos.column, 1);850assert.equal(pos.source, 'http://example.com/bar.js');851assert.equal(pos.name, null);852853pos = smc.generatedPositionFor({854line: 1,855column: 1,856source: 'http://example.com/bar.js'857});858assert.equal(pos.line, 2);859assert.equal(pos.column, 2);860861pos = smc.originalPositionFor({862line: 4,863column: 4864});865assert.equal(pos.line, 2);866assert.equal(pos.column, 2);867assert.equal(pos.source, 'http://example.com/baz.js');868assert.equal(pos.name, 'dirtMcGirt');869870pos = smc.generatedPositionFor({871line: 2,872column: 2,873source: 'http://example.com/baz.js'874});875assert.equal(pos.line, 4);876assert.equal(pos.column, 4);877};878});879function run_test() {880runSourceMapTests('test/source-map/test-source-map-consumer', do_throw);881}882883884