Comparing version 0.6.1 to 0.6.2
@@ -17,3 +17,3 @@ #!/usr/bin/env node | ||
d: 'datauri', | ||
x: 'exclude' | ||
x: 'excludeContent' | ||
} | ||
@@ -20,0 +20,0 @@ }); |
# changelog | ||
## 0.6.2 | ||
* Handle segments of length 1 (normal segments have a length of 4 or 5) ([#10](https://github.com/Rich-Harris/sorcery/issues/10)) | ||
* Fix `excludeContent` CLI option ([#12](https://github.com/Rich-Harris/sorcery/pull/12)) | ||
* Fix `sources` array on Windows ([#11](https://github.com/Rich-Harris/sorcery/pull/11)) | ||
## 0.6.1 | ||
@@ -4,0 +10,0 @@ |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var path = require('path'); | ||
var vlq = require('vlq'); | ||
var crc32 = require('buffer-crc32'); | ||
@@ -26,8 +25,21 @@ crc32 = 'default' in crc32 ? crc32['default'] : crc32; | ||
'\\/\\*#?\\s*' + SOURCEMAPPING_URL + '=([^\'"]+)\\s\\*\\/)') + // css | ||
'\\s*$', 'g'); // js | ||
'\\s*$', 'g'); | ||
function slash(path) { | ||
if (typeof path === 'string') return path.replace(/\\/g, '/'); | ||
return path; | ||
} | ||
/** | ||
* Encodes a string as base64 | ||
* @param {string} str - the string to encode | ||
* @returns {string} | ||
*/ | ||
function btoa(str) { | ||
return new Buffer(str).toString('base64'); | ||
}var __classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; | ||
} | ||
function __classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var SourceMap = (function () { | ||
@@ -57,2 +69,49 @@ function SourceMap(properties) { | ||
var integerToChar = {}; | ||
var charToInteger = {}; | ||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) { | ||
charToInteger[ char ] = i; | ||
integerToChar[ i ] = char; | ||
}); | ||
function encodeInteger ( num ) { | ||
var result = '', clamped; | ||
if ( num < 0 ) { | ||
num = ( -num << 1 ) | 1; | ||
} else { | ||
num <<= 1; | ||
} | ||
do { | ||
clamped = num & 31; | ||
num >>= 5; | ||
if ( num > 0 ) { | ||
clamped |= 32; | ||
} | ||
result += integerToChar[ clamped ]; | ||
} while ( num > 0 ); | ||
return result; | ||
} | ||
function encode ( value ) { | ||
var result, i; | ||
if ( typeof value === 'number' ) { | ||
result = encodeInteger( value ); | ||
} else { | ||
result = ''; | ||
for ( i = 0; i < value.length; i += 1 ) { | ||
result += encodeInteger( value[i] ); | ||
} | ||
} | ||
return result; | ||
} | ||
function encodeMappings(decoded) { | ||
@@ -100,3 +159,3 @@ var offsets = { | ||
return vlq.encode(result); | ||
return encode(result); | ||
} | ||
@@ -111,3 +170,3 @@ } | ||
var ___classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };// css | ||
function ___classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
@@ -145,2 +204,4 @@ var Chain = (function () { | ||
var applySegment = function (segment, result) { | ||
if (segment.length < 4) return; | ||
var traced = _this.node.sources[segment[1]].trace( // source | ||
@@ -211,3 +272,3 @@ segment[2], // source code line | ||
sources: allSources.map(function (source) { | ||
return path.relative(options.base || path.dirname(_this.node.file), source); | ||
return slash(path.relative(options.base || path.dirname(_this.node.file), source)); | ||
}), | ||
@@ -254,3 +315,3 @@ sourcesContent: allSources.map(function (source) { | ||
return Chain; | ||
})(); // source | ||
})(); | ||
@@ -263,2 +324,40 @@ function resolveSourcePath(node, sourceRoot, source) { | ||
function decode ( string ) { | ||
var result = [], | ||
len = string.length, | ||
i, | ||
hasContinuationBit, | ||
shift = 0, | ||
value = 0, | ||
integer, | ||
shouldNegate; | ||
for ( i = 0; i < len; i += 1 ) { | ||
integer = charToInteger[ string[i] ]; | ||
if ( integer === undefined ) { | ||
throw new Error( 'Invalid character (' + string[i] + ')' ); | ||
} | ||
hasContinuationBit = integer & 32; | ||
integer &= 31; | ||
value += integer << shift; | ||
if ( hasContinuationBit ) { | ||
shift += 5; | ||
} else { | ||
shouldNegate = value & 1; | ||
value >>= 1; | ||
result.push( shouldNegate ? -value : value ); | ||
// reset | ||
value = shift = 0; | ||
} | ||
} | ||
return result; | ||
} | ||
function decodeSegments(encodedSegments) { | ||
@@ -269,3 +368,3 @@ var i = encodedSegments.length; | ||
while (i--) { | ||
segments[i] = vlq.decode(encodedSegments[i]); | ||
segments[i] = decode(encodedSegments[i]); | ||
} | ||
@@ -343,5 +442,23 @@ | ||
/** | ||
* Decodes a base64 string | ||
* @param {string} base64 - the string to decode | ||
* @returns {string} | ||
*/ | ||
function atob(base64) { | ||
return new Buffer(base64, 'base64').toString('utf8'); | ||
} | ||
/** | ||
* Turns a sourceMappingURL into a sourcemap | ||
* @param {string} url - the URL (i.e. sourceMappingURL=url). Can | ||
be a base64-encoded data URI | ||
* @param {string} base - the URL against which relative URLS | ||
should be resolved | ||
* @param {boolean} sync - if `true`, return a promise, otherwise | ||
return the sourcemap | ||
* @returns {object} - a version 3 sourcemap | ||
*/ | ||
function getMapFromUrl(url, base, sync) { | ||
@@ -393,2 +510,3 @@ if (/^data:/.test(url)) { | ||
} | ||
function getMap(node, sourceMapByPath, sync) { | ||
@@ -422,3 +540,3 @@ if (node.file in sourceMapByPath) { | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
@@ -565,2 +683,4 @@ var Node = (function () { | ||
if (generatedCodeColumn === columnIndex) { | ||
if (segments[i].length < 4) return null; | ||
var _sourceFileIndex = segments[i][1]; | ||
@@ -587,8 +707,29 @@ var _sourceCodeLine = segments[i][2]; | ||
return Node; | ||
})(); // sometimes exists in sourcesContent, sometimes doesn't | ||
})(); | ||
function load(file, options) { | ||
var _init = init(file, options); | ||
var node = _init.node; | ||
var sourcesContentByPath = _init.sourcesContentByPath; | ||
var sourceMapByPath = _init.sourceMapByPath; | ||
return node.load(sourcesContentByPath, sourceMapByPath).then(function () { | ||
return node.isOriginalSource ? null : new Chain(node, sourcesContentByPath); | ||
}); | ||
} | ||
function loadSync(file) { | ||
var options = arguments[1] === undefined ? {} : arguments[1]; | ||
var _init2 = init(file, options); | ||
var node = _init2.node; | ||
var sourcesContentByPath = _init2.sourcesContentByPath; | ||
var sourceMapByPath = _init2.sourceMapByPath; | ||
node.loadSync(sourcesContentByPath, sourceMapByPath); | ||
return node.isOriginalSource ? null : new Chain(node, sourcesContentByPath); | ||
} | ||
function init(file) { | ||
@@ -616,29 +757,4 @@ var options = arguments[1] === undefined ? {} : arguments[1]; | ||
} | ||
function load(file, options) { | ||
var _init = init(file, options); | ||
var node = _init.node; | ||
var sourcesContentByPath = _init.sourcesContentByPath; | ||
var sourceMapByPath = _init.sourceMapByPath; | ||
return node.load(sourcesContentByPath, sourceMapByPath).then(function () { | ||
return node.isOriginalSource ? null : new Chain(node, sourcesContentByPath); | ||
}); | ||
} | ||
function loadSync(file) { | ||
var options = arguments[1] === undefined ? {} : arguments[1]; | ||
var _init2 = init(file, options); | ||
var node = _init2.node; | ||
var sourcesContentByPath = _init2.sourcesContentByPath; | ||
var sourceMapByPath = _init2.sourceMapByPath; | ||
node.loadSync(sourcesContentByPath, sourceMapByPath); | ||
return node.isOriginalSource ? null : new Chain(node, sourcesContentByPath); | ||
} | ||
exports.load = load; | ||
exports.loadSync = loadSync; | ||
//# sourceMappingURL=sorcery.js.map | ||
exports.loadSync = loadSync; |
{ | ||
"name": "sorcery", | ||
"description": "Resolve a chain of sourcemaps back to the original source", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"author": "Rich Harris", | ||
@@ -24,3 +24,3 @@ "repository": "https://github.com/Rich-Harris/sorcery", | ||
"gobble-cli": "^0.4.2", | ||
"gobble-rollup": "^0.1.1", | ||
"gobble-rollup": "^0.3.0", | ||
"less": "^2.5.0", | ||
@@ -27,0 +27,0 @@ "mocha": "^2.1.0", |
@@ -5,2 +5,3 @@ import { basename, dirname, extname, relative, resolve } from 'path'; | ||
import encodeMappings from './utils/encodeMappings'; | ||
import slash from './utils/slash'; | ||
@@ -40,2 +41,4 @@ let SOURCEMAPPING_URL = 'sourceMa'; | ||
const applySegment = ( segment, result ) => { | ||
if ( segment.length < 4 ) return; | ||
const traced = this.node.sources[ segment[1] ].trace( // source | ||
@@ -108,3 +111,3 @@ segment[2], // source code line | ||
file: basename( this.node.file ), | ||
sources: allSources.map( source => relative( options.base || dirname( this.node.file ), source ) ), | ||
sources: allSources.map( source => slash( relative( options.base || dirname( this.node.file ), source ) ) ), | ||
sourcesContent: allSources.map( source => includeContent ? this.sourcesContentByPath[ source ] : null ), | ||
@@ -163,2 +166,2 @@ names: allNames, | ||
return `\n//# ${SOURCEMAPPING_URL}=${url}\n`; | ||
} | ||
} |
@@ -134,2 +134,4 @@ import { dirname, resolve } from 'path'; | ||
if ( generatedCodeColumn === columnIndex ) { | ||
if ( segments[i].length < 4 ) return null; | ||
let sourceFileIndex = segments[i][1]; | ||
@@ -136,0 +138,0 @@ let sourceCodeLine = segments[i][2]; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1110
45938