sorcery
Advanced tools
Comparing version 0.10.0 to 0.11.0
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var path = require('path'); | ||
var sander = require('sander'); | ||
var charToInteger = {}; | ||
var integerToChar = {}; | ||
var __commonjs_global = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this; | ||
function __commonjs(fn, module) { return module = { exports: {} }, fn(module, module.exports, __commonjs_global), module.exports; } | ||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) { | ||
charToInteger[ char ] = i; | ||
integerToChar[ i ] = char; | ||
}); | ||
var sourcemapCodec_umd = __commonjs(function (module, exports, global) { | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.sourcemapCodec = {})); | ||
})(__commonjs_global, (function (exports) { 'use strict'; | ||
function decode$1 ( string ) { | ||
var result = [], | ||
len = string.length, | ||
i, | ||
hasContinuationBit, | ||
shift = 0, | ||
value = 0, | ||
integer, | ||
shouldNegate; | ||
const comma = ','.charCodeAt(0); | ||
const semicolon = ';'.charCodeAt(0); | ||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | ||
const intToChar = new Uint8Array(64); // 64 possible chars. | ||
const charToInt = new Uint8Array(128); // z is 122 in ASCII | ||
for (let i = 0; i < chars.length; i++) { | ||
const c = chars.charCodeAt(i); | ||
intToChar[i] = c; | ||
charToInt[c] = i; | ||
} | ||
// Provide a fallback for older environments. | ||
const td = typeof TextDecoder !== 'undefined' | ||
? /* #__PURE__ */ new TextDecoder() | ||
: typeof Buffer !== 'undefined' | ||
? { | ||
decode(buf) { | ||
const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength); | ||
return out.toString(); | ||
}, | ||
} | ||
: { | ||
decode(buf) { | ||
let out = ''; | ||
for (let i = 0; i < buf.length; i++) { | ||
out += String.fromCharCode(buf[i]); | ||
} | ||
return out; | ||
}, | ||
}; | ||
function decode(mappings) { | ||
const state = new Int32Array(5); | ||
const decoded = []; | ||
let index = 0; | ||
do { | ||
const semi = indexOf(mappings, index); | ||
const line = []; | ||
let sorted = true; | ||
let lastCol = 0; | ||
state[0] = 0; | ||
for (let i = index; i < semi; i++) { | ||
let seg; | ||
i = decodeInteger(mappings, i, state, 0); // genColumn | ||
const col = state[0]; | ||
if (col < lastCol) | ||
sorted = false; | ||
lastCol = col; | ||
if (hasMoreVlq(mappings, i, semi)) { | ||
i = decodeInteger(mappings, i, state, 1); // sourcesIndex | ||
i = decodeInteger(mappings, i, state, 2); // sourceLine | ||
i = decodeInteger(mappings, i, state, 3); // sourceColumn | ||
if (hasMoreVlq(mappings, i, semi)) { | ||
i = decodeInteger(mappings, i, state, 4); // namesIndex | ||
seg = [col, state[1], state[2], state[3], state[4]]; | ||
} | ||
else { | ||
seg = [col, state[1], state[2], state[3]]; | ||
} | ||
} | ||
else { | ||
seg = [col]; | ||
} | ||
line.push(seg); | ||
} | ||
if (!sorted) | ||
sort(line); | ||
decoded.push(line); | ||
index = semi + 1; | ||
} while (index <= mappings.length); | ||
return decoded; | ||
} | ||
function indexOf(mappings, index) { | ||
const idx = mappings.indexOf(';', index); | ||
return idx === -1 ? mappings.length : idx; | ||
} | ||
function decodeInteger(mappings, pos, state, j) { | ||
let value = 0; | ||
let shift = 0; | ||
let integer = 0; | ||
do { | ||
const c = mappings.charCodeAt(pos++); | ||
integer = charToInt[c]; | ||
value |= (integer & 31) << shift; | ||
shift += 5; | ||
} while (integer & 32); | ||
const shouldNegate = value & 1; | ||
value >>>= 1; | ||
if (shouldNegate) { | ||
value = -0x80000000 | -value; | ||
} | ||
state[j] += value; | ||
return pos; | ||
} | ||
function hasMoreVlq(mappings, i, length) { | ||
if (i >= length) | ||
return false; | ||
return mappings.charCodeAt(i) !== comma; | ||
} | ||
function sort(line) { | ||
line.sort(sortComparator); | ||
} | ||
function sortComparator(a, b) { | ||
return a[0] - b[0]; | ||
} | ||
function encode(decoded) { | ||
const state = new Int32Array(5); | ||
const bufLength = 1024 * 16; | ||
const subLength = bufLength - 36; | ||
const buf = new Uint8Array(bufLength); | ||
const sub = buf.subarray(0, subLength); | ||
let pos = 0; | ||
let out = ''; | ||
for (let i = 0; i < decoded.length; i++) { | ||
const line = decoded[i]; | ||
if (i > 0) { | ||
if (pos === bufLength) { | ||
out += td.decode(buf); | ||
pos = 0; | ||
} | ||
buf[pos++] = semicolon; | ||
} | ||
if (line.length === 0) | ||
continue; | ||
state[0] = 0; | ||
for (let j = 0; j < line.length; j++) { | ||
const segment = line[j]; | ||
// We can push up to 5 ints, each int can take at most 7 chars, and we | ||
// may push a comma. | ||
if (pos > subLength) { | ||
out += td.decode(sub); | ||
buf.copyWithin(0, subLength, pos); | ||
pos -= subLength; | ||
} | ||
if (j > 0) | ||
buf[pos++] = comma; | ||
pos = encodeInteger(buf, pos, state, segment, 0); // genColumn | ||
if (segment.length === 1) | ||
continue; | ||
pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex | ||
pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine | ||
pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn | ||
if (segment.length === 4) | ||
continue; | ||
pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex | ||
} | ||
} | ||
return out + td.decode(buf.subarray(0, pos)); | ||
} | ||
function encodeInteger(buf, pos, state, segment, j) { | ||
const next = segment[j]; | ||
let num = next - state[j]; | ||
state[j] = next; | ||
num = num < 0 ? (-num << 1) | 1 : num << 1; | ||
do { | ||
let clamped = num & 0b011111; | ||
num >>>= 5; | ||
if (num > 0) | ||
clamped |= 0b100000; | ||
buf[pos++] = intToChar[clamped]; | ||
} while (num > 0); | ||
return pos; | ||
} | ||
for ( i = 0; i < len; i += 1 ) { | ||
integer = charToInteger[ string[i] ]; | ||
exports.decode = decode; | ||
exports.encode = encode; | ||
if ( integer === undefined ) { | ||
throw new Error( 'Invalid character (' + string[i] + ')' ); | ||
} | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
hasContinuationBit = integer & 32; | ||
})); | ||
}); | ||
integer &= 31; | ||
value += integer << shift; | ||
var codec = (sourcemapCodec_umd && typeof sourcemapCodec_umd === 'object' && 'default' in sourcemapCodec_umd ? sourcemapCodec_umd['default'] : sourcemapCodec_umd); | ||
if ( hasContinuationBit ) { | ||
shift += 5; | ||
} else { | ||
shouldNegate = value & 1; | ||
value >>= 1; | ||
result.push( shouldNegate ? -value : value ); | ||
// reset | ||
value = shift = 0; | ||
} | ||
} | ||
return result; | ||
} | ||
function encode$1 ( 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 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 decodeSegments(encodedSegments) { | ||
var i = encodedSegments.length; | ||
var segments = new Array(i); | ||
while (i--) { | ||
segments[i] = decode$1(encodedSegments[i]); | ||
}return segments; | ||
} | ||
function decode(mappings) { | ||
var sourceFileIndex = 0; // second field | ||
var sourceCodeLine = 0; // third field | ||
var sourceCodeColumn = 0; // fourth field | ||
var nameIndex = 0; // fifth field | ||
var lines = mappings.split(';'); | ||
var numLines = lines.length; | ||
var decoded = new Array(numLines); | ||
var i = undefined; | ||
var j = undefined; | ||
var line = undefined; | ||
var generatedCodeColumn = undefined; | ||
var decodedLine = undefined; | ||
var segments = undefined; | ||
var segment = undefined; | ||
var result = undefined; | ||
for (i = 0; i < numLines; i += 1) { | ||
line = lines[i]; | ||
generatedCodeColumn = 0; // first field - reset each time | ||
decodedLine = []; | ||
segments = decodeSegments(line.split(',')); | ||
for (j = 0; j < segments.length; j += 1) { | ||
segment = segments[j]; | ||
if (!segment.length) { | ||
break; | ||
} | ||
generatedCodeColumn += segment[0]; | ||
result = [generatedCodeColumn]; | ||
decodedLine.push(result); | ||
if (segment.length === 1) { | ||
// only one field! | ||
continue; | ||
} | ||
sourceFileIndex += segment[1]; | ||
sourceCodeLine += segment[2]; | ||
sourceCodeColumn += segment[3]; | ||
result.push(sourceFileIndex, sourceCodeLine, sourceCodeColumn); | ||
if (segment.length === 5) { | ||
nameIndex += segment[4]; | ||
result.push(nameIndex); | ||
} | ||
} | ||
decoded[i] = decodedLine; | ||
} | ||
return decoded; | ||
} | ||
function encode(decoded) { | ||
var offsets = { | ||
generatedCodeColumn: 0, | ||
sourceFileIndex: 0, // second field | ||
sourceCodeLine: 0, // third field | ||
sourceCodeColumn: 0, // fourth field | ||
nameIndex: 0 // fifth field | ||
}; | ||
return decoded.map(function (line) { | ||
offsets.generatedCodeColumn = 0; // first field - reset each time | ||
return line.map(encodeSegment).join(','); | ||
}).join(';'); | ||
function encodeSegment(segment) { | ||
if (!segment.length) { | ||
return segment; | ||
} | ||
var result = new Array(segment.length); | ||
result[0] = segment[0] - offsets.generatedCodeColumn; | ||
offsets.generatedCodeColumn = segment[0]; | ||
if (segment.length === 1) { | ||
// only one field! | ||
return encode$1(result); | ||
} | ||
result[1] = segment[1] - offsets.sourceFileIndex; | ||
result[2] = segment[2] - offsets.sourceCodeLine; | ||
result[3] = segment[3] - offsets.sourceCodeColumn; | ||
offsets.sourceFileIndex = segment[1]; | ||
offsets.sourceCodeLine = segment[2]; | ||
offsets.sourceCodeColumn = segment[3]; | ||
if (segment.length === 5) { | ||
result[4] = segment[4] - offsets.nameIndex; | ||
offsets.nameIndex = segment[4]; | ||
} | ||
return encode$1(result); | ||
} | ||
} | ||
/** | ||
@@ -246,3 +229,3 @@ * Decodes a base64 string | ||
if ( !match ) { | ||
throw new Error( ("" + SOURCEMAPPING_URL$1 + " is not base64-encoded") ); | ||
throw new Error( (SOURCEMAPPING_URL$1 + " is not base64-encoded") ); | ||
} | ||
@@ -260,3 +243,3 @@ | ||
} else { | ||
return sander.readFile( url, { encoding: 'utf-8' }).then( function ( json ) { return parseJSON( json, url ); } ); | ||
return sander.readFile( url, { encoding: 'utf-8' }).then( function (json) { return parseJSON( json, url ); } ); | ||
} | ||
@@ -269,3 +252,3 @@ } | ||
// assume we want the last occurence | ||
index = str.lastIndexOf( ("" + SOURCEMAPPING_URL$1 + "=") ); | ||
index = str.lastIndexOf( (SOURCEMAPPING_URL$1 + "=") ); | ||
@@ -338,6 +321,6 @@ if ( index === -1 ) { | ||
return getContent( this, sourcesContentByPath ).then( function ( content ) { | ||
return getContent( this, sourcesContentByPath ).then( function (content) { | ||
this$1.content = sourcesContentByPath[ this$1.file ] = content; | ||
return getMap( this$1, sourceMapByPath ).then( function ( map ) { | ||
return getMap( this$1, sourceMapByPath ).then( function (map) { | ||
if ( !map ) return null; | ||
@@ -348,3 +331,3 @@ | ||
var decodingStart = process.hrtime(); | ||
this$1.mappings = decode( map.mappings ); | ||
this$1.mappings = codec.decode( map.mappings ); | ||
var decodingTime = process.hrtime( decodingStart ); | ||
@@ -364,3 +347,3 @@ this$1._stats.decodingTime = 1e9 * decodingTime[0] + decodingTime[1]; | ||
var promises = this$1.sources.map( function ( node ) { return node.load( sourcesContentByPath, sourceMapByPath ); } ); | ||
var promises = this$1.sources.map( function (node) { return node.load( sourcesContentByPath, sourceMapByPath ); } ); | ||
return sander.Promise.all( promises ); | ||
@@ -387,3 +370,3 @@ }); | ||
this.map = map; | ||
this.mappings = decode( map.mappings ); | ||
this.mappings = codec.decode( map.mappings ); | ||
@@ -422,6 +405,6 @@ sourcesContent = map.sourcesContent || []; | ||
trace: function trace ( lineIndex, columnIndex, name ) { | ||
var this$1 = this; | ||
// If this node doesn't have a source map, we have | ||
// to assume it is the original source | ||
var this$1 = this; | ||
if ( this.isOriginalSource ) { | ||
@@ -620,3 +603,3 @@ return { | ||
var encodingStart = process.hrtime(); | ||
var mappings = encode( resolved ); | ||
var mappings = codec.encode( resolved ); | ||
var encodingTime = process.hrtime( encodingStart ); | ||
@@ -629,4 +612,4 @@ this._stats.encodingTime = 1e9 * encodingTime[0] + encodingTime[1]; | ||
file: path.basename( this.node.file ), | ||
sources: allSources.map( function ( source ) { return slash( path.relative( options.base || path.dirname( this$1.node.file ), source ) ); } ), | ||
sourcesContent: allSources.map( function ( source ) { return includeContent ? this$1.sourcesContentByPath[ source ] : null; } ), | ||
sources: allSources.map( function (source) { return slash( path.relative( options.base || path.dirname( this$1.node.file ), source ) ); } ), | ||
sourcesContent: allSources.map( function (source) { return includeContent ? this$1.sourcesContentByPath[ source ] : null; } ), | ||
names: allNames, | ||
@@ -649,3 +632,6 @@ mappings: mappings | ||
var ref = processWriteOptions( dest, this, options ), resolved = ref.resolved, content = ref.content, map = ref.map; | ||
var ref = processWriteOptions( dest, this, options ); | ||
var resolved = ref.resolved; | ||
var content = ref.content; | ||
var map = ref.map; | ||
@@ -669,3 +655,6 @@ var promises = [ sander.writeFile( resolved, content ) ]; | ||
var ref = processWriteOptions( dest, this, options ), resolved = ref.resolved, content = ref.content, map = ref.map; | ||
var ref = processWriteOptions( dest, this, options ); | ||
var resolved = ref.resolved; | ||
var content = ref.content; | ||
var map = ref.map; | ||
@@ -714,3 +703,6 @@ sander.writeFileSync( resolved, content ); | ||
function load ( file, options ) { | ||
var ref = init( file, options ), node = ref.node, sourcesContentByPath = ref.sourcesContentByPath, sourceMapByPath = ref.sourceMapByPath; | ||
var ref = init( file, options ); | ||
var node = ref.node; | ||
var sourcesContentByPath = ref.sourcesContentByPath; | ||
var sourceMapByPath = ref.sourceMapByPath; | ||
@@ -724,3 +716,6 @@ return node.load( sourcesContentByPath, sourceMapByPath ) | ||
var ref = init( file, options ), node = ref.node, sourcesContentByPath = ref.sourcesContentByPath, sourceMapByPath = ref.sourceMapByPath; | ||
var ref = init( file, options ); | ||
var node = ref.node; | ||
var sourcesContentByPath = ref.sourcesContentByPath; | ||
var sourceMapByPath = ref.sourceMapByPath; | ||
@@ -740,3 +735,3 @@ node.loadSync( sourcesContentByPath, sourceMapByPath ); | ||
if ( options.content ) { | ||
Object.keys( options.content ).forEach( function ( key ) { | ||
Object.keys( options.content ).forEach( function (key) { | ||
sourcesContentByPath[ path.resolve( key ) ] = options.content[ key ]; | ||
@@ -747,3 +742,3 @@ }); | ||
if ( options.sourcemaps ) { | ||
Object.keys( options.sourcemaps ).forEach( function ( key ) { | ||
Object.keys( options.sourcemaps ).forEach( function (key) { | ||
sourceMapByPath[ path.resolve( key ) ] = options.sourcemaps[ key ]; | ||
@@ -750,0 +745,0 @@ }); |
import { resolve, dirname, relative, basename, extname } from 'path'; | ||
import { readFileSync, Promise, readFile, writeFileSync, writeFile } from 'sander'; | ||
import { readFileSync, Promise as Promise$1, readFile, writeFileSync, writeFile } from 'sander'; | ||
var charToInteger = {}; | ||
var integerToChar = {}; | ||
var __commonjs_global = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this; | ||
function __commonjs(fn, module) { return module = { exports: {} }, fn(module, module.exports, __commonjs_global), module.exports; } | ||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) { | ||
charToInteger[ char ] = i; | ||
integerToChar[ i ] = char; | ||
}); | ||
var sourcemapCodec_umd = __commonjs(function (module, exports, global) { | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.sourcemapCodec = {})); | ||
})(__commonjs_global, (function (exports) { 'use strict'; | ||
function decode$1 ( string ) { | ||
var result = [], | ||
len = string.length, | ||
i, | ||
hasContinuationBit, | ||
shift = 0, | ||
value = 0, | ||
integer, | ||
shouldNegate; | ||
const comma = ','.charCodeAt(0); | ||
const semicolon = ';'.charCodeAt(0); | ||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | ||
const intToChar = new Uint8Array(64); // 64 possible chars. | ||
const charToInt = new Uint8Array(128); // z is 122 in ASCII | ||
for (let i = 0; i < chars.length; i++) { | ||
const c = chars.charCodeAt(i); | ||
intToChar[i] = c; | ||
charToInt[c] = i; | ||
} | ||
// Provide a fallback for older environments. | ||
const td = typeof TextDecoder !== 'undefined' | ||
? /* #__PURE__ */ new TextDecoder() | ||
: typeof Buffer !== 'undefined' | ||
? { | ||
decode(buf) { | ||
const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength); | ||
return out.toString(); | ||
}, | ||
} | ||
: { | ||
decode(buf) { | ||
let out = ''; | ||
for (let i = 0; i < buf.length; i++) { | ||
out += String.fromCharCode(buf[i]); | ||
} | ||
return out; | ||
}, | ||
}; | ||
function decode(mappings) { | ||
const state = new Int32Array(5); | ||
const decoded = []; | ||
let index = 0; | ||
do { | ||
const semi = indexOf(mappings, index); | ||
const line = []; | ||
let sorted = true; | ||
let lastCol = 0; | ||
state[0] = 0; | ||
for (let i = index; i < semi; i++) { | ||
let seg; | ||
i = decodeInteger(mappings, i, state, 0); // genColumn | ||
const col = state[0]; | ||
if (col < lastCol) | ||
sorted = false; | ||
lastCol = col; | ||
if (hasMoreVlq(mappings, i, semi)) { | ||
i = decodeInteger(mappings, i, state, 1); // sourcesIndex | ||
i = decodeInteger(mappings, i, state, 2); // sourceLine | ||
i = decodeInteger(mappings, i, state, 3); // sourceColumn | ||
if (hasMoreVlq(mappings, i, semi)) { | ||
i = decodeInteger(mappings, i, state, 4); // namesIndex | ||
seg = [col, state[1], state[2], state[3], state[4]]; | ||
} | ||
else { | ||
seg = [col, state[1], state[2], state[3]]; | ||
} | ||
} | ||
else { | ||
seg = [col]; | ||
} | ||
line.push(seg); | ||
} | ||
if (!sorted) | ||
sort(line); | ||
decoded.push(line); | ||
index = semi + 1; | ||
} while (index <= mappings.length); | ||
return decoded; | ||
} | ||
function indexOf(mappings, index) { | ||
const idx = mappings.indexOf(';', index); | ||
return idx === -1 ? mappings.length : idx; | ||
} | ||
function decodeInteger(mappings, pos, state, j) { | ||
let value = 0; | ||
let shift = 0; | ||
let integer = 0; | ||
do { | ||
const c = mappings.charCodeAt(pos++); | ||
integer = charToInt[c]; | ||
value |= (integer & 31) << shift; | ||
shift += 5; | ||
} while (integer & 32); | ||
const shouldNegate = value & 1; | ||
value >>>= 1; | ||
if (shouldNegate) { | ||
value = -0x80000000 | -value; | ||
} | ||
state[j] += value; | ||
return pos; | ||
} | ||
function hasMoreVlq(mappings, i, length) { | ||
if (i >= length) | ||
return false; | ||
return mappings.charCodeAt(i) !== comma; | ||
} | ||
function sort(line) { | ||
line.sort(sortComparator); | ||
} | ||
function sortComparator(a, b) { | ||
return a[0] - b[0]; | ||
} | ||
function encode(decoded) { | ||
const state = new Int32Array(5); | ||
const bufLength = 1024 * 16; | ||
const subLength = bufLength - 36; | ||
const buf = new Uint8Array(bufLength); | ||
const sub = buf.subarray(0, subLength); | ||
let pos = 0; | ||
let out = ''; | ||
for (let i = 0; i < decoded.length; i++) { | ||
const line = decoded[i]; | ||
if (i > 0) { | ||
if (pos === bufLength) { | ||
out += td.decode(buf); | ||
pos = 0; | ||
} | ||
buf[pos++] = semicolon; | ||
} | ||
if (line.length === 0) | ||
continue; | ||
state[0] = 0; | ||
for (let j = 0; j < line.length; j++) { | ||
const segment = line[j]; | ||
// We can push up to 5 ints, each int can take at most 7 chars, and we | ||
// may push a comma. | ||
if (pos > subLength) { | ||
out += td.decode(sub); | ||
buf.copyWithin(0, subLength, pos); | ||
pos -= subLength; | ||
} | ||
if (j > 0) | ||
buf[pos++] = comma; | ||
pos = encodeInteger(buf, pos, state, segment, 0); // genColumn | ||
if (segment.length === 1) | ||
continue; | ||
pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex | ||
pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine | ||
pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn | ||
if (segment.length === 4) | ||
continue; | ||
pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex | ||
} | ||
} | ||
return out + td.decode(buf.subarray(0, pos)); | ||
} | ||
function encodeInteger(buf, pos, state, segment, j) { | ||
const next = segment[j]; | ||
let num = next - state[j]; | ||
state[j] = next; | ||
num = num < 0 ? (-num << 1) | 1 : num << 1; | ||
do { | ||
let clamped = num & 0b011111; | ||
num >>>= 5; | ||
if (num > 0) | ||
clamped |= 0b100000; | ||
buf[pos++] = intToChar[clamped]; | ||
} while (num > 0); | ||
return pos; | ||
} | ||
for ( i = 0; i < len; i += 1 ) { | ||
integer = charToInteger[ string[i] ]; | ||
exports.decode = decode; | ||
exports.encode = encode; | ||
if ( integer === undefined ) { | ||
throw new Error( 'Invalid character (' + string[i] + ')' ); | ||
} | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
hasContinuationBit = integer & 32; | ||
})); | ||
}); | ||
integer &= 31; | ||
value += integer << shift; | ||
var codec = (sourcemapCodec_umd && typeof sourcemapCodec_umd === 'object' && 'default' in sourcemapCodec_umd ? sourcemapCodec_umd['default'] : sourcemapCodec_umd); | ||
if ( hasContinuationBit ) { | ||
shift += 5; | ||
} else { | ||
shouldNegate = value & 1; | ||
value >>= 1; | ||
result.push( shouldNegate ? -value : value ); | ||
// reset | ||
value = shift = 0; | ||
} | ||
} | ||
return result; | ||
} | ||
function encode$1 ( 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 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 decodeSegments(encodedSegments) { | ||
var i = encodedSegments.length; | ||
var segments = new Array(i); | ||
while (i--) { | ||
segments[i] = decode$1(encodedSegments[i]); | ||
}return segments; | ||
} | ||
function decode(mappings) { | ||
var sourceFileIndex = 0; // second field | ||
var sourceCodeLine = 0; // third field | ||
var sourceCodeColumn = 0; // fourth field | ||
var nameIndex = 0; // fifth field | ||
var lines = mappings.split(';'); | ||
var numLines = lines.length; | ||
var decoded = new Array(numLines); | ||
var i = undefined; | ||
var j = undefined; | ||
var line = undefined; | ||
var generatedCodeColumn = undefined; | ||
var decodedLine = undefined; | ||
var segments = undefined; | ||
var segment = undefined; | ||
var result = undefined; | ||
for (i = 0; i < numLines; i += 1) { | ||
line = lines[i]; | ||
generatedCodeColumn = 0; // first field - reset each time | ||
decodedLine = []; | ||
segments = decodeSegments(line.split(',')); | ||
for (j = 0; j < segments.length; j += 1) { | ||
segment = segments[j]; | ||
if (!segment.length) { | ||
break; | ||
} | ||
generatedCodeColumn += segment[0]; | ||
result = [generatedCodeColumn]; | ||
decodedLine.push(result); | ||
if (segment.length === 1) { | ||
// only one field! | ||
continue; | ||
} | ||
sourceFileIndex += segment[1]; | ||
sourceCodeLine += segment[2]; | ||
sourceCodeColumn += segment[3]; | ||
result.push(sourceFileIndex, sourceCodeLine, sourceCodeColumn); | ||
if (segment.length === 5) { | ||
nameIndex += segment[4]; | ||
result.push(nameIndex); | ||
} | ||
} | ||
decoded[i] = decodedLine; | ||
} | ||
return decoded; | ||
} | ||
function encode(decoded) { | ||
var offsets = { | ||
generatedCodeColumn: 0, | ||
sourceFileIndex: 0, // second field | ||
sourceCodeLine: 0, // third field | ||
sourceCodeColumn: 0, // fourth field | ||
nameIndex: 0 // fifth field | ||
}; | ||
return decoded.map(function (line) { | ||
offsets.generatedCodeColumn = 0; // first field - reset each time | ||
return line.map(encodeSegment).join(','); | ||
}).join(';'); | ||
function encodeSegment(segment) { | ||
if (!segment.length) { | ||
return segment; | ||
} | ||
var result = new Array(segment.length); | ||
result[0] = segment[0] - offsets.generatedCodeColumn; | ||
offsets.generatedCodeColumn = segment[0]; | ||
if (segment.length === 1) { | ||
// only one field! | ||
return encode$1(result); | ||
} | ||
result[1] = segment[1] - offsets.sourceFileIndex; | ||
result[2] = segment[2] - offsets.sourceCodeLine; | ||
result[3] = segment[3] - offsets.sourceCodeColumn; | ||
offsets.sourceFileIndex = segment[1]; | ||
offsets.sourceCodeLine = segment[2]; | ||
offsets.sourceCodeColumn = segment[3]; | ||
if (segment.length === 5) { | ||
result[4] = segment[4] - offsets.nameIndex; | ||
offsets.nameIndex = segment[4]; | ||
} | ||
return encode$1(result); | ||
} | ||
} | ||
/** | ||
@@ -244,3 +225,3 @@ * Decodes a base64 string | ||
if ( !match ) { | ||
throw new Error( ("" + SOURCEMAPPING_URL$1 + " is not base64-encoded") ); | ||
throw new Error( (SOURCEMAPPING_URL$1 + " is not base64-encoded") ); | ||
} | ||
@@ -258,3 +239,3 @@ | ||
} else { | ||
return readFile( url, { encoding: 'utf-8' }).then( function ( json ) { return parseJSON( json, url ); } ); | ||
return readFile( url, { encoding: 'utf-8' }).then( function (json) { return parseJSON( json, url ); } ); | ||
} | ||
@@ -267,3 +248,3 @@ } | ||
// assume we want the last occurence | ||
index = str.lastIndexOf( ("" + SOURCEMAPPING_URL$1 + "=") ); | ||
index = str.lastIndexOf( (SOURCEMAPPING_URL$1 + "=") ); | ||
@@ -336,6 +317,6 @@ if ( index === -1 ) { | ||
return getContent( this, sourcesContentByPath ).then( function ( content ) { | ||
return getContent( this, sourcesContentByPath ).then( function (content) { | ||
this$1.content = sourcesContentByPath[ this$1.file ] = content; | ||
return getMap( this$1, sourceMapByPath ).then( function ( map ) { | ||
return getMap( this$1, sourceMapByPath ).then( function (map) { | ||
if ( !map ) return null; | ||
@@ -346,3 +327,3 @@ | ||
var decodingStart = process.hrtime(); | ||
this$1.mappings = decode( map.mappings ); | ||
this$1.mappings = codec.decode( map.mappings ); | ||
var decodingTime = process.hrtime( decodingStart ); | ||
@@ -362,3 +343,3 @@ this$1._stats.decodingTime = 1e9 * decodingTime[0] + decodingTime[1]; | ||
var promises = this$1.sources.map( function ( node ) { return node.load( sourcesContentByPath, sourceMapByPath ); } ); | ||
var promises = this$1.sources.map( function (node) { return node.load( sourcesContentByPath, sourceMapByPath ); } ); | ||
return Promise$1.all( promises ); | ||
@@ -385,3 +366,3 @@ }); | ||
this.map = map; | ||
this.mappings = decode( map.mappings ); | ||
this.mappings = codec.decode( map.mappings ); | ||
@@ -420,6 +401,6 @@ sourcesContent = map.sourcesContent || []; | ||
trace: function trace ( lineIndex, columnIndex, name ) { | ||
var this$1 = this; | ||
// If this node doesn't have a source map, we have | ||
// to assume it is the original source | ||
var this$1 = this; | ||
if ( this.isOriginalSource ) { | ||
@@ -618,3 +599,3 @@ return { | ||
var encodingStart = process.hrtime(); | ||
var mappings = encode( resolved ); | ||
var mappings = codec.encode( resolved ); | ||
var encodingTime = process.hrtime( encodingStart ); | ||
@@ -627,4 +608,4 @@ this._stats.encodingTime = 1e9 * encodingTime[0] + encodingTime[1]; | ||
file: basename( this.node.file ), | ||
sources: allSources.map( function ( source ) { return slash( relative( options.base || dirname( this$1.node.file ), source ) ); } ), | ||
sourcesContent: allSources.map( function ( source ) { return includeContent ? this$1.sourcesContentByPath[ source ] : null; } ), | ||
sources: allSources.map( function (source) { return slash( relative( options.base || dirname( this$1.node.file ), source ) ); } ), | ||
sourcesContent: allSources.map( function (source) { return includeContent ? this$1.sourcesContentByPath[ source ] : null; } ), | ||
names: allNames, | ||
@@ -647,3 +628,6 @@ mappings: mappings | ||
var ref = processWriteOptions( dest, this, options ), resolved = ref.resolved, content = ref.content, map = ref.map; | ||
var ref = processWriteOptions( dest, this, options ); | ||
var resolved = ref.resolved; | ||
var content = ref.content; | ||
var map = ref.map; | ||
@@ -667,3 +651,6 @@ var promises = [ writeFile( resolved, content ) ]; | ||
var ref = processWriteOptions( dest, this, options ), resolved = ref.resolved, content = ref.content, map = ref.map; | ||
var ref = processWriteOptions( dest, this, options ); | ||
var resolved = ref.resolved; | ||
var content = ref.content; | ||
var map = ref.map; | ||
@@ -712,3 +699,6 @@ writeFileSync( resolved, content ); | ||
function load ( file, options ) { | ||
var ref = init( file, options ), node = ref.node, sourcesContentByPath = ref.sourcesContentByPath, sourceMapByPath = ref.sourceMapByPath; | ||
var ref = init( file, options ); | ||
var node = ref.node; | ||
var sourcesContentByPath = ref.sourcesContentByPath; | ||
var sourceMapByPath = ref.sourceMapByPath; | ||
@@ -722,3 +712,6 @@ return node.load( sourcesContentByPath, sourceMapByPath ) | ||
var ref = init( file, options ), node = ref.node, sourcesContentByPath = ref.sourcesContentByPath, sourceMapByPath = ref.sourceMapByPath; | ||
var ref = init( file, options ); | ||
var node = ref.node; | ||
var sourcesContentByPath = ref.sourcesContentByPath; | ||
var sourceMapByPath = ref.sourceMapByPath; | ||
@@ -738,3 +731,3 @@ node.loadSync( sourcesContentByPath, sourceMapByPath ); | ||
if ( options.content ) { | ||
Object.keys( options.content ).forEach( function ( key ) { | ||
Object.keys( options.content ).forEach( function (key) { | ||
sourcesContentByPath[ resolve( key ) ] = options.content[ key ]; | ||
@@ -745,3 +738,3 @@ }); | ||
if ( options.sourcemaps ) { | ||
Object.keys( options.sourcemaps ).forEach( function ( key ) { | ||
Object.keys( options.sourcemaps ).forEach( function (key) { | ||
sourceMapByPath[ resolve( key ) ] = options.sourcemaps[ key ]; | ||
@@ -748,0 +741,0 @@ }); |
107
package.json
{ | ||
"name": "sorcery", | ||
"description": "Resolve a chain of sourcemaps back to the original source", | ||
"version": "0.10.0", | ||
"author": "Rich Harris", | ||
"repository": "https://github.com/Rich-Harris/sorcery", | ||
"main": "dist/sorcery.cjs.js", | ||
"jsnext:main": "dist/sorcery.es6.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"buffer-crc32": "^0.2.5", | ||
"minimist": "^1.2.0", | ||
"sander": "^0.5.0", | ||
"sourcemap-codec": "^1.3.0" | ||
}, | ||
"devDependencies": { | ||
"buble": "^0.5.6", | ||
"codecov.io": "^0.1.6", | ||
"coffee-script": "^1.10.0", | ||
"eslint": "^2.8.0", | ||
"istanbul": "^0.4.3", | ||
"less": "^2.6.1", | ||
"mocha": "^2.4.5", | ||
"promise-map-series": "^0.2.2", | ||
"remap-istanbul": "^0.6.3", | ||
"rollup": "^0.26.0", | ||
"rollup-plugin-buble": "^0.5.0", | ||
"rollup-plugin-commonjs": "^2.2.1", | ||
"rollup-plugin-npm": "^1.4.0", | ||
"source-map": "^0.5.3", | ||
"source-map-support": "^0.4.0", | ||
"uglify-js": "^2.6.2" | ||
}, | ||
"bin": { | ||
"sorcery": "bin/index.js" | ||
}, | ||
"scripts": { | ||
"build": "rm -rf dist && rollup -c -f cjs -o dist/sorcery.cjs.js && rollup -c -f es6 -o dist/sorcery.es6.js", | ||
"pretest": "npm run build", | ||
"prepare-tests": "node test/samples/prepare-tests.js", | ||
"test": "mocha --compilers js:buble/register", | ||
"prepublish": "npm test", | ||
"lint": "eslint src", | ||
"pretest-coverage": "npm run build", | ||
"test-coverage": "rm -rf coverage/* && istanbul cover --report json node_modules/.bin/_mocha -- -u exports -R spec test/test.js", | ||
"posttest-coverage": "remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.json -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.lcov -t lcovonly -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped -t html -b dist", | ||
"ci": "npm run test-coverage && codecov < coverage/coverage-remapped.lcov" | ||
}, | ||
"files": [ | ||
"src/", | ||
"dist/", | ||
"bin/", | ||
"README.md" | ||
] | ||
"name": "sorcery", | ||
"description": "Resolve a chain of sourcemaps back to the original source", | ||
"version": "0.11.0", | ||
"author": "Rich Harris", | ||
"repository": "https://github.com/Rich-Harris/sorcery", | ||
"main": "dist/sorcery.cjs.js", | ||
"jsnext:main": "dist/sorcery.es6.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"buffer-crc32": "^0.2.5", | ||
"minimist": "^1.2.0", | ||
"sander": "^0.5.0", | ||
"@jridgewell/sourcemap-codec": "^1.4.14" | ||
}, | ||
"devDependencies": { | ||
"buble": "^0.10.4", | ||
"codecov.io": "^0.1.6", | ||
"coffee-script": "^1.10.0", | ||
"eslint": "^2.8.0", | ||
"glob": "^7.0.3", | ||
"istanbul": "^0.4.3", | ||
"less": "^2.6.1", | ||
"mocha": "^2.4.5", | ||
"promise-map-series": "^0.2.2", | ||
"remap-istanbul": "^0.6.3", | ||
"rollup": "^0.31.0", | ||
"rollup-plugin-buble": "^0.10.0", | ||
"rollup-plugin-commonjs": "^2.2.1", | ||
"rollup-plugin-npm": "^1.4.0", | ||
"source-map": "^0.5.3", | ||
"source-map-support": "^0.4.0", | ||
"uglify-js": "^2.6.2" | ||
}, | ||
"bin": { | ||
"sorcery": "bin/sorcery" | ||
}, | ||
"scripts": { | ||
"build": "rm -rf dist && rollup -c -f cjs -o dist/sorcery.cjs.js && rollup -c -f es6 -o dist/sorcery.es6.js", | ||
"pretest": "npm run build", | ||
"prepare-tests": "node test/samples/prepare-tests.js", | ||
"test": "mocha --compilers js:buble/register", | ||
"prepublish": "npm test", | ||
"lint": "eslint src", | ||
"pretest-coverage": "npm run build", | ||
"test-coverage": "rm -rf coverage/* && istanbul cover --report json node_modules/.bin/_mocha -- -u exports -R spec test/test.js", | ||
"posttest-coverage": "remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.json -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.lcov -t lcovonly -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped -t html -b dist", | ||
"ci": "npm run test-coverage && codecov < coverage/coverage-remapped.lcov" | ||
}, | ||
"files": [ | ||
"src/", | ||
"dist/", | ||
"bin/", | ||
"README.md" | ||
] | ||
} |
import { basename, dirname, extname, relative, resolve } from 'path'; | ||
import { writeFile, writeFileSync } from 'sander'; | ||
import { encode } from 'sourcemap-codec'; | ||
import codec from '@jridgewell/sourcemap-codec'; | ||
import SourceMap from './SourceMap.js'; | ||
@@ -99,3 +99,3 @@ import slash from './utils/slash.js'; | ||
let encodingStart = process.hrtime(); | ||
let mappings = encode( resolved ); | ||
let mappings = codec.encode( resolved ); | ||
let encodingTime = process.hrtime( encodingStart ); | ||
@@ -102,0 +102,0 @@ this._stats.encodingTime = 1e9 * encodingTime[0] + encodingTime[1]; |
import { dirname, resolve } from 'path'; | ||
import { readFile, readFileSync, Promise } from 'sander'; | ||
import { decode } from 'sourcemap-codec'; | ||
import codec from '@jridgewell/sourcemap-codec'; | ||
import getMap from './utils/getMap.js'; | ||
@@ -40,3 +40,3 @@ | ||
let decodingStart = process.hrtime(); | ||
this.mappings = decode( map.mappings ); | ||
this.mappings = codec.decode( map.mappings ); | ||
let decodingTime = process.hrtime( decodingStart ); | ||
@@ -78,3 +78,3 @@ this._stats.decodingTime = 1e9 * decodingTime[0] + decodingTime[1]; | ||
this.map = map; | ||
this.mappings = decode( map.mappings ); | ||
this.mappings = codec.decode( map.mappings ); | ||
@@ -81,0 +81,0 @@ sourcesContent = map.sourcesContent || []; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
156797
1640
17
20
+ Added@jridgewell/sourcemap-codec@1.4.15(transitive)
- Removedsourcemap-codec@^1.3.0
- Removedsourcemap-codec@1.4.8(transitive)