mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-13 19:12:49 +00:00
updated bunch of file paths and changed the way posts are loaded
This commit is contained in:
62
node_modules/escodegen/node_modules/source-map/test/run-tests.js
generated
vendored
Executable file
62
node_modules/escodegen/node_modules/source-map/test/run-tests.js
generated
vendored
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env node
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var util = require('./source-map/util');
|
||||
|
||||
function run(tests) {
|
||||
var total = 0;
|
||||
var passed = 0;
|
||||
|
||||
for (var i = 0; i < tests.length; i++) {
|
||||
for (var k in tests[i].testCase) {
|
||||
if (/^test/.test(k)) {
|
||||
total++;
|
||||
try {
|
||||
tests[i].testCase[k](assert, util);
|
||||
passed++;
|
||||
}
|
||||
catch (e) {
|
||||
console.log('FAILED ' + tests[i].name + ': ' + k + '!');
|
||||
console.log(e.stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('');
|
||||
console.log(passed + ' / ' + total + ' tests passed.');
|
||||
console.log('');
|
||||
|
||||
return total - passed;
|
||||
}
|
||||
|
||||
function isTestFile(f) {
|
||||
var testToRun = process.argv[2];
|
||||
return testToRun
|
||||
? path.basename(testToRun) === f
|
||||
: /^test\-.*?\.js/.test(f);
|
||||
}
|
||||
|
||||
function toModule(f) {
|
||||
return './source-map/' + f.replace(/\.js$/, '');
|
||||
}
|
||||
|
||||
var requires = fs.readdirSync(path.join(__dirname, 'source-map'))
|
||||
.filter(isTestFile)
|
||||
.map(toModule);
|
||||
|
||||
var code = run(requires.map(require).map(function (mod, i) {
|
||||
return {
|
||||
name: requires[i],
|
||||
testCase: mod
|
||||
};
|
||||
}));
|
||||
|
||||
process.exit(code);
|
||||
26
node_modules/escodegen/node_modules/source-map/test/source-map/test-api.js
generated
vendored
Normal file
26
node_modules/escodegen/node_modules/source-map/test/source-map/test-api.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2012 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var sourceMap;
|
||||
try {
|
||||
sourceMap = require('../../lib/source-map');
|
||||
} catch (e) {
|
||||
sourceMap = {};
|
||||
Components.utils.import('resource:///modules/devtools/SourceMap.jsm', sourceMap);
|
||||
}
|
||||
|
||||
exports['test that the api is properly exposed in the top level'] = function (assert, util) {
|
||||
assert.equal(typeof sourceMap.SourceMapGenerator, "function");
|
||||
assert.equal(typeof sourceMap.SourceMapConsumer, "function");
|
||||
assert.equal(typeof sourceMap.SourceNode, "function");
|
||||
};
|
||||
|
||||
});
|
||||
104
node_modules/escodegen/node_modules/source-map/test/source-map/test-array-set.js
generated
vendored
Normal file
104
node_modules/escodegen/node_modules/source-map/test/source-map/test-array-set.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var ArraySet = require('../../lib/source-map/array-set').ArraySet;
|
||||
|
||||
function makeTestSet() {
|
||||
var set = new ArraySet();
|
||||
for (var i = 0; i < 100; i++) {
|
||||
set.add(String(i));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
exports['test .has() membership'] = function (assert, util) {
|
||||
var set = makeTestSet();
|
||||
for (var i = 0; i < 100; i++) {
|
||||
assert.ok(set.has(String(i)));
|
||||
}
|
||||
};
|
||||
|
||||
exports['test .indexOf() elements'] = function (assert, util) {
|
||||
var set = makeTestSet();
|
||||
for (var i = 0; i < 100; i++) {
|
||||
assert.strictEqual(set.indexOf(String(i)), i);
|
||||
}
|
||||
};
|
||||
|
||||
exports['test .at() indexing'] = function (assert, util) {
|
||||
var set = makeTestSet();
|
||||
for (var i = 0; i < 100; i++) {
|
||||
assert.strictEqual(set.at(i), String(i));
|
||||
}
|
||||
};
|
||||
|
||||
exports['test creating from an array'] = function (assert, util) {
|
||||
var set = ArraySet.fromArray(['foo', 'bar', 'baz', 'quux', 'hasOwnProperty']);
|
||||
|
||||
assert.ok(set.has('foo'));
|
||||
assert.ok(set.has('bar'));
|
||||
assert.ok(set.has('baz'));
|
||||
assert.ok(set.has('quux'));
|
||||
assert.ok(set.has('hasOwnProperty'));
|
||||
|
||||
assert.strictEqual(set.indexOf('foo'), 0);
|
||||
assert.strictEqual(set.indexOf('bar'), 1);
|
||||
assert.strictEqual(set.indexOf('baz'), 2);
|
||||
assert.strictEqual(set.indexOf('quux'), 3);
|
||||
|
||||
assert.strictEqual(set.at(0), 'foo');
|
||||
assert.strictEqual(set.at(1), 'bar');
|
||||
assert.strictEqual(set.at(2), 'baz');
|
||||
assert.strictEqual(set.at(3), 'quux');
|
||||
};
|
||||
|
||||
exports['test that you can add __proto__; see github issue #30'] = function (assert, util) {
|
||||
var set = new ArraySet();
|
||||
set.add('__proto__');
|
||||
assert.ok(set.has('__proto__'));
|
||||
assert.strictEqual(set.at(0), '__proto__');
|
||||
assert.strictEqual(set.indexOf('__proto__'), 0);
|
||||
};
|
||||
|
||||
exports['test .fromArray() with duplicates'] = function (assert, util) {
|
||||
var set = ArraySet.fromArray(['foo', 'foo']);
|
||||
assert.ok(set.has('foo'));
|
||||
assert.strictEqual(set.at(0), 'foo');
|
||||
assert.strictEqual(set.indexOf('foo'), 0);
|
||||
assert.strictEqual(set.toArray().length, 1);
|
||||
|
||||
set = ArraySet.fromArray(['foo', 'foo'], true);
|
||||
assert.ok(set.has('foo'));
|
||||
assert.strictEqual(set.at(0), 'foo');
|
||||
assert.strictEqual(set.at(1), 'foo');
|
||||
assert.strictEqual(set.indexOf('foo'), 0);
|
||||
assert.strictEqual(set.toArray().length, 2);
|
||||
};
|
||||
|
||||
exports['test .add() with duplicates'] = function (assert, util) {
|
||||
var set = new ArraySet();
|
||||
set.add('foo');
|
||||
|
||||
set.add('foo');
|
||||
assert.ok(set.has('foo'));
|
||||
assert.strictEqual(set.at(0), 'foo');
|
||||
assert.strictEqual(set.indexOf('foo'), 0);
|
||||
assert.strictEqual(set.toArray().length, 1);
|
||||
|
||||
set.add('foo', true);
|
||||
assert.ok(set.has('foo'));
|
||||
assert.strictEqual(set.at(0), 'foo');
|
||||
assert.strictEqual(set.at(1), 'foo');
|
||||
assert.strictEqual(set.indexOf('foo'), 0);
|
||||
assert.strictEqual(set.toArray().length, 2);
|
||||
};
|
||||
|
||||
});
|
||||
23
node_modules/escodegen/node_modules/source-map/test/source-map/test-base64-vlq.js
generated
vendored
Normal file
23
node_modules/escodegen/node_modules/source-map/test/source-map/test-base64-vlq.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var base64VLQ = require('../../lib/source-map/base64-vlq');
|
||||
|
||||
exports['test normal encoding and decoding'] = function (assert, util) {
|
||||
var result = {};
|
||||
for (var i = -255; i < 256; i++) {
|
||||
base64VLQ.decode(base64VLQ.encode(i), result);
|
||||
assert.equal(result.value, i);
|
||||
assert.equal(result.rest, "");
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
35
node_modules/escodegen/node_modules/source-map/test/source-map/test-base64.js
generated
vendored
Normal file
35
node_modules/escodegen/node_modules/source-map/test/source-map/test-base64.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var base64 = require('../../lib/source-map/base64');
|
||||
|
||||
exports['test out of range encoding'] = function (assert, util) {
|
||||
assert.throws(function () {
|
||||
base64.encode(-1);
|
||||
});
|
||||
assert.throws(function () {
|
||||
base64.encode(64);
|
||||
});
|
||||
};
|
||||
|
||||
exports['test out of range decoding'] = function (assert, util) {
|
||||
assert.throws(function () {
|
||||
base64.decode('=');
|
||||
});
|
||||
};
|
||||
|
||||
exports['test normal encoding and decoding'] = function (assert, util) {
|
||||
for (var i = 0; i < 64; i++) {
|
||||
assert.equal(base64.decode(base64.encode(i)), i);
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
54
node_modules/escodegen/node_modules/source-map/test/source-map/test-binary-search.js
generated
vendored
Normal file
54
node_modules/escodegen/node_modules/source-map/test/source-map/test-binary-search.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var binarySearch = require('../../lib/source-map/binary-search');
|
||||
|
||||
function numberCompare(a, b) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
exports['test too high'] = 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(haystack[binarySearch.search(needle, haystack, numberCompare)], 20);
|
||||
};
|
||||
|
||||
exports['test too low'] = 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(binarySearch.search(needle, haystack, numberCompare), -1);
|
||||
};
|
||||
|
||||
exports['test exact search'] = function (assert, util) {
|
||||
var needle = 4;
|
||||
var haystack = [2,4,6,8,10,12,14,16,18,20];
|
||||
|
||||
assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 4);
|
||||
};
|
||||
|
||||
exports['test fuzzy search'] = 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);
|
||||
};
|
||||
|
||||
});
|
||||
84
node_modules/escodegen/node_modules/source-map/test/source-map/test-dog-fooding.js
generated
vendored
Normal file
84
node_modules/escodegen/node_modules/source-map/test/source-map/test-dog-fooding.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var SourceMapConsumer = require('../../lib/source-map/source-map-consumer').SourceMapConsumer;
|
||||
var SourceMapGenerator = require('../../lib/source-map/source-map-generator').SourceMapGenerator;
|
||||
|
||||
exports['test eating our own dog food'] = function (assert, util) {
|
||||
var smg = new SourceMapGenerator({
|
||||
file: 'testing.js',
|
||||
sourceRoot: '/wu/tang'
|
||||
});
|
||||
|
||||
smg.addMapping({
|
||||
source: 'gza.coffee',
|
||||
original: { line: 1, column: 0 },
|
||||
generated: { line: 2, column: 2 }
|
||||
});
|
||||
|
||||
smg.addMapping({
|
||||
source: 'gza.coffee',
|
||||
original: { line: 2, column: 0 },
|
||||
generated: { line: 3, column: 2 }
|
||||
});
|
||||
|
||||
smg.addMapping({
|
||||
source: 'gza.coffee',
|
||||
original: { line: 3, column: 0 },
|
||||
generated: { line: 4, column: 2 }
|
||||
});
|
||||
|
||||
smg.addMapping({
|
||||
source: 'gza.coffee',
|
||||
original: { line: 4, column: 0 },
|
||||
generated: { line: 5, column: 2 }
|
||||
});
|
||||
|
||||
smg.addMapping({
|
||||
source: 'gza.coffee',
|
||||
original: { line: 5, column: 10 },
|
||||
generated: { line: 6, column: 12 }
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
};
|
||||
|
||||
});
|
||||
874
node_modules/escodegen/node_modules/source-map/test/source-map/test-source-map-consumer.js
generated
vendored
Normal file
874
node_modules/escodegen/node_modules/source-map/test/source-map/test-source-map-consumer.js
generated
vendored
Normal file
@@ -0,0 +1,874 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var SourceMapConsumer = require('../../lib/source-map/source-map-consumer').SourceMapConsumer;
|
||||
var IndexedSourceMapConsumer = require('../../lib/source-map/indexed-source-map-consumer').IndexedSourceMapConsumer;
|
||||
var BasicSourceMapConsumer = require('../../lib/source-map/basic-source-map-consumer').BasicSourceMapConsumer;
|
||||
var SourceMapGenerator = require('../../lib/source-map/source-map-generator').SourceMapGenerator;
|
||||
|
||||
exports['test that we can instantiate with a string or an object'] = function (assert, util) {
|
||||
assert.doesNotThrow(function () {
|
||||
var map = new SourceMapConsumer(util.testMap);
|
||||
});
|
||||
assert.doesNotThrow(function () {
|
||||
var map = new SourceMapConsumer(JSON.stringify(util.testMap));
|
||||
});
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
map = new SourceMapConsumer(util.testMap);
|
||||
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.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');
|
||||
assert.equal(sources[1], 'two.js');
|
||||
assert.equal(sources.length, 2);
|
||||
|
||||
map = new SourceMapConsumer(util.testMapEmptySourceRoot);
|
||||
sources = map.sources;
|
||||
assert.equal(sources[0], 'one.js');
|
||||
assert.equal(sources[1], 'two.js');
|
||||
assert.equal(sources.length, 2);
|
||||
};
|
||||
|
||||
exports['test that the source root is reflected in a mapping\'s source field'] = function (assert, util) {
|
||||
var map;
|
||||
var mapping;
|
||||
|
||||
map = new SourceMapConsumer(util.testMap);
|
||||
|
||||
mapping = map.originalPositionFor({
|
||||
line: 2,
|
||||
column: 1
|
||||
});
|
||||
assert.equal(mapping.source, '/the/root/two.js');
|
||||
|
||||
mapping = map.originalPositionFor({
|
||||
line: 1,
|
||||
column: 1
|
||||
});
|
||||
assert.equal(mapping.source, '/the/root/one.js');
|
||||
|
||||
|
||||
map = new SourceMapConsumer(util.testMapNoSourceRoot);
|
||||
|
||||
mapping = map.originalPositionFor({
|
||||
line: 2,
|
||||
column: 1
|
||||
});
|
||||
assert.equal(mapping.source, 'two.js');
|
||||
|
||||
mapping = map.originalPositionFor({
|
||||
line: 1,
|
||||
column: 1
|
||||
});
|
||||
assert.equal(mapping.source, 'one.js');
|
||||
|
||||
|
||||
map = new SourceMapConsumer(util.testMapEmptySourceRoot);
|
||||
|
||||
mapping = map.originalPositionFor({
|
||||
line: 2,
|
||||
column: 1
|
||||
});
|
||||
assert.equal(mapping.source, 'two.js');
|
||||
|
||||
mapping = map.originalPositionFor({
|
||||
line: 1,
|
||||
column: 1
|
||||
});
|
||||
assert.equal(mapping.source, 'one.js');
|
||||
};
|
||||
|
||||
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(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);
|
||||
};
|
||||
|
||||
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, 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(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);
|
||||
};
|
||||
|
||||
|
||||
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(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);
|
||||
};
|
||||
|
||||
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 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);
|
||||
};
|
||||
|
||||
exports['test mapping tokens fuzzy in indexed source map'] = function (assert, util) {
|
||||
var map = new SourceMapConsumer(util.indexedTestMap);
|
||||
|
||||
// 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 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);
|
||||
};
|
||||
|
||||
exports['test mappings and end of lines'] = function (assert, util) {
|
||||
var smg = new SourceMapGenerator({
|
||||
file: 'foo.js'
|
||||
});
|
||||
smg.addMapping({
|
||||
original: { line: 1, column: 1 },
|
||||
generated: { line: 1, column: 1 },
|
||||
source: 'bar.js'
|
||||
});
|
||||
smg.addMapping({
|
||||
original: { line: 2, column: 2 },
|
||||
generated: { line: 2, column: 2 },
|
||||
source: 'bar.js'
|
||||
});
|
||||
|
||||
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)
|
||||
|
||||
// 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);
|
||||
};
|
||||
|
||||
exports['test creating source map consumers with )]}\' prefix'] = function (assert, util) {
|
||||
assert.doesNotThrow(function () {
|
||||
var map = new SourceMapConsumer(")]}'" + JSON.stringify(util.testMap));
|
||||
});
|
||||
};
|
||||
|
||||
exports['test eachMapping'] = function (assert, util) {
|
||||
var map;
|
||||
|
||||
map = new SourceMapConsumer(util.testMap);
|
||||
var previousLine = -Infinity;
|
||||
var previousColumn = -Infinity;
|
||||
map.eachMapping(function (mapping) {
|
||||
assert.ok(mapping.generatedLine >= previousLine);
|
||||
|
||||
assert.ok(mapping.source === '/the/root/one.js' || mapping.source === '/the/root/two.js');
|
||||
|
||||
if (mapping.generatedLine === previousLine) {
|
||||
assert.ok(mapping.generatedColumn >= previousColumn);
|
||||
previousColumn = mapping.generatedColumn;
|
||||
}
|
||||
else {
|
||||
previousLine = mapping.generatedLine;
|
||||
previousColumn = -Infinity;
|
||||
}
|
||||
});
|
||||
|
||||
map = new SourceMapConsumer(util.testMapNoSourceRoot);
|
||||
map.eachMapping(function (mapping) {
|
||||
assert.ok(mapping.source === 'one.js' || mapping.source === 'two.js');
|
||||
});
|
||||
|
||||
map = new SourceMapConsumer(util.testMapEmptySourceRoot);
|
||||
map.eachMapping(function (mapping) {
|
||||
assert.ok(mapping.source === 'one.js' || mapping.source === 'two.js');
|
||||
});
|
||||
};
|
||||
|
||||
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;
|
||||
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 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 = {};
|
||||
map.eachMapping(function () {
|
||||
assert.equal(this, context);
|
||||
}, 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;
|
||||
|
||||
assert.equal(sourcesContent[0], ' ONE.foo = function (bar) {\n return baz(bar);\n };');
|
||||
assert.equal(sourcesContent[1], ' TWO.inc = function (n) {\n return n + 1;\n };');
|
||||
assert.equal(sourcesContent.length, 2);
|
||||
};
|
||||
|
||||
exports['test that we can get the original sources for the sources'] = function (assert, util) {
|
||||
var map = new SourceMapConsumer(util.testMapWithSourcesContent);
|
||||
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 that we can get the original source content with relative source paths'] = function (assert, util) {
|
||||
var map = new SourceMapConsumer(util.testMapRelativeSources);
|
||||
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 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',
|
||||
file: 'baz.js'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 1, column: 1 },
|
||||
generated: { line: 2, column: 2 },
|
||||
source: 'bang.coffee'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 5, column: 5 },
|
||||
generated: { line: 6, column: 6 },
|
||||
source: 'bang.coffee'
|
||||
});
|
||||
map = new SourceMapConsumer(map.toString());
|
||||
|
||||
// Should handle without sourceRoot.
|
||||
var pos = map.generatedPositionFor({
|
||||
line: 1,
|
||||
column: 1,
|
||||
source: 'bang.coffee'
|
||||
});
|
||||
|
||||
assert.equal(pos.line, 2);
|
||||
assert.equal(pos.column, 2);
|
||||
|
||||
// Should handle with sourceRoot.
|
||||
var pos = map.generatedPositionFor({
|
||||
line: 1,
|
||||
column: 1,
|
||||
source: 'foo/bar/bang.coffee'
|
||||
});
|
||||
|
||||
assert.equal(pos.line, 2);
|
||||
assert.equal(pos.column, 2);
|
||||
};
|
||||
|
||||
exports['test allGeneratedPositionsFor'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'generated.js'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 1, column: 1 },
|
||||
generated: { line: 2, column: 2 },
|
||||
source: 'foo.coffee'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 1, column: 1 },
|
||||
generated: { line: 2, column: 2 },
|
||||
source: 'bar.coffee'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 2, column: 1 },
|
||||
generated: { line: 3, column: 2 },
|
||||
source: 'bar.coffee'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 2, column: 2 },
|
||||
generated: { line: 3, column: 3 },
|
||||
source: 'bar.coffee'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 3, column: 1 },
|
||||
generated: { line: 4, column: 2 },
|
||||
source: 'bar.coffee'
|
||||
});
|
||||
map = new SourceMapConsumer(map.toString());
|
||||
|
||||
var mappings = map.allGeneratedPositionsFor({
|
||||
line: 2,
|
||||
source: 'bar.coffee'
|
||||
});
|
||||
|
||||
assert.equal(mappings.length, 2);
|
||||
assert.equal(mappings[0].line, 3);
|
||||
assert.equal(mappings[0].column, 2);
|
||||
assert.equal(mappings[1].line, 3);
|
||||
assert.equal(mappings[1].column, 3);
|
||||
};
|
||||
|
||||
exports['test allGeneratedPositionsFor for line with no mappings'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'generated.js'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 1, column: 1 },
|
||||
generated: { line: 2, column: 2 },
|
||||
source: 'foo.coffee'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 1, column: 1 },
|
||||
generated: { line: 2, column: 2 },
|
||||
source: 'bar.coffee'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 3, column: 1 },
|
||||
generated: { line: 4, column: 2 },
|
||||
source: 'bar.coffee'
|
||||
});
|
||||
map = new SourceMapConsumer(map.toString());
|
||||
|
||||
var mappings = map.allGeneratedPositionsFor({
|
||||
line: 2,
|
||||
source: 'bar.coffee'
|
||||
});
|
||||
|
||||
assert.equal(mappings.length, 0);
|
||||
};
|
||||
|
||||
exports['test allGeneratedPositionsFor source map with no mappings'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'generated.js'
|
||||
});
|
||||
map = new SourceMapConsumer(map.toString());
|
||||
|
||||
var mappings = map.allGeneratedPositionsFor({
|
||||
line: 2,
|
||||
source: 'bar.coffee'
|
||||
});
|
||||
|
||||
assert.equal(mappings.length, 0);
|
||||
};
|
||||
|
||||
exports['test computeColumnSpans'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'generated.js'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 1, column: 1 },
|
||||
generated: { line: 1, column: 1 },
|
||||
source: 'foo.coffee'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 2, column: 1 },
|
||||
generated: { line: 2, column: 1 },
|
||||
source: 'foo.coffee'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 2, column: 2 },
|
||||
generated: { line: 2, column: 10 },
|
||||
source: 'foo.coffee'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 2, column: 3 },
|
||||
generated: { line: 2, column: 20 },
|
||||
source: 'foo.coffee'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 3, column: 1 },
|
||||
generated: { line: 3, column: 1 },
|
||||
source: 'foo.coffee'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 3, column: 2 },
|
||||
generated: { line: 3, column: 2 },
|
||||
source: 'foo.coffee'
|
||||
});
|
||||
map = new SourceMapConsumer(map.toString());
|
||||
|
||||
map.computeColumnSpans();
|
||||
|
||||
var mappings = map.allGeneratedPositionsFor({
|
||||
line: 1,
|
||||
source: 'foo.coffee'
|
||||
});
|
||||
|
||||
assert.equal(mappings.length, 1);
|
||||
assert.equal(mappings[0].lastColumn, Infinity);
|
||||
|
||||
var mappings = map.allGeneratedPositionsFor({
|
||||
line: 2,
|
||||
source: 'foo.coffee'
|
||||
});
|
||||
|
||||
assert.equal(mappings.length, 3);
|
||||
assert.equal(mappings[0].lastColumn, 9);
|
||||
assert.equal(mappings[1].lastColumn, 19);
|
||||
assert.equal(mappings[2].lastColumn, Infinity);
|
||||
|
||||
var mappings = map.allGeneratedPositionsFor({
|
||||
line: 3,
|
||||
source: 'foo.coffee'
|
||||
});
|
||||
|
||||
assert.equal(mappings.length, 2);
|
||||
assert.equal(mappings[0].lastColumn, 1);
|
||||
assert.equal(mappings[1].lastColumn, Infinity);
|
||||
};
|
||||
|
||||
exports['test sourceRoot + originalPositionFor'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
sourceRoot: 'foo/bar',
|
||||
file: 'baz.js'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 1, column: 1 },
|
||||
generated: { line: 2, column: 2 },
|
||||
source: 'bang.coffee'
|
||||
});
|
||||
map = new SourceMapConsumer(map.toString());
|
||||
|
||||
var pos = map.originalPositionFor({
|
||||
line: 2,
|
||||
column: 2,
|
||||
});
|
||||
|
||||
// Should always have the prepended source root
|
||||
assert.equal(pos.source, 'foo/bar/bang.coffee');
|
||||
assert.equal(pos.line, 1);
|
||||
assert.equal(pos.column, 1);
|
||||
};
|
||||
|
||||
exports['test github issue #56'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
sourceRoot: 'http://',
|
||||
file: 'www.example.com/foo.js'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 1, column: 1 },
|
||||
generated: { line: 2, column: 2 },
|
||||
source: 'www.example.com/original.js'
|
||||
});
|
||||
map = new SourceMapConsumer(map.toString());
|
||||
|
||||
var sources = map.sources;
|
||||
assert.equal(sources.length, 1);
|
||||
assert.equal(sources[0], 'http://www.example.com/original.js');
|
||||
};
|
||||
|
||||
exports['test github issue #43'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
sourceRoot: 'http://example.com',
|
||||
file: 'foo.js'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 1, column: 1 },
|
||||
generated: { line: 2, column: 2 },
|
||||
source: 'http://cdn.example.com/original.js'
|
||||
});
|
||||
map = new SourceMapConsumer(map.toString());
|
||||
|
||||
var sources = map.sources;
|
||||
assert.equal(sources.length, 1,
|
||||
'Should only be one source.');
|
||||
assert.equal(sources[0], 'http://cdn.example.com/original.js',
|
||||
'Should not be joined with the sourceRoot.');
|
||||
};
|
||||
|
||||
exports['test absolute path, but same host sources'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
sourceRoot: 'http://example.com/foo/bar',
|
||||
file: 'foo.js'
|
||||
});
|
||||
map.addMapping({
|
||||
original: { line: 1, column: 1 },
|
||||
generated: { line: 2, column: 2 },
|
||||
source: '/original.js'
|
||||
});
|
||||
map = new SourceMapConsumer(map.toString());
|
||||
|
||||
var sources = map.sources;
|
||||
assert.equal(sources.length, 1,
|
||||
'Should only be one source.');
|
||||
assert.equal(sources[0], 'http://example.com/original.js',
|
||||
'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,
|
||||
"file": "foo.js",
|
||||
"sourceRoot": "http://example.com/",
|
||||
"sources": ["/a"],
|
||||
"names": [],
|
||||
"mappings": "AACA",
|
||||
"sourcesContent": ["foo"]
|
||||
});
|
||||
|
||||
assert.equal(map.sourceContentFor("a"), "foo");
|
||||
assert.equal(map.sourceContentFor("/a"), "foo");
|
||||
};
|
||||
|
||||
exports['test bug 885597'] = function (assert, util) {
|
||||
var map = new SourceMapConsumer({
|
||||
"version": 3,
|
||||
"file": "foo.js",
|
||||
"sourceRoot": "file:///Users/AlGore/Invented/The/Internet/",
|
||||
"sources": ["/a"],
|
||||
"names": [],
|
||||
"mappings": "AACA",
|
||||
"sourcesContent": ["foo"]
|
||||
});
|
||||
|
||||
var s = map.sources[0];
|
||||
assert.equal(map.sourceContentFor(s), "foo");
|
||||
};
|
||||
|
||||
exports['test github issue #72, duplicate sources'] = function (assert, util) {
|
||||
var map = new SourceMapConsumer({
|
||||
"version": 3,
|
||||
"file": "foo.js",
|
||||
"sources": ["source1.js", "source1.js", "source3.js"],
|
||||
"names": [],
|
||||
"mappings": ";EAAC;;IAEE;;MEEE",
|
||||
"sourceRoot": "http://example.com"
|
||||
});
|
||||
|
||||
var pos = map.originalPositionFor({
|
||||
line: 2,
|
||||
column: 2
|
||||
});
|
||||
assert.equal(pos.source, 'http://example.com/source1.js');
|
||||
assert.equal(pos.line, 1);
|
||||
assert.equal(pos.column, 1);
|
||||
|
||||
var pos = map.originalPositionFor({
|
||||
line: 4,
|
||||
column: 4
|
||||
});
|
||||
assert.equal(pos.source, 'http://example.com/source1.js');
|
||||
assert.equal(pos.line, 3);
|
||||
assert.equal(pos.column, 3);
|
||||
|
||||
var pos = map.originalPositionFor({
|
||||
line: 6,
|
||||
column: 6
|
||||
});
|
||||
assert.equal(pos.source, 'http://example.com/source3.js');
|
||||
assert.equal(pos.line, 5);
|
||||
assert.equal(pos.column, 5);
|
||||
};
|
||||
|
||||
exports['test github issue #72, duplicate names'] = function (assert, util) {
|
||||
var map = new SourceMapConsumer({
|
||||
"version": 3,
|
||||
"file": "foo.js",
|
||||
"sources": ["source.js"],
|
||||
"names": ["name1", "name1", "name3"],
|
||||
"mappings": ";EAACA;;IAEEA;;MAEEE",
|
||||
"sourceRoot": "http://example.com"
|
||||
});
|
||||
|
||||
var pos = map.originalPositionFor({
|
||||
line: 2,
|
||||
column: 2
|
||||
});
|
||||
assert.equal(pos.name, 'name1');
|
||||
assert.equal(pos.line, 1);
|
||||
assert.equal(pos.column, 1);
|
||||
|
||||
var pos = map.originalPositionFor({
|
||||
line: 4,
|
||||
column: 4
|
||||
});
|
||||
assert.equal(pos.name, 'name1');
|
||||
assert.equal(pos.line, 3);
|
||||
assert.equal(pos.column, 3);
|
||||
|
||||
var pos = map.originalPositionFor({
|
||||
line: 6,
|
||||
column: 6
|
||||
});
|
||||
assert.equal(pos.name, 'name3');
|
||||
assert.equal(pos.line, 5);
|
||||
assert.equal(pos.column, 5);
|
||||
};
|
||||
|
||||
exports['test SourceMapConsumer.fromSourceMap'] = function (assert, util) {
|
||||
var smg = new SourceMapGenerator({
|
||||
sourceRoot: 'http://example.com/',
|
||||
file: 'foo.js'
|
||||
});
|
||||
smg.addMapping({
|
||||
original: { line: 1, column: 1 },
|
||||
generated: { line: 2, column: 2 },
|
||||
source: 'bar.js'
|
||||
});
|
||||
smg.addMapping({
|
||||
original: { line: 2, column: 2 },
|
||||
generated: { line: 4, column: 4 },
|
||||
source: 'baz.js',
|
||||
name: 'dirtMcGirt'
|
||||
});
|
||||
smg.setSourceContent('baz.js', 'baz.js content');
|
||||
|
||||
var smc = SourceMapConsumer.fromSourceMap(smg);
|
||||
assert.equal(smc.file, 'foo.js');
|
||||
assert.equal(smc.sourceRoot, 'http://example.com/');
|
||||
assert.equal(smc.sources.length, 2);
|
||||
assert.equal(smc.sources[0], 'http://example.com/bar.js');
|
||||
assert.equal(smc.sources[1], 'http://example.com/baz.js');
|
||||
assert.equal(smc.sourceContentFor('baz.js'), 'baz.js content');
|
||||
|
||||
var pos = smc.originalPositionFor({
|
||||
line: 2,
|
||||
column: 2
|
||||
});
|
||||
assert.equal(pos.line, 1);
|
||||
assert.equal(pos.column, 1);
|
||||
assert.equal(pos.source, 'http://example.com/bar.js');
|
||||
assert.equal(pos.name, null);
|
||||
|
||||
pos = smc.generatedPositionFor({
|
||||
line: 1,
|
||||
column: 1,
|
||||
source: 'http://example.com/bar.js'
|
||||
});
|
||||
assert.equal(pos.line, 2);
|
||||
assert.equal(pos.column, 2);
|
||||
|
||||
pos = smc.originalPositionFor({
|
||||
line: 4,
|
||||
column: 4
|
||||
});
|
||||
assert.equal(pos.line, 2);
|
||||
assert.equal(pos.column, 2);
|
||||
assert.equal(pos.source, 'http://example.com/baz.js');
|
||||
assert.equal(pos.name, 'dirtMcGirt');
|
||||
|
||||
pos = smc.generatedPositionFor({
|
||||
line: 2,
|
||||
column: 2,
|
||||
source: 'http://example.com/baz.js'
|
||||
});
|
||||
assert.equal(pos.line, 4);
|
||||
assert.equal(pos.column, 4);
|
||||
};
|
||||
});
|
||||
679
node_modules/escodegen/node_modules/source-map/test/source-map/test-source-map-generator.js
generated
vendored
Normal file
679
node_modules/escodegen/node_modules/source-map/test/source-map/test-source-map-generator.js
generated
vendored
Normal file
@@ -0,0 +1,679 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var SourceMapGenerator = require('../../lib/source-map/source-map-generator').SourceMapGenerator;
|
||||
var SourceMapConsumer = require('../../lib/source-map/source-map-consumer').SourceMapConsumer;
|
||||
var SourceNode = require('../../lib/source-map/source-node').SourceNode;
|
||||
var util = require('./util');
|
||||
|
||||
exports['test some simple stuff'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'foo.js',
|
||||
sourceRoot: '.'
|
||||
});
|
||||
assert.ok(true);
|
||||
|
||||
var map = new SourceMapGenerator().toJSON();
|
||||
assert.ok(!('file' in map));
|
||||
assert.ok(!('sourceRoot' in map));
|
||||
};
|
||||
|
||||
exports['test JSON serialization'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'foo.js',
|
||||
sourceRoot: '.'
|
||||
});
|
||||
assert.equal(map.toString(), JSON.stringify(map));
|
||||
};
|
||||
|
||||
exports['test adding mappings (case 1)'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'generated-foo.js',
|
||||
sourceRoot: '.'
|
||||
});
|
||||
|
||||
assert.doesNotThrow(function () {
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 1 }
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports['test adding mappings (case 2)'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'generated-foo.js',
|
||||
sourceRoot: '.'
|
||||
});
|
||||
|
||||
assert.doesNotThrow(function () {
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 1 },
|
||||
source: 'bar.js',
|
||||
original: { line: 1, column: 1 }
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports['test adding mappings (case 3)'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'generated-foo.js',
|
||||
sourceRoot: '.'
|
||||
});
|
||||
|
||||
assert.doesNotThrow(function () {
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 1 },
|
||||
source: 'bar.js',
|
||||
original: { line: 1, column: 1 },
|
||||
name: 'someToken'
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports['test adding mappings (invalid)'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'generated-foo.js',
|
||||
sourceRoot: '.'
|
||||
});
|
||||
|
||||
// Not enough info.
|
||||
assert.throws(function () {
|
||||
map.addMapping({});
|
||||
});
|
||||
|
||||
// Original file position, but no source.
|
||||
assert.throws(function () {
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 1 },
|
||||
original: { line: 1, column: 1 }
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
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',
|
||||
sourceRoot: '/the/root'
|
||||
});
|
||||
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 1 },
|
||||
original: { line: 1, column: 1 },
|
||||
source: 'one.js'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 5 },
|
||||
original: { line: 1, column: 5 },
|
||||
source: 'one.js'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 9 },
|
||||
original: { line: 1, column: 11 },
|
||||
source: 'one.js'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 18 },
|
||||
original: { line: 1, column: 21 },
|
||||
source: 'one.js',
|
||||
name: 'bar'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 21 },
|
||||
original: { line: 2, column: 3 },
|
||||
source: 'one.js'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 28 },
|
||||
original: { line: 2, column: 10 },
|
||||
source: 'one.js',
|
||||
name: 'baz'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 32 },
|
||||
original: { line: 2, column: 14 },
|
||||
source: 'one.js',
|
||||
name: 'bar'
|
||||
});
|
||||
|
||||
map.addMapping({
|
||||
generated: { line: 2, column: 1 },
|
||||
original: { line: 1, column: 1 },
|
||||
source: 'two.js'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 2, column: 5 },
|
||||
original: { line: 1, column: 5 },
|
||||
source: 'two.js'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 2, column: 9 },
|
||||
original: { line: 1, column: 11 },
|
||||
source: 'two.js'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 2, column: 18 },
|
||||
original: { line: 1, column: 21 },
|
||||
source: 'two.js',
|
||||
name: 'n'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 2, column: 21 },
|
||||
original: { line: 2, column: 3 },
|
||||
source: 'two.js'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 2, column: 28 },
|
||||
original: { line: 2, column: 10 },
|
||||
source: 'two.js',
|
||||
name: 'n'
|
||||
});
|
||||
|
||||
map = JSON.parse(map.toString());
|
||||
|
||||
util.assertEqualMaps(assert, map, util.testMap);
|
||||
};
|
||||
|
||||
exports['test that adding a mapping with an empty string name does not break generation'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'generated-foo.js',
|
||||
sourceRoot: '.'
|
||||
});
|
||||
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 1 },
|
||||
source: 'bar.js',
|
||||
original: { line: 1, column: 1 },
|
||||
name: ''
|
||||
});
|
||||
|
||||
assert.doesNotThrow(function () {
|
||||
JSON.parse(map.toString());
|
||||
});
|
||||
};
|
||||
|
||||
exports['test that source content can be set'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'min.js',
|
||||
sourceRoot: '/the/root'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 1 },
|
||||
original: { line: 1, column: 1 },
|
||||
source: 'one.js'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 2, column: 1 },
|
||||
original: { line: 1, column: 1 },
|
||||
source: 'two.js'
|
||||
});
|
||||
map.setSourceContent('one.js', 'one file content');
|
||||
|
||||
map = JSON.parse(map.toString());
|
||||
assert.equal(map.sources[0], 'one.js');
|
||||
assert.equal(map.sources[1], 'two.js');
|
||||
assert.equal(map.sourcesContent[0], 'one file content');
|
||||
assert.equal(map.sourcesContent[1], null);
|
||||
};
|
||||
|
||||
exports['test .fromSourceMap'] = function (assert, util) {
|
||||
var map = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(util.testMap));
|
||||
util.assertEqualMaps(assert, map.toJSON(), util.testMap);
|
||||
};
|
||||
|
||||
exports['test .fromSourceMap with sourcesContent'] = function (assert, util) {
|
||||
var map = SourceMapGenerator.fromSourceMap(
|
||||
new SourceMapConsumer(util.testMapWithSourcesContent));
|
||||
util.assertEqualMaps(assert, map.toJSON(), util.testMapWithSourcesContent);
|
||||
};
|
||||
|
||||
exports['test applySourceMap'] = function (assert, util) {
|
||||
var node = new SourceNode(null, null, null, [
|
||||
new SourceNode(2, 0, 'fileX', 'lineX2\n'),
|
||||
'genA1\n',
|
||||
new SourceNode(2, 0, 'fileY', 'lineY2\n'),
|
||||
'genA2\n',
|
||||
new SourceNode(1, 0, 'fileX', 'lineX1\n'),
|
||||
'genA3\n',
|
||||
new SourceNode(1, 0, 'fileY', 'lineY1\n')
|
||||
]);
|
||||
var mapStep1 = node.toStringWithSourceMap({
|
||||
file: 'fileA'
|
||||
}).map;
|
||||
mapStep1.setSourceContent('fileX', 'lineX1\nlineX2\n');
|
||||
mapStep1 = mapStep1.toJSON();
|
||||
|
||||
node = new SourceNode(null, null, null, [
|
||||
'gen1\n',
|
||||
new SourceNode(1, 0, 'fileA', 'lineA1\n'),
|
||||
new SourceNode(2, 0, 'fileA', 'lineA2\n'),
|
||||
new SourceNode(3, 0, 'fileA', 'lineA3\n'),
|
||||
new SourceNode(4, 0, 'fileA', 'lineA4\n'),
|
||||
new SourceNode(1, 0, 'fileB', 'lineB1\n'),
|
||||
new SourceNode(2, 0, 'fileB', 'lineB2\n'),
|
||||
'gen2\n'
|
||||
]);
|
||||
var mapStep2 = node.toStringWithSourceMap({
|
||||
file: 'fileGen'
|
||||
}).map;
|
||||
mapStep2.setSourceContent('fileB', 'lineB1\nlineB2\n');
|
||||
mapStep2 = mapStep2.toJSON();
|
||||
|
||||
node = new SourceNode(null, null, null, [
|
||||
'gen1\n',
|
||||
new SourceNode(2, 0, 'fileX', 'lineA1\n'),
|
||||
new SourceNode(2, 0, 'fileA', 'lineA2\n'),
|
||||
new SourceNode(2, 0, 'fileY', 'lineA3\n'),
|
||||
new SourceNode(4, 0, 'fileA', 'lineA4\n'),
|
||||
new SourceNode(1, 0, 'fileB', 'lineB1\n'),
|
||||
new SourceNode(2, 0, 'fileB', 'lineB2\n'),
|
||||
'gen2\n'
|
||||
]);
|
||||
var expectedMap = node.toStringWithSourceMap({
|
||||
file: 'fileGen'
|
||||
}).map;
|
||||
expectedMap.setSourceContent('fileX', 'lineX1\nlineX2\n');
|
||||
expectedMap.setSourceContent('fileB', 'lineB1\nlineB2\n');
|
||||
expectedMap = expectedMap.toJSON();
|
||||
|
||||
// apply source map "mapStep1" to "mapStep2"
|
||||
var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(mapStep2));
|
||||
generator.applySourceMap(new SourceMapConsumer(mapStep1));
|
||||
var actualMap = generator.toJSON();
|
||||
|
||||
util.assertEqualMaps(assert, actualMap, expectedMap);
|
||||
};
|
||||
|
||||
exports['test applySourceMap throws when file is missing'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'test.js'
|
||||
});
|
||||
var map2 = new SourceMapGenerator();
|
||||
assert.throws(function() {
|
||||
map.applySourceMap(new SourceMapConsumer(map2.toJSON()));
|
||||
});
|
||||
};
|
||||
|
||||
exports['test the two additional parameters of applySourceMap'] = function (assert, util) {
|
||||
// Assume the following directory structure:
|
||||
//
|
||||
// http://foo.org/
|
||||
// bar.coffee
|
||||
// app/
|
||||
// coffee/
|
||||
// foo.coffee
|
||||
// temp/
|
||||
// bundle.js
|
||||
// temp_maps/
|
||||
// bundle.js.map
|
||||
// public/
|
||||
// bundle.min.js
|
||||
// bundle.min.js.map
|
||||
//
|
||||
// http://www.example.com/
|
||||
// baz.coffee
|
||||
|
||||
var bundleMap = new SourceMapGenerator({
|
||||
file: 'bundle.js'
|
||||
});
|
||||
bundleMap.addMapping({
|
||||
generated: { line: 3, column: 3 },
|
||||
original: { line: 2, column: 2 },
|
||||
source: '../../coffee/foo.coffee'
|
||||
});
|
||||
bundleMap.setSourceContent('../../coffee/foo.coffee', 'foo coffee');
|
||||
bundleMap.addMapping({
|
||||
generated: { line: 13, column: 13 },
|
||||
original: { line: 12, column: 12 },
|
||||
source: '/bar.coffee'
|
||||
});
|
||||
bundleMap.setSourceContent('/bar.coffee', 'bar coffee');
|
||||
bundleMap.addMapping({
|
||||
generated: { line: 23, column: 23 },
|
||||
original: { line: 22, column: 22 },
|
||||
source: 'http://www.example.com/baz.coffee'
|
||||
});
|
||||
bundleMap.setSourceContent(
|
||||
'http://www.example.com/baz.coffee',
|
||||
'baz coffee'
|
||||
);
|
||||
bundleMap = new SourceMapConsumer(bundleMap.toJSON());
|
||||
|
||||
var minifiedMap = new SourceMapGenerator({
|
||||
file: 'bundle.min.js',
|
||||
sourceRoot: '..'
|
||||
});
|
||||
minifiedMap.addMapping({
|
||||
generated: { line: 1, column: 1 },
|
||||
original: { line: 3, column: 3 },
|
||||
source: 'temp/bundle.js'
|
||||
});
|
||||
minifiedMap.addMapping({
|
||||
generated: { line: 11, column: 11 },
|
||||
original: { line: 13, column: 13 },
|
||||
source: 'temp/bundle.js'
|
||||
});
|
||||
minifiedMap.addMapping({
|
||||
generated: { line: 21, column: 21 },
|
||||
original: { line: 23, column: 23 },
|
||||
source: 'temp/bundle.js'
|
||||
});
|
||||
minifiedMap = new SourceMapConsumer(minifiedMap.toJSON());
|
||||
|
||||
var expectedMap = function (sources) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'bundle.min.js',
|
||||
sourceRoot: '..'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 1 },
|
||||
original: { line: 2, column: 2 },
|
||||
source: sources[0]
|
||||
});
|
||||
map.setSourceContent(sources[0], 'foo coffee');
|
||||
map.addMapping({
|
||||
generated: { line: 11, column: 11 },
|
||||
original: { line: 12, column: 12 },
|
||||
source: sources[1]
|
||||
});
|
||||
map.setSourceContent(sources[1], 'bar coffee');
|
||||
map.addMapping({
|
||||
generated: { line: 21, column: 21 },
|
||||
original: { line: 22, column: 22 },
|
||||
source: sources[2]
|
||||
});
|
||||
map.setSourceContent(sources[2], 'baz coffee');
|
||||
return map.toJSON();
|
||||
}
|
||||
|
||||
var actualMap = function (aSourceMapPath) {
|
||||
var map = SourceMapGenerator.fromSourceMap(minifiedMap);
|
||||
// Note that relying on `bundleMap.file` (which is simply 'bundle.js')
|
||||
// instead of supplying the second parameter wouldn't work here.
|
||||
map.applySourceMap(bundleMap, '../temp/bundle.js', aSourceMapPath);
|
||||
return map.toJSON();
|
||||
}
|
||||
|
||||
util.assertEqualMaps(assert, actualMap('../temp/temp_maps'), expectedMap([
|
||||
'coffee/foo.coffee',
|
||||
'/bar.coffee',
|
||||
'http://www.example.com/baz.coffee'
|
||||
]));
|
||||
|
||||
util.assertEqualMaps(assert, actualMap('/app/temp/temp_maps'), expectedMap([
|
||||
'/app/coffee/foo.coffee',
|
||||
'/bar.coffee',
|
||||
'http://www.example.com/baz.coffee'
|
||||
]));
|
||||
|
||||
util.assertEqualMaps(assert, actualMap('http://foo.org/app/temp/temp_maps'), expectedMap([
|
||||
'http://foo.org/app/coffee/foo.coffee',
|
||||
'http://foo.org/bar.coffee',
|
||||
'http://www.example.com/baz.coffee'
|
||||
]));
|
||||
|
||||
// If the third parameter is omitted or set to the current working
|
||||
// directory we get incorrect source paths:
|
||||
|
||||
util.assertEqualMaps(assert, actualMap(), expectedMap([
|
||||
'../coffee/foo.coffee',
|
||||
'/bar.coffee',
|
||||
'http://www.example.com/baz.coffee'
|
||||
]));
|
||||
|
||||
util.assertEqualMaps(assert, actualMap(''), expectedMap([
|
||||
'../coffee/foo.coffee',
|
||||
'/bar.coffee',
|
||||
'http://www.example.com/baz.coffee'
|
||||
]));
|
||||
|
||||
util.assertEqualMaps(assert, actualMap('.'), expectedMap([
|
||||
'../coffee/foo.coffee',
|
||||
'/bar.coffee',
|
||||
'http://www.example.com/baz.coffee'
|
||||
]));
|
||||
|
||||
util.assertEqualMaps(assert, actualMap('./'), expectedMap([
|
||||
'../coffee/foo.coffee',
|
||||
'/bar.coffee',
|
||||
'http://www.example.com/baz.coffee'
|
||||
]));
|
||||
};
|
||||
|
||||
exports['test applySourceMap name handling'] = function (assert, util) {
|
||||
// Imagine some CoffeeScript code being compiled into JavaScript and then
|
||||
// minified.
|
||||
|
||||
var assertName = function(coffeeName, jsName, expectedName) {
|
||||
var minifiedMap = new SourceMapGenerator({
|
||||
file: 'test.js.min'
|
||||
});
|
||||
minifiedMap.addMapping({
|
||||
generated: { line: 1, column: 4 },
|
||||
original: { line: 1, column: 4 },
|
||||
source: 'test.js',
|
||||
name: jsName
|
||||
});
|
||||
|
||||
var coffeeMap = new SourceMapGenerator({
|
||||
file: 'test.js'
|
||||
});
|
||||
coffeeMap.addMapping({
|
||||
generated: { line: 1, column: 4 },
|
||||
original: { line: 1, column: 0 },
|
||||
source: 'test.coffee',
|
||||
name: coffeeName
|
||||
});
|
||||
|
||||
minifiedMap.applySourceMap(new SourceMapConsumer(coffeeMap.toJSON()));
|
||||
|
||||
new SourceMapConsumer(minifiedMap.toJSON()).eachMapping(function(mapping) {
|
||||
assert.equal(mapping.name, expectedName);
|
||||
});
|
||||
};
|
||||
|
||||
// `foo = 1` -> `var foo = 1;` -> `var a=1`
|
||||
// CoffeeScript doesn’t rename variables, so there’s no need for it to
|
||||
// provide names in its source maps. Minifiers do rename variables and
|
||||
// therefore do provide names in their source maps. So that name should be
|
||||
// retained if the original map lacks names.
|
||||
assertName(null, 'foo', 'foo');
|
||||
|
||||
// `foo = 1` -> `var coffee$foo = 1;` -> `var a=1`
|
||||
// Imagine that CoffeeScript prefixed all variables with `coffee$`. Even
|
||||
// though the minifier then also provides a name, the original name is
|
||||
// what corresponds to the source.
|
||||
assertName('foo', 'coffee$foo', 'foo');
|
||||
|
||||
// `foo = 1` -> `var coffee$foo = 1;` -> `var coffee$foo=1`
|
||||
// Minifiers can turn off variable mangling. Then there’s no need to
|
||||
// provide names in the source map, but the names from the original map are
|
||||
// still needed.
|
||||
assertName('foo', null, 'foo');
|
||||
|
||||
// `foo = 1` -> `var foo = 1;` -> `var foo=1`
|
||||
// No renaming at all.
|
||||
assertName(null, null, null);
|
||||
};
|
||||
|
||||
exports['test sorting with duplicate generated mappings'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'test.js'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 3, column: 0 },
|
||||
original: { line: 2, column: 0 },
|
||||
source: 'a.js'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 2, column: 0 }
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 2, column: 0 }
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 0 },
|
||||
original: { line: 1, column: 0 },
|
||||
source: 'a.js'
|
||||
});
|
||||
|
||||
util.assertEqualMaps(assert, map.toJSON(), {
|
||||
version: 3,
|
||||
file: 'test.js',
|
||||
sources: ['a.js'],
|
||||
names: [],
|
||||
mappings: 'AAAA;A;AACA'
|
||||
});
|
||||
};
|
||||
|
||||
exports['test ignore duplicate mappings.'] = function (assert, util) {
|
||||
var init = { file: 'min.js', sourceRoot: '/the/root' };
|
||||
var map1, map2;
|
||||
|
||||
// null original source location
|
||||
var nullMapping1 = {
|
||||
generated: { line: 1, column: 0 }
|
||||
};
|
||||
var nullMapping2 = {
|
||||
generated: { line: 2, column: 2 }
|
||||
};
|
||||
|
||||
map1 = new SourceMapGenerator(init);
|
||||
map2 = new SourceMapGenerator(init);
|
||||
|
||||
map1.addMapping(nullMapping1);
|
||||
map1.addMapping(nullMapping1);
|
||||
|
||||
map2.addMapping(nullMapping1);
|
||||
|
||||
util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON());
|
||||
|
||||
map1.addMapping(nullMapping2);
|
||||
map1.addMapping(nullMapping1);
|
||||
|
||||
map2.addMapping(nullMapping2);
|
||||
|
||||
util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON());
|
||||
|
||||
// original source location
|
||||
var srcMapping1 = {
|
||||
generated: { line: 1, column: 0 },
|
||||
original: { line: 11, column: 0 },
|
||||
source: 'srcMapping1.js'
|
||||
};
|
||||
var srcMapping2 = {
|
||||
generated: { line: 2, column: 2 },
|
||||
original: { line: 11, column: 0 },
|
||||
source: 'srcMapping2.js'
|
||||
};
|
||||
|
||||
map1 = new SourceMapGenerator(init);
|
||||
map2 = new SourceMapGenerator(init);
|
||||
|
||||
map1.addMapping(srcMapping1);
|
||||
map1.addMapping(srcMapping1);
|
||||
|
||||
map2.addMapping(srcMapping1);
|
||||
|
||||
util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON());
|
||||
|
||||
map1.addMapping(srcMapping2);
|
||||
map1.addMapping(srcMapping1);
|
||||
|
||||
map2.addMapping(srcMapping2);
|
||||
|
||||
util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON());
|
||||
|
||||
// full original source and name information
|
||||
var fullMapping1 = {
|
||||
generated: { line: 1, column: 0 },
|
||||
original: { line: 11, column: 0 },
|
||||
source: 'fullMapping1.js',
|
||||
name: 'fullMapping1'
|
||||
};
|
||||
var fullMapping2 = {
|
||||
generated: { line: 2, column: 2 },
|
||||
original: { line: 11, column: 0 },
|
||||
source: 'fullMapping2.js',
|
||||
name: 'fullMapping2'
|
||||
};
|
||||
|
||||
map1 = new SourceMapGenerator(init);
|
||||
map2 = new SourceMapGenerator(init);
|
||||
|
||||
map1.addMapping(fullMapping1);
|
||||
map1.addMapping(fullMapping1);
|
||||
|
||||
map2.addMapping(fullMapping1);
|
||||
|
||||
util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON());
|
||||
|
||||
map1.addMapping(fullMapping2);
|
||||
map1.addMapping(fullMapping1);
|
||||
|
||||
map2.addMapping(fullMapping2);
|
||||
|
||||
util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON());
|
||||
};
|
||||
|
||||
exports['test github issue #72, check for duplicate names or sources'] = function (assert, util) {
|
||||
var map = new SourceMapGenerator({
|
||||
file: 'test.js'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 1, column: 1 },
|
||||
original: { line: 2, column: 2 },
|
||||
source: 'a.js',
|
||||
name: 'foo'
|
||||
});
|
||||
map.addMapping({
|
||||
generated: { line: 3, column: 3 },
|
||||
original: { line: 4, column: 4 },
|
||||
source: 'a.js',
|
||||
name: 'foo'
|
||||
});
|
||||
util.assertEqualMaps(assert, map.toJSON(), {
|
||||
version: 3,
|
||||
file: 'test.js',
|
||||
sources: ['a.js'],
|
||||
names: ['foo'],
|
||||
mappings: 'CACEA;;GAEEA'
|
||||
});
|
||||
};
|
||||
|
||||
exports['test setting sourcesContent to null when already null'] = function (assert, util) {
|
||||
var smg = new SourceMapGenerator({ file: "foo.js" });
|
||||
assert.doesNotThrow(function() {
|
||||
smg.setSourceContent("bar.js", null);
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
612
node_modules/escodegen/node_modules/source-map/test/source-map/test-source-node.js
generated
vendored
Normal file
612
node_modules/escodegen/node_modules/source-map/test/source-map/test-source-node.js
generated
vendored
Normal file
@@ -0,0 +1,612 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var SourceMapGenerator = require('../../lib/source-map/source-map-generator').SourceMapGenerator;
|
||||
var SourceMapConsumer = require('../../lib/source-map/source-map-consumer').SourceMapConsumer;
|
||||
var SourceNode = require('../../lib/source-map/source-node').SourceNode;
|
||||
|
||||
function forEachNewline(fn) {
|
||||
return function (assert, util) {
|
||||
['\n', '\r\n'].forEach(fn.bind(null, assert, util));
|
||||
}
|
||||
}
|
||||
|
||||
exports['test .add()'] = function (assert, util) {
|
||||
var node = new SourceNode(null, null, null);
|
||||
|
||||
// Adding a string works.
|
||||
node.add('function noop() {}');
|
||||
|
||||
// Adding another source node works.
|
||||
node.add(new SourceNode(null, null, null));
|
||||
|
||||
// Adding an array works.
|
||||
node.add(['function foo() {',
|
||||
new SourceNode(null, null, null,
|
||||
'return 10;'),
|
||||
'}']);
|
||||
|
||||
// Adding other stuff doesn't.
|
||||
assert.throws(function () {
|
||||
node.add({});
|
||||
});
|
||||
assert.throws(function () {
|
||||
node.add(function () {});
|
||||
});
|
||||
};
|
||||
|
||||
exports['test .prepend()'] = function (assert, util) {
|
||||
var node = new SourceNode(null, null, null);
|
||||
|
||||
// Prepending a string works.
|
||||
node.prepend('function noop() {}');
|
||||
assert.equal(node.children[0], 'function noop() {}');
|
||||
assert.equal(node.children.length, 1);
|
||||
|
||||
// Prepending another source node works.
|
||||
node.prepend(new SourceNode(null, null, null));
|
||||
assert.equal(node.children[0], '');
|
||||
assert.equal(node.children[1], 'function noop() {}');
|
||||
assert.equal(node.children.length, 2);
|
||||
|
||||
// Prepending an array works.
|
||||
node.prepend(['function foo() {',
|
||||
new SourceNode(null, null, null,
|
||||
'return 10;'),
|
||||
'}']);
|
||||
assert.equal(node.children[0], 'function foo() {');
|
||||
assert.equal(node.children[1], 'return 10;');
|
||||
assert.equal(node.children[2], '}');
|
||||
assert.equal(node.children[3], '');
|
||||
assert.equal(node.children[4], 'function noop() {}');
|
||||
assert.equal(node.children.length, 5);
|
||||
|
||||
// Prepending other stuff doesn't.
|
||||
assert.throws(function () {
|
||||
node.prepend({});
|
||||
});
|
||||
assert.throws(function () {
|
||||
node.prepend(function () {});
|
||||
});
|
||||
};
|
||||
|
||||
exports['test .toString()'] = function (assert, util) {
|
||||
assert.equal((new SourceNode(null, null, null,
|
||||
['function foo() {',
|
||||
new SourceNode(null, null, null, 'return 10;'),
|
||||
'}'])).toString(),
|
||||
'function foo() {return 10;}');
|
||||
};
|
||||
|
||||
exports['test .join()'] = function (assert, util) {
|
||||
assert.equal((new SourceNode(null, null, null,
|
||||
['a', 'b', 'c', 'd'])).join(', ').toString(),
|
||||
'a, b, c, d');
|
||||
};
|
||||
|
||||
exports['test .walk()'] = function (assert, util) {
|
||||
var node = new SourceNode(null, null, null,
|
||||
['(function () {\n',
|
||||
' ', new SourceNode(1, 0, 'a.js', ['someCall()']), ';\n',
|
||||
' ', new SourceNode(2, 0, 'b.js', ['if (foo) bar()']), ';\n',
|
||||
'}());']);
|
||||
var expected = [
|
||||
{ str: '(function () {\n', source: null, line: null, column: null },
|
||||
{ str: ' ', source: null, line: null, column: null },
|
||||
{ str: 'someCall()', source: 'a.js', line: 1, column: 0 },
|
||||
{ str: ';\n', source: null, line: null, column: null },
|
||||
{ str: ' ', source: null, line: null, column: null },
|
||||
{ str: 'if (foo) bar()', source: 'b.js', line: 2, column: 0 },
|
||||
{ str: ';\n', source: null, line: null, column: null },
|
||||
{ str: '}());', source: null, line: null, column: null },
|
||||
];
|
||||
var i = 0;
|
||||
node.walk(function (chunk, loc) {
|
||||
assert.equal(expected[i].str, chunk);
|
||||
assert.equal(expected[i].source, loc.source);
|
||||
assert.equal(expected[i].line, loc.line);
|
||||
assert.equal(expected[i].column, loc.column);
|
||||
i++;
|
||||
});
|
||||
};
|
||||
|
||||
exports['test .replaceRight'] = function (assert, util) {
|
||||
var node;
|
||||
|
||||
// Not nested
|
||||
node = new SourceNode(null, null, null, 'hello world');
|
||||
node.replaceRight(/world/, 'universe');
|
||||
assert.equal(node.toString(), 'hello universe');
|
||||
|
||||
// Nested
|
||||
node = new SourceNode(null, null, null,
|
||||
[new SourceNode(null, null, null, 'hey sexy mama, '),
|
||||
new SourceNode(null, null, null, 'want to kill all humans?')]);
|
||||
node.replaceRight(/kill all humans/, 'watch Futurama');
|
||||
assert.equal(node.toString(), 'hey sexy mama, want to watch Futurama?');
|
||||
};
|
||||
|
||||
exports['test .toStringWithSourceMap()'] = forEachNewline(function (assert, util, nl) {
|
||||
var node = new SourceNode(null, null, null,
|
||||
['(function () {' + nl,
|
||||
' ',
|
||||
new SourceNode(1, 0, 'a.js', 'someCall', 'originalCall'),
|
||||
new SourceNode(1, 8, 'a.js', '()'),
|
||||
';' + nl,
|
||||
' ', new SourceNode(2, 0, 'b.js', ['if (foo) bar()']), ';' + nl,
|
||||
'}());']);
|
||||
var result = node.toStringWithSourceMap({
|
||||
file: 'foo.js'
|
||||
});
|
||||
|
||||
assert.equal(result.code, [
|
||||
'(function () {',
|
||||
' someCall();',
|
||||
' if (foo) bar();',
|
||||
'}());'
|
||||
].join(nl));
|
||||
|
||||
var map = result.map;
|
||||
var mapWithoutOptions = node.toStringWithSourceMap().map;
|
||||
|
||||
assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator');
|
||||
assert.ok(mapWithoutOptions instanceof SourceMapGenerator, 'mapWithoutOptions instanceof SourceMapGenerator');
|
||||
assert.ok(!('file' in mapWithoutOptions));
|
||||
mapWithoutOptions._file = 'foo.js';
|
||||
util.assertEqualMaps(assert, map.toJSON(), mapWithoutOptions.toJSON());
|
||||
|
||||
map = new SourceMapConsumer(map.toString());
|
||||
|
||||
var actual;
|
||||
|
||||
actual = map.originalPositionFor({
|
||||
line: 1,
|
||||
column: 4
|
||||
});
|
||||
assert.equal(actual.source, null);
|
||||
assert.equal(actual.line, null);
|
||||
assert.equal(actual.column, null);
|
||||
|
||||
actual = map.originalPositionFor({
|
||||
line: 2,
|
||||
column: 2
|
||||
});
|
||||
assert.equal(actual.source, 'a.js');
|
||||
assert.equal(actual.line, 1);
|
||||
assert.equal(actual.column, 0);
|
||||
assert.equal(actual.name, 'originalCall');
|
||||
|
||||
actual = map.originalPositionFor({
|
||||
line: 3,
|
||||
column: 2
|
||||
});
|
||||
assert.equal(actual.source, 'b.js');
|
||||
assert.equal(actual.line, 2);
|
||||
assert.equal(actual.column, 0);
|
||||
|
||||
actual = map.originalPositionFor({
|
||||
line: 3,
|
||||
column: 16
|
||||
});
|
||||
assert.equal(actual.source, null);
|
||||
assert.equal(actual.line, null);
|
||||
assert.equal(actual.column, null);
|
||||
|
||||
actual = map.originalPositionFor({
|
||||
line: 4,
|
||||
column: 2
|
||||
});
|
||||
assert.equal(actual.source, null);
|
||||
assert.equal(actual.line, null);
|
||||
assert.equal(actual.column, null);
|
||||
});
|
||||
|
||||
exports['test .fromStringWithSourceMap()'] = forEachNewline(function (assert, util, nl) {
|
||||
var testCode = util.testGeneratedCode.replace(/\n/g, nl);
|
||||
var node = SourceNode.fromStringWithSourceMap(
|
||||
testCode,
|
||||
new SourceMapConsumer(util.testMap));
|
||||
|
||||
var result = node.toStringWithSourceMap({
|
||||
file: 'min.js'
|
||||
});
|
||||
var map = result.map;
|
||||
var code = result.code;
|
||||
|
||||
assert.equal(code, testCode);
|
||||
assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator');
|
||||
map = map.toJSON();
|
||||
assert.equal(map.version, util.testMap.version);
|
||||
assert.equal(map.file, util.testMap.file);
|
||||
assert.equal(map.mappings, util.testMap.mappings);
|
||||
});
|
||||
|
||||
exports['test .fromStringWithSourceMap() empty map'] = forEachNewline(function (assert, util, nl) {
|
||||
var node = SourceNode.fromStringWithSourceMap(
|
||||
util.testGeneratedCode.replace(/\n/g, nl),
|
||||
new SourceMapConsumer(util.emptyMap));
|
||||
var result = node.toStringWithSourceMap({
|
||||
file: 'min.js'
|
||||
});
|
||||
var map = result.map;
|
||||
var code = result.code;
|
||||
|
||||
assert.equal(code, util.testGeneratedCode.replace(/\n/g, nl));
|
||||
assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator');
|
||||
map = map.toJSON();
|
||||
assert.equal(map.version, util.emptyMap.version);
|
||||
assert.equal(map.file, util.emptyMap.file);
|
||||
assert.equal(map.mappings.length, util.emptyMap.mappings.length);
|
||||
assert.equal(map.mappings, util.emptyMap.mappings);
|
||||
});
|
||||
|
||||
exports['test .fromStringWithSourceMap() complex version'] = forEachNewline(function (assert, util, nl) {
|
||||
var input = new SourceNode(null, null, null, [
|
||||
"(function() {" + nl,
|
||||
" var Test = {};" + nl,
|
||||
" ", new SourceNode(1, 0, "a.js", "Test.A = { value: 1234 };" + nl),
|
||||
" ", new SourceNode(2, 0, "a.js", "Test.A.x = 'xyz';"), nl,
|
||||
"}());" + nl,
|
||||
"/* Generated Source */"]);
|
||||
input = input.toStringWithSourceMap({
|
||||
file: 'foo.js'
|
||||
});
|
||||
|
||||
var node = SourceNode.fromStringWithSourceMap(
|
||||
input.code,
|
||||
new SourceMapConsumer(input.map.toString()));
|
||||
|
||||
var result = node.toStringWithSourceMap({
|
||||
file: 'foo.js'
|
||||
});
|
||||
var map = result.map;
|
||||
var code = result.code;
|
||||
|
||||
assert.equal(code, input.code);
|
||||
assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator');
|
||||
map = map.toJSON();
|
||||
var inputMap = input.map.toJSON();
|
||||
util.assertEqualMaps(assert, map, inputMap);
|
||||
});
|
||||
|
||||
exports['test .fromStringWithSourceMap() third argument'] = function (assert, util) {
|
||||
// Assume the following directory structure:
|
||||
//
|
||||
// http://foo.org/
|
||||
// bar.coffee
|
||||
// app/
|
||||
// coffee/
|
||||
// foo.coffee
|
||||
// coffeeBundle.js # Made from {foo,bar,baz}.coffee
|
||||
// maps/
|
||||
// coffeeBundle.js.map
|
||||
// js/
|
||||
// foo.js
|
||||
// public/
|
||||
// app.js # Made from {foo,coffeeBundle}.js
|
||||
// app.js.map
|
||||
//
|
||||
// http://www.example.com/
|
||||
// baz.coffee
|
||||
|
||||
var coffeeBundle = new SourceNode(1, 0, 'foo.coffee', 'foo(coffee);\n');
|
||||
coffeeBundle.setSourceContent('foo.coffee', 'foo coffee');
|
||||
coffeeBundle.add(new SourceNode(2, 0, '/bar.coffee', 'bar(coffee);\n'));
|
||||
coffeeBundle.add(new SourceNode(3, 0, 'http://www.example.com/baz.coffee', 'baz(coffee);'));
|
||||
coffeeBundle = coffeeBundle.toStringWithSourceMap({
|
||||
file: 'foo.js',
|
||||
sourceRoot: '..'
|
||||
});
|
||||
|
||||
var foo = new SourceNode(1, 0, 'foo.js', 'foo(js);');
|
||||
|
||||
var test = function(relativePath, expectedSources) {
|
||||
var app = new SourceNode();
|
||||
app.add(SourceNode.fromStringWithSourceMap(
|
||||
coffeeBundle.code,
|
||||
new SourceMapConsumer(coffeeBundle.map.toString()),
|
||||
relativePath));
|
||||
app.add(foo);
|
||||
var i = 0;
|
||||
app.walk(function (chunk, loc) {
|
||||
assert.equal(loc.source, expectedSources[i]);
|
||||
i++;
|
||||
});
|
||||
app.walkSourceContents(function (sourceFile, sourceContent) {
|
||||
assert.equal(sourceFile, expectedSources[0]);
|
||||
assert.equal(sourceContent, 'foo coffee');
|
||||
})
|
||||
};
|
||||
|
||||
test('../coffee/maps', [
|
||||
'../coffee/foo.coffee',
|
||||
'/bar.coffee',
|
||||
'http://www.example.com/baz.coffee',
|
||||
'foo.js'
|
||||
]);
|
||||
|
||||
// If the third parameter is omitted or set to the current working
|
||||
// directory we get incorrect source paths:
|
||||
|
||||
test(undefined, [
|
||||
'../foo.coffee',
|
||||
'/bar.coffee',
|
||||
'http://www.example.com/baz.coffee',
|
||||
'foo.js'
|
||||
]);
|
||||
|
||||
test('', [
|
||||
'../foo.coffee',
|
||||
'/bar.coffee',
|
||||
'http://www.example.com/baz.coffee',
|
||||
'foo.js'
|
||||
]);
|
||||
|
||||
test('.', [
|
||||
'../foo.coffee',
|
||||
'/bar.coffee',
|
||||
'http://www.example.com/baz.coffee',
|
||||
'foo.js'
|
||||
]);
|
||||
|
||||
test('./', [
|
||||
'../foo.coffee',
|
||||
'/bar.coffee',
|
||||
'http://www.example.com/baz.coffee',
|
||||
'foo.js'
|
||||
]);
|
||||
};
|
||||
|
||||
exports['test .toStringWithSourceMap() merging duplicate mappings'] = forEachNewline(function (assert, util, nl) {
|
||||
var input = new SourceNode(null, null, null, [
|
||||
new SourceNode(1, 0, "a.js", "(function"),
|
||||
new SourceNode(1, 0, "a.js", "() {" + nl),
|
||||
" ",
|
||||
new SourceNode(1, 0, "a.js", "var Test = "),
|
||||
new SourceNode(1, 0, "b.js", "{};" + nl),
|
||||
new SourceNode(2, 0, "b.js", "Test"),
|
||||
new SourceNode(2, 0, "b.js", ".A", "A"),
|
||||
new SourceNode(2, 20, "b.js", " = { value: ", "A"),
|
||||
"1234",
|
||||
new SourceNode(2, 40, "b.js", " };" + nl, "A"),
|
||||
"}());" + nl,
|
||||
"/* Generated Source */"
|
||||
]);
|
||||
input = input.toStringWithSourceMap({
|
||||
file: 'foo.js'
|
||||
});
|
||||
|
||||
assert.equal(input.code, [
|
||||
"(function() {",
|
||||
" var Test = {};",
|
||||
"Test.A = { value: 1234 };",
|
||||
"}());",
|
||||
"/* Generated Source */"
|
||||
].join(nl))
|
||||
|
||||
var correctMap = new SourceMapGenerator({
|
||||
file: 'foo.js'
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 1, column: 0 },
|
||||
source: 'a.js',
|
||||
original: { line: 1, column: 0 }
|
||||
});
|
||||
// Here is no need for a empty mapping,
|
||||
// because mappings ends at eol
|
||||
correctMap.addMapping({
|
||||
generated: { line: 2, column: 2 },
|
||||
source: 'a.js',
|
||||
original: { line: 1, column: 0 }
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 2, column: 13 },
|
||||
source: 'b.js',
|
||||
original: { line: 1, column: 0 }
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 3, column: 0 },
|
||||
source: 'b.js',
|
||||
original: { line: 2, column: 0 }
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 3, column: 4 },
|
||||
source: 'b.js',
|
||||
name: 'A',
|
||||
original: { line: 2, column: 0 }
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 3, column: 6 },
|
||||
source: 'b.js',
|
||||
name: 'A',
|
||||
original: { line: 2, column: 20 }
|
||||
});
|
||||
// This empty mapping is required,
|
||||
// because there is a hole in the middle of the line
|
||||
correctMap.addMapping({
|
||||
generated: { line: 3, column: 18 }
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 3, column: 22 },
|
||||
source: 'b.js',
|
||||
name: 'A',
|
||||
original: { line: 2, column: 40 }
|
||||
});
|
||||
// Here is no need for a empty mapping,
|
||||
// because mappings ends at eol
|
||||
|
||||
var inputMap = input.map.toJSON();
|
||||
correctMap = correctMap.toJSON();
|
||||
util.assertEqualMaps(assert, inputMap, correctMap);
|
||||
});
|
||||
|
||||
exports['test .toStringWithSourceMap() multi-line SourceNodes'] = forEachNewline(function (assert, util, nl) {
|
||||
var input = new SourceNode(null, null, null, [
|
||||
new SourceNode(1, 0, "a.js", "(function() {" + nl + "var nextLine = 1;" + nl + "anotherLine();" + nl),
|
||||
new SourceNode(2, 2, "b.js", "Test.call(this, 123);" + nl),
|
||||
new SourceNode(2, 2, "b.js", "this['stuff'] = 'v';" + nl),
|
||||
new SourceNode(2, 2, "b.js", "anotherLine();" + nl),
|
||||
"/*" + nl + "Generated" + nl + "Source" + nl + "*/" + nl,
|
||||
new SourceNode(3, 4, "c.js", "anotherLine();" + nl),
|
||||
"/*" + nl + "Generated" + nl + "Source" + nl + "*/"
|
||||
]);
|
||||
input = input.toStringWithSourceMap({
|
||||
file: 'foo.js'
|
||||
});
|
||||
|
||||
assert.equal(input.code, [
|
||||
"(function() {",
|
||||
"var nextLine = 1;",
|
||||
"anotherLine();",
|
||||
"Test.call(this, 123);",
|
||||
"this['stuff'] = 'v';",
|
||||
"anotherLine();",
|
||||
"/*",
|
||||
"Generated",
|
||||
"Source",
|
||||
"*/",
|
||||
"anotherLine();",
|
||||
"/*",
|
||||
"Generated",
|
||||
"Source",
|
||||
"*/"
|
||||
].join(nl));
|
||||
|
||||
var correctMap = new SourceMapGenerator({
|
||||
file: 'foo.js'
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 1, column: 0 },
|
||||
source: 'a.js',
|
||||
original: { line: 1, column: 0 }
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 2, column: 0 },
|
||||
source: 'a.js',
|
||||
original: { line: 1, column: 0 }
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 3, column: 0 },
|
||||
source: 'a.js',
|
||||
original: { line: 1, column: 0 }
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 4, column: 0 },
|
||||
source: 'b.js',
|
||||
original: { line: 2, column: 2 }
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 5, column: 0 },
|
||||
source: 'b.js',
|
||||
original: { line: 2, column: 2 }
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 6, column: 0 },
|
||||
source: 'b.js',
|
||||
original: { line: 2, column: 2 }
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 11, column: 0 },
|
||||
source: 'c.js',
|
||||
original: { line: 3, column: 4 }
|
||||
});
|
||||
|
||||
var inputMap = input.map.toJSON();
|
||||
correctMap = correctMap.toJSON();
|
||||
util.assertEqualMaps(assert, inputMap, correctMap);
|
||||
});
|
||||
|
||||
exports['test .toStringWithSourceMap() with empty string'] = function (assert, util) {
|
||||
var node = new SourceNode(1, 0, 'empty.js', '');
|
||||
var result = node.toStringWithSourceMap();
|
||||
assert.equal(result.code, '');
|
||||
};
|
||||
|
||||
exports['test .toStringWithSourceMap() with consecutive newlines'] = forEachNewline(function (assert, util, nl) {
|
||||
var input = new SourceNode(null, null, null, [
|
||||
"/***/" + nl + nl,
|
||||
new SourceNode(1, 0, "a.js", "'use strict';" + nl),
|
||||
new SourceNode(2, 0, "a.js", "a();"),
|
||||
]);
|
||||
input = input.toStringWithSourceMap({
|
||||
file: 'foo.js'
|
||||
});
|
||||
|
||||
assert.equal(input.code, [
|
||||
"/***/",
|
||||
"",
|
||||
"'use strict';",
|
||||
"a();",
|
||||
].join(nl));
|
||||
|
||||
var correctMap = new SourceMapGenerator({
|
||||
file: 'foo.js'
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 3, column: 0 },
|
||||
source: 'a.js',
|
||||
original: { line: 1, column: 0 }
|
||||
});
|
||||
correctMap.addMapping({
|
||||
generated: { line: 4, column: 0 },
|
||||
source: 'a.js',
|
||||
original: { line: 2, column: 0 }
|
||||
});
|
||||
|
||||
var inputMap = input.map.toJSON();
|
||||
correctMap = correctMap.toJSON();
|
||||
util.assertEqualMaps(assert, inputMap, correctMap);
|
||||
});
|
||||
|
||||
exports['test setSourceContent with toStringWithSourceMap'] = function (assert, util) {
|
||||
var aNode = new SourceNode(1, 1, 'a.js', 'a');
|
||||
aNode.setSourceContent('a.js', 'someContent');
|
||||
var node = new SourceNode(null, null, null,
|
||||
['(function () {\n',
|
||||
' ', aNode,
|
||||
' ', new SourceNode(1, 1, 'b.js', 'b'),
|
||||
'}());']);
|
||||
node.setSourceContent('b.js', 'otherContent');
|
||||
var map = node.toStringWithSourceMap({
|
||||
file: 'foo.js'
|
||||
}).map;
|
||||
|
||||
assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator');
|
||||
map = new SourceMapConsumer(map.toString());
|
||||
|
||||
assert.equal(map.sources.length, 2);
|
||||
assert.equal(map.sources[0], 'a.js');
|
||||
assert.equal(map.sources[1], 'b.js');
|
||||
assert.equal(map.sourcesContent.length, 2);
|
||||
assert.equal(map.sourcesContent[0], 'someContent');
|
||||
assert.equal(map.sourcesContent[1], 'otherContent');
|
||||
};
|
||||
|
||||
exports['test walkSourceContents'] = function (assert, util) {
|
||||
var aNode = new SourceNode(1, 1, 'a.js', 'a');
|
||||
aNode.setSourceContent('a.js', 'someContent');
|
||||
var node = new SourceNode(null, null, null,
|
||||
['(function () {\n',
|
||||
' ', aNode,
|
||||
' ', new SourceNode(1, 1, 'b.js', 'b'),
|
||||
'}());']);
|
||||
node.setSourceContent('b.js', 'otherContent');
|
||||
var results = [];
|
||||
node.walkSourceContents(function (sourceFile, sourceContent) {
|
||||
results.push([sourceFile, sourceContent]);
|
||||
});
|
||||
assert.equal(results.length, 2);
|
||||
assert.equal(results[0][0], 'a.js');
|
||||
assert.equal(results[0][1], 'someContent');
|
||||
assert.equal(results[1][0], 'b.js');
|
||||
assert.equal(results[1][1], 'otherContent');
|
||||
};
|
||||
});
|
||||
216
node_modules/escodegen/node_modules/source-map/test/source-map/test-util.js
generated
vendored
Normal file
216
node_modules/escodegen/node_modules/source-map/test/source-map/test-util.js
generated
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2014 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var libUtil = require('../../lib/source-map/util');
|
||||
|
||||
exports['test urls'] = function (assert, util) {
|
||||
var assertUrl = function (url) {
|
||||
assert.equal(url, libUtil.urlGenerate(libUtil.urlParse(url)));
|
||||
};
|
||||
assertUrl('http://');
|
||||
assertUrl('http://www.example.com');
|
||||
assertUrl('http://user:pass@www.example.com');
|
||||
assertUrl('http://www.example.com:80');
|
||||
assertUrl('http://www.example.com/');
|
||||
assertUrl('http://www.example.com/foo/bar');
|
||||
assertUrl('http://www.example.com/foo/bar/');
|
||||
assertUrl('http://user:pass@www.example.com:80/foo/bar/');
|
||||
|
||||
assertUrl('//');
|
||||
assertUrl('//www.example.com');
|
||||
assertUrl('file:///www.example.com');
|
||||
|
||||
assert.equal(libUtil.urlParse(''), null);
|
||||
assert.equal(libUtil.urlParse('.'), null);
|
||||
assert.equal(libUtil.urlParse('..'), null);
|
||||
assert.equal(libUtil.urlParse('a'), null);
|
||||
assert.equal(libUtil.urlParse('a/b'), null);
|
||||
assert.equal(libUtil.urlParse('a//b'), null);
|
||||
assert.equal(libUtil.urlParse('/a'), null);
|
||||
assert.equal(libUtil.urlParse('data:foo,bar'), null);
|
||||
};
|
||||
|
||||
exports['test normalize()'] = function (assert, util) {
|
||||
assert.equal(libUtil.normalize('/..'), '/');
|
||||
assert.equal(libUtil.normalize('/../'), '/');
|
||||
assert.equal(libUtil.normalize('/../../../..'), '/');
|
||||
assert.equal(libUtil.normalize('/../../../../a/b/c'), '/a/b/c');
|
||||
assert.equal(libUtil.normalize('/a/b/c/../../../d/../../e'), '/e');
|
||||
|
||||
assert.equal(libUtil.normalize('..'), '..');
|
||||
assert.equal(libUtil.normalize('../'), '../');
|
||||
assert.equal(libUtil.normalize('../../a/'), '../../a/');
|
||||
assert.equal(libUtil.normalize('a/..'), '.');
|
||||
assert.equal(libUtil.normalize('a/../../..'), '../..');
|
||||
|
||||
assert.equal(libUtil.normalize('/.'), '/');
|
||||
assert.equal(libUtil.normalize('/./'), '/');
|
||||
assert.equal(libUtil.normalize('/./././.'), '/');
|
||||
assert.equal(libUtil.normalize('/././././a/b/c'), '/a/b/c');
|
||||
assert.equal(libUtil.normalize('/a/b/c/./././d/././e'), '/a/b/c/d/e');
|
||||
|
||||
assert.equal(libUtil.normalize(''), '.');
|
||||
assert.equal(libUtil.normalize('.'), '.');
|
||||
assert.equal(libUtil.normalize('./'), '.');
|
||||
assert.equal(libUtil.normalize('././a'), 'a');
|
||||
assert.equal(libUtil.normalize('a/./'), 'a/');
|
||||
assert.equal(libUtil.normalize('a/././.'), 'a');
|
||||
|
||||
assert.equal(libUtil.normalize('/a/b//c////d/////'), '/a/b/c/d/');
|
||||
assert.equal(libUtil.normalize('///a/b//c////d/////'), '///a/b/c/d/');
|
||||
assert.equal(libUtil.normalize('a/b//c////d'), 'a/b/c/d');
|
||||
|
||||
assert.equal(libUtil.normalize('.///.././../a/b//./..'), '../../a')
|
||||
|
||||
assert.equal(libUtil.normalize('http://www.example.com'), 'http://www.example.com');
|
||||
assert.equal(libUtil.normalize('http://www.example.com/'), 'http://www.example.com/');
|
||||
assert.equal(libUtil.normalize('http://www.example.com/./..//a/b/c/.././d//'), 'http://www.example.com/a/b/d/');
|
||||
};
|
||||
|
||||
exports['test join()'] = function (assert, util) {
|
||||
assert.equal(libUtil.join('a', 'b'), 'a/b');
|
||||
assert.equal(libUtil.join('a/', 'b'), 'a/b');
|
||||
assert.equal(libUtil.join('a//', 'b'), 'a/b');
|
||||
assert.equal(libUtil.join('a', 'b/'), 'a/b/');
|
||||
assert.equal(libUtil.join('a', 'b//'), 'a/b/');
|
||||
assert.equal(libUtil.join('a/', '/b'), '/b');
|
||||
assert.equal(libUtil.join('a//', '//b'), '//b');
|
||||
|
||||
assert.equal(libUtil.join('a', '..'), '.');
|
||||
assert.equal(libUtil.join('a', '../b'), 'b');
|
||||
assert.equal(libUtil.join('a/b', '../c'), 'a/c');
|
||||
|
||||
assert.equal(libUtil.join('a', '.'), 'a');
|
||||
assert.equal(libUtil.join('a', './b'), 'a/b');
|
||||
assert.equal(libUtil.join('a/b', './c'), 'a/b/c');
|
||||
|
||||
assert.equal(libUtil.join('a', 'http://www.example.com'), 'http://www.example.com');
|
||||
assert.equal(libUtil.join('a', 'data:foo,bar'), 'data:foo,bar');
|
||||
|
||||
|
||||
assert.equal(libUtil.join('', 'b'), 'b');
|
||||
assert.equal(libUtil.join('.', 'b'), 'b');
|
||||
assert.equal(libUtil.join('', 'b/'), 'b/');
|
||||
assert.equal(libUtil.join('.', 'b/'), 'b/');
|
||||
assert.equal(libUtil.join('', 'b//'), 'b/');
|
||||
assert.equal(libUtil.join('.', 'b//'), 'b/');
|
||||
|
||||
assert.equal(libUtil.join('', '..'), '..');
|
||||
assert.equal(libUtil.join('.', '..'), '..');
|
||||
assert.equal(libUtil.join('', '../b'), '../b');
|
||||
assert.equal(libUtil.join('.', '../b'), '../b');
|
||||
|
||||
assert.equal(libUtil.join('', '.'), '.');
|
||||
assert.equal(libUtil.join('.', '.'), '.');
|
||||
assert.equal(libUtil.join('', './b'), 'b');
|
||||
assert.equal(libUtil.join('.', './b'), 'b');
|
||||
|
||||
assert.equal(libUtil.join('', 'http://www.example.com'), 'http://www.example.com');
|
||||
assert.equal(libUtil.join('.', 'http://www.example.com'), 'http://www.example.com');
|
||||
assert.equal(libUtil.join('', 'data:foo,bar'), 'data:foo,bar');
|
||||
assert.equal(libUtil.join('.', 'data:foo,bar'), 'data:foo,bar');
|
||||
|
||||
|
||||
assert.equal(libUtil.join('..', 'b'), '../b');
|
||||
assert.equal(libUtil.join('..', 'b/'), '../b/');
|
||||
assert.equal(libUtil.join('..', 'b//'), '../b/');
|
||||
|
||||
assert.equal(libUtil.join('..', '..'), '../..');
|
||||
assert.equal(libUtil.join('..', '../b'), '../../b');
|
||||
|
||||
assert.equal(libUtil.join('..', '.'), '..');
|
||||
assert.equal(libUtil.join('..', './b'), '../b');
|
||||
|
||||
assert.equal(libUtil.join('..', 'http://www.example.com'), 'http://www.example.com');
|
||||
assert.equal(libUtil.join('..', 'data:foo,bar'), 'data:foo,bar');
|
||||
|
||||
|
||||
assert.equal(libUtil.join('a', ''), 'a');
|
||||
assert.equal(libUtil.join('a', '.'), 'a');
|
||||
assert.equal(libUtil.join('a/', ''), 'a');
|
||||
assert.equal(libUtil.join('a/', '.'), 'a');
|
||||
assert.equal(libUtil.join('a//', ''), 'a');
|
||||
assert.equal(libUtil.join('a//', '.'), 'a');
|
||||
assert.equal(libUtil.join('/a', ''), '/a');
|
||||
assert.equal(libUtil.join('/a', '.'), '/a');
|
||||
assert.equal(libUtil.join('', ''), '.');
|
||||
assert.equal(libUtil.join('.', ''), '.');
|
||||
assert.equal(libUtil.join('.', ''), '.');
|
||||
assert.equal(libUtil.join('.', '.'), '.');
|
||||
assert.equal(libUtil.join('..', ''), '..');
|
||||
assert.equal(libUtil.join('..', '.'), '..');
|
||||
assert.equal(libUtil.join('http://foo.org/a', ''), 'http://foo.org/a');
|
||||
assert.equal(libUtil.join('http://foo.org/a', '.'), 'http://foo.org/a');
|
||||
assert.equal(libUtil.join('http://foo.org/a/', ''), 'http://foo.org/a');
|
||||
assert.equal(libUtil.join('http://foo.org/a/', '.'), 'http://foo.org/a');
|
||||
assert.equal(libUtil.join('http://foo.org/a//', ''), 'http://foo.org/a');
|
||||
assert.equal(libUtil.join('http://foo.org/a//', '.'), 'http://foo.org/a');
|
||||
assert.equal(libUtil.join('http://foo.org', ''), 'http://foo.org/');
|
||||
assert.equal(libUtil.join('http://foo.org', '.'), 'http://foo.org/');
|
||||
assert.equal(libUtil.join('http://foo.org/', ''), 'http://foo.org/');
|
||||
assert.equal(libUtil.join('http://foo.org/', '.'), 'http://foo.org/');
|
||||
assert.equal(libUtil.join('http://foo.org//', ''), 'http://foo.org/');
|
||||
assert.equal(libUtil.join('http://foo.org//', '.'), 'http://foo.org/');
|
||||
assert.equal(libUtil.join('//www.example.com', ''), '//www.example.com/');
|
||||
assert.equal(libUtil.join('//www.example.com', '.'), '//www.example.com/');
|
||||
|
||||
|
||||
assert.equal(libUtil.join('http://foo.org/a', 'b'), 'http://foo.org/a/b');
|
||||
assert.equal(libUtil.join('http://foo.org/a/', 'b'), 'http://foo.org/a/b');
|
||||
assert.equal(libUtil.join('http://foo.org/a//', 'b'), 'http://foo.org/a/b');
|
||||
assert.equal(libUtil.join('http://foo.org/a', 'b/'), 'http://foo.org/a/b/');
|
||||
assert.equal(libUtil.join('http://foo.org/a', 'b//'), 'http://foo.org/a/b/');
|
||||
assert.equal(libUtil.join('http://foo.org/a/', '/b'), 'http://foo.org/b');
|
||||
assert.equal(libUtil.join('http://foo.org/a//', '//b'), 'http://b');
|
||||
|
||||
assert.equal(libUtil.join('http://foo.org/a', '..'), 'http://foo.org/');
|
||||
assert.equal(libUtil.join('http://foo.org/a', '../b'), 'http://foo.org/b');
|
||||
assert.equal(libUtil.join('http://foo.org/a/b', '../c'), 'http://foo.org/a/c');
|
||||
|
||||
assert.equal(libUtil.join('http://foo.org/a', '.'), 'http://foo.org/a');
|
||||
assert.equal(libUtil.join('http://foo.org/a', './b'), 'http://foo.org/a/b');
|
||||
assert.equal(libUtil.join('http://foo.org/a/b', './c'), 'http://foo.org/a/b/c');
|
||||
|
||||
assert.equal(libUtil.join('http://foo.org/a', 'http://www.example.com'), 'http://www.example.com');
|
||||
assert.equal(libUtil.join('http://foo.org/a', 'data:foo,bar'), 'data:foo,bar');
|
||||
|
||||
|
||||
assert.equal(libUtil.join('http://foo.org', 'a'), 'http://foo.org/a');
|
||||
assert.equal(libUtil.join('http://foo.org/', 'a'), 'http://foo.org/a');
|
||||
assert.equal(libUtil.join('http://foo.org//', 'a'), 'http://foo.org/a');
|
||||
assert.equal(libUtil.join('http://foo.org', '/a'), 'http://foo.org/a');
|
||||
assert.equal(libUtil.join('http://foo.org/', '/a'), 'http://foo.org/a');
|
||||
assert.equal(libUtil.join('http://foo.org//', '/a'), 'http://foo.org/a');
|
||||
|
||||
|
||||
assert.equal(libUtil.join('http://', 'www.example.com'), 'http://www.example.com');
|
||||
assert.equal(libUtil.join('file:///', 'www.example.com'), 'file:///www.example.com');
|
||||
assert.equal(libUtil.join('http://', 'ftp://example.com'), 'ftp://example.com');
|
||||
|
||||
assert.equal(libUtil.join('http://www.example.com', '//foo.org/bar'), 'http://foo.org/bar');
|
||||
assert.equal(libUtil.join('//www.example.com', '//foo.org/bar'), '//foo.org/bar');
|
||||
};
|
||||
|
||||
// TODO Issue #128: Define and test this function properly.
|
||||
exports['test relative()'] = function (assert, util) {
|
||||
assert.equal(libUtil.relative('/the/root', '/the/root/one.js'), 'one.js');
|
||||
assert.equal(libUtil.relative('/the/root', '/the/rootone.js'), '/the/rootone.js');
|
||||
|
||||
assert.equal(libUtil.relative('', '/the/root/one.js'), '/the/root/one.js');
|
||||
assert.equal(libUtil.relative('.', '/the/root/one.js'), '/the/root/one.js');
|
||||
assert.equal(libUtil.relative('', 'the/root/one.js'), 'the/root/one.js');
|
||||
assert.equal(libUtil.relative('.', 'the/root/one.js'), 'the/root/one.js');
|
||||
|
||||
assert.equal(libUtil.relative('/', '/the/root/one.js'), 'the/root/one.js');
|
||||
assert.equal(libUtil.relative('/', 'the/root/one.js'), 'the/root/one.js');
|
||||
};
|
||||
|
||||
});
|
||||
299
node_modules/escodegen/node_modules/source-map/test/source-map/util.js
generated
vendored
Normal file
299
node_modules/escodegen/node_modules/source-map/test/source-map/util.js
generated
vendored
Normal file
@@ -0,0 +1,299 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
if (typeof define !== 'function') {
|
||||
var define = require('amdefine')(module, require);
|
||||
}
|
||||
define(function (require, exports, module) {
|
||||
|
||||
var util = require('../../lib/source-map/util');
|
||||
|
||||
// This is a test mapping which maps functions from two different files
|
||||
// (one.js and two.js) to a minified generated source.
|
||||
//
|
||||
// Here is one.js:
|
||||
//
|
||||
// ONE.foo = function (bar) {
|
||||
// return baz(bar);
|
||||
// };
|
||||
//
|
||||
// Here is two.js:
|
||||
//
|
||||
// TWO.inc = function (n) {
|
||||
// return n + 1;
|
||||
// };
|
||||
//
|
||||
// And here is the generated code (min.js):
|
||||
//
|
||||
// ONE.foo=function(a){return baz(a);};
|
||||
// TWO.inc=function(a){return a+1;};
|
||||
exports.testGeneratedCode = " ONE.foo=function(a){return baz(a);};\n"+
|
||||
" TWO.inc=function(a){return a+1;};";
|
||||
exports.testMap = {
|
||||
version: 3,
|
||||
file: 'min.js',
|
||||
names: ['bar', 'baz', 'n'],
|
||||
sources: ['one.js', 'two.js'],
|
||||
sourceRoot: '/the/root',
|
||||
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
|
||||
};
|
||||
exports.testMapNoSourceRoot = {
|
||||
version: 3,
|
||||
file: 'min.js',
|
||||
names: ['bar', 'baz', 'n'],
|
||||
sources: ['one.js', 'two.js'],
|
||||
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
|
||||
};
|
||||
exports.testMapEmptySourceRoot = {
|
||||
version: 3,
|
||||
file: 'min.js',
|
||||
names: ['bar', 'baz', 'n'],
|
||||
sources: ['one.js', 'two.js'],
|
||||
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',
|
||||
names: ['bar', 'baz', 'n'],
|
||||
sources: ['one.js', 'two.js'],
|
||||
sourcesContent: [
|
||||
' ONE.foo = function (bar) {\n' +
|
||||
' return baz(bar);\n' +
|
||||
' };',
|
||||
' TWO.inc = function (n) {\n' +
|
||||
' return n + 1;\n' +
|
||||
' };'
|
||||
],
|
||||
sourceRoot: '/the/root',
|
||||
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
|
||||
};
|
||||
exports.testMapRelativeSources = {
|
||||
version: 3,
|
||||
file: 'min.js',
|
||||
names: ['bar', 'baz', 'n'],
|
||||
sources: ['./one.js', './two.js'],
|
||||
sourcesContent: [
|
||||
' ONE.foo = function (bar) {\n' +
|
||||
' return baz(bar);\n' +
|
||||
' };',
|
||||
' TWO.inc = function (n) {\n' +
|
||||
' return n + 1;\n' +
|
||||
' };'
|
||||
],
|
||||
sourceRoot: '/the/root',
|
||||
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
|
||||
};
|
||||
exports.emptyMap = {
|
||||
version: 3,
|
||||
file: 'min.js',
|
||||
names: [],
|
||||
sources: [],
|
||||
mappings: ''
|
||||
};
|
||||
|
||||
|
||||
function assertMapping(generatedLine, generatedColumn, originalSource,
|
||||
originalLine, originalColumn, name, map, assert,
|
||||
dontTestGenerated, dontTestOriginal) {
|
||||
if (!dontTestOriginal) {
|
||||
var origMapping = map.originalPositionFor({
|
||||
line: generatedLine,
|
||||
column: generatedColumn
|
||||
});
|
||||
assert.equal(origMapping.name, name,
|
||||
'Incorrect name, expected ' + JSON.stringify(name)
|
||||
+ ', got ' + JSON.stringify(origMapping.name));
|
||||
assert.equal(origMapping.line, originalLine,
|
||||
'Incorrect line, expected ' + JSON.stringify(originalLine)
|
||||
+ ', got ' + JSON.stringify(origMapping.line));
|
||||
assert.equal(origMapping.column, originalColumn,
|
||||
'Incorrect column, expected ' + JSON.stringify(originalColumn)
|
||||
+ ', got ' + JSON.stringify(origMapping.column));
|
||||
|
||||
var expectedSource;
|
||||
|
||||
if (originalSource && map.sourceRoot && originalSource.indexOf(map.sourceRoot) === 0) {
|
||||
expectedSource = originalSource;
|
||||
} else if (originalSource) {
|
||||
expectedSource = map.sourceRoot
|
||||
? util.join(map.sourceRoot, originalSource)
|
||||
: originalSource;
|
||||
} else {
|
||||
expectedSource = null;
|
||||
}
|
||||
|
||||
assert.equal(origMapping.source, expectedSource,
|
||||
'Incorrect source, expected ' + JSON.stringify(expectedSource)
|
||||
+ ', got ' + JSON.stringify(origMapping.source));
|
||||
}
|
||||
|
||||
if (!dontTestGenerated) {
|
||||
var genMapping = map.generatedPositionFor({
|
||||
source: originalSource,
|
||||
line: originalLine,
|
||||
column: originalColumn
|
||||
});
|
||||
assert.equal(genMapping.line, generatedLine,
|
||||
'Incorrect line, expected ' + JSON.stringify(generatedLine)
|
||||
+ ', got ' + JSON.stringify(genMapping.line));
|
||||
assert.equal(genMapping.column, generatedColumn,
|
||||
'Incorrect column, expected ' + JSON.stringify(generatedColumn)
|
||||
+ ', got ' + JSON.stringify(genMapping.column));
|
||||
}
|
||||
}
|
||||
exports.assertMapping = assertMapping;
|
||||
|
||||
function assertEqualMaps(assert, actualMap, expectedMap) {
|
||||
assert.equal(actualMap.version, expectedMap.version, "version mismatch");
|
||||
assert.equal(actualMap.file, expectedMap.file, "file mismatch");
|
||||
assert.equal(actualMap.names.length,
|
||||
expectedMap.names.length,
|
||||
"names length mismatch: " +
|
||||
actualMap.names.join(", ") + " != " + expectedMap.names.join(", "));
|
||||
for (var i = 0; i < actualMap.names.length; i++) {
|
||||
assert.equal(actualMap.names[i],
|
||||
expectedMap.names[i],
|
||||
"names[" + i + "] mismatch: " +
|
||||
actualMap.names.join(", ") + " != " + expectedMap.names.join(", "));
|
||||
}
|
||||
assert.equal(actualMap.sources.length,
|
||||
expectedMap.sources.length,
|
||||
"sources length mismatch: " +
|
||||
actualMap.sources.join(", ") + " != " + expectedMap.sources.join(", "));
|
||||
for (var i = 0; i < actualMap.sources.length; i++) {
|
||||
assert.equal(actualMap.sources[i],
|
||||
expectedMap.sources[i],
|
||||
"sources[" + i + "] length mismatch: " +
|
||||
actualMap.sources.join(", ") + " != " + expectedMap.sources.join(", "));
|
||||
}
|
||||
assert.equal(actualMap.sourceRoot,
|
||||
expectedMap.sourceRoot,
|
||||
"sourceRoot mismatch: " +
|
||||
actualMap.sourceRoot + " != " + expectedMap.sourceRoot);
|
||||
assert.equal(actualMap.mappings, expectedMap.mappings,
|
||||
"mappings mismatch:\nActual: " + actualMap.mappings + "\nExpected: " + expectedMap.mappings);
|
||||
if (actualMap.sourcesContent) {
|
||||
assert.equal(actualMap.sourcesContent.length,
|
||||
expectedMap.sourcesContent.length,
|
||||
"sourcesContent length mismatch");
|
||||
for (var i = 0; i < actualMap.sourcesContent.length; i++) {
|
||||
assert.equal(actualMap.sourcesContent[i],
|
||||
expectedMap.sourcesContent[i],
|
||||
"sourcesContent[" + i + "] mismatch");
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.assertEqualMaps = assertEqualMaps;
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user