Bug 1136146 - Merge version 0.4.0 of the source-map library with fx-team.

This commit is contained in:
Eddy Bruël 2015-03-10 13:50:04 +01:00
parent 5afa9ebb1f
commit 7f81303974
11 changed files with 2436 additions and 1017 deletions

View File

@ -79,7 +79,7 @@ function testSetBreakpointBlankLine() {
let sourceForm = getSourceForm(gSources, COFFEE_URL);
let source = gDebugger.gThreadClient.source(sourceForm);
source.setBreakpoint({ line: 3 }, aResponse => {
source.setBreakpoint({ line: 1 }, aResponse => {
ok(!aResponse.error,
"Should be able to set a breakpoint in a coffee source file on a blank line.");
ok(aResponse.actualLocation,
@ -147,7 +147,7 @@ function testStepping() {
is(aPacket.frame.environment.bindings.variables.start.value, 0,
"'start' is 0.");
is(aPacket.frame.environment.bindings.variables.stop.value, 5,
"'stop' hasn't been assigned to yet.");
"'stop' is 5.");
is(aPacket.frame.environment.bindings.variables.pivot.value.type, "undefined",
"'pivot' hasn't been assigned to yet.");

View File

@ -45,11 +45,11 @@ function testSetBreakpoint() {
let sourceForm = getSourceForm(gSources, JS_URL);
let source = gDebugger.gThreadClient.source(sourceForm);
source.setBreakpoint({ line: 30, column: 21 }, aResponse => {
source.setBreakpoint({ line: 30 }, aResponse => {
ok(!aResponse.error,
"Should be able to set a breakpoint in a js file.");
ok(!aResponse.actualLocation,
"Should be able to set a breakpoint on line 30 and column 10.");
"Should be able to set a breakpoint on line 30.");
gDebugger.gClient.addOneTimeListener("resumed", () => {
waitForCaretAndScopes(gPanel, 30).then(() => {

View File

@ -2584,7 +2584,7 @@ SourceActor.prototype = {
*/
_invertSourceMap: function ({ code, mappings }) {
const generator = new SourceMapGenerator({ file: this.url });
return DevToolsUtils.yieldingEach(mappings, m => {
return DevToolsUtils.yieldingEach(mappings._array, m => {
let mapping = {
generated: {
line: m.generatedLine,
@ -5698,7 +5698,8 @@ ThreadSources.prototype = {
} = map.generatedPositionFor({
source: originalSourceActor.url,
line: originalLine,
column: originalColumn == null ? Infinity : originalColumn
column: originalColumn == null ? 0 : originalColumn,
bias: SourceMapConsumer.LEAST_UPPER_BOUND
});
return new GeneratedLocation(

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -126,6 +126,113 @@ define('test/source-map/util', ['require', 'exports', 'module' , 'lib/source-ma
sourceRoot: '',
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
};
// This mapping is identical to above, but uses the indexed format instead.
exports.indexedTestMap = {
version: 3,
file: 'min.js',
sections: [
{
offset: {
line: 0,
column: 0
},
map: {
version: 3,
sources: [
"one.js"
],
sourcesContent: [
' ONE.foo = function (bar) {\n' +
' return baz(bar);\n' +
' };',
],
names: [
"bar",
"baz"
],
mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID",
file: "min.js",
sourceRoot: "/the/root"
}
},
{
offset: {
line: 1,
column: 0
},
map: {
version: 3,
sources: [
"two.js"
],
sourcesContent: [
' TWO.inc = function (n) {\n' +
' return n + 1;\n' +
' };'
],
names: [
"n"
],
mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA",
file: "min.js",
sourceRoot: "/the/root"
}
}
]
};
exports.indexedTestMapDifferentSourceRoots = {
version: 3,
file: 'min.js',
sections: [
{
offset: {
line: 0,
column: 0
},
map: {
version: 3,
sources: [
"one.js"
],
sourcesContent: [
' ONE.foo = function (bar) {\n' +
' return baz(bar);\n' +
' };',
],
names: [
"bar",
"baz"
],
mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID",
file: "min.js",
sourceRoot: "/the/root"
}
},
{
offset: {
line: 1,
column: 0
},
map: {
version: 3,
sources: [
"two.js"
],
sourcesContent: [
' TWO.inc = function (n) {\n' +
' return n + 1;\n' +
' };'
],
names: [
"n"
],
mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA",
file: "min.js",
sourceRoot: "/different/root"
}
}
]
};
exports.testMapWithSourcesContent = {
version: 3,
file: 'min.js',
@ -168,12 +275,13 @@ define('test/source-map/util', ['require', 'exports', 'module' , 'lib/source-ma
function assertMapping(generatedLine, generatedColumn, originalSource,
originalLine, originalColumn, name, map, assert,
originalLine, originalColumn, name, bias, map, assert,
dontTestGenerated, dontTestOriginal) {
if (!dontTestOriginal) {
var origMapping = map.originalPositionFor({
line: generatedLine,
column: generatedColumn
column: generatedColumn,
bias: bias
});
assert.equal(origMapping.name, name,
'Incorrect name, expected ' + JSON.stringify(name)
@ -206,7 +314,8 @@ define('test/source-map/util', ['require', 'exports', 'module' , 'lib/source-ma
var genMapping = map.generatedPositionFor({
source: originalSource,
line: originalLine,
column: originalColumn
column: originalColumn,
bias: bias
});
assert.equal(genMapping.line, generatedLine,
'Incorrect line, expected ' + JSON.stringify(generatedLine)
@ -521,7 +630,7 @@ define('lib/source-map/util', ['require', 'exports', 'module' , ], function(requ
return cmp;
}
cmp = strcmp(mappingA.name, mappingB.name);
cmp = mappingA.generatedColumn - mappingB.generatedColumn;
if (cmp) {
return cmp;
}
@ -531,7 +640,7 @@ define('lib/source-map/util', ['require', 'exports', 'module' , ], function(requ
return cmp;
}
return mappingA.generatedColumn - mappingB.generatedColumn;
return strcmp(mappingA.name, mappingB.name);
};
exports.compareByOriginalPositions = compareByOriginalPositions;

View File

@ -19,9 +19,10 @@ define("test/source-map/test-base64-vlq", ["require", "exports", "module"], func
exports['test normal encoding and decoding'] = function (assert, util) {
var result = {};
for (var i = -255; i < 256; i++) {
base64VLQ.decode(base64VLQ.encode(i), result);
var str = base64VLQ.encode(i);
base64VLQ.decode(str, 0, result);
assert.equal(result.value, i);
assert.equal(result.rest, "");
assert.equal(result.rest, str.length);
}
};

View File

@ -20,7 +20,7 @@ define("test/source-map/test-binary-search", ["require", "exports", "module"], f
return a - b;
}
exports['test too high'] = function (assert, util) {
exports['test too high with default (glb) bias'] = function (assert, util) {
var needle = 30;
var haystack = [2,4,6,8,10,12,14,16,18,20];
@ -31,7 +31,7 @@ define("test/source-map/test-binary-search", ["require", "exports", "module"], f
assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 20);
};
exports['test too low'] = function (assert, util) {
exports['test too low with default (glb) bias'] = function (assert, util) {
var needle = 1;
var haystack = [2,4,6,8,10,12,14,16,18,20];
@ -42,6 +42,30 @@ define("test/source-map/test-binary-search", ["require", "exports", "module"], f
assert.equal(binarySearch.search(needle, haystack, numberCompare), -1);
};
exports['test too high with lub bias'] = function (assert, util) {
var needle = 30;
var haystack = [2,4,6,8,10,12,14,16,18,20];
assert.doesNotThrow(function () {
binarySearch.search(needle, haystack, numberCompare);
});
assert.equal(binarySearch.search(needle, haystack, numberCompare,
binarySearch.LEAST_UPPER_BOUND), -1);
};
exports['test too low with lub bias'] = function (assert, util) {
var needle = 1;
var haystack = [2,4,6,8,10,12,14,16,18,20];
assert.doesNotThrow(function () {
binarySearch.search(needle, haystack, numberCompare);
});
assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare,
binarySearch.LEAST_UPPER_BOUND)], 2);
};
exports['test exact search'] = function (assert, util) {
var needle = 4;
var haystack = [2,4,6,8,10,12,14,16,18,20];
@ -49,13 +73,29 @@ define("test/source-map/test-binary-search", ["require", "exports", "module"], f
assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 4);
};
exports['test fuzzy search'] = function (assert, util) {
exports['test fuzzy search with default (glb) bias'] = function (assert, util) {
var needle = 19;
var haystack = [2,4,6,8,10,12,14,16,18,20];
assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 18);
};
exports['test fuzzy search with lub bias'] = function (assert, util) {
var needle = 19;
var haystack = [2,4,6,8,10,12,14,16,18,20];
assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare,
binarySearch.LEAST_UPPER_BOUND)], 20);
};
exports['test multiple matches'] = function (assert, util) {
var needle = 5;
var haystack = [1, 1, 2, 5, 5, 5, 13, 21];
assert.equal(binarySearch.search(needle, haystack, numberCompare,
binarySearch.LEAST_UPPER_BOUND), 3);
};
});
function run_test() {
runSourceMapTests('test/source-map/test-binary-search', do_throw);

View File

@ -56,34 +56,55 @@ define("test/source-map/test-dog-fooding", ["require", "exports", "module"], fun
var smc = new SourceMapConsumer(smg.toString());
// Exact
util.assertMapping(2, 2, '/wu/tang/gza.coffee', 1, 0, null, smc, assert);
util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 0, null, smc, assert);
util.assertMapping(4, 2, '/wu/tang/gza.coffee', 3, 0, null, smc, assert);
util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 0, null, smc, assert);
util.assertMapping(6, 12, '/wu/tang/gza.coffee', 5, 10, null, smc, assert);
util.assertMapping(2, 2, '/wu/tang/gza.coffee', 1, 0, null, null, smc, assert);
util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 0, null, null, smc, assert);
util.assertMapping(4, 2, '/wu/tang/gza.coffee', 3, 0, null, null, smc, assert);
util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 0, null, null, smc, assert);
util.assertMapping(6, 12, '/wu/tang/gza.coffee', 5, 10, null, null, smc, assert);
// Fuzzy
// Generated to original
util.assertMapping(2, 0, null, null, null, null, smc, assert, true);
util.assertMapping(2, 9, '/wu/tang/gza.coffee', 1, 0, null, smc, assert, true);
util.assertMapping(3, 0, null, null, null, null, smc, assert, true);
util.assertMapping(3, 9, '/wu/tang/gza.coffee', 2, 0, null, smc, assert, true);
util.assertMapping(4, 0, null, null, null, null, smc, assert, true);
util.assertMapping(4, 9, '/wu/tang/gza.coffee', 3, 0, null, smc, assert, true);
util.assertMapping(5, 0, null, null, null, null, smc, assert, true);
util.assertMapping(5, 9, '/wu/tang/gza.coffee', 4, 0, null, smc, assert, true);
util.assertMapping(6, 0, null, null, null, null, smc, assert, true);
util.assertMapping(6, 9, null, null, null, null, smc, assert, true);
util.assertMapping(6, 13, '/wu/tang/gza.coffee', 5, 10, null, smc, assert, true);
// Generated to original with default (glb) bias.
util.assertMapping(2, 0, null, null, null, null, null, smc, assert, true);
util.assertMapping(2, 9, '/wu/tang/gza.coffee', 1, 0, null, null, smc, assert, true);
util.assertMapping(3, 0, null, null, null, null, null, smc, assert, true);
util.assertMapping(3, 9, '/wu/tang/gza.coffee', 2, 0, null, null, smc, assert, true);
util.assertMapping(4, 0, null, null, null, null, null, smc, assert, true);
util.assertMapping(4, 9, '/wu/tang/gza.coffee', 3, 0, null, null, smc, assert, true);
util.assertMapping(5, 0, null, null, null, null, null, smc, assert, true);
util.assertMapping(5, 9, '/wu/tang/gza.coffee', 4, 0, null, null, smc, assert, true);
util.assertMapping(6, 0, null, null, null, null, null, smc, assert, true);
util.assertMapping(6, 9, null, null, null, null, null, smc, assert, true);
util.assertMapping(6, 13, '/wu/tang/gza.coffee', 5, 10, null, null, smc, assert, true);
// Original to generated
util.assertMapping(2, 2, '/wu/tang/gza.coffee', 1, 1, null, smc, assert, null, true);
util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 3, null, smc, assert, null, true);
util.assertMapping(4, 2, '/wu/tang/gza.coffee', 3, 6, null, smc, assert, null, true);
util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 9, null, smc, assert, null, true);
util.assertMapping(5, 2, '/wu/tang/gza.coffee', 5, 9, null, smc, assert, null, true);
util.assertMapping(6, 12, '/wu/tang/gza.coffee', 6, 19, null, smc, assert, null, true);
// Generated to original with lub bias.
util.assertMapping(2, 0, '/wu/tang/gza.coffee', 1, 0, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true);
util.assertMapping(2, 9, null, null, null, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true);
util.assertMapping(3, 0, '/wu/tang/gza.coffee', 2, 0, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true);
util.assertMapping(3, 9, null, null, null, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true);
util.assertMapping(4, 0, '/wu/tang/gza.coffee', 3, 0, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true);
util.assertMapping(4, 9, null, null, null, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true);
util.assertMapping(5, 0, '/wu/tang/gza.coffee', 4, 0, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true);
util.assertMapping(5, 9, null, null, null, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true);
util.assertMapping(6, 0, '/wu/tang/gza.coffee', 5, 10, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true);
util.assertMapping(6, 9, '/wu/tang/gza.coffee', 5, 10, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true);
util.assertMapping(6, 13, null, null, null, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, true);
// Original to generated with default (glb) bias
util.assertMapping(2, 2, '/wu/tang/gza.coffee', 1, 1, null, null, smc, assert, null, true);
util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 3, null, null, smc, assert, null, true);
util.assertMapping(4, 2, '/wu/tang/gza.coffee', 3, 6, null, null, smc, assert, null, true);
util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 9, null, null, smc, assert, null, true);
util.assertMapping(5, 2, '/wu/tang/gza.coffee', 5, 9, null, null, smc, assert, null, true);
util.assertMapping(6, 12, '/wu/tang/gza.coffee', 6, 19, null, null, smc, assert, null, true);
// Original to generated with lub bias.
util.assertMapping(3, 2, '/wu/tang/gza.coffee', 1, 1, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true);
util.assertMapping(4, 2, '/wu/tang/gza.coffee', 2, 3, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true);
util.assertMapping(5, 2, '/wu/tang/gza.coffee', 3, 6, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true);
util.assertMapping(6, 12, '/wu/tang/gza.coffee', 4, 9, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true);
util.assertMapping(6, 12, '/wu/tang/gza.coffee', 5, 9, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true);
util.assertMapping(null, null, '/wu/tang/gza.coffee', 6, 19, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true);
};
});

View File

@ -15,6 +15,8 @@ Components.utils.import('resource://test/Utils.jsm');
define("test/source-map/test-source-map-consumer", ["require", "exports", "module"], function (require, exports, module) {
var SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer;
var IndexedSourceMapConsumer = require('source-map/source-map-consumer').IndexedSourceMapConsumer;
var BasicSourceMapConsumer = require('source-map/source-map-consumer').BasicSourceMapConsumer;
var SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
exports['test that we can instantiate with a string or an object'] = function (assert, util) {
@ -26,6 +28,18 @@ define("test/source-map/test-source-map-consumer", ["require", "exports", "modul
});
};
exports['test that the object returned from new SourceMapConsumer inherits from SourceMapConsumer'] = function (assert, util) {
assert.ok(new SourceMapConsumer(util.testMap) instanceof SourceMapConsumer);
}
exports['test that a BasicSourceMapConsumer is returned for sourcemaps without sections'] = function(assert, util) {
assert.ok(new SourceMapConsumer(util.testMap) instanceof BasicSourceMapConsumer);
};
exports['test that an IndexedSourceMapConsumer is returned for sourcemaps with sections'] = function(assert, util) {
assert.ok(new SourceMapConsumer(util.indexedTestMap) instanceof IndexedSourceMapConsumer);
};
exports['test that the `sources` field has the original sources'] = function (assert, util) {
var map;
var sources;
@ -36,6 +50,18 @@ define("test/source-map/test-source-map-consumer", ["require", "exports", "modul
assert.equal(sources[1], '/the/root/two.js');
assert.equal(sources.length, 2);
map = new SourceMapConsumer(util.indexedTestMap);
sources = map.sources;
assert.equal(sources[0], '/the/root/one.js');
assert.equal(sources[1], '/the/root/two.js');
assert.equal(sources.length, 2);
map = new SourceMapConsumer(util.indexedTestMapDifferentSourceRoots);
sources = map.sources;
assert.equal(sources[0], '/the/root/one.js');
assert.equal(sources[1], '/different/root/two.js');
assert.equal(sources.length, 2);
map = new SourceMapConsumer(util.testMapNoSourceRoot);
sources = map.sources;
assert.equal(sources[0], 'one.js');
@ -101,34 +127,107 @@ define("test/source-map/test-source-map-consumer", ["require", "exports", "modul
exports['test mapping tokens back exactly'] = function (assert, util) {
var map = new SourceMapConsumer(util.testMap);
util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, map, assert);
util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, map, assert);
util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, map, assert);
util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', map, assert);
util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, map, assert);
util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert);
util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', map, assert);
util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, null, map, assert);
util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, null, map, assert);
util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, null, map, assert);
util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', null, map, assert);
util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, null, map, assert);
util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', null, map, assert);
util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', null, map, assert);
util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, map, assert);
util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, map, assert);
util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, map, assert);
util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', map, assert);
util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, map, assert);
util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', map, assert);
util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, null, map, assert);
util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, null, map, assert);
util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, null, map, assert);
util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', null, map, assert);
util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, null, map, assert);
util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', null, map, assert);
};
exports['test mapping tokens back exactly in indexed source map'] = function (assert, util) {
var map = new SourceMapConsumer(util.indexedTestMap);
util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, null, map, assert);
util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, null, map, assert);
util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, null, map, assert);
util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', null, map, assert);
util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, null, map, assert);
util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', null, map, assert);
util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', null, map, assert);
util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, null, map, assert);
util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, null, map, assert);
util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, null, map, assert);
util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', null, map, assert);
util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, null, map, assert);
util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', null, map, assert);
};
exports['test mapping tokens back exactly'] = function (assert, util) {
var map = new SourceMapConsumer(util.testMap);
util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, null, map, assert);
util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, null, map, assert);
util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, null, map, assert);
util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', null, map, assert);
util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, null, map, assert);
util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', null, map, assert);
util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', null, map, assert);
util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, null, map, assert);
util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, null, map, assert);
util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, null, map, assert);
util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', null, map, assert);
util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, null, map, assert);
util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', null, map, assert);
};
exports['test mapping tokens fuzzy'] = function (assert, util) {
var map = new SourceMapConsumer(util.testMap);
// Finding original positions
util.assertMapping(1, 20, '/the/root/one.js', 1, 21, 'bar', map, assert, true);
util.assertMapping(1, 30, '/the/root/one.js', 2, 10, 'baz', map, assert, true);
util.assertMapping(2, 12, '/the/root/two.js', 1, 11, null, map, assert, true);
// Finding original positions with default (glb) bias.
util.assertMapping(1, 20, '/the/root/one.js', 1, 21, 'bar', null, map, assert, true);
util.assertMapping(1, 30, '/the/root/one.js', 2, 10, 'baz', null, map, assert, true);
util.assertMapping(2, 12, '/the/root/two.js', 1, 11, null, null, map, assert, true);
// Finding generated positions
util.assertMapping(1, 18, '/the/root/one.js', 1, 22, 'bar', map, assert, null, true);
util.assertMapping(1, 28, '/the/root/one.js', 2, 13, 'baz', map, assert, null, true);
util.assertMapping(2, 9, '/the/root/two.js', 1, 16, null, map, assert, null, true);
// Finding original positions with lub bias.
util.assertMapping(1, 16, '/the/root/one.js', 1, 21, 'bar', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, true);
util.assertMapping(1, 26, '/the/root/one.js', 2, 10, 'baz', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, true);
util.assertMapping(2, 6, '/the/root/two.js', 1, 11, null, SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, true);
// Finding generated positions with default (glb) bias.
util.assertMapping(1, 18, '/the/root/one.js', 1, 22, 'bar', null, map, assert, null, true);
util.assertMapping(1, 28, '/the/root/one.js', 2, 13, 'baz', null, map, assert, null, true);
util.assertMapping(2, 9, '/the/root/two.js', 1, 16, null, null, map, assert, null, true);
// Finding generated positions with lub bias.
util.assertMapping(1, 18, '/the/root/one.js', 1, 20, 'bar', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true);
util.assertMapping(1, 28, '/the/root/one.js', 2, 7, 'baz', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true);
util.assertMapping(2, 9, '/the/root/two.js', 1, 6, null, SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true);
};
exports['test mapping tokens fuzzy in indexed source map'] = function (assert, util) {
var map = new SourceMapConsumer(util.indexedTestMap);
// Finding original positions with default (glb) bias.
util.assertMapping(1, 20, '/the/root/one.js', 1, 21, 'bar', null, map, assert, true);
util.assertMapping(1, 30, '/the/root/one.js', 2, 10, 'baz', null, map, assert, true);
util.assertMapping(2, 12, '/the/root/two.js', 1, 11, null, null, map, assert, true);
// Finding original positions with lub bias.
util.assertMapping(1, 16, '/the/root/one.js', 1, 21, 'bar', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, true);
util.assertMapping(1, 26, '/the/root/one.js', 2, 10, 'baz', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, true);
util.assertMapping(2, 6, '/the/root/two.js', 1, 11, null, SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, true);
// Finding generated positions with default (glb) bias.
util.assertMapping(1, 18, '/the/root/one.js', 1, 22, 'bar', null, map, assert, null, true);
util.assertMapping(1, 28, '/the/root/one.js', 2, 13, 'baz', null, map, assert, null, true);
util.assertMapping(2, 9, '/the/root/two.js', 1, 16, null, null, map, assert, null, true);
// Finding generated positions with lub bias.
util.assertMapping(1, 18, '/the/root/one.js', 1, 20, 'bar', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true);
util.assertMapping(1, 28, '/the/root/one.js', 2, 7, 'baz', SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true);
util.assertMapping(2, 9, '/the/root/two.js', 1, 6, null, SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true);
};
exports['test mappings and end of lines'] = function (assert, util) {
@ -149,10 +248,10 @@ define("test/source-map/test-source-map-consumer", ["require", "exports", "modul
var map = SourceMapConsumer.fromSourceMap(smg);
// When finding original positions, mappings end at the end of the line.
util.assertMapping(2, 1, null, null, null, null, map, assert, true)
util.assertMapping(2, 1, null, null, null, null, null, map, assert, true)
// When finding generated positions, mappings do not end at the end of the line.
util.assertMapping(1, 1, 'bar.js', 2, 1, null, map, assert, null, true);
util.assertMapping(1, 1, 'bar.js', 2, 1, null, null, map, assert, null, true);
};
exports['test creating source map consumers with )]}\' prefix'] = function (assert, util) {
@ -193,6 +292,29 @@ define("test/source-map/test-source-map-consumer", ["require", "exports", "modul
});
};
exports['test eachMapping for indexed source maps'] = function(assert, util) {
var map = new SourceMapConsumer(util.indexedTestMap);
var previousLine = -Infinity;
var previousColumn = -Infinity;
map.eachMapping(function (mapping) {
assert.ok(mapping.generatedLine >= previousLine);
if (mapping.source) {
assert.equal(mapping.source.indexOf(util.testMap.sourceRoot), 0);
}
if (mapping.generatedLine === previousLine) {
assert.ok(mapping.generatedColumn >= previousColumn);
previousColumn = mapping.generatedColumn;
}
else {
previousLine = mapping.generatedLine;
previousColumn = -Infinity;
}
});
};
exports['test iterating over mappings in a different order'] = function (assert, util) {
var map = new SourceMapConsumer(util.testMap);
var previousLine = -Infinity;
@ -221,6 +343,34 @@ define("test/source-map/test-source-map-consumer", ["require", "exports", "modul
}, null, SourceMapConsumer.ORIGINAL_ORDER);
};
exports['test iterating over mappings in a different order in indexed source maps'] = function (assert, util) {
var map = new SourceMapConsumer(util.indexedTestMap);
var previousLine = -Infinity;
var previousColumn = -Infinity;
var previousSource = "";
map.eachMapping(function (mapping) {
assert.ok(mapping.source >= previousSource);
if (mapping.source === previousSource) {
assert.ok(mapping.originalLine >= previousLine);
if (mapping.originalLine === previousLine) {
assert.ok(mapping.originalColumn >= previousColumn);
previousColumn = mapping.originalColumn;
}
else {
previousLine = mapping.originalLine;
previousColumn = -Infinity;
}
}
else {
previousSource = mapping.source;
previousLine = -Infinity;
previousColumn = -Infinity;
}
}, null, SourceMapConsumer.ORIGINAL_ORDER);
};
exports['test that we can set the context for `this` in eachMapping'] = function (assert, util) {
var map = new SourceMapConsumer(util.testMap);
var context = {};
@ -229,6 +379,14 @@ define("test/source-map/test-source-map-consumer", ["require", "exports", "modul
}, context);
};
exports['test that we can set the context for `this` in eachMapping in indexed source maps'] = function (assert, util) {
var map = new SourceMapConsumer(util.indexedTestMap);
var context = {};
map.eachMapping(function () {
assert.equal(this, context);
}, context);
};
exports['test that the `sourcesContent` field has the original sources'] = function (assert, util) {
var map = new SourceMapConsumer(util.testMapWithSourcesContent);
var sourcesContent = map.sourcesContent;
@ -276,6 +434,26 @@ define("test/source-map/test-source-map-consumer", ["require", "exports", "modul
}, Error);
};
exports['test that we can get the original source content for the sources on an indexed source map'] = function (assert, util) {
var map = new SourceMapConsumer(util.indexedTestMap);
var sources = map.sources;
assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };');
assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };');
assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };');
assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };');
assert.throws(function () {
map.sourceContentFor("");
}, Error);
assert.throws(function () {
map.sourceContentFor("/the/root/three.js");
}, Error);
assert.throws(function () {
map.sourceContentFor("three.js");
}, Error);
};
exports['test sourceRoot + generatedPositionFor'] = function (assert, util) {
var map = new SourceMapGenerator({
sourceRoot: 'foo/bar',
@ -544,6 +722,20 @@ define("test/source-map/test-source-map-consumer", ["require", "exports", "modul
'Source should be relative the host of the source root.');
};
exports['test indexed source map errors when sections are out of order by line'] = function(assert, util) {
// Make a deep copy of the indexedTestMap
var misorderedIndexedTestMap = JSON.parse(JSON.stringify(util.indexedTestMap));
misorderedIndexedTestMap.sections[0].offset = {
line: 2,
column: 0
};
assert.throws(function() {
new SourceMapConsumer(misorderedIndexedTestMap);
}, Error);
};
exports['test github issue #64'] = function (assert, util) {
var map = new SourceMapConsumer({
"version": 3,

View File

@ -103,6 +103,27 @@ define("test/source-map/test-source-map-generator", ["require", "exports", "modu
});
};
exports['test adding mappings with skipValidation'] = function (assert, util) {
var map = new SourceMapGenerator({
file: 'generated-foo.js',
sourceRoot: '.',
skipValidation: true
});
// Not enough info, caught by `util.getArgs`
assert.throws(function () {
map.addMapping({});
});
// Original file position, but no source. Not checked.
assert.doesNotThrow(function () {
map.addMapping({
generated: { line: 1, column: 1 },
original: { line: 1, column: 1 }
});
});
};
exports['test that the correct mappings are being generated'] = function (assert, util) {
var map = new SourceMapGenerator({
file: 'min.js',
@ -660,6 +681,48 @@ define("test/source-map/test-source-map-generator", ["require", "exports", "modu
});
};
exports['test applySourceMap with unexact match'] = function (assert, util) {
var map1 = new SourceMapGenerator({
file: 'bundled-source'
});
map1.addMapping({
generated: { line: 1, column: 4 },
original: { line: 1, column: 4 },
source: 'transformed-source'
});
map1.addMapping({
generated: { line: 2, column: 4 },
original: { line: 2, column: 4 },
source: 'transformed-source'
});
var map2 = new SourceMapGenerator({
file: 'transformed-source'
});
map2.addMapping({
generated: { line: 2, column: 0 },
original: { line: 1, column: 0 },
source: 'original-source'
});
var expectedMap = new SourceMapGenerator({
file: 'bundled-source'
});
expectedMap.addMapping({
generated: { line: 1, column: 4 },
original: { line: 1, column: 4 },
source: 'transformed-source'
});
expectedMap.addMapping({
generated: { line: 2, column: 4 },
original: { line: 1, column: 0 },
source: 'original-source'
});
map1.applySourceMap(new SourceMapConsumer(map2.toJSON()));
util.assertEqualMaps(assert, map1.toJSON(), expectedMap.toJSON());
};
});
function run_test() {
runSourceMapTests('test/source-map/test-source-map-generator', do_throw);