You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

magic-string

Package Overview
Dependencies
Maintainers
1
Versions
121
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

to
0.11.2

4

CHANGELOG.md
# changelog
## 0.11.2
* Support sourcemaps with moved content
## 0.11.1

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

67

dist/magic-string.cjs.js

@@ -48,3 +48,3 @@ 'use strict';

if ( this.edited ) {
if ( this.content.length ) throw new Error( "Cannot split a chunk that has already been edited (\"" + (this.original) + "\")" );
if ( this.content.length ) throw new Error( ("Cannot split a chunk that has already been edited (\"" + (this.original) + "\")") );

@@ -121,2 +121,21 @@ // zero-length edited chunks are a special case (overlapping replacements)

function getLocator ( source ) {
var originalLines = source.split( '\n' );
return function locate ( index ) {
var len = originalLines.length;
var lineStart = 0;
for ( var i = 0; i < len; i += 1 ) {
var line = originalLines[i];
var lineEnd = lineStart + line.length + 1; // +1 for newline
if ( lineEnd > index ) return { line: i, column: index - lineStart };
lineStart = lineEnd;
}
};
}
function encodeMappings ( original, intro, chunks, hires, sourcemapLocations, sourceIndex, offsets, names ) {

@@ -128,12 +147,13 @@ var rawLines = [];

var originalCharIndex = 0;
var generatedCodeColumn = 0;
var sourceCodeLine = 0;
var sourceCodeColumn = 0;
function addSegmentsUntil ( end ) {
var locate = getLocator( original );
function addUneditedChunk ( chunk ) {
var originalCharIndex = chunk.start;
var first = true;
while ( originalCharIndex < end ) {
var ref = locate( originalCharIndex ), line = ref.line, column = ref.column;
while ( originalCharIndex < chunk.end ) {
if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {

@@ -143,4 +163,4 @@ rawSegments.push({

generatedCodeColumn: generatedCodeColumn,
sourceCodeLine: sourceCodeLine,
sourceCodeColumn: sourceCodeColumn,
sourceCodeLine: line,
sourceCodeColumn: column,
sourceCodeName: -1,

@@ -152,4 +172,4 @@ sourceIndex: sourceIndex

if ( original[ originalCharIndex ] === '\n' ) {
sourceCodeLine += 1;
sourceCodeColumn = 0;
line += 1;
column = 0;
generatedCodeLine += 1;

@@ -159,3 +179,3 @@ rawLines[ generatedCodeLine ] = rawSegments = [];

} else {
sourceCodeColumn += 1;
column += 1;
generatedCodeColumn += 1;

@@ -171,2 +191,3 @@ }

var chunk = chunks[i];
var ref = locate( chunk.start ), line = ref.line, column = ref.column;

@@ -178,4 +199,4 @@ if ( chunk.edited ) {

generatedCodeColumn: generatedCodeColumn,
sourceCodeLine: sourceCodeLine,
sourceCodeColumn: sourceCodeColumn,
sourceCodeLine: line,
sourceCodeColumn: column,
sourceCodeName: chunk.storeName ? names.indexOf( chunk.original ) : -1,

@@ -201,16 +222,12 @@ sourceIndex: sourceIndex

if ( lines.length ) {
sourceCodeLine += lines.length;
sourceCodeColumn = lastLine.length;
line += lines.length;
column = lastLine.length;
} else {
sourceCodeColumn += lastLine.length;
column += lastLine.length;
}
} else {
addSegmentsUntil( chunk.end );
addUneditedChunk( chunk );
}
originalCharIndex = chunk.end;
}
addSegmentsUntil( original.length );
offsets.sourceIndex = offsets.sourceIndex || 0;

@@ -383,3 +400,3 @@ offsets.sourceCodeLine = offsets.sourceCodeLine || 0;

var replacer = function ( match ) {
if ( shouldIndentNextCharacter ) return "" + indentStr + "" + match + "";
if ( shouldIndentNextCharacter ) return ("" + indentStr + "" + match);
shouldIndentNextCharacter = true;

@@ -578,3 +595,3 @@ return match;

if ( chunk.start < start || chunk.end > end ) {
if ( chunk.edited ) throw new Error( "Cannot use replaced characters (" + start + ", " + end + ") as slice anchors" );
if ( chunk.edited ) throw new Error( ("Cannot use replaced characters (" + start + ", " + end + ") as slice anchors") );

@@ -716,3 +733,3 @@ var sliceStart = Math.max( start - chunk.start, 0 );

if ( source.content.original !== uniqueSource.content ) {
throw new Error( "Illegal source: same filename (" + (source.filename) + "), different contents" );
throw new Error( ("Illegal source: same filename (" + (source.filename) + "), different contents") );
}

@@ -719,0 +736,0 @@ }

@@ -46,3 +46,3 @@ import { encode } from 'vlq';

if ( this.edited ) {
if ( this.content.length ) throw new Error( "Cannot split a chunk that has already been edited (\"" + (this.original) + "\")" );
if ( this.content.length ) throw new Error( ("Cannot split a chunk that has already been edited (\"" + (this.original) + "\")") );

@@ -119,2 +119,21 @@ // zero-length edited chunks are a special case (overlapping replacements)

function getLocator ( source ) {
var originalLines = source.split( '\n' );
return function locate ( index ) {
var len = originalLines.length;
var lineStart = 0;
for ( var i = 0; i < len; i += 1 ) {
var line = originalLines[i];
var lineEnd = lineStart + line.length + 1; // +1 for newline
if ( lineEnd > index ) return { line: i, column: index - lineStart };
lineStart = lineEnd;
}
};
}
function encodeMappings ( original, intro, chunks, hires, sourcemapLocations, sourceIndex, offsets, names ) {

@@ -126,12 +145,13 @@ var rawLines = [];

var originalCharIndex = 0;
var generatedCodeColumn = 0;
var sourceCodeLine = 0;
var sourceCodeColumn = 0;
function addSegmentsUntil ( end ) {
var locate = getLocator( original );
function addUneditedChunk ( chunk ) {
var originalCharIndex = chunk.start;
var first = true;
while ( originalCharIndex < end ) {
var ref = locate( originalCharIndex ), line = ref.line, column = ref.column;
while ( originalCharIndex < chunk.end ) {
if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {

@@ -141,4 +161,4 @@ rawSegments.push({

generatedCodeColumn: generatedCodeColumn,
sourceCodeLine: sourceCodeLine,
sourceCodeColumn: sourceCodeColumn,
sourceCodeLine: line,
sourceCodeColumn: column,
sourceCodeName: -1,

@@ -150,4 +170,4 @@ sourceIndex: sourceIndex

if ( original[ originalCharIndex ] === '\n' ) {
sourceCodeLine += 1;
sourceCodeColumn = 0;
line += 1;
column = 0;
generatedCodeLine += 1;

@@ -157,3 +177,3 @@ rawLines[ generatedCodeLine ] = rawSegments = [];

} else {
sourceCodeColumn += 1;
column += 1;
generatedCodeColumn += 1;

@@ -169,2 +189,3 @@ }

var chunk = chunks[i];
var ref = locate( chunk.start ), line = ref.line, column = ref.column;

@@ -176,4 +197,4 @@ if ( chunk.edited ) {

generatedCodeColumn: generatedCodeColumn,
sourceCodeLine: sourceCodeLine,
sourceCodeColumn: sourceCodeColumn,
sourceCodeLine: line,
sourceCodeColumn: column,
sourceCodeName: chunk.storeName ? names.indexOf( chunk.original ) : -1,

@@ -199,16 +220,12 @@ sourceIndex: sourceIndex

if ( lines.length ) {
sourceCodeLine += lines.length;
sourceCodeColumn = lastLine.length;
line += lines.length;
column = lastLine.length;
} else {
sourceCodeColumn += lastLine.length;
column += lastLine.length;
}
} else {
addSegmentsUntil( chunk.end );
addUneditedChunk( chunk );
}
originalCharIndex = chunk.end;
}
addSegmentsUntil( original.length );
offsets.sourceIndex = offsets.sourceIndex || 0;

@@ -381,3 +398,3 @@ offsets.sourceCodeLine = offsets.sourceCodeLine || 0;

var replacer = function ( match ) {
if ( shouldIndentNextCharacter ) return "" + indentStr + "" + match + "";
if ( shouldIndentNextCharacter ) return ("" + indentStr + "" + match);
shouldIndentNextCharacter = true;

@@ -576,3 +593,3 @@ return match;

if ( chunk.start < start || chunk.end > end ) {
if ( chunk.edited ) throw new Error( "Cannot use replaced characters (" + start + ", " + end + ") as slice anchors" );
if ( chunk.edited ) throw new Error( ("Cannot use replaced characters (" + start + ", " + end + ") as slice anchors") );

@@ -714,3 +731,3 @@ var sliceStart = Math.max( start - chunk.start, 0 );

if ( source.content.original !== uniqueSource.content ) {
throw new Error( "Illegal source: same filename (" + (source.filename) + "), different contents" );
throw new Error( ("Illegal source: same filename (" + (source.filename) + "), different contents") );
}

@@ -717,0 +734,0 @@ }

@@ -50,3 +50,3 @@ (function (global, factory) {

if ( this.edited ) {
if ( this.content.length ) throw new Error( "Cannot split a chunk that has already been edited (\"" + (this.original) + "\")" );
if ( this.content.length ) throw new Error( ("Cannot split a chunk that has already been edited (\"" + (this.original) + "\")") );

@@ -169,2 +169,21 @@ // zero-length edited chunks are a special case (overlapping replacements)

function getLocator ( source ) {
var originalLines = source.split( '\n' );
return function locate ( index ) {
var len = originalLines.length;
var lineStart = 0;
for ( var i = 0; i < len; i += 1 ) {
var line = originalLines[i];
var lineEnd = lineStart + line.length + 1; // +1 for newline
if ( lineEnd > index ) return { line: i, column: index - lineStart };
lineStart = lineEnd;
}
};
}
function encodeMappings ( original, intro, chunks, hires, sourcemapLocations, sourceIndex, offsets, names ) {

@@ -176,12 +195,13 @@ var rawLines = [];

var originalCharIndex = 0;
var generatedCodeColumn = 0;
var sourceCodeLine = 0;
var sourceCodeColumn = 0;
function addSegmentsUntil ( end ) {
var locate = getLocator( original );
function addUneditedChunk ( chunk ) {
var originalCharIndex = chunk.start;
var first = true;
while ( originalCharIndex < end ) {
var ref = locate( originalCharIndex ), line = ref.line, column = ref.column;
while ( originalCharIndex < chunk.end ) {
if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {

@@ -191,4 +211,4 @@ rawSegments.push({

generatedCodeColumn: generatedCodeColumn,
sourceCodeLine: sourceCodeLine,
sourceCodeColumn: sourceCodeColumn,
sourceCodeLine: line,
sourceCodeColumn: column,
sourceCodeName: -1,

@@ -200,4 +220,4 @@ sourceIndex: sourceIndex

if ( original[ originalCharIndex ] === '\n' ) {
sourceCodeLine += 1;
sourceCodeColumn = 0;
line += 1;
column = 0;
generatedCodeLine += 1;

@@ -207,3 +227,3 @@ rawLines[ generatedCodeLine ] = rawSegments = [];

} else {
sourceCodeColumn += 1;
column += 1;
generatedCodeColumn += 1;

@@ -219,2 +239,3 @@ }

var chunk = chunks[i];
var ref = locate( chunk.start ), line = ref.line, column = ref.column;

@@ -226,4 +247,4 @@ if ( chunk.edited ) {

generatedCodeColumn: generatedCodeColumn,
sourceCodeLine: sourceCodeLine,
sourceCodeColumn: sourceCodeColumn,
sourceCodeLine: line,
sourceCodeColumn: column,
sourceCodeName: chunk.storeName ? names.indexOf( chunk.original ) : -1,

@@ -249,16 +270,12 @@ sourceIndex: sourceIndex

if ( lines.length ) {
sourceCodeLine += lines.length;
sourceCodeColumn = lastLine.length;
line += lines.length;
column = lastLine.length;
} else {
sourceCodeColumn += lastLine.length;
column += lastLine.length;
}
} else {
addSegmentsUntil( chunk.end );
addUneditedChunk( chunk );
}
originalCharIndex = chunk.end;
}
addSegmentsUntil( original.length );
offsets.sourceIndex = offsets.sourceIndex || 0;

@@ -431,3 +448,3 @@ offsets.sourceCodeLine = offsets.sourceCodeLine || 0;

var replacer = function ( match ) {
if ( shouldIndentNextCharacter ) return "" + indentStr + "" + match + "";
if ( shouldIndentNextCharacter ) return ("" + indentStr + "" + match);
shouldIndentNextCharacter = true;

@@ -626,3 +643,3 @@ return match;

if ( chunk.start < start || chunk.end > end ) {
if ( chunk.edited ) throw new Error( "Cannot use replaced characters (" + start + ", " + end + ") as slice anchors" );
if ( chunk.edited ) throw new Error( ("Cannot use replaced characters (" + start + ", " + end + ") as slice anchors") );

@@ -764,3 +781,3 @@ var sliceStart = Math.max( start - chunk.start, 0 );

if ( source.content.original !== uniqueSource.content ) {
throw new Error( "Illegal source: same filename (" + (source.filename) + "), different contents" );
throw new Error( ("Illegal source: same filename (" + (source.filename) + "), different contents") );
}

@@ -767,0 +784,0 @@ }

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

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

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

import { encode } from 'vlq';
function getLocator ( source ) {
let originalLines = source.split( '\n' );
return function locate ( index ) {
const len = originalLines.length;
let lineStart = 0;
for ( let i = 0; i < len; i += 1 ) {
const line = originalLines[i];
const lineEnd = lineStart + line.length + 1; // +1 for newline
if ( lineEnd > index ) return { line: i, column: index - lineStart };
lineStart = lineEnd;
}
};
}
export default function encodeMappings ( original, intro, chunks, hires, sourcemapLocations, sourceIndex, offsets, names ) {

@@ -9,12 +28,13 @@ let rawLines = [];

let originalCharIndex = 0;
let generatedCodeColumn = 0;
let sourceCodeLine = 0;
let sourceCodeColumn = 0;
function addSegmentsUntil ( end ) {
const locate = getLocator( original );
function addUneditedChunk ( chunk ) {
let originalCharIndex = chunk.start;
let first = true;
while ( originalCharIndex < end ) {
let { line, column } = locate( originalCharIndex );
while ( originalCharIndex < chunk.end ) {
if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {

@@ -24,4 +44,4 @@ rawSegments.push({

generatedCodeColumn,
sourceCodeLine,
sourceCodeColumn,
sourceCodeLine: line,
sourceCodeColumn: column,
sourceCodeName: -1,

@@ -33,4 +53,4 @@ sourceIndex

if ( original[ originalCharIndex ] === '\n' ) {
sourceCodeLine += 1;
sourceCodeColumn = 0;
line += 1;
column = 0;
generatedCodeLine += 1;

@@ -40,3 +60,3 @@ rawLines[ generatedCodeLine ] = rawSegments = [];

} else {
sourceCodeColumn += 1;
column += 1;
generatedCodeColumn += 1;

@@ -52,2 +72,3 @@ }

const chunk = chunks[i];
let { line, column } = locate( chunk.start );

@@ -59,4 +80,4 @@ if ( chunk.edited ) {

generatedCodeColumn,
sourceCodeLine,
sourceCodeColumn,
sourceCodeLine: line,
sourceCodeColumn: column,
sourceCodeName: chunk.storeName ? names.indexOf( chunk.original ) : -1,

@@ -82,16 +103,12 @@ sourceIndex

if ( lines.length ) {
sourceCodeLine += lines.length;
sourceCodeColumn = lastLine.length;
line += lines.length;
column = lastLine.length;
} else {
sourceCodeColumn += lastLine.length;
column += lastLine.length;
}
} else {
addSegmentsUntil( chunk.end );
addUneditedChunk( chunk );
}
originalCharIndex = chunk.end;
}
addSegmentsUntil( original.length );
offsets.sourceIndex = offsets.sourceIndex || 0;

@@ -98,0 +115,0 @@ offsets.sourceCodeLine = offsets.sourceCodeLine || 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