Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

magic-string

Package Overview
Dependencies
Maintainers
2
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magic-string - npm Package Compare versions

Comparing version 0.22.5 to 0.23.0

4

CHANGELOG.md
# 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 @@

119

dist/magic-string.cjs.js
'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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc