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.23.1 to 0.23.2

4

CHANGELOG.md
# magic-string changelog
## 0.23.2
* Add `generateDecodedMap` methods ([#134](https://github.com/Rich-Harris/magic-string/pull/134))
## 0.23.1

@@ -4,0 +8,0 @@

141

dist/magic-string.cjs.js
'use strict';
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 Chunk ( start, end, content ) {

@@ -181,3 +233,3 @@ this.start = start;

this.names = properties.names;
this.mappings = properties.mappings;
this.mappings = encode(properties.mappings);
}

@@ -272,54 +324,2 @@

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 ) {

@@ -336,3 +336,3 @@ var this$1 = this;

this.addEdit = function ( sourceIndex, content, original, loc, nameIndex ) {
this.addEdit = function ( sourceIndex, content, loc, nameIndex ) {
if ( content.length ) {

@@ -409,6 +409,2 @@ var segment = [

};
this.encode = function () {
return encode(this$1.raw);
};
}

@@ -544,3 +540,3 @@

generateMap: function generateMap ( options ) {
generateDecodedMap: function generateDecodedMap ( options ) {
var this$1 = this;

@@ -566,3 +562,3 @@

if ( chunk.edited ) {
mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
mappings.addEdit( sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
} else {

@@ -575,3 +571,3 @@ mappings.addUneditedChunk( sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations );

var map = new SourceMap({
return {
file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),

@@ -581,7 +577,10 @@ sources: [ options.source ? getRelativePath( options.file || '', options.source ) : null ],

names: names,
mappings: mappings.encode()
});
return map;
mappings: mappings.raw
};
},
generateMap: function generateMap ( options ) {
return new SourceMap(this.generateDecodedMap( options ));
},
getIndentString: function getIndentString () {

@@ -1124,3 +1123,3 @@ return this.indentStr === null ? '\t' : this.indentStr;

generateMap: function generateMap ( options ) {
generateDecodedMap: function generateDecodedMap ( options ) {
var this$1 = this;

@@ -1162,3 +1161,3 @@ if ( options === void 0 ) options = {};

if ( chunk.edited ) {
mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
mappings.addEdit( sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
} else {

@@ -1181,3 +1180,3 @@ mappings.addUneditedChunk( sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations );

return new SourceMap({
return {
file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),

@@ -1191,6 +1190,10 @@ sources: this.uniqueSources.map( function (source) {

names: names,
mappings: mappings.encode()
});
mappings: mappings.raw
};
},
generateMap: function generateMap ( options ) {
return new SourceMap(this.generateDecodedMap( options ));
},
getIndentString: function getIndentString () {

@@ -1197,0 +1200,0 @@ var indentStringCounts = {};

@@ -0,1 +1,53 @@

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 Chunk ( start, end, content ) {

@@ -179,3 +231,3 @@ this.start = start;

this.names = properties.names;
this.mappings = properties.mappings;
this.mappings = encode(properties.mappings);
}

@@ -270,54 +322,2 @@

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 ) {

@@ -334,3 +334,3 @@ var this$1 = this;

this.addEdit = function ( sourceIndex, content, original, loc, nameIndex ) {
this.addEdit = function ( sourceIndex, content, loc, nameIndex ) {
if ( content.length ) {

@@ -407,6 +407,2 @@ var segment = [

};
this.encode = function () {
return encode(this$1.raw);
};
}

@@ -542,3 +538,3 @@

generateMap: function generateMap ( options ) {
generateDecodedMap: function generateDecodedMap ( options ) {
var this$1 = this;

@@ -564,3 +560,3 @@

if ( chunk.edited ) {
mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
mappings.addEdit( sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
} else {

@@ -573,3 +569,3 @@ mappings.addUneditedChunk( sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations );

var map = new SourceMap({
return {
file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),

@@ -579,7 +575,10 @@ sources: [ options.source ? getRelativePath( options.file || '', options.source ) : null ],

names: names,
mappings: mappings.encode()
});
return map;
mappings: mappings.raw
};
},
generateMap: function generateMap ( options ) {
return new SourceMap(this.generateDecodedMap( options ));
},
getIndentString: function getIndentString () {

@@ -1122,3 +1121,3 @@ return this.indentStr === null ? '\t' : this.indentStr;

generateMap: function generateMap ( options ) {
generateDecodedMap: function generateDecodedMap ( options ) {
var this$1 = this;

@@ -1160,3 +1159,3 @@ if ( options === void 0 ) options = {};

if ( chunk.edited ) {
mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
mappings.addEdit( sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
} else {

@@ -1179,3 +1178,3 @@ mappings.addUneditedChunk( sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations );

return new SourceMap({
return {
file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),

@@ -1189,6 +1188,10 @@ sources: this.uniqueSources.map( function (source) {

names: names,
mappings: mappings.encode()
});
mappings: mappings.raw
};
},
generateMap: function generateMap ( options ) {
return new SourceMap(this.generateDecodedMap( options ));
},
getIndentString: function getIndentString () {

@@ -1319,4 +1322,4 @@ var indentStringCounts = {};

export { Bundle };
export { Bundle, SourceMap };
export default MagicString$1;
//# sourceMappingURL=magic-string.es.js.map

@@ -7,2 +7,54 @@ (function (global, factory) {

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 Chunk ( start, end, content ) {

@@ -186,3 +238,3 @@ this.start = start;

this.names = properties.names;
this.mappings = properties.mappings;
this.mappings = encode(properties.mappings);
}

@@ -277,54 +329,2 @@

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 ) {

@@ -341,3 +341,3 @@ var this$1 = this;

this.addEdit = function ( sourceIndex, content, original, loc, nameIndex ) {
this.addEdit = function ( sourceIndex, content, loc, nameIndex ) {
if ( content.length ) {

@@ -414,6 +414,2 @@ var segment = [

};
this.encode = function () {
return encode(this$1.raw);
};
}

@@ -549,3 +545,3 @@

generateMap: function generateMap ( options ) {
generateDecodedMap: function generateDecodedMap ( options ) {
var this$1 = this;

@@ -571,3 +567,3 @@

if ( chunk.edited ) {
mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
mappings.addEdit( sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
} else {

@@ -580,3 +576,3 @@ mappings.addUneditedChunk( sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations );

var map = new SourceMap({
return {
file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),

@@ -586,7 +582,10 @@ sources: [ options.source ? getRelativePath( options.file || '', options.source ) : null ],

names: names,
mappings: mappings.encode()
});
return map;
mappings: mappings.raw
};
},
generateMap: function generateMap ( options ) {
return new SourceMap(this.generateDecodedMap( options ));
},
getIndentString: function getIndentString () {

@@ -1129,3 +1128,3 @@ return this.indentStr === null ? '\t' : this.indentStr;

generateMap: function generateMap ( options ) {
generateDecodedMap: function generateDecodedMap ( options ) {
var this$1 = this;

@@ -1167,3 +1166,3 @@ if ( options === void 0 ) options = {};

if ( chunk.edited ) {
mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
mappings.addEdit( sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
} else {

@@ -1186,3 +1185,3 @@ mappings.addUneditedChunk( sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations );

return new SourceMap({
return {
file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),

@@ -1196,6 +1195,10 @@ sources: this.uniqueSources.map( function (source) {

names: names,
mappings: mappings.encode()
});
mappings: mappings.raw
};
},
generateMap: function generateMap ( options ) {
return new SourceMap(this.generateDecodedMap( options ));
},
getIndentString: function getIndentString () {

@@ -1202,0 +1205,0 @@ var indentStringCounts = {};

@@ -13,3 +13,13 @@ export interface BundleOptions {

export interface SourceMap {
export interface DecodedSourceMap {
file: string;
sources: string[];
sourcesContent: string[];
names: string[];
mappings: number[][][];
}
export class SourceMap {
constructor(properties: DecodedSourceMap);
version: string;

@@ -32,2 +42,3 @@ file: string;

generateMap(options?: Partial<SourceMapOptions>): SourceMap;
generateDecodedMap(options?: Partial<SourceMapOptions>): DecodedSourceMap;
getIndentString(): string;

@@ -69,2 +80,3 @@ indent(indentStr?: string): Bundle;

generateMap(options?: Partial<SourceMapOptions>): SourceMap;
generateDecodedMap(options?: Partial<SourceMapOptions>): DecodedSourceMap;
getIndentString(): string;

@@ -71,0 +83,0 @@

@@ -5,3 +5,3 @@ {

"author": "Rich Harris",
"version": "0.23.1",
"version": "0.23.2",
"repository": "https://github.com/rich-harris/magic-string",

@@ -8,0 +8,0 @@ "main": "dist/magic-string.cjs.js",

@@ -105,2 +105,6 @@ # magic-string

### s.generateDecodedMap( options )
Generates a sourcemap object with raw mappings in array form, rather than encoded as a string. See `generateMap` documentation below for options details. Useful if you need to manipulate the sourcemap further, but most of the time you will use `generateMap` instead.
### s.generateMap( options )

@@ -107,0 +111,0 @@

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