magic-string
Advanced tools
Comparing version 0.22.5 to 0.23.0
# magic-string changelog | ||
## 0.23.0 | ||
* Use `sourcemap-codec` for improved performance ([#133](https://github.com/Rich-Harris/magic-string/pull/133)) | ||
## 0.22.5 | ||
@@ -4,0 +8,0 @@ |
'use strict'; | ||
var vlq = require('vlq'); | ||
function Chunk ( start, end, content ) { | ||
@@ -283,13 +281,57 @@ this.start = start; | ||
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
function encode(decoded) { | ||
var sourceFileIndex = 0; // second field | ||
var sourceCodeLine = 0; // third field | ||
var sourceCodeColumn = 0; // fourth field | ||
var nameIndex = 0; // fifth field | ||
var mappings = ''; | ||
for (var i = 0; i < decoded.length; i++) { | ||
var line = decoded[i]; | ||
if (i > 0) | ||
mappings += ';'; | ||
if (line.length === 0) | ||
continue; | ||
var generatedCodeColumn = 0; // first field | ||
var lineMappings = []; | ||
for (var _i = 0, line_1 = line; _i < line_1.length; _i++) { | ||
var segment = line_1[_i]; | ||
var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn); | ||
generatedCodeColumn = segment[0]; | ||
if (segment.length > 1) { | ||
segmentMappings += | ||
encodeInteger(segment[1] - sourceFileIndex) + | ||
encodeInteger(segment[2] - sourceCodeLine) + | ||
encodeInteger(segment[3] - sourceCodeColumn); | ||
sourceFileIndex = segment[1]; | ||
sourceCodeLine = segment[2]; | ||
sourceCodeColumn = segment[3]; | ||
} | ||
if (segment.length === 5) { | ||
segmentMappings += encodeInteger(segment[4] - nameIndex); | ||
nameIndex = segment[4]; | ||
} | ||
lineMappings.push(segmentMappings); | ||
} | ||
mappings += lineMappings.join(','); | ||
} | ||
return mappings; | ||
} | ||
function encodeInteger(num) { | ||
var result = ''; | ||
num = num < 0 ? (-num << 1) | 1 : num << 1; | ||
do { | ||
var clamped = num & 31; | ||
num >>= 5; | ||
if (num > 0) { | ||
clamped |= 32; | ||
} | ||
result += chars[clamped]; | ||
} while (num > 0); | ||
return result; | ||
} | ||
function Mappings ( hires ) { | ||
var this$1 = this; | ||
var offsets = { | ||
generatedCodeColumn: 0, | ||
sourceIndex: 0, | ||
sourceCodeLine: 0, | ||
sourceCodeColumn: 0, | ||
sourceCodeName: 0 | ||
}; | ||
var generatedCodeLine = 0; | ||
@@ -305,8 +347,12 @@ var generatedCodeColumn = 0; | ||
if ( content.length ) { | ||
rawSegments.push([ | ||
var segment = [ | ||
generatedCodeColumn, | ||
sourceIndex, | ||
loc.line, | ||
loc.column, | ||
nameIndex ]); | ||
loc.column | ||
]; | ||
if ( nameIndex >= 0 ) { | ||
segment.push( nameIndex ); | ||
} | ||
rawSegments.push( segment ); | ||
} else if ( pending ) { | ||
@@ -330,4 +376,3 @@ rawSegments.push( pending ); | ||
loc.line, | ||
loc.column, | ||
-1 | ||
loc.column | ||
]); | ||
@@ -355,4 +400,4 @@ } | ||
loc.line, | ||
loc.column, | ||
-1 ]; | ||
loc.column | ||
]; | ||
}; | ||
@@ -364,38 +409,16 @@ | ||
var lines = str.split( '\n' ); | ||
var lastLine = lines.pop(); | ||
if ( lines.length ) { | ||
generatedCodeLine += lines.length; | ||
this$1.raw[ generatedCodeLine ] = rawSegments = []; | ||
generatedCodeColumn = lastLine.length; | ||
} else { | ||
generatedCodeColumn += lastLine.length; | ||
if ( lines.length > 1 ) { | ||
for ( var i = 0; i < lines.length - 1; i++ ) { | ||
generatedCodeLine++; | ||
this$1.raw[generatedCodeLine] = rawSegments = []; | ||
} | ||
generatedCodeColumn = 0; | ||
} | ||
generatedCodeColumn += lines[lines.length - 1].length; | ||
}; | ||
this.encode = function () { | ||
return this$1.raw.map( function (segments) { | ||
var generatedCodeColumn = 0; | ||
return segments.map( function (segment) { | ||
var arr = [ | ||
segment[0] - generatedCodeColumn, | ||
segment[1] - offsets.sourceIndex, | ||
segment[2] - offsets.sourceCodeLine, | ||
segment[3] - offsets.sourceCodeColumn | ||
]; | ||
generatedCodeColumn = segment[0]; | ||
offsets.sourceIndex = segment[1]; | ||
offsets.sourceCodeLine = segment[2]; | ||
offsets.sourceCodeColumn = segment[3]; | ||
if ( ~segment[4] ) { | ||
arr.push( segment[4] - offsets.sourceCodeName ); | ||
offsets.sourceCodeName = segment[4]; | ||
} | ||
return vlq.encode( arr ); | ||
}).join( ',' ); | ||
}).join( ';' ); | ||
return encode(this$1.raw); | ||
}; | ||
@@ -402,0 +425,0 @@ } |
@@ -1,3 +0,1 @@ | ||
import { encode } from 'vlq'; | ||
function Chunk ( start, end, content ) { | ||
@@ -281,13 +279,57 @@ this.start = start; | ||
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
function encode(decoded) { | ||
var sourceFileIndex = 0; // second field | ||
var sourceCodeLine = 0; // third field | ||
var sourceCodeColumn = 0; // fourth field | ||
var nameIndex = 0; // fifth field | ||
var mappings = ''; | ||
for (var i = 0; i < decoded.length; i++) { | ||
var line = decoded[i]; | ||
if (i > 0) | ||
mappings += ';'; | ||
if (line.length === 0) | ||
continue; | ||
var generatedCodeColumn = 0; // first field | ||
var lineMappings = []; | ||
for (var _i = 0, line_1 = line; _i < line_1.length; _i++) { | ||
var segment = line_1[_i]; | ||
var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn); | ||
generatedCodeColumn = segment[0]; | ||
if (segment.length > 1) { | ||
segmentMappings += | ||
encodeInteger(segment[1] - sourceFileIndex) + | ||
encodeInteger(segment[2] - sourceCodeLine) + | ||
encodeInteger(segment[3] - sourceCodeColumn); | ||
sourceFileIndex = segment[1]; | ||
sourceCodeLine = segment[2]; | ||
sourceCodeColumn = segment[3]; | ||
} | ||
if (segment.length === 5) { | ||
segmentMappings += encodeInteger(segment[4] - nameIndex); | ||
nameIndex = segment[4]; | ||
} | ||
lineMappings.push(segmentMappings); | ||
} | ||
mappings += lineMappings.join(','); | ||
} | ||
return mappings; | ||
} | ||
function encodeInteger(num) { | ||
var result = ''; | ||
num = num < 0 ? (-num << 1) | 1 : num << 1; | ||
do { | ||
var clamped = num & 31; | ||
num >>= 5; | ||
if (num > 0) { | ||
clamped |= 32; | ||
} | ||
result += chars[clamped]; | ||
} while (num > 0); | ||
return result; | ||
} | ||
function Mappings ( hires ) { | ||
var this$1 = this; | ||
var offsets = { | ||
generatedCodeColumn: 0, | ||
sourceIndex: 0, | ||
sourceCodeLine: 0, | ||
sourceCodeColumn: 0, | ||
sourceCodeName: 0 | ||
}; | ||
var generatedCodeLine = 0; | ||
@@ -303,8 +345,12 @@ var generatedCodeColumn = 0; | ||
if ( content.length ) { | ||
rawSegments.push([ | ||
var segment = [ | ||
generatedCodeColumn, | ||
sourceIndex, | ||
loc.line, | ||
loc.column, | ||
nameIndex ]); | ||
loc.column | ||
]; | ||
if ( nameIndex >= 0 ) { | ||
segment.push( nameIndex ); | ||
} | ||
rawSegments.push( segment ); | ||
} else if ( pending ) { | ||
@@ -328,4 +374,3 @@ rawSegments.push( pending ); | ||
loc.line, | ||
loc.column, | ||
-1 | ||
loc.column | ||
]); | ||
@@ -353,4 +398,4 @@ } | ||
loc.line, | ||
loc.column, | ||
-1 ]; | ||
loc.column | ||
]; | ||
}; | ||
@@ -362,38 +407,16 @@ | ||
var lines = str.split( '\n' ); | ||
var lastLine = lines.pop(); | ||
if ( lines.length ) { | ||
generatedCodeLine += lines.length; | ||
this$1.raw[ generatedCodeLine ] = rawSegments = []; | ||
generatedCodeColumn = lastLine.length; | ||
} else { | ||
generatedCodeColumn += lastLine.length; | ||
if ( lines.length > 1 ) { | ||
for ( var i = 0; i < lines.length - 1; i++ ) { | ||
generatedCodeLine++; | ||
this$1.raw[generatedCodeLine] = rawSegments = []; | ||
} | ||
generatedCodeColumn = 0; | ||
} | ||
generatedCodeColumn += lines[lines.length - 1].length; | ||
}; | ||
this.encode = function () { | ||
return this$1.raw.map( function (segments) { | ||
var generatedCodeColumn = 0; | ||
return segments.map( function (segment) { | ||
var arr = [ | ||
segment[0] - generatedCodeColumn, | ||
segment[1] - offsets.sourceIndex, | ||
segment[2] - offsets.sourceCodeLine, | ||
segment[3] - offsets.sourceCodeColumn | ||
]; | ||
generatedCodeColumn = segment[0]; | ||
offsets.sourceIndex = segment[1]; | ||
offsets.sourceCodeLine = segment[2]; | ||
offsets.sourceCodeColumn = segment[3]; | ||
if ( ~segment[4] ) { | ||
arr.push( segment[4] - offsets.sourceCodeName ); | ||
offsets.sourceCodeName = segment[4]; | ||
} | ||
return encode( arr ); | ||
}).join( ',' ); | ||
}).join( ';' ); | ||
return encode(this$1.raw); | ||
}; | ||
@@ -400,0 +423,0 @@ } |
@@ -285,48 +285,52 @@ (function (global, factory) { | ||
var charToInteger = {}; | ||
var integerToChar = {}; | ||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) { | ||
charToInteger[ char ] = i; | ||
integerToChar[ i ] = char; | ||
}); | ||
function encode ( value ) { | ||
var result; | ||
if ( typeof value === 'number' ) { | ||
result = encodeInteger( value ); | ||
} else { | ||
result = ''; | ||
for ( var i = 0; i < value.length; i += 1 ) { | ||
result += encodeInteger( value[i] ); | ||
} | ||
} | ||
return result; | ||
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
function encode(decoded) { | ||
var sourceFileIndex = 0; // second field | ||
var sourceCodeLine = 0; // third field | ||
var sourceCodeColumn = 0; // fourth field | ||
var nameIndex = 0; // fifth field | ||
var mappings = ''; | ||
for (var i = 0; i < decoded.length; i++) { | ||
var line = decoded[i]; | ||
if (i > 0) | ||
mappings += ';'; | ||
if (line.length === 0) | ||
continue; | ||
var generatedCodeColumn = 0; // first field | ||
var lineMappings = []; | ||
for (var _i = 0, line_1 = line; _i < line_1.length; _i++) { | ||
var segment = line_1[_i]; | ||
var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn); | ||
generatedCodeColumn = segment[0]; | ||
if (segment.length > 1) { | ||
segmentMappings += | ||
encodeInteger(segment[1] - sourceFileIndex) + | ||
encodeInteger(segment[2] - sourceCodeLine) + | ||
encodeInteger(segment[3] - sourceCodeColumn); | ||
sourceFileIndex = segment[1]; | ||
sourceCodeLine = segment[2]; | ||
sourceCodeColumn = segment[3]; | ||
} | ||
if (segment.length === 5) { | ||
segmentMappings += encodeInteger(segment[4] - nameIndex); | ||
nameIndex = segment[4]; | ||
} | ||
lineMappings.push(segmentMappings); | ||
} | ||
mappings += lineMappings.join(','); | ||
} | ||
return mappings; | ||
} | ||
function encodeInteger ( num ) { | ||
var result = ''; | ||
if ( num < 0 ) { | ||
num = ( -num << 1 ) | 1; | ||
} else { | ||
num <<= 1; | ||
} | ||
do { | ||
var clamped = num & 31; | ||
num >>= 5; | ||
if ( num > 0 ) { | ||
clamped |= 32; | ||
} | ||
result += integerToChar[ clamped ]; | ||
} while ( num > 0 ); | ||
return result; | ||
function encodeInteger(num) { | ||
var result = ''; | ||
num = num < 0 ? (-num << 1) | 1 : num << 1; | ||
do { | ||
var clamped = num & 31; | ||
num >>= 5; | ||
if (num > 0) { | ||
clamped |= 32; | ||
} | ||
result += chars[clamped]; | ||
} while (num > 0); | ||
return result; | ||
} | ||
@@ -337,10 +341,2 @@ | ||
var offsets = { | ||
generatedCodeColumn: 0, | ||
sourceIndex: 0, | ||
sourceCodeLine: 0, | ||
sourceCodeColumn: 0, | ||
sourceCodeName: 0 | ||
}; | ||
var generatedCodeLine = 0; | ||
@@ -356,8 +352,12 @@ var generatedCodeColumn = 0; | ||
if ( content.length ) { | ||
rawSegments.push([ | ||
var segment = [ | ||
generatedCodeColumn, | ||
sourceIndex, | ||
loc.line, | ||
loc.column, | ||
nameIndex ]); | ||
loc.column | ||
]; | ||
if ( nameIndex >= 0 ) { | ||
segment.push( nameIndex ); | ||
} | ||
rawSegments.push( segment ); | ||
} else if ( pending ) { | ||
@@ -381,4 +381,3 @@ rawSegments.push( pending ); | ||
loc.line, | ||
loc.column, | ||
-1 | ||
loc.column | ||
]); | ||
@@ -406,4 +405,4 @@ } | ||
loc.line, | ||
loc.column, | ||
-1 ]; | ||
loc.column | ||
]; | ||
}; | ||
@@ -415,38 +414,16 @@ | ||
var lines = str.split( '\n' ); | ||
var lastLine = lines.pop(); | ||
if ( lines.length ) { | ||
generatedCodeLine += lines.length; | ||
this$1.raw[ generatedCodeLine ] = rawSegments = []; | ||
generatedCodeColumn = lastLine.length; | ||
} else { | ||
generatedCodeColumn += lastLine.length; | ||
if ( lines.length > 1 ) { | ||
for ( var i = 0; i < lines.length - 1; i++ ) { | ||
generatedCodeLine++; | ||
this$1.raw[generatedCodeLine] = rawSegments = []; | ||
} | ||
generatedCodeColumn = 0; | ||
} | ||
generatedCodeColumn += lines[lines.length - 1].length; | ||
}; | ||
this.encode = function () { | ||
return this$1.raw.map( function (segments) { | ||
var generatedCodeColumn = 0; | ||
return segments.map( function (segment) { | ||
var arr = [ | ||
segment[0] - generatedCodeColumn, | ||
segment[1] - offsets.sourceIndex, | ||
segment[2] - offsets.sourceCodeLine, | ||
segment[3] - offsets.sourceCodeColumn | ||
]; | ||
generatedCodeColumn = segment[0]; | ||
offsets.sourceIndex = segment[1]; | ||
offsets.sourceCodeLine = segment[2]; | ||
offsets.sourceCodeColumn = segment[3]; | ||
if ( ~segment[4] ) { | ||
arr.push( segment[4] - offsets.sourceCodeName ); | ||
offsets.sourceCodeName = segment[4]; | ||
} | ||
return encode( arr ); | ||
}).join( ',' ); | ||
}).join( ';' ); | ||
return encode(this$1.raw); | ||
}; | ||
@@ -453,0 +430,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Rich Harris", | ||
"version": "0.22.5", | ||
"version": "0.23.0", | ||
"repository": "https://github.com/rich-harris/magic-string", | ||
@@ -14,3 +14,3 @@ "main": "dist/magic-string.cjs.js", | ||
"dependencies": { | ||
"vlq": "^0.2.2" | ||
"sourcemap-codec": "^1.4.1" | ||
}, | ||
@@ -17,0 +17,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
361677
3086
0
+ Addedsourcemap-codec@^1.4.1
+ Addedsourcemap-codec@1.4.8(transitive)
- Removedvlq@^0.2.2
- Removedvlq@0.2.3(transitive)