1 /* -*- Mode: js; js-indent-level: 2; -*- */
3 * Copyright 2011 Mozilla Foundation and contributors
4 * Licensed under the New BSD license. See LICENSE or:
5 * http://opensource.org/licenses/BSD-3-Clause
7 if (typeof define !== 'function') {
8 var define = require('amdefine')(module, require);
10 define(function (require, exports, module) {
12 var SourceMapConsumer = require('../../lib/source-map/source-map-consumer').SourceMapConsumer;
13 var IndexedSourceMapConsumer = require('../../lib/source-map/indexed-source-map-consumer').IndexedSourceMapConsumer;
14 var BasicSourceMapConsumer = require('../../lib/source-map/basic-source-map-consumer').BasicSourceMapConsumer;
15 var SourceMapGenerator = require('../../lib/source-map/source-map-generator').SourceMapGenerator;
17 exports['test that we can instantiate with a string or an object'] = function (assert, util) {
18 assert.doesNotThrow(function () {
19 var map = new SourceMapConsumer(util.testMap);
21 assert.doesNotThrow(function () {
22 var map = new SourceMapConsumer(JSON.stringify(util.testMap));
26 exports['test that the object returned from new SourceMapConsumer inherits from SourceMapConsumer'] = function (assert, util) {
27 assert.ok(new SourceMapConsumer(util.testMap) instanceof SourceMapConsumer);
30 exports['test that a BasicSourceMapConsumer is returned for sourcemaps without sections'] = function(assert, util) {
31 assert.ok(new SourceMapConsumer(util.testMap) instanceof BasicSourceMapConsumer);
34 exports['test that an IndexedSourceMapConsumer is returned for sourcemaps with sections'] = function(assert, util) {
35 assert.ok(new SourceMapConsumer(util.indexedTestMap) instanceof IndexedSourceMapConsumer);
38 exports['test that the `sources` field has the original sources'] = function (assert, util) {
42 map = new SourceMapConsumer(util.testMap);
43 sources = map.sources;
44 assert.equal(sources[0], '/the/root/one.js');
45 assert.equal(sources[1], '/the/root/two.js');
46 assert.equal(sources.length, 2);
48 map = new SourceMapConsumer(util.indexedTestMap);
49 sources = map.sources;
50 assert.equal(sources[0], '/the/root/one.js');
51 assert.equal(sources[1], '/the/root/two.js');
52 assert.equal(sources.length, 2);
54 map = new SourceMapConsumer(util.indexedTestMapDifferentSourceRoots);
55 sources = map.sources;
56 assert.equal(sources[0], '/the/root/one.js');
57 assert.equal(sources[1], '/different/root/two.js');
58 assert.equal(sources.length, 2);
60 map = new SourceMapConsumer(util.testMapNoSourceRoot);
61 sources = map.sources;
62 assert.equal(sources[0], 'one.js');
63 assert.equal(sources[1], 'two.js');
64 assert.equal(sources.length, 2);
66 map = new SourceMapConsumer(util.testMapEmptySourceRoot);
67 sources = map.sources;
68 assert.equal(sources[0], 'one.js');
69 assert.equal(sources[1], 'two.js');
70 assert.equal(sources.length, 2);
73 exports['test that the source root is reflected in a mapping\'s source field'] = function (assert, util) {
77 map = new SourceMapConsumer(util.testMap);
79 mapping = map.originalPositionFor({
83 assert.equal(mapping.source, '/the/root/two.js');
85 mapping = map.originalPositionFor({
89 assert.equal(mapping.source, '/the/root/one.js');
92 map = new SourceMapConsumer(util.testMapNoSourceRoot);
94 mapping = map.originalPositionFor({
98 assert.equal(mapping.source, 'two.js');
100 mapping = map.originalPositionFor({
104 assert.equal(mapping.source, 'one.js');
107 map = new SourceMapConsumer(util.testMapEmptySourceRoot);
109 mapping = map.originalPositionFor({
113 assert.equal(mapping.source, 'two.js');
115 mapping = map.originalPositionFor({
119 assert.equal(mapping.source, 'one.js');
122 exports['test mapping tokens back exactly'] = function (assert, util) {
123 var map = new SourceMapConsumer(util.testMap);
125 util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, map, assert);
126 util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, map, assert);
127 util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, map, assert);
128 util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', map, assert);
129 util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, map, assert);
130 util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert);
131 util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', map, assert);
133 util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, map, assert);
134 util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, map, assert);
135 util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, map, assert);
136 util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', map, assert);
137 util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, map, assert);
138 util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', map, assert);
141 exports['test mapping tokens back exactly in indexed source map'] = function (assert, util) {
142 var map = new SourceMapConsumer(util.indexedTestMap);
144 util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, map, assert);
145 util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, map, assert);
146 util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, map, assert);
147 util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', map, assert);
148 util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, map, assert);
149 util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert);
150 util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', map, assert);
152 util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, map, assert);
153 util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, map, assert);
154 util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, map, assert);
155 util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', map, assert);
156 util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, map, assert);
157 util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', map, assert);
161 exports['test mapping tokens back exactly'] = function (assert, util) {
162 var map = new SourceMapConsumer(util.testMap);
164 util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, map, assert);
165 util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, map, assert);
166 util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, map, assert);
167 util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', map, assert);
168 util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, map, assert);
169 util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert);
170 util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', map, assert);
172 util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, map, assert);
173 util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, map, assert);
174 util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, map, assert);
175 util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', map, assert);
176 util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, map, assert);
177 util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', map, assert);
180 exports['test mapping tokens fuzzy'] = function (assert, util) {
181 var map = new SourceMapConsumer(util.testMap);
183 // Finding original positions
184 util.assertMapping(1, 20, '/the/root/one.js', 1, 21, 'bar', map, assert, true);
185 util.assertMapping(1, 30, '/the/root/one.js', 2, 10, 'baz', map, assert, true);
186 util.assertMapping(2, 12, '/the/root/two.js', 1, 11, null, map, assert, true);
188 // Finding generated positions
189 util.assertMapping(1, 18, '/the/root/one.js', 1, 22, 'bar', map, assert, null, true);
190 util.assertMapping(1, 28, '/the/root/one.js', 2, 13, 'baz', map, assert, null, true);
191 util.assertMapping(2, 9, '/the/root/two.js', 1, 16, null, map, assert, null, true);
194 exports['test mapping tokens fuzzy in indexed source map'] = function (assert, util) {
195 var map = new SourceMapConsumer(util.indexedTestMap);
197 // Finding original positions
198 util.assertMapping(1, 20, '/the/root/one.js', 1, 21, 'bar', map, assert, true);
199 util.assertMapping(1, 30, '/the/root/one.js', 2, 10, 'baz', map, assert, true);
200 util.assertMapping(2, 12, '/the/root/two.js', 1, 11, null, map, assert, true);
202 // Finding generated positions
203 util.assertMapping(1, 18, '/the/root/one.js', 1, 22, 'bar', map, assert, null, true);
204 util.assertMapping(1, 28, '/the/root/one.js', 2, 13, 'baz', map, assert, null, true);
205 util.assertMapping(2, 9, '/the/root/two.js', 1, 16, null, map, assert, null, true);
208 exports['test mappings and end of lines'] = function (assert, util) {
209 var smg = new SourceMapGenerator({
213 original: { line: 1, column: 1 },
214 generated: { line: 1, column: 1 },
218 original: { line: 2, column: 2 },
219 generated: { line: 2, column: 2 },
223 var map = SourceMapConsumer.fromSourceMap(smg);
225 // When finding original positions, mappings end at the end of the line.
226 util.assertMapping(2, 1, null, null, null, null, map, assert, true)
228 // When finding generated positions, mappings do not end at the end of the line.
229 util.assertMapping(1, 1, 'bar.js', 2, 1, null, map, assert, null, true);
232 exports['test creating source map consumers with )]}\' prefix'] = function (assert, util) {
233 assert.doesNotThrow(function () {
234 var map = new SourceMapConsumer(")]}'" + JSON.stringify(util.testMap));
238 exports['test eachMapping'] = function (assert, util) {
241 map = new SourceMapConsumer(util.testMap);
242 var previousLine = -Infinity;
243 var previousColumn = -Infinity;
244 map.eachMapping(function (mapping) {
245 assert.ok(mapping.generatedLine >= previousLine);
247 assert.ok(mapping.source === '/the/root/one.js' || mapping.source === '/the/root/two.js');
249 if (mapping.generatedLine === previousLine) {
250 assert.ok(mapping.generatedColumn >= previousColumn);
251 previousColumn = mapping.generatedColumn;
254 previousLine = mapping.generatedLine;
255 previousColumn = -Infinity;
259 map = new SourceMapConsumer(util.testMapNoSourceRoot);
260 map.eachMapping(function (mapping) {
261 assert.ok(mapping.source === 'one.js' || mapping.source === 'two.js');
264 map = new SourceMapConsumer(util.testMapEmptySourceRoot);
265 map.eachMapping(function (mapping) {
266 assert.ok(mapping.source === 'one.js' || mapping.source === 'two.js');
270 exports['test eachMapping for indexed source maps'] = function(assert, util) {
271 var map = new SourceMapConsumer(util.indexedTestMap);
272 var previousLine = -Infinity;
273 var previousColumn = -Infinity;
274 map.eachMapping(function (mapping) {
275 assert.ok(mapping.generatedLine >= previousLine);
277 if (mapping.source) {
278 assert.equal(mapping.source.indexOf(util.testMap.sourceRoot), 0);
281 if (mapping.generatedLine === previousLine) {
282 assert.ok(mapping.generatedColumn >= previousColumn);
283 previousColumn = mapping.generatedColumn;
286 previousLine = mapping.generatedLine;
287 previousColumn = -Infinity;
293 exports['test iterating over mappings in a different order'] = function (assert, util) {
294 var map = new SourceMapConsumer(util.testMap);
295 var previousLine = -Infinity;
296 var previousColumn = -Infinity;
297 var previousSource = "";
298 map.eachMapping(function (mapping) {
299 assert.ok(mapping.source >= previousSource);
301 if (mapping.source === previousSource) {
302 assert.ok(mapping.originalLine >= previousLine);
304 if (mapping.originalLine === previousLine) {
305 assert.ok(mapping.originalColumn >= previousColumn);
306 previousColumn = mapping.originalColumn;
309 previousLine = mapping.originalLine;
310 previousColumn = -Infinity;
314 previousSource = mapping.source;
315 previousLine = -Infinity;
316 previousColumn = -Infinity;
318 }, null, SourceMapConsumer.ORIGINAL_ORDER);
321 exports['test iterating over mappings in a different order in indexed source maps'] = function (assert, util) {
322 var map = new SourceMapConsumer(util.indexedTestMap);
323 var previousLine = -Infinity;
324 var previousColumn = -Infinity;
325 var previousSource = "";
326 map.eachMapping(function (mapping) {
327 assert.ok(mapping.source >= previousSource);
329 if (mapping.source === previousSource) {
330 assert.ok(mapping.originalLine >= previousLine);
332 if (mapping.originalLine === previousLine) {
333 assert.ok(mapping.originalColumn >= previousColumn);
334 previousColumn = mapping.originalColumn;
337 previousLine = mapping.originalLine;
338 previousColumn = -Infinity;
342 previousSource = mapping.source;
343 previousLine = -Infinity;
344 previousColumn = -Infinity;
346 }, null, SourceMapConsumer.ORIGINAL_ORDER);
349 exports['test that we can set the context for `this` in eachMapping'] = function (assert, util) {
350 var map = new SourceMapConsumer(util.testMap);
352 map.eachMapping(function () {
353 assert.equal(this, context);
357 exports['test that we can set the context for `this` in eachMapping in indexed source maps'] = function (assert, util) {
358 var map = new SourceMapConsumer(util.indexedTestMap);
360 map.eachMapping(function () {
361 assert.equal(this, context);
365 exports['test that the `sourcesContent` field has the original sources'] = function (assert, util) {
366 var map = new SourceMapConsumer(util.testMapWithSourcesContent);
367 var sourcesContent = map.sourcesContent;
369 assert.equal(sourcesContent[0], ' ONE.foo = function (bar) {\n return baz(bar);\n };');
370 assert.equal(sourcesContent[1], ' TWO.inc = function (n) {\n return n + 1;\n };');
371 assert.equal(sourcesContent.length, 2);
374 exports['test that we can get the original sources for the sources'] = function (assert, util) {
375 var map = new SourceMapConsumer(util.testMapWithSourcesContent);
376 var sources = map.sources;
378 assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };');
379 assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };');
380 assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };');
381 assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };');
382 assert.throws(function () {
383 map.sourceContentFor("");
385 assert.throws(function () {
386 map.sourceContentFor("/the/root/three.js");
388 assert.throws(function () {
389 map.sourceContentFor("three.js");
393 exports['test that we can get the original source content with relative source paths'] = function (assert, util) {
394 var map = new SourceMapConsumer(util.testMapRelativeSources);
395 var sources = map.sources;
397 assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };');
398 assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };');
399 assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };');
400 assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };');
401 assert.throws(function () {
402 map.sourceContentFor("");
404 assert.throws(function () {
405 map.sourceContentFor("/the/root/three.js");
407 assert.throws(function () {
408 map.sourceContentFor("three.js");
412 exports['test that we can get the original source content for the sources on an indexed source map'] = function (assert, util) {
413 var map = new SourceMapConsumer(util.indexedTestMap);
414 var sources = map.sources;
416 assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };');
417 assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };');
418 assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };');
419 assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };');
420 assert.throws(function () {
421 map.sourceContentFor("");
423 assert.throws(function () {
424 map.sourceContentFor("/the/root/three.js");
426 assert.throws(function () {
427 map.sourceContentFor("three.js");
432 exports['test sourceRoot + generatedPositionFor'] = function (assert, util) {
433 var map = new SourceMapGenerator({
434 sourceRoot: 'foo/bar',
438 original: { line: 1, column: 1 },
439 generated: { line: 2, column: 2 },
440 source: 'bang.coffee'
443 original: { line: 5, column: 5 },
444 generated: { line: 6, column: 6 },
445 source: 'bang.coffee'
447 map = new SourceMapConsumer(map.toString());
449 // Should handle without sourceRoot.
450 var pos = map.generatedPositionFor({
453 source: 'bang.coffee'
456 assert.equal(pos.line, 2);
457 assert.equal(pos.column, 2);
459 // Should handle with sourceRoot.
460 var pos = map.generatedPositionFor({
463 source: 'foo/bar/bang.coffee'
466 assert.equal(pos.line, 2);
467 assert.equal(pos.column, 2);
470 exports['test allGeneratedPositionsFor'] = function (assert, util) {
471 var map = new SourceMapGenerator({
475 original: { line: 1, column: 1 },
476 generated: { line: 2, column: 2 },
480 original: { line: 1, column: 1 },
481 generated: { line: 2, column: 2 },
485 original: { line: 2, column: 1 },
486 generated: { line: 3, column: 2 },
490 original: { line: 2, column: 2 },
491 generated: { line: 3, column: 3 },
495 original: { line: 3, column: 1 },
496 generated: { line: 4, column: 2 },
499 map = new SourceMapConsumer(map.toString());
501 var mappings = map.allGeneratedPositionsFor({
506 assert.equal(mappings.length, 2);
507 assert.equal(mappings[0].line, 3);
508 assert.equal(mappings[0].column, 2);
509 assert.equal(mappings[1].line, 3);
510 assert.equal(mappings[1].column, 3);
513 exports['test allGeneratedPositionsFor for line with no mappings'] = function (assert, util) {
514 var map = new SourceMapGenerator({
518 original: { line: 1, column: 1 },
519 generated: { line: 2, column: 2 },
523 original: { line: 1, column: 1 },
524 generated: { line: 2, column: 2 },
528 original: { line: 3, column: 1 },
529 generated: { line: 4, column: 2 },
532 map = new SourceMapConsumer(map.toString());
534 var mappings = map.allGeneratedPositionsFor({
539 assert.equal(mappings.length, 0);
542 exports['test allGeneratedPositionsFor source map with no mappings'] = function (assert, util) {
543 var map = new SourceMapGenerator({
546 map = new SourceMapConsumer(map.toString());
548 var mappings = map.allGeneratedPositionsFor({
553 assert.equal(mappings.length, 0);
556 exports['test computeColumnSpans'] = function (assert, util) {
557 var map = new SourceMapGenerator({
561 original: { line: 1, column: 1 },
562 generated: { line: 1, column: 1 },
566 original: { line: 2, column: 1 },
567 generated: { line: 2, column: 1 },
571 original: { line: 2, column: 2 },
572 generated: { line: 2, column: 10 },
576 original: { line: 2, column: 3 },
577 generated: { line: 2, column: 20 },
581 original: { line: 3, column: 1 },
582 generated: { line: 3, column: 1 },
586 original: { line: 3, column: 2 },
587 generated: { line: 3, column: 2 },
590 map = new SourceMapConsumer(map.toString());
592 map.computeColumnSpans();
594 var mappings = map.allGeneratedPositionsFor({
599 assert.equal(mappings.length, 1);
600 assert.equal(mappings[0].lastColumn, Infinity);
602 var mappings = map.allGeneratedPositionsFor({
607 assert.equal(mappings.length, 3);
608 assert.equal(mappings[0].lastColumn, 9);
609 assert.equal(mappings[1].lastColumn, 19);
610 assert.equal(mappings[2].lastColumn, Infinity);
612 var mappings = map.allGeneratedPositionsFor({
617 assert.equal(mappings.length, 2);
618 assert.equal(mappings[0].lastColumn, 1);
619 assert.equal(mappings[1].lastColumn, Infinity);
622 exports['test sourceRoot + originalPositionFor'] = function (assert, util) {
623 var map = new SourceMapGenerator({
624 sourceRoot: 'foo/bar',
628 original: { line: 1, column: 1 },
629 generated: { line: 2, column: 2 },
630 source: 'bang.coffee'
632 map = new SourceMapConsumer(map.toString());
634 var pos = map.originalPositionFor({
639 // Should always have the prepended source root
640 assert.equal(pos.source, 'foo/bar/bang.coffee');
641 assert.equal(pos.line, 1);
642 assert.equal(pos.column, 1);
645 exports['test github issue #56'] = function (assert, util) {
646 var map = new SourceMapGenerator({
647 sourceRoot: 'http://',
648 file: 'www.example.com/foo.js'
651 original: { line: 1, column: 1 },
652 generated: { line: 2, column: 2 },
653 source: 'www.example.com/original.js'
655 map = new SourceMapConsumer(map.toString());
657 var sources = map.sources;
658 assert.equal(sources.length, 1);
659 assert.equal(sources[0], 'http://www.example.com/original.js');
662 exports['test github issue #43'] = function (assert, util) {
663 var map = new SourceMapGenerator({
664 sourceRoot: 'http://example.com',
668 original: { line: 1, column: 1 },
669 generated: { line: 2, column: 2 },
670 source: 'http://cdn.example.com/original.js'
672 map = new SourceMapConsumer(map.toString());
674 var sources = map.sources;
675 assert.equal(sources.length, 1,
676 'Should only be one source.');
677 assert.equal(sources[0], 'http://cdn.example.com/original.js',
678 'Should not be joined with the sourceRoot.');
681 exports['test absolute path, but same host sources'] = function (assert, util) {
682 var map = new SourceMapGenerator({
683 sourceRoot: 'http://example.com/foo/bar',
687 original: { line: 1, column: 1 },
688 generated: { line: 2, column: 2 },
689 source: '/original.js'
691 map = new SourceMapConsumer(map.toString());
693 var sources = map.sources;
694 assert.equal(sources.length, 1,
695 'Should only be one source.');
696 assert.equal(sources[0], 'http://example.com/original.js',
697 'Source should be relative the host of the source root.');
700 exports['test indexed source map errors when sections are out of order by line'] = function(assert, util) {
701 // Make a deep copy of the indexedTestMap
702 var misorderedIndexedTestMap = JSON.parse(JSON.stringify(util.indexedTestMap));
704 misorderedIndexedTestMap.sections[0].offset = {
709 assert.throws(function() {
710 new SourceMapConsumer(misorderedIndexedTestMap);
714 exports['test github issue #64'] = function (assert, util) {
715 var map = new SourceMapConsumer({
718 "sourceRoot": "http://example.com/",
722 "sourcesContent": ["foo"]
725 assert.equal(map.sourceContentFor("a"), "foo");
726 assert.equal(map.sourceContentFor("/a"), "foo");
729 exports['test bug 885597'] = function (assert, util) {
730 var map = new SourceMapConsumer({
733 "sourceRoot": "file:///Users/AlGore/Invented/The/Internet/",
737 "sourcesContent": ["foo"]
740 var s = map.sources[0];
741 assert.equal(map.sourceContentFor(s), "foo");
744 exports['test github issue #72, duplicate sources'] = function (assert, util) {
745 var map = new SourceMapConsumer({
748 "sources": ["source1.js", "source1.js", "source3.js"],
750 "mappings": ";EAAC;;IAEE;;MEEE",
751 "sourceRoot": "http://example.com"
754 var pos = map.originalPositionFor({
758 assert.equal(pos.source, 'http://example.com/source1.js');
759 assert.equal(pos.line, 1);
760 assert.equal(pos.column, 1);
762 var pos = map.originalPositionFor({
766 assert.equal(pos.source, 'http://example.com/source1.js');
767 assert.equal(pos.line, 3);
768 assert.equal(pos.column, 3);
770 var pos = map.originalPositionFor({
774 assert.equal(pos.source, 'http://example.com/source3.js');
775 assert.equal(pos.line, 5);
776 assert.equal(pos.column, 5);
779 exports['test github issue #72, duplicate names'] = function (assert, util) {
780 var map = new SourceMapConsumer({
783 "sources": ["source.js"],
784 "names": ["name1", "name1", "name3"],
785 "mappings": ";EAACA;;IAEEA;;MAEEE",
786 "sourceRoot": "http://example.com"
789 var pos = map.originalPositionFor({
793 assert.equal(pos.name, 'name1');
794 assert.equal(pos.line, 1);
795 assert.equal(pos.column, 1);
797 var pos = map.originalPositionFor({
801 assert.equal(pos.name, 'name1');
802 assert.equal(pos.line, 3);
803 assert.equal(pos.column, 3);
805 var pos = map.originalPositionFor({
809 assert.equal(pos.name, 'name3');
810 assert.equal(pos.line, 5);
811 assert.equal(pos.column, 5);
814 exports['test SourceMapConsumer.fromSourceMap'] = function (assert, util) {
815 var smg = new SourceMapGenerator({
816 sourceRoot: 'http://example.com/',
820 original: { line: 1, column: 1 },
821 generated: { line: 2, column: 2 },
825 original: { line: 2, column: 2 },
826 generated: { line: 4, column: 4 },
830 smg.setSourceContent('baz.js', 'baz.js content');
832 var smc = SourceMapConsumer.fromSourceMap(smg);
833 assert.equal(smc.file, 'foo.js');
834 assert.equal(smc.sourceRoot, 'http://example.com/');
835 assert.equal(smc.sources.length, 2);
836 assert.equal(smc.sources[0], 'http://example.com/bar.js');
837 assert.equal(smc.sources[1], 'http://example.com/baz.js');
838 assert.equal(smc.sourceContentFor('baz.js'), 'baz.js content');
840 var pos = smc.originalPositionFor({
844 assert.equal(pos.line, 1);
845 assert.equal(pos.column, 1);
846 assert.equal(pos.source, 'http://example.com/bar.js');
847 assert.equal(pos.name, null);
849 pos = smc.generatedPositionFor({
852 source: 'http://example.com/bar.js'
854 assert.equal(pos.line, 2);
855 assert.equal(pos.column, 2);
857 pos = smc.originalPositionFor({
861 assert.equal(pos.line, 2);
862 assert.equal(pos.column, 2);
863 assert.equal(pos.source, 'http://example.com/baz.js');
864 assert.equal(pos.name, 'dirtMcGirt');
866 pos = smc.generatedPositionFor({
869 source: 'http://example.com/baz.js'
871 assert.equal(pos.line, 4);
872 assert.equal(pos.column, 4);