pax_global_header00006660000000000000000000000064121656722510014521gustar00rootroot0000000000000052 comment=d6f3689999d9130a0b426fcc46c1f183a85ed56a parse-base64vlq-mappings-0.1.4/000077500000000000000000000000001216567225100162565ustar00rootroot00000000000000parse-base64vlq-mappings-0.1.4/.gitignore000066400000000000000000000001451216567225100202460ustar00rootroot00000000000000lib-cov *.seed *.log *.csv *.dat *.out *.pid *.gz pids logs results node_modules npm-debug.log tmp parse-base64vlq-mappings-0.1.4/.travis.yml000066400000000000000000000000531216567225100203650ustar00rootroot00000000000000language: node_js node_js: - 0.6 - 0.8 parse-base64vlq-mappings-0.1.4/LICENSE000066400000000000000000000020661216567225100172670ustar00rootroot00000000000000Copyright 2013 Thorsten Lorenz. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. parse-base64vlq-mappings-0.1.4/MOZILLA_LICENSE000066400000000000000000000027661216567225100204650ustar00rootroot00000000000000 Copyright (c) 2009-2011, Mozilla Foundation and contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the Mozilla Foundation nor the names of project contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. parse-base64vlq-mappings-0.1.4/README.md000066400000000000000000000023761216567225100175450ustar00rootroot00000000000000# parse-base64vlq-mappings [![build status](https://secure.travis-ci.org/thlorenz/parse-base64vlq-mappings.png)](http://travis-ci.org/thlorenz/parse-base64vlq-mappings) Parses out base64 VLQ encoded mappings. The code is mostly lifted from [mozilla's source-map module](https://github.com/mozilla/source-map) in order to separate out the parse function into its own module. ```js var parse = require('parse-base64vlq-mappings'); var mappings = parse('AAAA;AACA;AACA;AACA;AACA'); console.log(mappings); ``` ``` [ { generated: { line: 1, column: 0 }, original: { line: 1, column: 0 } }, { generated: { line: 2, column: 0 }, original: { line: 2, column: 0 } }, { generated: { line: 3, column: 0 }, original: { line: 3, column: 0 } }, { generated: { line: 4, column: 0 }, original: { line: 4, column: 0 } }, { generated: { line: 5, column: 0 }, original: { line: 5, column: 0 } } ] ``` ## Caveat Main intended use is either for testing generated mappings or to add offsets to existing mappings. Therefore is is assumed that all mappings relate to the same generated/original file, i.e. only information about generated line and column vs. original line and column is preserved. Additionally all name information is disregarded during the parse. parse-base64vlq-mappings-0.1.4/base64-vlq.js000066400000000000000000000053561216567225100205110ustar00rootroot00000000000000'use strict'; /* * Copyright 2011 Mozilla Foundation and contributors * Licensed under the New BSD license. See LICENSE or: * http://opensource.org/licenses/BSD-3-Clause */ var base64 = require('./base64'); // A single base 64 digit can contain 6 bits of data. For the base 64 variable // length quantities we use in the source map spec, the first bit is the sign, // the next four bits are the actual value, and the 6th bit is the // continuation bit. The continuation bit tells us whether there are more // digits in this value following this digit. // // Continuation // | Sign // | | // V V // 101011 var VLQ_BASE_SHIFT = 5; // binary: 100000 var VLQ_BASE = 1 << VLQ_BASE_SHIFT; // binary: 011111 var VLQ_BASE_MASK = VLQ_BASE - 1; // binary: 100000 var VLQ_CONTINUATION_BIT = VLQ_BASE; /** * Converts from a two-complement value to a value where the sign bit is * is placed in the least significant bit. For example, as decimals: * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) */ function toVLQSigned(aValue) { return aValue < 0 ? ((-aValue) << 1) + 1 : (aValue << 1) + 0; } /** * Converts to a two-complement value from a value where the sign bit is * is placed in the least significant bit. For example, as decimals: * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 */ function fromVLQSigned(aValue) { var isNegative = (aValue & 1) === 1; var shifted = aValue >> 1; return isNegative ? -shifted : shifted; } /** * Returns the base 64 VLQ encoded value. */ exports.encode = function base64VLQ_encode(aValue) { var encoded = ""; var digit; var vlq = toVLQSigned(aValue); do { digit = vlq & VLQ_BASE_MASK; vlq >>>= VLQ_BASE_SHIFT; if (vlq > 0) { // There are still more digits in this value, so we must make sure the // continuation bit is marked. digit |= VLQ_CONTINUATION_BIT; } encoded += base64.encode(digit); } while (vlq > 0); return encoded; }; /** * Decodes the next base 64 VLQ value from the given string and returns the * value and the rest of the string. */ exports.decode = function base64VLQ_decode(aStr) { var i = 0; var strLen = aStr.length; var result = 0; var shift = 0; var continuation, digit; do { if (i >= strLen) { throw new Error("Expected more digits in base 64 VLQ value."); } digit = base64.decode(aStr.charAt(i++)); continuation = !!(digit & VLQ_CONTINUATION_BIT); digit &= VLQ_BASE_MASK; result = result + (digit << shift); shift += VLQ_BASE_SHIFT; } while (continuation); return { value: fromVLQSigned(result), rest: aStr.slice(i) }; }; parse-base64vlq-mappings-0.1.4/base64.js000066400000000000000000000016061216567225100177030ustar00rootroot00000000000000/* * Copyright 2011 Mozilla Foundation and contributors * Licensed under the New BSD license. See LICENSE or: * http://opensource.org/licenses/BSD-3-Clause */ var charToIntMap = {}; var intToCharMap = {}; 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' .split('') .forEach(function (ch, index) { charToIntMap[ch] = index; intToCharMap[index] = ch; }); /** * Encode an integer in the range of 0 to 63 to a single base 64 digit. */ exports.encode = function base64_encode(aNumber) { if (aNumber in intToCharMap) { return intToCharMap[aNumber]; } throw new TypeError("Must be between 0 and 63: " + aNumber); }; /** * Decode a single base 64 digit to an integer. */ exports.decode = function base64_decode(aChar) { if (aChar in charToIntMap) { return charToIntMap[aChar]; } throw new TypeError("Not a valid base 64 digit: " + aChar); }; parse-base64vlq-mappings-0.1.4/example/000077500000000000000000000000001216567225100177115ustar00rootroot00000000000000parse-base64vlq-mappings-0.1.4/example/one-to-one-mappings.js000066400000000000000000000001631216567225100240430ustar00rootroot00000000000000'use strict'; var parse = require('..'); var mappings = parse('AAAA;AACA;AACA;AACA;AACA'); console.log(mappings); parse-base64vlq-mappings-0.1.4/index.js000066400000000000000000000046441216567225100177330ustar00rootroot00000000000000'use strict'; /* * Copyright 2011 Mozilla Foundation and contributors * Licensed under the New BSD license. See LICENSE or: * http://opensource.org/licenses/BSD-3-Clause */ var base64VLQ = require('./base64-vlq'); module.exports = function parse(str_) { var generatedLine = 1 , previousGeneratedColumn = 0 , previousOriginalLine = 0 , previousOriginalColumn = 0 , mappingSeparator = /^[,;]/ , mappings = [] , str = str_ , mapping , temp; while (str.length > 0) { if (str.charAt(0) === ';') { generatedLine++; str = str.slice(1); previousGeneratedColumn = 0; } else if (str.charAt(0) === ',') { str = str.slice(1); } else { mapping = { generated: { } }; mapping.generated.line = generatedLine; // Generated column. temp = base64VLQ.decode(str); mapping.generated.column = previousGeneratedColumn + temp.value; previousGeneratedColumn = mapping.generated.column; str = temp.rest; if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) { // Original source. temp = base64VLQ.decode(str); str = temp.rest; if (str.length === 0 || mappingSeparator.test(str.charAt(0))) { throw new Error('Found a source, but no line and column'); } // Original line. temp = base64VLQ.decode(str); mapping.original = { }; mapping.original.line = previousOriginalLine + temp.value; previousOriginalLine = mapping.original.line; // Lines are stored 0-based mapping.original.line += 1; str = temp.rest; if (str.length === 0 || mappingSeparator.test(str.charAt(0))) { throw new Error('Found a source and line, but no column'); } // Original column. temp = base64VLQ.decode(str); mapping.original.column = previousOriginalColumn + temp.value; previousOriginalColumn = mapping.original.column; str = temp.rest; // XXX: all name information is currently lost which may not be desirable /*if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) { // Original name. temp = base64VLQ.decode(str); mapping.name = this._names.at(previousName + temp.value); previousName += temp.value; str = temp.rest; }*/ } mappings.push(mapping); } } return mappings; }; parse-base64vlq-mappings-0.1.4/package.json000066400000000000000000000013401216567225100205420ustar00rootroot00000000000000{ "name": "parse-base64vlq-mappings", "version": "0.1.4", "description": "Parses out base64 VLQ encoded mappings.", "main": "index.js", "scripts": { "test": "tap test/*.js" }, "repository": { "type": "git", "url": "git://github.com/thlorenz/parse-base64vlq-mappings.git" }, "homepage": "https://github.com/thlorenz/parse-base64vlq-mappings", "dependencies": {}, "devDependencies": { "source-map": "~0.1.9", "tap": "~0.4.3" }, "keywords": [ "base64", "vlq", "parse", "sourcemap", "mappings" ], "author": { "name": "Thorsten Lorenz", "email": "thlorenz@gmx.de", "url": "http://thlorenz.com" }, "license": "MIT", "engine": { "node": ">=0.6" } } parse-base64vlq-mappings-0.1.4/test/000077500000000000000000000000001216567225100172355ustar00rootroot00000000000000parse-base64vlq-mappings-0.1.4/test/parse-base64vlq-mappings.js000066400000000000000000000045311216567225100243310ustar00rootroot00000000000000'use strict'; /*jshint asi: true */ var test = require('tap').test , parse = require('..') , Generator = require('source-map').SourceMapGenerator test('parsing generated one to one mappings with last line having no original', function (t) { var gen = new Generator({ file: 'foo.js' }) var add = [ { generated: { line: 1, column: 0 }, original: { line: 1, column: 0 }, source: 'foo.js', name: null }, { generated: { line: 2, column: 0 }, original: { line: 2, column: 0 }, source: 'foo.js', name: null }, { generated: { line: 3, column: 0 }, original: { line: 3, column: 0 }, source: 'foo.js', name: null }, { generated: { line: 4, column: 0 }, original: { line: 4, column: 0 }, source: 'foo.js', name: null }, { generated: { line: 5, column: 0 }, original: { line: 5, column: 0 }, source: 'foo.js', name: null }, { generated: { line: 6, column: 0 } } ] add.forEach(gen.addMapping.bind(gen)) var addedMappings = add.map(function (m) { return m.original ? { generated: m.generated, original: m.original } : { generated: m.generated } }) var mappings = gen.toJSON().mappings , parsed = parse(mappings) t.deepEqual(parsed, addedMappings, 'parses out added mappings') t.end() }); test('parsing generated offset mappings with last line having no original', function (t) { var gen = new Generator({ file: 'foo.js' }) var add = [ { generated: { line: 21, column: 0 }, original: { line: 1, column: 0 }, source: 'foo.js', name: null }, { generated: { line: 22, column: 3 }, original: { line: 2, column: 0 }, source: 'foo.js', name: null }, { generated: { line: 23, column: 0 }, original: { line: 3, column: 2 }, source: 'foo.js', name: null }, { generated: { line: 24, column: 0 }, original: { line: 4, column: 5 }, source: 'foo.js', name: null }, { generated: { line: 25, column: 0 } } ] add.forEach(gen.addMapping.bind(gen)) var addedMappings = add.map(function (m) { return m.original ? { generated: m.generated, original: m.original } : { generated: m.generated } }) var mappings = gen.toJSON().mappings , parsed = parse(mappings) t.deepEqual(parsed, addedMappings, 'parses out added mappings') t.end() });