react / wstein / node_modules / browserify / node_modules / insert-module-globals / node_modules / combine-source-map / node_modules / inline-source-map / node_modules / source-map / test / source-map / test-source-map-consumer.js
80620 views/* -*- Mode: js; js-indent-level: 2; -*- */1/*2* Copyright 2011 Mozilla Foundation and contributors3* Licensed under the New BSD license. See LICENSE or:4* http://opensource.org/licenses/BSD-3-Clause5*/6if (typeof define !== 'function') {7var define = require('amdefine')(module, require);8}9define(function (require, exports, module) {1011var SourceMapConsumer = require('../../lib/source-map/source-map-consumer').SourceMapConsumer;12var IndexedSourceMapConsumer = require('../../lib/source-map/indexed-source-map-consumer').IndexedSourceMapConsumer;13var BasicSourceMapConsumer = require('../../lib/source-map/basic-source-map-consumer').BasicSourceMapConsumer;14var SourceMapGenerator = require('../../lib/source-map/source-map-generator').SourceMapGenerator;1516exports['test that we can instantiate with a string or an object'] = function (assert, util) {17assert.doesNotThrow(function () {18var map = new SourceMapConsumer(util.testMap);19});20assert.doesNotThrow(function () {21var map = new SourceMapConsumer(JSON.stringify(util.testMap));22});23};2425exports['test that the object returned from new SourceMapConsumer inherits from SourceMapConsumer'] = function (assert, util) {26assert.ok(new SourceMapConsumer(util.testMap) instanceof SourceMapConsumer);27}2829exports['test that a BasicSourceMapConsumer is returned for sourcemaps without sections'] = function(assert, util) {30assert.ok(new SourceMapConsumer(util.testMap) instanceof BasicSourceMapConsumer);31};3233exports['test that an IndexedSourceMapConsumer is returned for sourcemaps with sections'] = function(assert, util) {34assert.ok(new SourceMapConsumer(util.indexedTestMap) instanceof IndexedSourceMapConsumer);35};3637exports['test that the `sources` field has the original sources'] = function (assert, util) {38var map;39var sources;4041map = new SourceMapConsumer(util.testMap);42sources = map.sources;43assert.equal(sources[0], '/the/root/one.js');44assert.equal(sources[1], '/the/root/two.js');45assert.equal(sources.length, 2);4647map = new SourceMapConsumer(util.indexedTestMap);48sources = map.sources;49assert.equal(sources[0], '/the/root/one.js');50assert.equal(sources[1], '/the/root/two.js');51assert.equal(sources.length, 2);5253map = new SourceMapConsumer(util.indexedTestMapDifferentSourceRoots);54sources = map.sources;55assert.equal(sources[0], '/the/root/one.js');56assert.equal(sources[1], '/different/root/two.js');57assert.equal(sources.length, 2);5859map = new SourceMapConsumer(util.testMapNoSourceRoot);60sources = map.sources;61assert.equal(sources[0], 'one.js');62assert.equal(sources[1], 'two.js');63assert.equal(sources.length, 2);6465map = new SourceMapConsumer(util.testMapEmptySourceRoot);66sources = map.sources;67assert.equal(sources[0], 'one.js');68assert.equal(sources[1], 'two.js');69assert.equal(sources.length, 2);70};7172exports['test that the source root is reflected in a mapping\'s source field'] = function (assert, util) {73var map;74var mapping;7576map = new SourceMapConsumer(util.testMap);7778mapping = map.originalPositionFor({79line: 2,80column: 181});82assert.equal(mapping.source, '/the/root/two.js');8384mapping = map.originalPositionFor({85line: 1,86column: 187});88assert.equal(mapping.source, '/the/root/one.js');899091map = new SourceMapConsumer(util.testMapNoSourceRoot);9293mapping = map.originalPositionFor({94line: 2,95column: 196});97assert.equal(mapping.source, 'two.js');9899mapping = map.originalPositionFor({100line: 1,101column: 1102});103assert.equal(mapping.source, 'one.js');104105106map = new SourceMapConsumer(util.testMapEmptySourceRoot);107108mapping = map.originalPositionFor({109line: 2,110column: 1111});112assert.equal(mapping.source, 'two.js');113114mapping = map.originalPositionFor({115line: 1,116column: 1117});118assert.equal(mapping.source, 'one.js');119};120121exports['test mapping tokens back exactly'] = function (assert, util) {122var map = new SourceMapConsumer(util.testMap);123124util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, map, assert);125util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, map, assert);126util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, map, assert);127util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', map, assert);128util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, map, assert);129util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert);130util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', map, assert);131132util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, map, assert);133util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, map, assert);134util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, map, assert);135util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', map, assert);136util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, map, assert);137util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', map, assert);138};139140exports['test mapping tokens back exactly in indexed source map'] = function (assert, util) {141var map = new SourceMapConsumer(util.indexedTestMap);142143util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, map, assert);144util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, map, assert);145util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, map, assert);146util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', map, assert);147util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, map, assert);148util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert);149util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', map, assert);150151util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, map, assert);152util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, map, assert);153util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, map, assert);154util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', map, assert);155util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, map, assert);156util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', map, assert);157};158159160exports['test mapping tokens back exactly'] = function (assert, util) {161var map = new SourceMapConsumer(util.testMap);162163util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, map, assert);164util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, map, assert);165util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, map, assert);166util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', map, assert);167util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, map, assert);168util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert);169util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', map, assert);170171util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, map, assert);172util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, map, assert);173util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, map, assert);174util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', map, assert);175util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, map, assert);176util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', map, assert);177};178179exports['test mapping tokens fuzzy'] = function (assert, util) {180var map = new SourceMapConsumer(util.testMap);181182// Finding original positions183util.assertMapping(1, 16, '/the/root/one.js', 1, 21, 'bar', map, assert, true);184util.assertMapping(1, 26, '/the/root/one.js', 2, 10, 'baz', map, assert, true);185util.assertMapping(2, 6, '/the/root/two.js', 1, 11, null, map, assert, true);186187// Finding generated positions188util.assertMapping(1, 18, '/the/root/one.js', 1, 20, 'bar', map, assert, null, true);189util.assertMapping(1, 28, '/the/root/one.js', 2, 7, 'baz', map, assert, null, true);190util.assertMapping(2, 9, '/the/root/two.js', 1, 6, null, map, assert, null, true);191};192193exports['test mapping tokens fuzzy in indexed source map'] = function (assert, util) {194var map = new SourceMapConsumer(util.indexedTestMap);195196// Finding original positions197util.assertMapping(1, 16, '/the/root/one.js', 1, 21, 'bar', map, assert, true);198util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert, true);199util.assertMapping(2, 6, '/the/root/two.js', 1, 11, null, map, assert, true);200201// Finding generated positions202util.assertMapping(1, 18, '/the/root/one.js', 1, 20, 'bar', map, assert, null, true);203util.assertMapping(1, 28, '/the/root/one.js', 2, 7, 'baz', map, assert, null, true);204util.assertMapping(2, 9, '/the/root/two.js', 1, 6, null, map, assert, null, true);205};206207exports['test mappings and end of lines'] = function (assert, util) {208var smg = new SourceMapGenerator({209file: 'foo.js'210});211smg.addMapping({212original: { line: 1, column: 1 },213generated: { line: 1, column: 1 },214source: 'bar.js'215});216smg.addMapping({217original: { line: 2, column: 2 },218generated: { line: 2, column: 2 },219source: 'bar.js'220});221222var map = SourceMapConsumer.fromSourceMap(smg);223224// When finding original positions, mappings end at the end of the line.225util.assertMapping(2, 3, null, null, null, null, map, assert, true)226227// When finding generated positions, mappings do not end at the end of the line.228util.assertMapping(2, 2, 'bar.js', 1, 2, null, map, assert, null, true);229};230231exports['test creating source map consumers with )]}\' prefix'] = function (assert, util) {232assert.doesNotThrow(function () {233var map = new SourceMapConsumer(")]}'" + JSON.stringify(util.testMap));234});235};236237exports['test eachMapping'] = function (assert, util) {238var map;239240map = new SourceMapConsumer(util.testMap);241var previousLine = -Infinity;242var previousColumn = -Infinity;243map.eachMapping(function (mapping) {244assert.ok(mapping.generatedLine >= previousLine);245246assert.ok(mapping.source === '/the/root/one.js' || mapping.source === '/the/root/two.js');247248if (mapping.generatedLine === previousLine) {249assert.ok(mapping.generatedColumn >= previousColumn);250previousColumn = mapping.generatedColumn;251}252else {253previousLine = mapping.generatedLine;254previousColumn = -Infinity;255}256});257258map = new SourceMapConsumer(util.testMapNoSourceRoot);259map.eachMapping(function (mapping) {260assert.ok(mapping.source === 'one.js' || mapping.source === 'two.js');261});262263map = new SourceMapConsumer(util.testMapEmptySourceRoot);264map.eachMapping(function (mapping) {265assert.ok(mapping.source === 'one.js' || mapping.source === 'two.js');266});267};268269exports['test eachMapping for indexed source maps'] = function(assert, util) {270var map = new SourceMapConsumer(util.indexedTestMap);271var previousLine = -Infinity;272var previousColumn = -Infinity;273map.eachMapping(function (mapping) {274assert.ok(mapping.generatedLine >= previousLine);275276if (mapping.source) {277assert.equal(mapping.source.indexOf(util.testMap.sourceRoot), 0);278}279280if (mapping.generatedLine === previousLine) {281assert.ok(mapping.generatedColumn >= previousColumn);282previousColumn = mapping.generatedColumn;283}284else {285previousLine = mapping.generatedLine;286previousColumn = -Infinity;287}288});289};290291292exports['test iterating over mappings in a different order'] = function (assert, util) {293var map = new SourceMapConsumer(util.testMap);294var previousLine = -Infinity;295var previousColumn = -Infinity;296var previousSource = "";297map.eachMapping(function (mapping) {298assert.ok(mapping.source >= previousSource);299300if (mapping.source === previousSource) {301assert.ok(mapping.originalLine >= previousLine);302303if (mapping.originalLine === previousLine) {304assert.ok(mapping.originalColumn >= previousColumn);305previousColumn = mapping.originalColumn;306}307else {308previousLine = mapping.originalLine;309previousColumn = -Infinity;310}311}312else {313previousSource = mapping.source;314previousLine = -Infinity;315previousColumn = -Infinity;316}317}, null, SourceMapConsumer.ORIGINAL_ORDER);318};319320exports['test iterating over mappings in a different order in indexed source maps'] = function (assert, util) {321var map = new SourceMapConsumer(util.indexedTestMap);322var previousLine = -Infinity;323var previousColumn = -Infinity;324var previousSource = "";325map.eachMapping(function (mapping) {326assert.ok(mapping.source >= previousSource);327328if (mapping.source === previousSource) {329assert.ok(mapping.originalLine >= previousLine);330331if (mapping.originalLine === previousLine) {332assert.ok(mapping.originalColumn >= previousColumn);333previousColumn = mapping.originalColumn;334}335else {336previousLine = mapping.originalLine;337previousColumn = -Infinity;338}339}340else {341previousSource = mapping.source;342previousLine = -Infinity;343previousColumn = -Infinity;344}345}, null, SourceMapConsumer.ORIGINAL_ORDER);346};347348exports['test that we can set the context for `this` in eachMapping'] = function (assert, util) {349var map = new SourceMapConsumer(util.testMap);350var context = {};351map.eachMapping(function () {352assert.equal(this, context);353}, context);354};355356exports['test that we can set the context for `this` in eachMapping in indexed source maps'] = function (assert, util) {357var map = new SourceMapConsumer(util.indexedTestMap);358var context = {};359map.eachMapping(function () {360assert.equal(this, context);361}, context);362};363364exports['test that the `sourcesContent` field has the original sources'] = function (assert, util) {365var map = new SourceMapConsumer(util.testMapWithSourcesContent);366var sourcesContent = map.sourcesContent;367368assert.equal(sourcesContent[0], ' ONE.foo = function (bar) {\n return baz(bar);\n };');369assert.equal(sourcesContent[1], ' TWO.inc = function (n) {\n return n + 1;\n };');370assert.equal(sourcesContent.length, 2);371};372373exports['test that we can get the original sources for the sources'] = function (assert, util) {374var map = new SourceMapConsumer(util.testMapWithSourcesContent);375var sources = map.sources;376377assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };');378assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };');379assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };');380assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };');381assert.throws(function () {382map.sourceContentFor("");383}, Error);384assert.throws(function () {385map.sourceContentFor("/the/root/three.js");386}, Error);387assert.throws(function () {388map.sourceContentFor("three.js");389}, Error);390};391392exports['test that we can get the original source content with relative source paths'] = function (assert, util) {393var map = new SourceMapConsumer(util.testMapRelativeSources);394var sources = map.sources;395396assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };');397assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };');398assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };');399assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };');400assert.throws(function () {401map.sourceContentFor("");402}, Error);403assert.throws(function () {404map.sourceContentFor("/the/root/three.js");405}, Error);406assert.throws(function () {407map.sourceContentFor("three.js");408}, Error);409};410411exports['test that we can get the original source content for the sources on an indexed source map'] = function (assert, util) {412var map = new SourceMapConsumer(util.indexedTestMap);413var sources = map.sources;414415assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };');416assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };');417assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };');418assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };');419assert.throws(function () {420map.sourceContentFor("");421}, Error);422assert.throws(function () {423map.sourceContentFor("/the/root/three.js");424}, Error);425assert.throws(function () {426map.sourceContentFor("three.js");427}, Error);428};429430431exports['test sourceRoot + generatedPositionFor'] = function (assert, util) {432var map = new SourceMapGenerator({433sourceRoot: 'foo/bar',434file: 'baz.js'435});436map.addMapping({437original: { line: 1, column: 1 },438generated: { line: 2, column: 2 },439source: 'bang.coffee'440});441map.addMapping({442original: { line: 5, column: 5 },443generated: { line: 6, column: 6 },444source: 'bang.coffee'445});446map = new SourceMapConsumer(map.toString());447448// Should handle without sourceRoot.449var pos = map.generatedPositionFor({450line: 1,451column: 1,452source: 'bang.coffee'453});454455assert.equal(pos.line, 2);456assert.equal(pos.column, 2);457458// Should handle with sourceRoot.459var pos = map.generatedPositionFor({460line: 1,461column: 1,462source: 'foo/bar/bang.coffee'463});464465assert.equal(pos.line, 2);466assert.equal(pos.column, 2);467};468469exports['test allGeneratedPositionsFor'] = function (assert, util) {470var map = new SourceMapGenerator({471file: 'generated.js'472});473map.addMapping({474original: { line: 1, column: 1 },475generated: { line: 2, column: 2 },476source: 'foo.coffee'477});478map.addMapping({479original: { line: 1, column: 1 },480generated: { line: 2, column: 2 },481source: 'bar.coffee'482});483map.addMapping({484original: { line: 2, column: 1 },485generated: { line: 3, column: 2 },486source: 'bar.coffee'487});488map.addMapping({489original: { line: 2, column: 2 },490generated: { line: 3, column: 3 },491source: 'bar.coffee'492});493map.addMapping({494original: { line: 3, column: 1 },495generated: { line: 4, column: 2 },496source: 'bar.coffee'497});498map = new SourceMapConsumer(map.toString());499500var mappings = map.allGeneratedPositionsFor({501line: 2,502source: 'bar.coffee'503});504505assert.equal(mappings.length, 2);506assert.equal(mappings[0].line, 3);507assert.equal(mappings[0].column, 2);508assert.equal(mappings[1].line, 3);509assert.equal(mappings[1].column, 3);510};511512exports['test allGeneratedPositionsFor for line with no mappings'] = function (assert, util) {513var map = new SourceMapGenerator({514file: 'generated.js'515});516map.addMapping({517original: { line: 1, column: 1 },518generated: { line: 2, column: 2 },519source: 'foo.coffee'520});521map.addMapping({522original: { line: 1, column: 1 },523generated: { line: 2, column: 2 },524source: 'bar.coffee'525});526map.addMapping({527original: { line: 3, column: 1 },528generated: { line: 4, column: 2 },529source: 'bar.coffee'530});531map = new SourceMapConsumer(map.toString());532533var mappings = map.allGeneratedPositionsFor({534line: 2,535source: 'bar.coffee'536});537538assert.equal(mappings.length, 0);539};540541exports['test allGeneratedPositionsFor source map with no mappings'] = function (assert, util) {542var map = new SourceMapGenerator({543file: 'generated.js'544});545map = new SourceMapConsumer(map.toString());546547var mappings = map.allGeneratedPositionsFor({548line: 2,549source: 'bar.coffee'550});551552assert.equal(mappings.length, 0);553};554555exports['test computeColumnSpans'] = function (assert, util) {556var map = new SourceMapGenerator({557file: 'generated.js'558});559map.addMapping({560original: { line: 1, column: 1 },561generated: { line: 1, column: 1 },562source: 'foo.coffee'563});564map.addMapping({565original: { line: 2, column: 1 },566generated: { line: 2, column: 1 },567source: 'foo.coffee'568});569map.addMapping({570original: { line: 2, column: 2 },571generated: { line: 2, column: 10 },572source: 'foo.coffee'573});574map.addMapping({575original: { line: 2, column: 3 },576generated: { line: 2, column: 20 },577source: 'foo.coffee'578});579map.addMapping({580original: { line: 3, column: 1 },581generated: { line: 3, column: 1 },582source: 'foo.coffee'583});584map.addMapping({585original: { line: 3, column: 2 },586generated: { line: 3, column: 2 },587source: 'foo.coffee'588});589map = new SourceMapConsumer(map.toString());590591map.computeColumnSpans();592593var mappings = map.allGeneratedPositionsFor({594line: 1,595source: 'foo.coffee'596});597598assert.equal(mappings.length, 1);599// assert.equal(mappings[0].lastColumn, Infinity);600601var mappings = map.allGeneratedPositionsFor({602line: 2,603source: 'foo.coffee'604});605606assert.equal(mappings.length, 3);607assert.equal(mappings[0].lastColumn, 9);608assert.equal(mappings[1].lastColumn, 19);609assert.equal(mappings[2].lastColumn, Infinity);610611var mappings = map.allGeneratedPositionsFor({612line: 3,613source: 'foo.coffee'614});615616assert.equal(mappings.length, 2);617assert.equal(mappings[0].lastColumn, 1);618assert.equal(mappings[1].lastColumn, Infinity);619};620621exports['test sourceRoot + originalPositionFor'] = function (assert, util) {622var map = new SourceMapGenerator({623sourceRoot: 'foo/bar',624file: 'baz.js'625});626map.addMapping({627original: { line: 1, column: 1 },628generated: { line: 2, column: 2 },629source: 'bang.coffee'630});631map = new SourceMapConsumer(map.toString());632633var pos = map.originalPositionFor({634line: 2,635column: 2,636});637638// Should always have the prepended source root639assert.equal(pos.source, 'foo/bar/bang.coffee');640assert.equal(pos.line, 1);641assert.equal(pos.column, 1);642};643644exports['test github issue #56'] = function (assert, util) {645var map = new SourceMapGenerator({646sourceRoot: 'http://',647file: 'www.example.com/foo.js'648});649map.addMapping({650original: { line: 1, column: 1 },651generated: { line: 2, column: 2 },652source: 'www.example.com/original.js'653});654map = new SourceMapConsumer(map.toString());655656var sources = map.sources;657assert.equal(sources.length, 1);658assert.equal(sources[0], 'http://www.example.com/original.js');659};660661exports['test github issue #43'] = function (assert, util) {662var map = new SourceMapGenerator({663sourceRoot: 'http://example.com',664file: 'foo.js'665});666map.addMapping({667original: { line: 1, column: 1 },668generated: { line: 2, column: 2 },669source: 'http://cdn.example.com/original.js'670});671map = new SourceMapConsumer(map.toString());672673var sources = map.sources;674assert.equal(sources.length, 1,675'Should only be one source.');676assert.equal(sources[0], 'http://cdn.example.com/original.js',677'Should not be joined with the sourceRoot.');678};679680exports['test absolute path, but same host sources'] = function (assert, util) {681var map = new SourceMapGenerator({682sourceRoot: 'http://example.com/foo/bar',683file: 'foo.js'684});685map.addMapping({686original: { line: 1, column: 1 },687generated: { line: 2, column: 2 },688source: '/original.js'689});690map = new SourceMapConsumer(map.toString());691692var sources = map.sources;693assert.equal(sources.length, 1,694'Should only be one source.');695assert.equal(sources[0], 'http://example.com/original.js',696'Source should be relative the host of the source root.');697};698699exports['test indexed source map errors when sections are out of order by line'] = function(assert, util) {700// Make a deep copy of the indexedTestMap701var misorderedIndexedTestMap = JSON.parse(JSON.stringify(util.indexedTestMap));702703misorderedIndexedTestMap.sections[0].offset = {704line: 2,705column: 0706};707708assert.throws(function() {709new SourceMapConsumer(misorderedIndexedTestMap);710}, Error);711};712713exports['test github issue #64'] = function (assert, util) {714var map = new SourceMapConsumer({715"version": 3,716"file": "foo.js",717"sourceRoot": "http://example.com/",718"sources": ["/a"],719"names": [],720"mappings": "AACA",721"sourcesContent": ["foo"]722});723724assert.equal(map.sourceContentFor("a"), "foo");725assert.equal(map.sourceContentFor("/a"), "foo");726};727728exports['test bug 885597'] = function (assert, util) {729var map = new SourceMapConsumer({730"version": 3,731"file": "foo.js",732"sourceRoot": "file:///Users/AlGore/Invented/The/Internet/",733"sources": ["/a"],734"names": [],735"mappings": "AACA",736"sourcesContent": ["foo"]737});738739var s = map.sources[0];740assert.equal(map.sourceContentFor(s), "foo");741};742743exports['test github issue #72, duplicate sources'] = function (assert, util) {744var map = new SourceMapConsumer({745"version": 3,746"file": "foo.js",747"sources": ["source1.js", "source1.js", "source3.js"],748"names": [],749"mappings": ";EAAC;;IAEE;;MEEE",750"sourceRoot": "http://example.com"751});752753var pos = map.originalPositionFor({754line: 2,755column: 2756});757assert.equal(pos.source, 'http://example.com/source1.js');758assert.equal(pos.line, 1);759assert.equal(pos.column, 1);760761var pos = map.originalPositionFor({762line: 4,763column: 4764});765assert.equal(pos.source, 'http://example.com/source1.js');766assert.equal(pos.line, 3);767assert.equal(pos.column, 3);768769var pos = map.originalPositionFor({770line: 6,771column: 6772});773assert.equal(pos.source, 'http://example.com/source3.js');774assert.equal(pos.line, 5);775assert.equal(pos.column, 5);776};777778exports['test github issue #72, duplicate names'] = function (assert, util) {779var map = new SourceMapConsumer({780"version": 3,781"file": "foo.js",782"sources": ["source.js"],783"names": ["name1", "name1", "name3"],784"mappings": ";EAACA;;IAEEA;;MAEEE",785"sourceRoot": "http://example.com"786});787788var pos = map.originalPositionFor({789line: 2,790column: 2791});792assert.equal(pos.name, 'name1');793assert.equal(pos.line, 1);794assert.equal(pos.column, 1);795796var pos = map.originalPositionFor({797line: 4,798column: 4799});800assert.equal(pos.name, 'name1');801assert.equal(pos.line, 3);802assert.equal(pos.column, 3);803804var pos = map.originalPositionFor({805line: 6,806column: 6807});808assert.equal(pos.name, 'name3');809assert.equal(pos.line, 5);810assert.equal(pos.column, 5);811};812813exports['test SourceMapConsumer.fromSourceMap'] = function (assert, util) {814var smg = new SourceMapGenerator({815sourceRoot: 'http://example.com/',816file: 'foo.js'817});818smg.addMapping({819original: { line: 1, column: 1 },820generated: { line: 2, column: 2 },821source: 'bar.js'822});823smg.addMapping({824original: { line: 2, column: 2 },825generated: { line: 4, column: 4 },826source: 'baz.js',827name: 'dirtMcGirt'828});829smg.setSourceContent('baz.js', 'baz.js content');830831var smc = SourceMapConsumer.fromSourceMap(smg);832assert.equal(smc.file, 'foo.js');833assert.equal(smc.sourceRoot, 'http://example.com/');834assert.equal(smc.sources.length, 2);835assert.equal(smc.sources[0], 'http://example.com/bar.js');836assert.equal(smc.sources[1], 'http://example.com/baz.js');837assert.equal(smc.sourceContentFor('baz.js'), 'baz.js content');838839var pos = smc.originalPositionFor({840line: 2,841column: 2842});843assert.equal(pos.line, 1);844assert.equal(pos.column, 1);845assert.equal(pos.source, 'http://example.com/bar.js');846assert.equal(pos.name, null);847848pos = smc.generatedPositionFor({849line: 1,850column: 1,851source: 'http://example.com/bar.js'852});853assert.equal(pos.line, 2);854assert.equal(pos.column, 2);855856pos = smc.originalPositionFor({857line: 4,858column: 4859});860assert.equal(pos.line, 2);861assert.equal(pos.column, 2);862assert.equal(pos.source, 'http://example.com/baz.js');863assert.equal(pos.name, 'dirtMcGirt');864865pos = smc.generatedPositionFor({866line: 2,867column: 2,868source: 'http://example.com/baz.js'869});870assert.equal(pos.line, 4);871assert.equal(pos.column, 4);872};873});874875876