diff --git a/Makefile.dryice.js b/Makefile.dryice.js deleted file mode 100644 index d6fc26a7..00000000 --- a/Makefile.dryice.js +++ /dev/null @@ -1,166 +0,0 @@ -/* -*- 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 path = require('path'); -var fs = require('fs'); -var copy = require('dryice').copy; - -function removeAmdefine(src) { - src = String(src).replace( - /if\s*\(typeof\s*define\s*!==\s*'function'\)\s*{\s*var\s*define\s*=\s*require\('amdefine'\)\(module,\s*require\);\s*}\s*/g, - ''); - src = src.replace( - /\b(define\(.*)('amdefine',?)/gm, - '$1'); - return src; -} -removeAmdefine.onRead = true; - -function makeNonRelative(src) { - return src - .replace(/require\('.\//g, 'require(\'source-map/') - .replace(/\.\.\/\.\.\/lib\//g, ''); -} -makeNonRelative.onRead = true; - -function buildBrowser() { - console.log('\nCreating dist/source-map.js'); - - var project = copy.createCommonJsProject({ - roots: [ path.join(__dirname, 'lib') ] - }); - - copy({ - source: [ - 'build/mini-require.js', - { - project: project, - require: [ 'source-map/source-map-generator', - 'source-map/source-map-consumer', - 'source-map/source-node'] - }, - 'build/suffix-browser.js' - ], - filter: [ - copy.filter.moduleDefines, - removeAmdefine - ], - dest: 'dist/source-map.js' - }); -} - -function buildBrowserMin() { - console.log('\nCreating dist/source-map.min.js'); - - copy({ - source: 'dist/source-map.js', - filter: copy.filter.uglifyjs, - dest: 'dist/source-map.min.js' - }); -} - -function buildFirefox() { - console.log('\nCreating dist/SourceMap.jsm'); - - var project = copy.createCommonJsProject({ - roots: [ path.join(__dirname, 'lib') ] - }); - - copy({ - source: [ - 'build/prefix-source-map.jsm', - { - project: project, - require: [ 'source-map/source-map-consumer', - 'source-map/source-map-generator', - 'source-map/source-node' ] - }, - 'build/suffix-source-map.jsm' - ], - filter: [ - copy.filter.moduleDefines, - removeAmdefine, - makeNonRelative - ], - dest: 'dist/SourceMap.jsm' - }); - - // Create dist/test/Utils.jsm - console.log('\nCreating dist/test/Utils.jsm'); - - project = copy.createCommonJsProject({ - roots: [ __dirname, path.join(__dirname, 'lib') ] - }); - - copy({ - source: [ - 'build/prefix-utils.jsm', - 'build/assert-shim.js', - { - project: project, - require: [ 'test/source-map/util' ] - }, - 'build/suffix-utils.jsm' - ], - filter: [ - copy.filter.moduleDefines, - removeAmdefine, - makeNonRelative - ], - dest: 'dist/test/Utils.jsm' - }); - - function isTestFile(f) { - return /^test\-.*?\.js/.test(f); - } - - var testFiles = fs.readdirSync(path.join(__dirname, 'test', 'source-map')).filter(isTestFile); - - testFiles.forEach(function (testFile) { - console.log('\nCreating', path.join('dist', 'test', testFile.replace(/\-/g, '_'))); - - copy({ - source: [ - 'build/test-prefix.js', - path.join('test', 'source-map', testFile), - 'build/test-suffix.js' - ], - filter: [ - removeAmdefine, - makeNonRelative, - function (input, source) { - return input.replace('define(', - 'define("' - + path.join('test', 'source-map', testFile.replace(/\.js$/, '')) - + '", ["require", "exports", "module"], '); - }, - function (input, source) { - return input.replace('{THIS_MODULE}', function () { - return "test/source-map/" + testFile.replace(/\.js$/, ''); - }); - } - ], - dest: path.join('dist', 'test', testFile.replace(/\-/g, '_')) - }); - }); -} - -function ensureDir(name) { - var dirExists = false; - try { - dirExists = fs.statSync(name).isDirectory(); - } catch (err) {} - - if (!dirExists) { - fs.mkdirSync(name, 0777); - } -} - -ensureDir("dist"); -ensureDir("dist/test"); -buildFirefox(); -buildBrowser(); -buildBrowserMin(); diff --git a/README.md b/README.md index b7c6786c..4d7716b5 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,13 @@ This is a library to generate and consume the source map format [described here][format]. -This library is written in the Asynchronous Module Definition format, and works -in the following environments: +This library is compatible with the following environments: -* Modern Browsers supporting ECMAScript 5 (either after the build, or with an - AMD loader such as RequireJS) +* Node.js versions 0.8.X and higher -* Inside Firefox (as a JSM file, after the build) +* On the web, with browsers supporting ECMAScript 5 (after the build) -* With NodeJS versions 0.8.X and higher +* Inside Firefox (after the build) ## Node @@ -23,19 +21,22 @@ Install Node and then run $ git clone https://fitzgen@github.com/mozilla/source-map.git $ cd source-map - $ npm link . Next, run - $ node Makefile.dryice.js + $ npm run build -This should spew a bunch of stuff to stdout, and create the following files: +This will create the following files: -* `dist/source-map.js` - The unminified browser version. +* `dist/source-map.js` - The plain browser build. -* `dist/source-map.min.js` - The minified browser version. +* `dist/source-map.min.js` - The minified browser build. -* `dist/SourceMap.jsm` - The JavaScript Module for inclusion in Firefox source. +* `dist/source-map.min.js.map` - The source map for the minified browser build. + +* `dist/source-map.debug.js` - The debug browser build. + +* `dist/source-map.debug.js.map` - The source map for the debug browser build. ## Examples @@ -152,8 +153,7 @@ var sourceMap = require('source-map'); var sourceMap = window.sourceMap; // Inside Firefox -let sourceMap = {}; -Components.utils.import('resource:///modules/devtools/SourceMap.jsm', sourceMap); +const sourceMap = require("devtools/toolkit/sourcemap/source-map.js"); ``` ### SourceMapConsumer @@ -473,20 +473,19 @@ The arguments are the same as those to `new SourceMapGenerator`. [![Build Status](https://travis-ci.org/mozilla/source-map.png?branch=master)](https://travis-ci.org/mozilla/source-map) -Install NodeJS version 0.8.0 or greater, then run `node test/run-tests.js`. +Install NodeJS version 0.8.0 or greater, then run `npm test`. -To add new tests, create a new file named `test/test-.js` -and export your test functions with names that start with "test", for example +To add new tests, create a new file named +`test/source-map/test-your-new-test-name.js` and export your test functions with +names that start with "test", for example ```js -exports["test doing the foo bar"] = function (assert, util) { +exports["test doing the foo bar"] = function (assert) { ... }; ``` -The new test will be located automatically when you run the suite. - -The `util` argument is the test utility module located at `test/source-map/util`. +The new tests will be located automatically when you run the suite. The `assert` argument is a cut down version of node's assert module. You have access to the following assertion functions: @@ -502,8 +501,8 @@ access to the following assertion functions: * `throws` (The reason for the restricted set of test functions is because we need the -tests to run inside Firefox's test suite as well and so the assert module is -shimmed in that environment. See `build/assert-shim.js`.) +tests to run inside Firefox's test suite as well and Firefox has a shimmed +assert module.) [format]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit [feature]: https://wiki.mozilla.org/DevTools/Features/SourceMap diff --git a/build/assert-shim.js b/build/assert-shim.js deleted file mode 100644 index 720909e6..00000000 --- a/build/assert-shim.js +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- 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 - */ -define('test/source-map/assert', ['require', 'exports'], function (require, exports) { - - let do_throw = function (msg) { - throw new Error(msg); - }; - - exports.init = function (throw_fn) { - do_throw = throw_fn; - }; - - exports.doesNotThrow = function (fn) { - try { - fn(); - } - catch (e) { - do_throw(e.message); - } - }; - - exports.equal = function (actual, expected, msg) { - msg = msg || String(actual) + ' != ' + String(expected); - if (actual != expected) { - do_throw(msg); - } - }; - - exports.ok = function (val, msg) { - msg = msg || String(val) + ' is falsey'; - if (!Boolean(val)) { - do_throw(msg); - } - }; - - exports.strictEqual = function (actual, expected, msg) { - msg = msg || String(actual) + ' !== ' + String(expected); - if (actual !== expected) { - do_throw(msg); - } - }; - - exports.throws = function (fn) { - try { - fn(); - do_throw('Expected an error to be thrown, but it wasn\'t.'); - } - catch (e) { - } - }; - -}); diff --git a/build/mini-require.js b/build/mini-require.js deleted file mode 100644 index 0daf4537..00000000 --- a/build/mini-require.js +++ /dev/null @@ -1,152 +0,0 @@ -/* -*- 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 - */ - -/** - * Define a module along with a payload. - * @param {string} moduleName Name for the payload - * @param {ignored} deps Ignored. For compatibility with CommonJS AMD Spec - * @param {function} payload Function with (require, exports, module) params - */ -function define(moduleName, deps, payload) { - if (typeof moduleName != "string") { - throw new TypeError('Expected string, got: ' + moduleName); - } - - if (arguments.length == 2) { - payload = deps; - } - - if (moduleName in define.modules) { - throw new Error("Module already defined: " + moduleName); - } - define.modules[moduleName] = payload; -}; - -/** - * The global store of un-instantiated modules - */ -define.modules = {}; - - -/** - * We invoke require() in the context of a Domain so we can have multiple - * sets of modules running separate from each other. - * This contrasts with JSMs which are singletons, Domains allows us to - * optionally load a CommonJS module twice with separate data each time. - * Perhaps you want 2 command lines with a different set of commands in each, - * for example. - */ -function Domain() { - this.modules = {}; - this._currentModule = null; -} - -(function () { - - /** - * Lookup module names and resolve them by calling the definition function if - * needed. - * There are 2 ways to call this, either with an array of dependencies and a - * callback to call when the dependencies are found (which can happen - * asynchronously in an in-page context) or with a single string an no callback - * where the dependency is resolved synchronously and returned. - * The API is designed to be compatible with the CommonJS AMD spec and - * RequireJS. - * @param {string[]|string} deps A name, or names for the payload - * @param {function|undefined} callback Function to call when the dependencies - * are resolved - * @return {undefined|object} The module required or undefined for - * array/callback method - */ - Domain.prototype.require = function(deps, callback) { - if (Array.isArray(deps)) { - var params = deps.map(function(dep) { - return this.lookup(dep); - }, this); - if (callback) { - callback.apply(null, params); - } - return undefined; - } - else { - return this.lookup(deps); - } - }; - - function normalize(path) { - var bits = path.split('/'); - var i = 1; - while (i < bits.length) { - if (bits[i] === '..') { - bits.splice(i-1, 1); - } else if (bits[i] === '.') { - bits.splice(i, 1); - } else { - i++; - } - } - return bits.join('/'); - } - - function join(a, b) { - a = a.trim(); - b = b.trim(); - if (/^\//.test(b)) { - return b; - } else { - return a.replace(/\/*$/, '/') + b; - } - } - - function dirname(path) { - var bits = path.split('/'); - bits.pop(); - return bits.join('/'); - } - - /** - * Lookup module names and resolve them by calling the definition function if - * needed. - * @param {string} moduleName A name for the payload to lookup - * @return {object} The module specified by aModuleName or null if not found. - */ - Domain.prototype.lookup = function(moduleName) { - if (/^\./.test(moduleName)) { - moduleName = normalize(join(dirname(this._currentModule), moduleName)); - } - - if (moduleName in this.modules) { - var module = this.modules[moduleName]; - return module; - } - - if (!(moduleName in define.modules)) { - throw new Error("Module not defined: " + moduleName); - } - - var module = define.modules[moduleName]; - - if (typeof module == "function") { - var exports = {}; - var previousModule = this._currentModule; - this._currentModule = moduleName; - module(this.require.bind(this), exports, { id: moduleName, uri: "" }); - this._currentModule = previousModule; - module = exports; - } - - // cache the resulting module object for next time - this.modules[moduleName] = module; - - return module; - }; - -}()); - -define.Domain = Domain; -define.globalDomain = new Domain(); -var require = define.globalDomain.require.bind(define.globalDomain); diff --git a/build/prefix-source-map.jsm b/build/prefix-source-map.jsm deleted file mode 100644 index 209dbd7d..00000000 --- a/build/prefix-source-map.jsm +++ /dev/null @@ -1,21 +0,0 @@ -/* -*- 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 - */ - -/* - * WARNING! - * - * Do not edit this file directly, it is built from the sources at - * https://github.com/mozilla/source-map/ - */ - -/////////////////////////////////////////////////////////////////////////////// - - -this.EXPORTED_SYMBOLS = [ "SourceMapConsumer", "SourceMapGenerator", "SourceNode" ]; - -Components.utils.import("resource://gre/modules/devtools/Console.jsm"); -Components.utils.import('resource://gre/modules/devtools/Require.jsm'); diff --git a/build/prefix-utils.jsm b/build/prefix-utils.jsm deleted file mode 100644 index ec5463f3..00000000 --- a/build/prefix-utils.jsm +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- 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 - */ - -/* - * WARNING! - * - * Do not edit this file directly, it is built from the sources at - * https://github.com/mozilla/source-map/ - */ - -let loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"] - .getService(Components.interfaces.mozIJSSubScriptLoader); -let exports = {}; -loader.loadSubScript("resource://gre/modules/devtools/sourcemap/source-map.js", exports); - -// Also bind on `this` for b2g bug on EXPORTED_SYMBOLS -let define = this.define = exports.define; - -let require = exports.require; - -this.EXPORTED_SYMBOLS = [ "define", "runSourceMapTests" ]; diff --git a/build/suffix-browser.js b/build/suffix-browser.js deleted file mode 100644 index 8502afd4..00000000 --- a/build/suffix-browser.js +++ /dev/null @@ -1,14 +0,0 @@ -/* -*- Mode: js; js-indent-level: 2; -*- */ -/////////////////////////////////////////////////////////////////////////////// - -this.define = define; -this.require = require; - -this.sourceMap = { - SourceMapConsumer: require('source-map/source-map-consumer').SourceMapConsumer, - SourceMapGenerator: require('source-map/source-map-generator').SourceMapGenerator, - SourceNode: require('source-map/source-node').SourceNode -}; -if (typeof module === "object" && module && module.exports) { - module.exports = this.sourceMap; -} diff --git a/build/suffix-source-map.jsm b/build/suffix-source-map.jsm deleted file mode 100644 index cf3c2d8d..00000000 --- a/build/suffix-source-map.jsm +++ /dev/null @@ -1,6 +0,0 @@ -/* -*- Mode: js; js-indent-level: 2; -*- */ -/////////////////////////////////////////////////////////////////////////////// - -this.SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer; -this.SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator; -this.SourceNode = require('source-map/source-node').SourceNode; diff --git a/build/suffix-utils.jsm b/build/suffix-utils.jsm deleted file mode 100644 index b31b84cb..00000000 --- a/build/suffix-utils.jsm +++ /dev/null @@ -1,21 +0,0 @@ -/* -*- 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 - */ -function runSourceMapTests(modName, do_throw) { - let mod = require(modName); - let assert = require('test/source-map/assert'); - let util = require('test/source-map/util'); - - assert.init(do_throw); - - for (let k in mod) { - if (/^test/.test(k)) { - mod[k](assert, util); - } - } - -} -this.runSourceMapTests = runSourceMapTests; diff --git a/build/test-prefix.js b/build/test-prefix.js deleted file mode 100644 index 1b13f300..00000000 --- a/build/test-prefix.js +++ /dev/null @@ -1,8 +0,0 @@ -/* - * WARNING! - * - * Do not edit this file directly, it is built from the sources at - * https://github.com/mozilla/source-map/ - */ - -Components.utils.import('resource://test/Utils.jsm'); diff --git a/build/test-suffix.js b/build/test-suffix.js deleted file mode 100644 index bec2de3f..00000000 --- a/build/test-suffix.js +++ /dev/null @@ -1,3 +0,0 @@ -function run_test() { - runSourceMapTests('{THIS_MODULE}', do_throw); -} diff --git a/lib/source-map/array-set.js b/lib/source-map/array-set.js index fea20522..0ffbb9fd 100644 --- a/lib/source-map/array-set.js +++ b/lib/source-map/array-set.js @@ -4,11 +4,7 @@ * 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('./util'); /** @@ -105,5 +101,4 @@ define(function (require, exports, module) { }; exports.ArraySet = ArraySet; - -}); +} diff --git a/lib/source-map/base64-vlq.js b/lib/source-map/base64-vlq.js index bbe9a58e..f2a07f7c 100644 --- a/lib/source-map/base64-vlq.js +++ b/lib/source-map/base64-vlq.js @@ -34,11 +34,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -if (typeof define !== 'function') { - var define = require('amdefine')(module, require); -} -define(function (require, exports, module) { - +{ var base64 = require('./base64'); // A single base 64 digit can contain 6 bits of data. For the base 64 variable @@ -142,5 +138,4 @@ define(function (require, exports, module) { aOutParam.value = fromVLQSigned(result); aOutParam.rest = aIndex; }; - -}); +} diff --git a/lib/source-map/base64.js b/lib/source-map/base64.js index d0a61319..dfda6ce1 100644 --- a/lib/source-map/base64.js +++ b/lib/source-map/base64.js @@ -4,11 +4,7 @@ * 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 intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); /** @@ -69,5 +65,4 @@ define(function (require, exports, module) { // Invalid base64 digit. return -1; }; - -}); +} diff --git a/lib/source-map/binary-search.js b/lib/source-map/binary-search.js index 7936f7e7..03161e6b 100644 --- a/lib/source-map/binary-search.js +++ b/lib/source-map/binary-search.js @@ -4,11 +4,7 @@ * 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) { - +{ exports.GREATEST_LOWER_BOUND = 1; exports.LEAST_UPPER_BOUND = 2; @@ -113,5 +109,4 @@ define(function (require, exports, module) { return index; }; - -}); +} diff --git a/lib/source-map/mapping-list.js b/lib/source-map/mapping-list.js index 6c5d3e4e..287a6076 100644 --- a/lib/source-map/mapping-list.js +++ b/lib/source-map/mapping-list.js @@ -4,11 +4,7 @@ * 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('./util'); /** @@ -81,5 +77,4 @@ define(function (require, exports, module) { }; exports.MappingList = MappingList; - -}); +} diff --git a/lib/source-map/quick-sort.js b/lib/source-map/quick-sort.js index e0551eda..f92823ce 100644 --- a/lib/source-map/quick-sort.js +++ b/lib/source-map/quick-sort.js @@ -4,11 +4,7 @@ * 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) { - +{ // It turns out that some (most?) JavaScript engines don't self-host // `Array.prototype.sort`. This makes sense because C++ will likely remain // faster than JS when doing raw CPU-intensive sorting. However, when using a @@ -116,5 +112,4 @@ define(function (require, exports, module) { exports.quickSort = function (ary, comparator) { doQuickSort(ary, comparator, 0, ary.length - 1); }; - -}); +} diff --git a/lib/source-map/source-map-consumer.js b/lib/source-map/source-map-consumer.js index 99763388..40cfcd50 100644 --- a/lib/source-map/source-map-consumer.js +++ b/lib/source-map/source-map-consumer.js @@ -4,11 +4,7 @@ * 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('./util'); var binarySearch = require('./binary-search'); var ArraySet = require('./array-set').ArraySet; @@ -1083,5 +1079,4 @@ define(function (require, exports, module) { }; exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer; - -}); +} diff --git a/lib/source-map/source-map-generator.js b/lib/source-map/source-map-generator.js index ad390845..ffc76cdf 100644 --- a/lib/source-map/source-map-generator.js +++ b/lib/source-map/source-map-generator.js @@ -4,11 +4,7 @@ * 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('./base64-vlq'); var util = require('./util'); var ArraySet = require('./array-set').ArraySet; @@ -397,5 +393,4 @@ define(function (require, exports, module) { }; exports.SourceMapGenerator = SourceMapGenerator; - -}); +} diff --git a/lib/source-map/source-node.js b/lib/source-map/source-node.js index 9ee90bd5..155db7e5 100644 --- a/lib/source-map/source-node.js +++ b/lib/source-map/source-node.js @@ -4,11 +4,7 @@ * 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('./source-map-generator').SourceMapGenerator; var util = require('./util'); @@ -410,5 +406,4 @@ define(function (require, exports, module) { }; exports.SourceNode = SourceNode; - -}); +} diff --git a/lib/source-map/util.js b/lib/source-map/util.js index c16e70c3..45815902 100644 --- a/lib/source-map/util.js +++ b/lib/source-map/util.js @@ -4,11 +4,7 @@ * 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) { - +{ /** * This is a helper function for getting values from parameter/options * objects. @@ -370,5 +366,4 @@ define(function (require, exports, module) { return strcmp(mappingA.name, mappingB.name); } exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; - -}); +} diff --git a/package.json b/package.json index 4962ab02..c56909ba 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "source-map", "description": "Generates and consumes source maps", - "version": "0.4.4", + "version": "0.5.0", "homepage": "https://github.com/mozilla/source-map", "author": "Nick Fitzgerald ", "contributors": [ @@ -52,17 +52,14 @@ "build/" ], "engines": { - "node": ">=0.8.0" + "node": ">=0.10.0" }, "license": "BSD-3-Clause", - "dependencies": { - "amdefine": ">=0.0.4" - }, - "devDependencies": { - "dryice": ">=0.4.8" - }, "scripts": { "test": "node test/run-tests.js", - "build": "node Makefile.dryice.js" + "build": "webpack --color" + }, + "devDependencies": { + "webpack": "^1.12.0" } } diff --git a/test/run-tests.js b/test/run-tests.js index 64a7c3a3..23b92464 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -8,7 +8,6 @@ var assert = require('assert'); var fs = require('fs'); var path = require('path'); -var util = require('./source-map/util'); function run(tests) { var total = 0; @@ -19,7 +18,7 @@ function run(tests) { if (/^test/.test(k)) { total++; try { - tests[i].testCase[k](assert, util); + tests[i].testCase[k](assert); passed++; } catch (e) { diff --git a/test/source-map/test-api.js b/test/source-map/test-api.js index de89d420..4ff76e9b 100644 --- a/test/source-map/test-api.js +++ b/test/source-map/test-api.js @@ -4,23 +4,12 @@ * 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) { - var loader = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {}); - sourceMap = loader.devtools.require("devtools/toolkit/sourcemap/source-map"); - } +{ + var sourceMap = require('../../lib/source-map'); - exports['test that the api is properly exposed in the top level'] = function (assert, util) { + exports['test that the api is properly exposed in the top level'] = function (assert) { assert.equal(typeof sourceMap.SourceMapGenerator, "function"); assert.equal(typeof sourceMap.SourceMapConsumer, "function"); assert.equal(typeof sourceMap.SourceNode, "function"); }; - -}); +} diff --git a/test/source-map/test-array-set.js b/test/source-map/test-array-set.js index b513db93..b28ef707 100644 --- a/test/source-map/test-array-set.js +++ b/test/source-map/test-array-set.js @@ -4,11 +4,7 @@ * 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() { @@ -19,28 +15,28 @@ define(function (require, exports, module) { return set; } - exports['test .has() membership'] = function (assert, util) { + exports['test .has() membership'] = function (assert) { var set = makeTestSet(); for (var i = 0; i < 100; i++) { assert.ok(set.has(String(i))); } }; - exports['test .indexOf() elements'] = function (assert, util) { + exports['test .indexOf() elements'] = function (assert) { var set = makeTestSet(); for (var i = 0; i < 100; i++) { assert.strictEqual(set.indexOf(String(i)), i); } }; - exports['test .at() indexing'] = function (assert, util) { + exports['test .at() indexing'] = function (assert) { 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) { + exports['test creating from an array'] = function (assert) { var set = ArraySet.fromArray(['foo', 'bar', 'baz', 'quux', 'hasOwnProperty']); assert.ok(set.has('foo')); @@ -60,7 +56,7 @@ define(function (require, exports, module) { assert.strictEqual(set.at(3), 'quux'); }; - exports['test that you can add __proto__; see github issue #30'] = function (assert, util) { + exports['test that you can add __proto__; see github issue #30'] = function (assert) { var set = new ArraySet(); set.add('__proto__'); assert.ok(set.has('__proto__')); @@ -68,7 +64,7 @@ define(function (require, exports, module) { assert.strictEqual(set.indexOf('__proto__'), 0); }; - exports['test .fromArray() with duplicates'] = function (assert, util) { + exports['test .fromArray() with duplicates'] = function (assert) { var set = ArraySet.fromArray(['foo', 'foo']); assert.ok(set.has('foo')); assert.strictEqual(set.at(0), 'foo'); @@ -83,7 +79,7 @@ define(function (require, exports, module) { assert.strictEqual(set.toArray().length, 2); }; - exports['test .add() with duplicates'] = function (assert, util) { + exports['test .add() with duplicates'] = function (assert) { var set = new ArraySet(); set.add('foo'); @@ -101,7 +97,7 @@ define(function (require, exports, module) { assert.strictEqual(set.toArray().length, 2); }; - exports['test .size()'] = function (assert, util) { + exports['test .size()'] = function (assert) { var set = new ArraySet(); set.add('foo'); set.add('bar'); @@ -109,7 +105,7 @@ define(function (require, exports, module) { assert.strictEqual(set.size(), 3); }; - exports['test .size() with disallowed duplicates'] = function (assert, util) { + exports['test .size() with disallowed duplicates'] = function (assert) { var set = new ArraySet(); set.add('foo'); @@ -124,7 +120,7 @@ define(function (require, exports, module) { assert.strictEqual(set.size(), 3); }; - exports['test .size() with allowed duplicates'] = function (assert, util) { + exports['test .size() with allowed duplicates'] = function (assert) { var set = new ArraySet(); set.add('foo'); @@ -138,5 +134,4 @@ define(function (require, exports, module) { assert.strictEqual(set.size(), 3); }; - -}); +} diff --git a/test/source-map/test-base64-vlq.js b/test/source-map/test-base64-vlq.js index e7b3749b..1163f62e 100644 --- a/test/source-map/test-base64-vlq.js +++ b/test/source-map/test-base64-vlq.js @@ -4,14 +4,10 @@ * 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) { + exports['test normal encoding and decoding'] = function (assert) { var result = {}; for (var i = -255; i < 256; i++) { var str = base64VLQ.encode(i); @@ -20,5 +16,4 @@ define(function (require, exports, module) { assert.equal(result.rest, str.length); } }; - -}); +} diff --git a/test/source-map/test-base64.js b/test/source-map/test-base64.js index 6ade961e..0d7de98c 100644 --- a/test/source-map/test-base64.js +++ b/test/source-map/test-base64.js @@ -4,14 +4,10 @@ * 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) { + exports['test out of range encoding'] = function (assert) { assert.throws(function () { base64.encode(-1); }); @@ -20,14 +16,13 @@ define(function (require, exports, module) { }); }; - exports['test out of range decoding'] = function (assert, util) { + exports['test out of range decoding'] = function (assert) { assert.equal(base64.decode('='.charCodeAt(0)), -1); }; - exports['test normal encoding and decoding'] = function (assert, util) { + exports['test normal encoding and decoding'] = function (assert) { for (var i = 0; i < 64; i++) { assert.equal(base64.decode(base64.encode(i).charCodeAt(0)), i); } }; - -}); +} diff --git a/test/source-map/test-binary-search.js b/test/source-map/test-binary-search.js index 807fadef..921669f1 100644 --- a/test/source-map/test-binary-search.js +++ b/test/source-map/test-binary-search.js @@ -4,18 +4,14 @@ * 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 with default (glb) bias'] = function (assert, util) { + exports['test too high with default (glb) bias'] = function (assert) { var needle = 30; var haystack = [2,4,6,8,10,12,14,16,18,20]; @@ -26,7 +22,7 @@ define(function (require, exports, module) { assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 20); }; - exports['test too low with default (glb) bias'] = function (assert, util) { + exports['test too low with default (glb) bias'] = function (assert) { var needle = 1; var haystack = [2,4,6,8,10,12,14,16,18,20]; @@ -37,7 +33,7 @@ define(function (require, exports, module) { assert.equal(binarySearch.search(needle, haystack, numberCompare), -1); }; - exports['test too high with lub bias'] = function (assert, util) { + exports['test too high with lub bias'] = function (assert) { var needle = 30; var haystack = [2,4,6,8,10,12,14,16,18,20]; @@ -49,7 +45,7 @@ define(function (require, exports, module) { binarySearch.LEAST_UPPER_BOUND), -1); }; - exports['test too low with lub bias'] = function (assert, util) { + exports['test too low with lub bias'] = function (assert) { var needle = 1; var haystack = [2,4,6,8,10,12,14,16,18,20]; @@ -61,21 +57,21 @@ define(function (require, exports, module) { binarySearch.LEAST_UPPER_BOUND)], 2); }; - exports['test exact search'] = function (assert, util) { + exports['test exact search'] = function (assert) { 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 with default (glb) bias'] = function (assert, util) { + exports['test fuzzy search with default (glb) bias'] = function (assert) { var needle = 19; var haystack = [2,4,6,8,10,12,14,16,18,20]; assert.equal(haystack[binarySearch.search(needle, haystack, numberCompare)], 18); }; - exports['test fuzzy search with lub bias'] = function (assert, util) { + exports['test fuzzy search with lub bias'] = function (assert) { var needle = 19; var haystack = [2,4,6,8,10,12,14,16,18,20]; @@ -83,7 +79,7 @@ define(function (require, exports, module) { binarySearch.LEAST_UPPER_BOUND)], 20); }; - exports['test multiple matches'] = function (assert, util) { + exports['test multiple matches'] = function (assert) { var needle = 5; var haystack = [1, 1, 2, 5, 5, 5, 13, 21]; @@ -91,12 +87,11 @@ define(function (require, exports, module) { binarySearch.LEAST_UPPER_BOUND), 3); }; - exports['test multiple matches at the beginning'] = function (assert, util) { + exports['test multiple matches at the beginning'] = function (assert) { var needle = 1; var haystack = [1, 1, 2, 5, 5, 5, 13, 21]; assert.equal(binarySearch.search(needle, haystack, numberCompare, binarySearch.LEAST_UPPER_BOUND), 0); }; - -}); +} diff --git a/test/source-map/test-dog-fooding.js b/test/source-map/test-dog-fooding.js index 1168ea52..17f82bbd 100644 --- a/test/source-map/test-dog-fooding.js +++ b/test/source-map/test-dog-fooding.js @@ -4,15 +4,12 @@ * 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("./util"); 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) { + exports['test eating our own dog food'] = function (assert) { var smg = new SourceMapGenerator({ file: 'testing.js', sourceRoot: '/wu/tang' @@ -101,5 +98,4 @@ define(function (require, exports, module) { util.assertMapping(6, 12, '/wu/tang/gza.coffee', 5, 9, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true); util.assertMapping(null, null, '/wu/tang/gza.coffee', 6, 19, null, SourceMapConsumer.LEAST_UPPER_BOUND, smc, assert, null, true); }; - -}); +} diff --git a/test/source-map/test-quick-sort.js b/test/source-map/test-quick-sort.js index 44587d74..79aaa037 100644 --- a/test/source-map/test-quick-sort.js +++ b/test/source-map/test-quick-sort.js @@ -4,18 +4,14 @@ * 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 quickSort = require('../../lib/source-map/quick-sort').quickSort; function numberCompare(a, b) { return a - b; } - exports['test sorting sorted array'] = function (assert, util) { + exports['test sorting sorted array'] = function (assert) { var ary = [0,1,2,3,4,5,6,7,8,9]; var quickSorted = ary.slice(); @@ -25,7 +21,7 @@ define(function (require, exports, module) { JSON.stringify(quickSorted)); }; - exports['test sorting reverse-sorted array'] = function (assert, util) { + exports['test sorting reverse-sorted array'] = function (assert) { var ary = [9,8,7,6,5,4,3,2,1,0]; var quickSorted = ary.slice(); @@ -35,7 +31,7 @@ define(function (require, exports, module) { JSON.stringify(quickSorted)); }; - exports['test sorting unsorted array'] = function (assert, util) { + exports['test sorting unsorted array'] = function (assert) { var ary = []; for (var i = 0; i < 10; i++) { ary.push(Math.random()); @@ -47,5 +43,4 @@ define(function (require, exports, module) { assert.equal(JSON.stringify(ary.sort(numberCompare)), JSON.stringify(quickSorted)); }; - -}); +} diff --git a/test/source-map/test-source-map-consumer.js b/test/source-map/test-source-map-consumer.js index 9a39197b..f196b92c 100644 --- a/test/source-map/test-source-map-consumer.js +++ b/test/source-map/test-source-map-consumer.js @@ -4,17 +4,14 @@ * 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("./util"); var SourceMapConsumer = require('../../lib/source-map/source-map-consumer').SourceMapConsumer; var IndexedSourceMapConsumer = require('../../lib/source-map/source-map-consumer').IndexedSourceMapConsumer; var BasicSourceMapConsumer = require('../../lib/source-map/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) { + exports['test that we can instantiate with a string or an object'] = function (assert) { assert.doesNotThrow(function () { var map = new SourceMapConsumer(util.testMap); }); @@ -23,19 +20,19 @@ define(function (require, exports, module) { }); }; - exports['test that the object returned from new SourceMapConsumer inherits from SourceMapConsumer'] = function (assert, util) { + exports['test that the object returned from new SourceMapConsumer inherits from SourceMapConsumer'] = function (assert) { assert.ok(new SourceMapConsumer(util.testMap) instanceof SourceMapConsumer); } - exports['test that a BasicSourceMapConsumer is returned for sourcemaps without sections'] = function(assert, util) { + exports['test that a BasicSourceMapConsumer is returned for sourcemaps without sections'] = function(assert) { assert.ok(new SourceMapConsumer(util.testMap) instanceof BasicSourceMapConsumer); }; - exports['test that an IndexedSourceMapConsumer is returned for sourcemaps with sections'] = function(assert, util) { + exports['test that an IndexedSourceMapConsumer is returned for sourcemaps with sections'] = function(assert) { assert.ok(new SourceMapConsumer(util.indexedTestMap) instanceof IndexedSourceMapConsumer); }; - exports['test that the `sources` field has the original sources'] = function (assert, util) { + exports['test that the `sources` field has the original sources'] = function (assert) { var map; var sources; @@ -70,7 +67,7 @@ define(function (require, exports, module) { assert.equal(sources.length, 2); }; - exports['test that the source root is reflected in a mapping\'s source field'] = function (assert, util) { + exports['test that the source root is reflected in a mapping\'s source field'] = function (assert) { var map; var mapping; @@ -119,7 +116,7 @@ define(function (require, exports, module) { assert.equal(mapping.source, 'one.js'); }; - exports['test mapping tokens back exactly'] = function (assert, util) { + exports['test mapping tokens back exactly'] = function (assert) { var map = new SourceMapConsumer(util.testMap); util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, null, map, assert); @@ -138,7 +135,7 @@ define(function (require, exports, module) { util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', null, map, assert); }; - exports['test mapping tokens back exactly in indexed source map'] = function (assert, util) { + exports['test mapping tokens back exactly in indexed source map'] = function (assert) { var map = new SourceMapConsumer(util.indexedTestMap); util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, null, map, assert); @@ -158,7 +155,7 @@ define(function (require, exports, module) { }; - exports['test mapping tokens back exactly'] = function (assert, util) { + exports['test mapping tokens back exactly'] = function (assert) { var map = new SourceMapConsumer(util.testMap); util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, null, map, assert); @@ -177,7 +174,7 @@ define(function (require, exports, module) { util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', null, map, assert); }; - exports['test mapping tokens fuzzy'] = function (assert, util) { + exports['test mapping tokens fuzzy'] = function (assert) { var map = new SourceMapConsumer(util.testMap); // Finding original positions with default (glb) bias. @@ -201,7 +198,7 @@ define(function (require, exports, module) { util.assertMapping(2, 9, '/the/root/two.js', 1, 6, null, SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true); }; - exports['test mapping tokens fuzzy in indexed source map'] = function (assert, util) { + exports['test mapping tokens fuzzy in indexed source map'] = function (assert) { var map = new SourceMapConsumer(util.indexedTestMap); // Finding original positions with default (glb) bias. @@ -225,7 +222,7 @@ define(function (require, exports, module) { util.assertMapping(2, 9, '/the/root/two.js', 1, 6, null, SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true); }; - exports['test mappings and end of lines'] = function (assert, util) { + exports['test mappings and end of lines'] = function (assert) { var smg = new SourceMapGenerator({ file: 'foo.js' }); @@ -257,13 +254,13 @@ define(function (require, exports, module) { util.assertMapping(null, null, 'bar.js', 3, 1, null, SourceMapConsumer.LEAST_UPPER_BOUND, map, assert, null, true); }; - exports['test creating source map consumers with )]}\' prefix'] = function (assert, util) { + exports['test creating source map consumers with )]}\' prefix'] = function (assert) { assert.doesNotThrow(function () { var map = new SourceMapConsumer(")]}'" + JSON.stringify(util.testMap)); }); }; - exports['test eachMapping'] = function (assert, util) { + exports['test eachMapping'] = function (assert) { var map; map = new SourceMapConsumer(util.testMap); @@ -295,7 +292,7 @@ define(function (require, exports, module) { }); }; - exports['test eachMapping for indexed source maps'] = function(assert, util) { + exports['test eachMapping for indexed source maps'] = function(assert) { var map = new SourceMapConsumer(util.indexedTestMap); var previousLine = -Infinity; var previousColumn = -Infinity; @@ -318,7 +315,7 @@ define(function (require, exports, module) { }; - exports['test iterating over mappings in a different order'] = function (assert, util) { + exports['test iterating over mappings in a different order'] = function (assert) { var map = new SourceMapConsumer(util.testMap); var previousLine = -Infinity; var previousColumn = -Infinity; @@ -346,7 +343,7 @@ define(function (require, exports, module) { }, null, SourceMapConsumer.ORIGINAL_ORDER); }; - exports['test iterating over mappings in a different order in indexed source maps'] = function (assert, util) { + exports['test iterating over mappings in a different order in indexed source maps'] = function (assert) { var map = new SourceMapConsumer(util.indexedTestMap); var previousLine = -Infinity; var previousColumn = -Infinity; @@ -374,7 +371,7 @@ define(function (require, exports, module) { }, null, SourceMapConsumer.ORIGINAL_ORDER); }; - exports['test that we can set the context for `this` in eachMapping'] = function (assert, util) { + exports['test that we can set the context for `this` in eachMapping'] = function (assert) { var map = new SourceMapConsumer(util.testMap); var context = {}; map.eachMapping(function () { @@ -382,7 +379,7 @@ define(function (require, exports, module) { }, context); }; - exports['test that we can set the context for `this` in eachMapping in indexed source maps'] = function (assert, util) { + exports['test that we can set the context for `this` in eachMapping in indexed source maps'] = function (assert) { var map = new SourceMapConsumer(util.indexedTestMap); var context = {}; map.eachMapping(function () { @@ -390,7 +387,7 @@ define(function (require, exports, module) { }, context); }; - exports['test that the `sourcesContent` field has the original sources'] = function (assert, util) { + exports['test that the `sourcesContent` field has the original sources'] = function (assert) { var map = new SourceMapConsumer(util.testMapWithSourcesContent); var sourcesContent = map.sourcesContent; @@ -399,7 +396,7 @@ define(function (require, exports, module) { assert.equal(sourcesContent.length, 2); }; - exports['test that we can get the original sources for the sources'] = function (assert, util) { + exports['test that we can get the original sources for the sources'] = function (assert) { var map = new SourceMapConsumer(util.testMapWithSourcesContent); var sources = map.sources; @@ -418,7 +415,7 @@ define(function (require, exports, module) { }, Error); }; - exports['test that we can get the original source content with relative source paths'] = function (assert, util) { + exports['test that we can get the original source content with relative source paths'] = function (assert) { var map = new SourceMapConsumer(util.testMapRelativeSources); var sources = map.sources; @@ -437,7 +434,7 @@ define(function (require, exports, module) { }, Error); }; - exports['test that we can get the original source content for the sources on an indexed source map'] = function (assert, util) { + exports['test that we can get the original source content for the sources on an indexed source map'] = function (assert) { var map = new SourceMapConsumer(util.indexedTestMap); var sources = map.sources; @@ -456,7 +453,7 @@ define(function (require, exports, module) { }, Error); }; - exports['test hasContentsOfAllSources, single source with contents'] = function (assert, util) { + exports['test hasContentsOfAllSources, single source with contents'] = function (assert) { // Has one source: foo.js (with contents). var mapWithContents = new SourceMapGenerator(); mapWithContents.addMapping({ source: 'foo.js', @@ -467,7 +464,7 @@ define(function (require, exports, module) { assert.ok(consumer.hasContentsOfAllSources()); }; - exports['test hasContentsOfAllSources, single source without contents'] = function (assert, util) { + exports['test hasContentsOfAllSources, single source without contents'] = function (assert) { // Has one source: foo.js (without contents). var mapWithoutContents = new SourceMapGenerator(); mapWithoutContents.addMapping({ source: 'foo.js', @@ -477,7 +474,7 @@ define(function (require, exports, module) { assert.ok(!consumer.hasContentsOfAllSources()); }; - exports['test hasContentsOfAllSources, two sources with contents'] = function (assert, util) { + exports['test hasContentsOfAllSources, two sources with contents'] = function (assert) { // Has two sources: foo.js (with contents) and bar.js (with contents). var mapWithBothContents = new SourceMapGenerator(); mapWithBothContents.addMapping({ source: 'foo.js', @@ -492,7 +489,7 @@ define(function (require, exports, module) { assert.ok(consumer.hasContentsOfAllSources()); }; - exports['test hasContentsOfAllSources, two sources one with and one without contents'] = function (assert, util) { + exports['test hasContentsOfAllSources, two sources one with and one without contents'] = function (assert) { // Has two sources: foo.js (with contents) and bar.js (without contents). var mapWithoutSomeContents = new SourceMapGenerator(); mapWithoutSomeContents.addMapping({ source: 'foo.js', @@ -506,7 +503,7 @@ define(function (require, exports, module) { assert.ok(!consumer.hasContentsOfAllSources()); }; - exports['test sourceRoot + generatedPositionFor'] = function (assert, util) { + exports['test sourceRoot + generatedPositionFor'] = function (assert) { var map = new SourceMapGenerator({ sourceRoot: 'foo/bar', file: 'baz.js' @@ -544,7 +541,7 @@ define(function (require, exports, module) { assert.equal(pos.column, 2); }; - exports['test sourceRoot + generatedPositionFor for path above the root'] = function (assert, util) { + exports['test sourceRoot + generatedPositionFor for path above the root'] = function (assert) { var map = new SourceMapGenerator({ sourceRoot: 'foo/bar', file: 'baz.js' @@ -567,7 +564,7 @@ define(function (require, exports, module) { assert.equal(pos.column, 2); }; - exports['test allGeneratedPositionsFor for line'] = function (assert, util) { + exports['test allGeneratedPositionsFor for line'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated.js' }); @@ -610,7 +607,7 @@ define(function (require, exports, module) { assert.equal(mappings[1].column, 3); }; - exports['test allGeneratedPositionsFor for line fuzzy'] = function (assert, util) { + exports['test allGeneratedPositionsFor for line fuzzy'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated.js' }); @@ -641,7 +638,7 @@ define(function (require, exports, module) { assert.equal(mappings[0].column, 2); }; - exports['test allGeneratedPositionsFor for empty source map'] = function (assert, util) { + exports['test allGeneratedPositionsFor for empty source map'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated.js' }); @@ -655,7 +652,7 @@ define(function (require, exports, module) { assert.equal(mappings.length, 0); }; - exports['test allGeneratedPositionsFor for column'] = function (assert, util) { + exports['test allGeneratedPositionsFor for column'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated.js' }); @@ -684,7 +681,7 @@ define(function (require, exports, module) { assert.equal(mappings[1].column, 3); }; - exports['test allGeneratedPositionsFor for column fuzzy'] = function (assert, util) { + exports['test allGeneratedPositionsFor for column fuzzy'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated.js' }); @@ -713,7 +710,7 @@ define(function (require, exports, module) { assert.equal(mappings[1].column, 3); }; - exports['test allGeneratedPositionsFor for column on different line fuzzy'] = function (assert, util) { + exports['test allGeneratedPositionsFor for column on different line fuzzy'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated.js' }); @@ -738,7 +735,7 @@ define(function (require, exports, module) { assert.equal(mappings.length, 0); }; - exports['test computeColumnSpans'] = function (assert, util) { + exports['test computeColumnSpans'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated.js' }); @@ -804,7 +801,7 @@ define(function (require, exports, module) { assert.equal(mappings[1].lastColumn, Infinity); }; - exports['test sourceRoot + originalPositionFor'] = function (assert, util) { + exports['test sourceRoot + originalPositionFor'] = function (assert) { var map = new SourceMapGenerator({ sourceRoot: 'foo/bar', file: 'baz.js' @@ -827,7 +824,7 @@ define(function (require, exports, module) { assert.equal(pos.column, 1); }; - exports['test github issue #56'] = function (assert, util) { + exports['test github issue #56'] = function (assert) { var map = new SourceMapGenerator({ sourceRoot: 'http://', file: 'www.example.com/foo.js' @@ -844,7 +841,7 @@ define(function (require, exports, module) { assert.equal(sources[0], 'http://www.example.com/original.js'); }; - exports['test github issue #43'] = function (assert, util) { + exports['test github issue #43'] = function (assert) { var map = new SourceMapGenerator({ sourceRoot: 'http://example.com', file: 'foo.js' @@ -863,7 +860,7 @@ define(function (require, exports, module) { 'Should not be joined with the sourceRoot.'); }; - exports['test absolute path, but same host sources'] = function (assert, util) { + exports['test absolute path, but same host sources'] = function (assert) { var map = new SourceMapGenerator({ sourceRoot: 'http://example.com/foo/bar', file: 'foo.js' @@ -882,7 +879,7 @@ define(function (require, exports, module) { '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) { + exports['test indexed source map errors when sections are out of order by line'] = function(assert) { // Make a deep copy of the indexedTestMap var misorderedIndexedTestMap = JSON.parse(JSON.stringify(util.indexedTestMap)); @@ -896,7 +893,7 @@ define(function (require, exports, module) { }, Error); }; - exports['test github issue #64'] = function (assert, util) { + exports['test github issue #64'] = function (assert) { var map = new SourceMapConsumer({ "version": 3, "file": "foo.js", @@ -911,7 +908,7 @@ define(function (require, exports, module) { assert.equal(map.sourceContentFor("/a"), "foo"); }; - exports['test bug 885597'] = function (assert, util) { + exports['test bug 885597'] = function (assert) { var map = new SourceMapConsumer({ "version": 3, "file": "foo.js", @@ -926,7 +923,7 @@ define(function (require, exports, module) { assert.equal(map.sourceContentFor(s), "foo"); }; - exports['test github issue #72, duplicate sources'] = function (assert, util) { + exports['test github issue #72, duplicate sources'] = function (assert) { var map = new SourceMapConsumer({ "version": 3, "file": "foo.js", @@ -961,7 +958,7 @@ define(function (require, exports, module) { assert.equal(pos.column, 5); }; - exports['test github issue #72, duplicate names'] = function (assert, util) { + exports['test github issue #72, duplicate names'] = function (assert) { var map = new SourceMapConsumer({ "version": 3, "file": "foo.js", @@ -996,7 +993,7 @@ define(function (require, exports, module) { assert.equal(pos.column, 5); }; - exports['test SourceMapConsumer.fromSourceMap'] = function (assert, util) { + exports['test SourceMapConsumer.fromSourceMap'] = function (assert) { var smg = new SourceMapGenerator({ sourceRoot: 'http://example.com/', file: 'foo.js' @@ -1057,7 +1054,7 @@ define(function (require, exports, module) { assert.equal(pos.column, 4); }; - exports['test issue #191'] = function (assert, util) { + exports['test issue #191'] = function (assert) { var generator = new SourceMapGenerator({ file: 'a.css' }); generator.addMapping({ source: 'b.css', @@ -1081,7 +1078,7 @@ define(function (require, exports, module) { "SourceMapConsumer from it should not throw"); }; - exports['test sources where their prefix is the source root: issue #199'] = function (assert, util) { + exports['test sources where their prefix is the source root: issue #199'] = function (assert) { var testSourceMap = { "version": 3, "sources": ["/source/app/app/app.js"], @@ -1102,7 +1099,7 @@ define(function (require, exports, module) { testSourceMap.sources.forEach(consumerHasSource); }; - exports['test sources where their prefix is the source root and the source root is a url: issue #199'] = function (assert, util) { + exports['test sources where their prefix is the source root and the source root is a url: issue #199'] = function (assert) { var testSourceMap = { "version": 3, "sources": ["http://example.com/source/app/app/app.js"], @@ -1121,5 +1118,4 @@ define(function (require, exports, module) { consumer.sources.forEach(consumerHasSource); testSourceMap.sources.forEach(consumerHasSource); }; - -}); +} diff --git a/test/source-map/test-source-map-generator.js b/test/source-map/test-source-map-generator.js index e1cb8f0e..0fbdcf37 100644 --- a/test/source-map/test-source-map-generator.js +++ b/test/source-map/test-source-map-generator.js @@ -4,17 +4,13 @@ * 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) { + exports['test some simple stuff'] = function (assert) { var map = new SourceMapGenerator({ file: 'foo.js', sourceRoot: '.' @@ -26,7 +22,7 @@ define(function (require, exports, module) { assert.ok(!('sourceRoot' in map)); }; - exports['test JSON serialization'] = function (assert, util) { + exports['test JSON serialization'] = function (assert) { var map = new SourceMapGenerator({ file: 'foo.js', sourceRoot: '.' @@ -34,7 +30,7 @@ define(function (require, exports, module) { assert.equal(map.toString(), JSON.stringify(map)); }; - exports['test adding mappings (case 1)'] = function (assert, util) { + exports['test adding mappings (case 1)'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated-foo.js', sourceRoot: '.' @@ -47,7 +43,7 @@ define(function (require, exports, module) { }); }; - exports['test adding mappings (case 2)'] = function (assert, util) { + exports['test adding mappings (case 2)'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated-foo.js', sourceRoot: '.' @@ -62,7 +58,7 @@ define(function (require, exports, module) { }); }; - exports['test adding mappings (case 3)'] = function (assert, util) { + exports['test adding mappings (case 3)'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated-foo.js', sourceRoot: '.' @@ -78,7 +74,7 @@ define(function (require, exports, module) { }); }; - exports['test adding mappings (invalid)'] = function (assert, util) { + exports['test adding mappings (invalid)'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated-foo.js', sourceRoot: '.' @@ -98,7 +94,7 @@ define(function (require, exports, module) { }); }; - exports['test adding mappings with skipValidation'] = function (assert, util) { + exports['test adding mappings with skipValidation'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated-foo.js', sourceRoot: '.', @@ -119,7 +115,7 @@ define(function (require, exports, module) { }); }; - exports['test that the correct mappings are being generated'] = function (assert, util) { + exports['test that the correct mappings are being generated'] = function (assert) { var map = new SourceMapGenerator({ file: 'min.js', sourceRoot: '/the/root' @@ -202,7 +198,7 @@ define(function (require, exports, module) { util.assertEqualMaps(assert, map, util.testMap); }; - exports['test that adding a mapping with an empty string name does not break generation'] = function (assert, util) { + exports['test that adding a mapping with an empty string name does not break generation'] = function (assert) { var map = new SourceMapGenerator({ file: 'generated-foo.js', sourceRoot: '.' @@ -220,7 +216,7 @@ define(function (require, exports, module) { }); }; - exports['test that source content can be set'] = function (assert, util) { + exports['test that source content can be set'] = function (assert) { var map = new SourceMapGenerator({ file: 'min.js', sourceRoot: '/the/root' @@ -244,18 +240,18 @@ define(function (require, exports, module) { assert.equal(map.sourcesContent[1], null); }; - exports['test .fromSourceMap'] = function (assert, util) { + exports['test .fromSourceMap'] = function (assert) { var map = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(util.testMap)); util.assertEqualMaps(assert, map.toJSON(), util.testMap); }; - exports['test .fromSourceMap with sourcesContent'] = function (assert, util) { + exports['test .fromSourceMap with sourcesContent'] = function (assert) { var map = SourceMapGenerator.fromSourceMap( new SourceMapConsumer(util.testMapWithSourcesContent)); util.assertEqualMaps(assert, map.toJSON(), util.testMapWithSourcesContent); }; - exports['test applySourceMap'] = function (assert, util) { + exports['test applySourceMap'] = function (assert) { var node = new SourceNode(null, null, null, [ new SourceNode(2, 0, 'fileX', 'lineX2\n'), 'genA1\n', @@ -312,7 +308,7 @@ define(function (require, exports, module) { util.assertEqualMaps(assert, actualMap, expectedMap); }; - exports['test applySourceMap throws when file is missing'] = function (assert, util) { + exports['test applySourceMap throws when file is missing'] = function (assert) { var map = new SourceMapGenerator({ file: 'test.js' }); @@ -322,7 +318,7 @@ define(function (require, exports, module) { }); }; - exports['test the two additional parameters of applySourceMap'] = function (assert, util) { + exports['test the two additional parameters of applySourceMap'] = function (assert) { // Assume the following directory structure: // // http://foo.org/ @@ -468,7 +464,7 @@ define(function (require, exports, module) { ])); }; - exports['test applySourceMap name handling'] = function (assert, util) { + exports['test applySourceMap name handling'] = function (assert) { // Imagine some CoffeeScript code being compiled into JavaScript and then // minified. @@ -524,7 +520,7 @@ define(function (require, exports, module) { assertName(null, null, null); }; - exports['test sorting with duplicate generated mappings'] = function (assert, util) { + exports['test sorting with duplicate generated mappings'] = function (assert) { var map = new SourceMapGenerator({ file: 'test.js' }); @@ -554,7 +550,7 @@ define(function (require, exports, module) { }); }; - exports['test ignore duplicate mappings.'] = function (assert, util) { + exports['test ignore duplicate mappings.'] = function (assert) { var init = { file: 'min.js', sourceRoot: '/the/root' }; var map1, map2; @@ -644,7 +640,7 @@ define(function (require, exports, module) { util.assertEqualMaps(assert, map1.toJSON(), map2.toJSON()); }; - exports['test github issue #72, check for duplicate names or sources'] = function (assert, util) { + exports['test github issue #72, check for duplicate names or sources'] = function (assert) { var map = new SourceMapGenerator({ file: 'test.js' }); @@ -669,14 +665,14 @@ define(function (require, exports, module) { }); }; - exports['test setting sourcesContent to null when already null'] = function (assert, util) { + exports['test setting sourcesContent to null when already null'] = function (assert) { var smg = new SourceMapGenerator({ file: "foo.js" }); assert.doesNotThrow(function() { smg.setSourceContent("bar.js", null); }); }; - exports['test applySourceMap with unexact match'] = function (assert, util) { + exports['test applySourceMap with unexact match'] = function (assert) { var map1 = new SourceMapGenerator({ file: 'bundled-source' }); @@ -719,7 +715,7 @@ define(function (require, exports, module) { util.assertEqualMaps(assert, map1.toJSON(), expectedMap.toJSON()); }; - exports['test issue #192'] = function (assert, util) { + exports['test issue #192'] = function (assert) { var generator = new SourceMapGenerator(); generator.addMapping({ source: 'a.js', @@ -741,5 +737,4 @@ define(function (require, exports, module) { "Should not de-duplicate mappings that have the same " + "generated positions, but different original positions."); }; - -}); +} diff --git a/test/source-map/test-source-node.js b/test/source-map/test-source-node.js index 139af4e4..70b98f96 100644 --- a/test/source-map/test-source-node.js +++ b/test/source-map/test-source-node.js @@ -4,22 +4,19 @@ * 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("./util"); 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)); + return function (assert) { + ['\n', '\r\n'].forEach(fn.bind(null, assert)); } } - exports['test .add()'] = function (assert, util) { + exports['test .add()'] = function (assert) { var node = new SourceNode(null, null, null); // Adding a string works. @@ -43,7 +40,7 @@ define(function (require, exports, module) { }); }; - exports['test .prepend()'] = function (assert, util) { + exports['test .prepend()'] = function (assert) { var node = new SourceNode(null, null, null); // Prepending a string works. @@ -78,7 +75,7 @@ define(function (require, exports, module) { }); }; - exports['test .toString()'] = function (assert, util) { + exports['test .toString()'] = function (assert) { assert.equal((new SourceNode(null, null, null, ['function foo() {', new SourceNode(null, null, null, 'return 10;'), @@ -86,13 +83,13 @@ define(function (require, exports, module) { 'function foo() {return 10;}'); }; - exports['test .join()'] = function (assert, util) { + exports['test .join()'] = function (assert) { assert.equal((new SourceNode(null, null, null, ['a', 'b', 'c', 'd'])).join(', ').toString(), 'a, b, c, d'); }; - exports['test .walk()'] = function (assert, util) { + exports['test .walk()'] = function (assert) { var node = new SourceNode(null, null, null, ['(function () {\n', ' ', new SourceNode(1, 0, 'a.js', ['someCall()']), ';\n', @@ -118,7 +115,7 @@ define(function (require, exports, module) { }); }; - exports['test .replaceRight'] = function (assert, util) { + exports['test .replaceRight'] = function (assert) { var node; // Not nested @@ -134,7 +131,7 @@ define(function (require, exports, module) { assert.equal(node.toString(), 'hey sexy mama, want to watch Futurama?'); }; - exports['test .toStringWithSourceMap()'] = forEachNewline(function (assert, util, nl) { + exports['test .toStringWithSourceMap()'] = forEachNewline(function (assert, nl) { var node = new SourceNode(null, null, null, ['(function () {' + nl, ' ', @@ -209,7 +206,7 @@ define(function (require, exports, module) { assert.equal(actual.column, null); }); - exports['test .fromStringWithSourceMap()'] = forEachNewline(function (assert, util, nl) { + exports['test .fromStringWithSourceMap()'] = forEachNewline(function (assert, nl) { var testCode = util.testGeneratedCode.replace(/\n/g, nl); var node = SourceNode.fromStringWithSourceMap( testCode, @@ -229,7 +226,7 @@ define(function (require, exports, module) { assert.equal(map.mappings, util.testMap.mappings); }); - exports['test .fromStringWithSourceMap() empty map'] = forEachNewline(function (assert, util, nl) { + exports['test .fromStringWithSourceMap() empty map'] = forEachNewline(function (assert, nl) { var node = SourceNode.fromStringWithSourceMap( util.testGeneratedCode.replace(/\n/g, nl), new SourceMapConsumer(util.emptyMap)); @@ -248,7 +245,7 @@ define(function (require, exports, module) { assert.equal(map.mappings, util.emptyMap.mappings); }); - exports['test .fromStringWithSourceMap() complex version'] = forEachNewline(function (assert, util, nl) { + exports['test .fromStringWithSourceMap() complex version'] = forEachNewline(function (assert, nl) { var input = new SourceNode(null, null, null, [ "(function() {" + nl, " var Test = {};" + nl, @@ -277,7 +274,7 @@ define(function (require, exports, module) { util.assertEqualMaps(assert, map, inputMap); }); - exports['test .fromStringWithSourceMap() third argument'] = function (assert, util) { + exports['test .fromStringWithSourceMap() third argument'] = function (assert) { // Assume the following directory structure: // // http://foo.org/ @@ -365,7 +362,7 @@ define(function (require, exports, module) { ]); }; - exports['test .toStringWithSourceMap() merging duplicate mappings'] = forEachNewline(function (assert, util, nl) { + exports['test .toStringWithSourceMap() merging duplicate mappings'] = forEachNewline(function (assert, nl) { var input = new SourceNode(null, null, null, [ new SourceNode(1, 0, "a.js", "(function"), new SourceNode(1, 0, "a.js", "() {" + nl), @@ -448,7 +445,7 @@ define(function (require, exports, module) { util.assertEqualMaps(assert, inputMap, correctMap); }); - exports['test .toStringWithSourceMap() multi-line SourceNodes'] = forEachNewline(function (assert, util, nl) { + exports['test .toStringWithSourceMap() multi-line SourceNodes'] = forEachNewline(function (assert, 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), @@ -524,13 +521,13 @@ define(function (require, exports, module) { util.assertEqualMaps(assert, inputMap, correctMap); }); - exports['test .toStringWithSourceMap() with empty string'] = function (assert, util) { + exports['test .toStringWithSourceMap() with empty string'] = function (assert) { 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) { + exports['test .toStringWithSourceMap() with consecutive newlines'] = forEachNewline(function (assert, nl) { var input = new SourceNode(null, null, null, [ "/***/" + nl + nl, new SourceNode(1, 0, "a.js", "'use strict';" + nl), @@ -566,7 +563,7 @@ define(function (require, exports, module) { util.assertEqualMaps(assert, inputMap, correctMap); }); - exports['test setSourceContent with toStringWithSourceMap'] = function (assert, util) { + exports['test setSourceContent with toStringWithSourceMap'] = function (assert) { var aNode = new SourceNode(1, 1, 'a.js', 'a'); aNode.setSourceContent('a.js', 'someContent'); var node = new SourceNode(null, null, null, @@ -590,7 +587,7 @@ define(function (require, exports, module) { assert.equal(map.sourcesContent[1], 'otherContent'); }; - exports['test walkSourceContents'] = function (assert, util) { + exports['test walkSourceContents'] = function (assert) { var aNode = new SourceNode(1, 1, 'a.js', 'a'); aNode.setSourceContent('a.js', 'someContent'); var node = new SourceNode(null, null, null, @@ -609,4 +606,4 @@ define(function (require, exports, module) { assert.equal(results[1][0], 'b.js'); assert.equal(results[1][1], 'otherContent'); }; -}); +} diff --git a/test/source-map/test-util.js b/test/source-map/test-util.js index 530dbdbc..c1b465f6 100644 --- a/test/source-map/test-util.js +++ b/test/source-map/test-util.js @@ -4,14 +4,10 @@ * 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) { + exports['test urls'] = function (assert) { var assertUrl = function (url) { assert.equal(url, libUtil.urlGenerate(libUtil.urlParse(url))); }; @@ -38,7 +34,7 @@ define(function (require, exports, module) { assert.equal(libUtil.urlParse('data:foo,bar'), null); }; - exports['test normalize()'] = function (assert, util) { + exports['test normalize()'] = function (assert) { assert.equal(libUtil.normalize('/..'), '/'); assert.equal(libUtil.normalize('/../'), '/'); assert.equal(libUtil.normalize('/../../../..'), '/'); @@ -75,7 +71,7 @@ define(function (require, exports, module) { 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) { + exports['test join()'] = function (assert) { assert.equal(libUtil.join('a', 'b'), 'a/b'); assert.equal(libUtil.join('a/', 'b'), 'a/b'); assert.equal(libUtil.join('a//', 'b'), 'a/b'); @@ -200,7 +196,7 @@ define(function (require, exports, module) { }; // TODO Issue #128: Define and test this function properly. - exports['test relative()'] = function (assert, util) { + exports['test relative()'] = function (assert) { assert.equal(libUtil.relative('/the/root', '/the/root/one.js'), 'one.js'); assert.equal(libUtil.relative('http://the/root', 'http://the/root/one.js'), 'one.js'); assert.equal(libUtil.relative('/the/root', '/the/rootone.js'), '../rootone.js'); @@ -216,5 +212,4 @@ define(function (require, exports, module) { assert.equal(libUtil.relative('/', '/the/root/one.js'), 'the/root/one.js'); assert.equal(libUtil.relative('/', 'the/root/one.js'), 'the/root/one.js'); }; - -}); +} diff --git a/test/source-map/util.js b/test/source-map/util.js index f48703bc..4c47555b 100644 --- a/test/source-map/util.js +++ b/test/source-map/util.js @@ -4,11 +4,7 @@ * 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 @@ -297,5 +293,4 @@ define(function (require, exports, module) { } } exports.assertEqualMaps = assertEqualMaps; - -}); +} diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 00000000..f66da805 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,85 @@ +// var ConcatSource = require("webpack/lib/ConcatSource"); +var BannerPlugin = require("webpack/lib/BannerPlugin"); +var fs = require("fs"); +var path = require("path"); +var webpack = require("webpack"); + +var distDir = path.join(__dirname, "dist"); + +module.exports = [ + // Plain build. + { + entry: "./lib/source-map.js", + output: { + path: distDir, + filename: "source-map.js", + library: "sourceMap", + libraryTarget: "umd", + }, + }, + + // Debug build. + { + entry: "./lib/source-map.js", + output: { + path: distDir, + filename: "source-map.debug.js", + library: "sourceMap", + libraryTarget: "umd", + }, + devtool: "#inline-source-map" + }, + + // Minified build. + { + entry: "./lib/source-map.js", + output: { + path: distDir, + filename: "source-map.min.js", + library: "sourceMap", + libraryTarget: "umd", + }, + plugins: [ + new webpack.optimize.UglifyJsPlugin({ + sourceMap: true + }) + ], + devtool: "#source-map" + } +]; + +/*** Build the tests for inclusion in mozilla-central. ************************/ + +var testFileRegex = /^test\-.*?\.js/; + +function isTestFile(file) { + return testFileRegex.test(file); +} + +var testsDir = path.join(__dirname, "test", "source-map"); +var testFiles = fs.readdirSync(testsDir).filter(isTestFile); + +// The xpcshell test harness expects a run_test function. Define this function +// and stringify it as banner at the top of each test file. +function run_test() { + for (var k in SOURCE_MAP_TEST_MODULE) { + if (/^test/.test(k)) { + SOURCE_MAP_TEST_MODULE[k](assert); + } + } +} + +testFiles.forEach(function (file) { + module.exports.push({ + entry: path.join(testsDir, file), + output: { + path: path.join(distDir, "test"), + filename: file.replace(/\-/g, "_"), + library: "SOURCE_MAP_TEST_MODULE" + }, + plugins: [ + new BannerPlugin(run_test.toString() + "\n\n", { raw: true }) + ], + devtool: "#inline-source-map" + }); +});