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

@microsoft/dynamicproto-js

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microsoft/dynamicproto-js - npm Package Compare versions

Comparing version 1.1.8 to 2.0.0

lib/dist/es5/amd/dynamicproto-js.js

58

lib/src/DynamicProto.ts
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { getGlobal, objHasOwnProperty, throwTypeError } from "@nevware21/ts-utils";
interface DynamicGlobalSettings {

@@ -130,31 +132,5 @@ /**

/**
* Gets the runtime global reference
* @returns
*/
function _getGlobal(): Window {
let result: any;
if (typeof globalThis !== UNDEFINED) {
result = globalThis;
}
if (!result && typeof self !== UNDEFINED) {
result = self;
}
if (!result && typeof window !== UNDEFINED) {
result = window;
}
if (!result && typeof global !== UNDEFINED) {
result = global;
}
return result || {};
}
// Since 1.1.7 moving these to the runtime global to work around mixed version and module issues
// See Issue https://github.com/microsoft/DynamicProto-JS/issues/57 for details
let _gbl = _getGlobal();
let _gbl = getGlobal();
let _gblInst: DynamicGlobalSettings = _gbl[DynProtoGlobalSettings] || (_gbl[DynProtoGlobalSettings] = {

@@ -169,10 +145,2 @@ o: {

/**
* Helper to check if the object contains a property of the name
* @ignore
*/
function _hasOwnProperty(obj:any, prop:string) {
return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
}
/**
* Helper used to check whether the target is an Object prototype or Array prototype

@@ -211,3 +179,3 @@ * @ignore

newProto = target[DynProtoBaseProto] || curProto;
if (!_hasOwnProperty(target, DynProtoBaseProto)) {
if (!objHasOwnProperty(target, DynProtoBaseProto)) {
// As this prototype doesn't have this property then this is from an inherited class so newProto is the base to return so save it

@@ -235,3 +203,3 @@ // so we can look it up value (which for a multiple hierarchy dynamicProto will be the base class)

for (let name in target) {
if (typeof name === "string" && _hasOwnProperty(target, name)) {
if (typeof name === "string" && objHasOwnProperty(target, name)) {
props.push(name);

@@ -258,3 +226,3 @@ }

function _isDynamicCandidate(target:any, funcName:string, skipOwn:boolean) {
return (funcName !== Constructor && typeof target[funcName] === strFunction && (skipOwn || _hasOwnProperty(target, funcName)));
return (funcName !== Constructor && typeof target[funcName] === strFunction && (skipOwn || objHasOwnProperty(target, funcName)));
}

@@ -268,3 +236,3 @@

function _throwTypeError(message:string) {
throw new TypeError("DynamicProto: " + message);
throwTypeError("DynamicProto: " + message);
}

@@ -372,3 +340,3 @@

// it will walk the proto chain and return any parent proto classname.
if (target && _hasOwnProperty(proto, DynClassName)) {
if (target && objHasOwnProperty(proto, DynClassName)) {

@@ -387,3 +355,3 @@ let instFuncTable = target[DynInstFuncTable] || {};

// If the instance already has an instance function we can't replace it
let canAddInst = !_hasOwnProperty(target, funcName);
let canAddInst = !objHasOwnProperty(target, funcName);

@@ -485,3 +453,3 @@ // Get current prototype

// Add a dynamic proto if one doesn't exist or if a prototype function exists and it's not a dynamic one
if (!_hasOwnProperty(proto, name) || (proto[name] && !proto[name][DynProxyTag])) {
if (!objHasOwnProperty(proto, name) || (proto[name] && !proto[name][DynProxyTag])) {
proto[name] = _createDynamicPrototype(proto, name);

@@ -532,3 +500,3 @@ }

function _getObjName(target:any, unknownValue?:string) {
if (_hasOwnProperty(target, Prototype)) {
if (objHasOwnProperty(target, Prototype)) {
// Look like a prototype

@@ -623,3 +591,3 @@ return target.name || unknownValue || UnknownValue

// Make sure that the passed theClass argument looks correct
if (!_hasOwnProperty(theClass, Prototype)) {
if (!objHasOwnProperty(theClass, Prototype)) {
_throwTypeError("theClass is an invalid class definition.");

@@ -635,3 +603,3 @@ }

let className = null;
if (_hasOwnProperty(classProto, DynClassName)) {
if (objHasOwnProperty(classProto, DynClassName)) {
// Only grab the class name if it's defined on this prototype (i.e. don't walk the prototype chain)

@@ -638,0 +606,0 @@ className = classProto[DynClassName];

{
"name": "@microsoft/dynamicproto-js",
"description": "Microsoft Dynamic Proto Utility",
"version": "1.1.8",
"version": "2.0.0",
"keywords": [

@@ -14,5 +14,5 @@ "javascript",

],
"main": "./lib/dist/node/dynamicproto-js.js",
"module": "./lib/dist/esm/dynamicproto-js.js",
"types": "./lib/types/dynamicproto-js.d.ts",
"main": "./lib/dist/es5/node/dynamicproto-js.js",
"module": "./lib/dist-es5/DynamicProto.js",
"types": "./lib/types/DynamicProto.d.ts",
"directories": {

@@ -42,3 +42,5 @@ "doc": "lib/docs"

"homepage": "https://github.com/microsoft/DynamicProto-JS#readme",
"dependencies": {},
"dependencies": {
"@nevware21/ts-utils": ">= 0.9.4 < 2.x"
},
"devDependencies": {

@@ -45,0 +47,0 @@ "@microsoft/rush": "5.82.1",

@@ -9,2 +9,8 @@ # Dynamic Proto JavaScript

> ES3 / IE8 support has been removed from Version 2.x.
>
> if you need to retain ES3 / IE8 support then you will need to use one of the 1.x versions which is now maintained on the old [master branch](https://github.com/microsoft/DynamicProto-JS/tree/master)
The version 2.x is maintained on the default [main branch](https://github.com/microsoft/DynamicProto-JS/tree/main)
## Documentation

@@ -457,4 +463,31 @@

## Browser Support
## Version 2.x
Version 2.x is maintained on the default [main branch](https://github.com/microsoft/DynamicProto-JS/tree/main)
> Breaking Changes from Version 1.x
>
> - Removed ES3 / IE8 support
### Browser Support
- ES5 Compliant browsers
![Chrome](https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![IE9](https://raw.githubusercontent.com/hotoo/browser-logos/master/ie9-10/ie9-10_48x48.png) | ![Edge](https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![Opera](https://raw.githubusercontent.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Safari](https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png)
--- | --- | --- | --- | --- | --- |
Latest ✔ | Latest ✔ | 9+ Full ✔ | Latest ✔ | Latest ✔ | Latest ✔ |
### Previous Versions
<details>
<summary>Version 1.x</summary>
Version 1.x is maintained on the [master branch](https://github.com/microsoft/DynamicProto-JS/tree/master)
### Browser Support (1.x)
- ES3 Compliant browsers
![Chrome](https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![IE8](https://raw.githubusercontent.com/hotoo/browser-logos/master/ie9-10/ie9-10_48x48.png) | ![Edge](https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![Opera](https://raw.githubusercontent.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Safari](https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png)

@@ -466,2 +499,4 @@ --- | --- | --- | --- | --- | --- |

Version 1.x ONLY, 2.x DOES NOT support ES3/IE8
As a library there are numerous users which cannot control the browsers that their customers use. As such we need to ensure that this library continues to "work" and does not break the JS execution when loaded by an older browser. While it would be ideal to just not support IE8 and older generation (ES3) browsers there are numerous large customers/users that continue to require pages to "work" and as noted they may or cannot control which browser that their end users choose to use.

@@ -493,2 +528,4 @@

</details>
## Contributing

@@ -495,0 +532,0 @@

# Releases
## 2.0.0 (Mar 27th, 2023)
### Breaking Changes from Version 1.x ###
- Removed ES3 / IE8 support
- ES5 `Object.defineProperty()` is required during runtime.
### Changes
- Version 2.x development moved to [main branch](https://github.com/microsoft/DynamicProto-JS/tree/main) which is now the default branch, Version 1.x is still maintained from the [master branch](https://github.com/microsoft/DynamicProto-JS/tree/master)
- Removed private internal getGlobal() and hasOwnProperty() functions to provide better minification when bundled with other packages that also implement these functions by using [@nevware21/ts-utils](https://github.com/nevware21/ts-utils) as the dependency.
## 1.1.8 (Feb 27th, 2023)

@@ -4,0 +16,0 @@

@@ -7,6 +7,6 @@ /*!

function encode(decoded) {
var sourceFileIndex = 0; // second field
var sourceCodeLine = 0; // third field
var sourceCodeColumn = 0; // fourth field
var nameIndex = 0; // fifth field
var sourceFileIndex = 0;
var sourceCodeLine = 0;
var sourceCodeColumn = 0;
var nameIndex = 0;
var mappings = '';

@@ -19,3 +19,3 @@ for (var i = 0; i < decoded.length; i++) {

continue;
var generatedCodeColumn = 0; // first field
var generatedCodeColumn = 0;
var lineMappings = [];

@@ -62,11 +62,8 @@ for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {

};
BitSet.prototype.add = function add (n) {
this.bits[n >> 5] |= 1 << (n & 31);
};
BitSet.prototype.has = function has (n) {
return !!(this.bits[n >> 5] & (1 << (n & 31)));
};
var Chunk = function Chunk(start, end, content) {

@@ -76,11 +73,7 @@ this.start = start;

this.original = content;
this.intro = '';
this.outro = '';
this.content = content;
this.storeName = false;
this.edited = false;
// we make these non-enumerable, for sanity while debugging
Object.defineProperties(this, {

@@ -91,14 +84,10 @@ previous: { writable: true, value: null },

};
Chunk.prototype.appendLeft = function appendLeft (content) {
this.outro += content;
};
Chunk.prototype.appendRight = function appendRight (content) {
this.intro = this.intro + content;
};
Chunk.prototype.clone = function clone () {
var chunk = new Chunk(this.start, this.end, this.original);
chunk.intro = this.intro;

@@ -109,10 +98,7 @@ chunk.outro = this.outro;

chunk.edited = this.edited;
return chunk;
};
Chunk.prototype.contains = function contains (index) {
return this.start < index && index < this.end;
};
Chunk.prototype.eachNext = function eachNext (fn) {

@@ -125,3 +111,2 @@ var chunk = this;

};
Chunk.prototype.eachPrevious = function eachPrevious (fn) {

@@ -134,3 +119,2 @@ var chunk = this;

};
Chunk.prototype.edit = function edit (content, storeName, contentOnly) {

@@ -143,32 +127,21 @@ this.content = content;

this.storeName = storeName;
this.edited = true;
return this;
};
Chunk.prototype.prependLeft = function prependLeft (content) {
this.outro = content + this.outro;
};
Chunk.prototype.prependRight = function prependRight (content) {
this.intro = content + this.intro;
};
Chunk.prototype.split = function split (index) {
var sliceIndex = index - this.start;
var originalBefore = this.original.slice(0, sliceIndex);
var originalAfter = this.original.slice(sliceIndex);
this.original = originalBefore;
var newChunk = new Chunk(index, this.end, originalAfter);
newChunk.outro = this.outro;
this.outro = '';
this.end = index;
if (this.edited) {
// TODO is this block necessary?...
newChunk.edit('', false);

@@ -179,3 +152,2 @@ this.content = '';

}
newChunk.next = this.next;

@@ -185,16 +157,11 @@ if (newChunk.next) { newChunk.next.previous = newChunk; }

this.next = newChunk;
return newChunk;
};
Chunk.prototype.toString = function toString () {
return this.intro + this.content + this.outro;
};
Chunk.prototype.trimEnd = function trimEnd (rx) {
this.outro = this.outro.replace(rx, '');
if (this.outro.length) { return true; }
var trimmed = this.content.replace(rx, '');
if (trimmed.length) {

@@ -207,3 +174,2 @@ if (trimmed !== this.content) {

this.edit('', undefined, true);
this.intro = this.intro.replace(rx, '');

@@ -213,9 +179,6 @@ if (this.intro.length) { return true; }

};
Chunk.prototype.trimStart = function trimStart (rx) {
this.intro = this.intro.replace(rx, '');
if (this.intro.length) { return true; }
var trimmed = this.content.replace(rx, '');
if (trimmed.length) {

@@ -229,3 +192,2 @@ if (trimmed !== this.content) {

this.edit('', undefined, true);
this.outro = this.outro.replace(rx, '');

@@ -235,3 +197,2 @@ if (this.outro.length) { return true; }

};
var btoa = function () {

@@ -245,3 +206,2 @@ throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');

}
var SourceMap = function SourceMap(properties) {

@@ -255,29 +215,18 @@ this.version = 3;

};
SourceMap.prototype.toString = function toString () {
return JSON.stringify(this);
};
SourceMap.prototype.toUrl = function toUrl () {
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
};
function guessIndent(code) {
var lines = code.split('\n');
var tabbed = lines.filter(function (line) { return /^\t+/.test(line); });
var spaced = lines.filter(function (line) { return /^ {2,}/.test(line); });
if (tabbed.length === 0 && spaced.length === 0) {
return null;
}
// More lines tabbed than spaced? Assume tabs, and
// default to tabs in the case of a tie (or nothing
// to go on)
if (tabbed.length >= spaced.length) {
return '\t';
}
// Otherwise, we need to guess the multiple
var min = spaced.reduce(function (previous, current) {

@@ -287,12 +236,8 @@ var numSpaces = /^ +/.exec(current)[0].length;

}, Infinity);
return new Array(min + 1).join(' ');
}
function getRelativePath(from, to) {
var fromParts = from.split(/[/\\]/);
var toParts = to.split(/[/\\]/);
fromParts.pop(); // get dirname
fromParts.pop();
while (fromParts[0] === toParts[0]) {

@@ -302,3 +247,2 @@ fromParts.shift();

}
if (fromParts.length) {

@@ -308,16 +252,11 @@ var i = fromParts.length;

}
return fromParts.concat(toParts).join('/');
}
var toString = Object.prototype.toString;
function isObject(thing) {
return toString.call(thing) === '[object Object]';
}
function getLocator(source) {
var originalLines = source.split('\n');
var lineOffsets = [];
for (var i = 0, pos = 0; i < originalLines.length; i++) {

@@ -327,3 +266,2 @@ lineOffsets.push(pos);

}
return function locate(index) {

@@ -345,3 +283,2 @@ var i = 0;

}
var Mappings = function Mappings(hires) {

@@ -355,3 +292,2 @@ this.hires = hires;

};
Mappings.prototype.addEdit = function addEdit (sourceIndex, content, loc, nameIndex) {

@@ -367,11 +303,8 @@ if (content.length) {

}
this.advance(content);
this.pending = null;
};
Mappings.prototype.addUneditedChunk = function addUneditedChunk (sourceIndex, chunk, original, loc, sourcemapLocations) {
var originalCharIndex = chunk.start;
var first = true;
while (originalCharIndex < chunk.end) {

@@ -381,3 +314,2 @@ if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {

}
if (original[originalCharIndex] === '\n') {

@@ -395,14 +327,9 @@ loc.line += 1;

}
originalCharIndex += 1;
}
this.pending = null;
};
Mappings.prototype.advance = function advance (str) {
if (!str) { return; }
var lines = str.split('\n');
if (lines.length > 1) {

@@ -415,8 +342,5 @@ for (var i = 0; i < lines.length - 1; i++) {

}
this.generatedCodeColumn += lines[lines.length - 1].length;
};
var n = '\n';
var warned = {

@@ -427,8 +351,5 @@ insertLeft: false,

};
var MagicString = function MagicString(string, options) {
if ( options === void 0 ) options = {};
var chunk = new Chunk(0, string.length, string);
Object.defineProperties(this, {

@@ -449,25 +370,17 @@ original: { writable: true, value: string },

});
this.byStart[0] = chunk;
this.byEnd[string.length] = chunk;
};
MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) {
this.sourcemapLocations.add(char);
};
MagicString.prototype.append = function append (content) {
if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
this.outro += content;
return this;
};
MagicString.prototype.appendLeft = function appendLeft (index, content) {
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
this._split(index);
var chunk = this.byEnd[index];
if (chunk) {

@@ -480,10 +393,6 @@ chunk.appendLeft(content);

};
MagicString.prototype.appendRight = function appendRight (index, content) {
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
this._split(index);
var chunk = this.byStart[index];
if (chunk) {

@@ -496,60 +405,40 @@ chunk.appendRight(content);

};
MagicString.prototype.clone = function clone () {
var cloned = new MagicString(this.original, { filename: this.filename });
var originalChunk = this.firstChunk;
var clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
while (originalChunk) {
cloned.byStart[clonedChunk.start] = clonedChunk;
cloned.byEnd[clonedChunk.end] = clonedChunk;
var nextOriginalChunk = originalChunk.next;
var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
if (nextClonedChunk) {
clonedChunk.next = nextClonedChunk;
nextClonedChunk.previous = clonedChunk;
clonedChunk = nextClonedChunk;
}
originalChunk = nextOriginalChunk;
}
cloned.lastChunk = clonedChunk;
if (this.indentExclusionRanges) {
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
}
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
cloned.intro = this.intro;
cloned.outro = this.outro;
return cloned;
};
MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
var this$1$1 = this;
options = options || {};
var sourceIndex = 0;
var names = Object.keys(this.storedNames);
var mappings = new Mappings(options.hires);
var locate = getLocator(this.original);
if (this.intro) {
mappings.advance(this.intro);
}
this.firstChunk.eachNext(function (chunk) {
var loc = locate(chunk.start);
if (chunk.intro.length) { mappings.advance(chunk.intro); }
if (chunk.edited) {

@@ -565,6 +454,4 @@ mappings.addEdit(

}
if (chunk.outro.length) { mappings.advance(chunk.outro); }
});
return {

@@ -578,14 +465,10 @@ file: options.file ? options.file.split(/[/\\]/).pop() : null,

};
MagicString.prototype.generateMap = function generateMap (options) {
return new SourceMap(this.generateDecodedMap(options));
};
MagicString.prototype.getIndentString = function getIndentString () {
return this.indentStr === null ? '\t' : this.indentStr;
};
MagicString.prototype.indent = function indent (indentStr, options) {
var pattern = /^[^\r\n]/gm;
if (isObject(indentStr)) {

@@ -595,12 +478,6 @@ options = indentStr;

}
indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
if (indentStr === '') { return this; } // noop
if (indentStr === '') { return this; }
options = options || {};
// Process exclusion ranges
var isExcluded = {};
if (options.exclude) {

@@ -615,3 +492,2 @@ var exclusions =

}
var shouldIndentNextCharacter = options.indentStart !== false;

@@ -623,15 +499,10 @@ var replacer = function (match) {

};
this.intro = this.intro.replace(pattern, replacer);
var charIndex = 0;
var chunk = this.firstChunk;
while (chunk) {
var end = chunk.end;
if (chunk.edited) {
if (!isExcluded[charIndex]) {
chunk.content = chunk.content.replace(pattern, replacer);
if (chunk.content.length) {

@@ -643,7 +514,5 @@ shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';

charIndex = chunk.start;
while (charIndex < end) {
if (!isExcluded[charIndex]) {
var char = this.original[charIndex];
if (char === '\n') {

@@ -653,3 +522,2 @@ shouldIndentNextCharacter = true;

shouldIndentNextCharacter = false;
if (charIndex === chunk.start) {

@@ -664,16 +532,11 @@ chunk.prependRight(indentStr);

}
charIndex += 1;
}
}
charIndex = chunk.end;
chunk = chunk.next;
}
this.outro = this.outro.replace(pattern, replacer);
return this;
};
MagicString.prototype.insert = function insert () {

@@ -684,3 +547,2 @@ throw new Error(

};
MagicString.prototype.insertLeft = function insertLeft (index, content) {

@@ -690,9 +552,7 @@ if (!warned.insertLeft) {

'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
); // eslint-disable-line no-console
);
warned.insertLeft = true;
}
return this.appendLeft(index, content);
};
MagicString.prototype.insertRight = function insertRight (index, content) {

@@ -702,32 +562,23 @@ if (!warned.insertRight) {

'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
); // eslint-disable-line no-console
);
warned.insertRight = true;
}
return this.prependRight(index, content);
};
MagicString.prototype.move = function move (start, end, index) {
if (index >= start && index <= end) { throw new Error('Cannot move a selection inside itself'); }
this._split(start);
this._split(end);
this._split(index);
var first = this.byStart[start];
var last = this.byEnd[end];
var oldLeft = first.previous;
var oldRight = last.next;
var newRight = this.byStart[index];
if (!newRight && last === this.lastChunk) { return this; }
var newLeft = newRight ? newRight.previous : this.lastChunk;
if (oldLeft) { oldLeft.next = oldRight; }
if (oldRight) { oldRight.previous = oldLeft; }
if (newLeft) { newLeft.next = first; }
if (newRight) { newRight.previous = last; }
if (!first.previous) { this.firstChunk = last.next; }

@@ -738,6 +589,4 @@ if (!last.next) {

}
first.previous = newLeft;
last.next = newRight || null;
if (!newLeft) { this.firstChunk = first; }

@@ -747,9 +596,6 @@ if (!newRight) { this.lastChunk = last; }

};
MagicString.prototype.overwrite = function overwrite (start, end, content, options) {
if (typeof content !== 'string') { throw new TypeError('replacement content must be a string'); }
while (start < 0) { start += this.original.length; }
while (end < 0) { end += this.original.length; }
if (end > this.original.length) { throw new Error('end is out of bounds'); }

@@ -760,6 +606,4 @@ if (start === end)

); }
this._split(start);
this._split(end);
if (options === true) {

@@ -769,6 +613,5 @@ if (!warned.storeName) {

'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
); // eslint-disable-line no-console
);
warned.storeName = true;
}
options = { storeName: true };

@@ -778,3 +621,2 @@ }

var contentOnly = options !== undefined ? options.contentOnly : false;
if (storeName) {

@@ -784,6 +626,4 @@ var original = this.original.slice(start, end);

}
var first = this.byStart[start];
var last = this.byEnd[end];
if (first) {

@@ -798,9 +638,5 @@ var chunk = first;

}
first.edit(content, storeName, contentOnly);
} else {
// must be inserting at the end
var newChunk = new Chunk(start, end, '').edit(content, storeName);
// TODO last chunk in the array may not be the last chunk, if it's moved...
last.next = newChunk;

@@ -811,17 +647,11 @@ newChunk.previous = last;

};
MagicString.prototype.prepend = function prepend (content) {
if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
this.intro = content + this.intro;
return this;
};
MagicString.prototype.prependLeft = function prependLeft (index, content) {
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
this._split(index);
var chunk = this.byEnd[index];
if (chunk) {

@@ -834,10 +664,6 @@ chunk.prependLeft(content);

};
MagicString.prototype.prependRight = function prependRight (index, content) {
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
this._split(index);
var chunk = this.byStart[index];
if (chunk) {

@@ -850,17 +676,11 @@ chunk.prependRight(content);

};
MagicString.prototype.remove = function remove (start, end) {
while (start < 0) { start += this.original.length; }
while (end < 0) { end += this.original.length; }
if (start === end) { return this; }
if (start < 0 || end > this.original.length) { throw new Error('Character is out of bounds'); }
if (start > end) { throw new Error('end must be greater than start'); }
this._split(start);
this._split(end);
var chunk = this.byStart[start];
while (chunk) {

@@ -870,3 +690,2 @@ chunk.intro = '';

chunk.edit('');
chunk = end > chunk.end ? this.byStart[chunk.end] : null;

@@ -876,3 +695,2 @@ }

};
MagicString.prototype.lastChar = function lastChar () {

@@ -889,3 +707,2 @@ if (this.outro.length) { return this.outro[this.outro.length - 1]; }

};
MagicString.prototype.lastLine = function lastLine () {

@@ -902,3 +719,2 @@ var lineIndex = this.outro.lastIndexOf(n);

}
if (chunk.content.length > 0) {

@@ -909,3 +725,2 @@ lineIndex = chunk.content.lastIndexOf(n);

}
if (chunk.intro.length > 0) {

@@ -921,26 +736,17 @@ lineIndex = chunk.intro.lastIndexOf(n);

};
MagicString.prototype.slice = function slice (start, end) {
if ( start === void 0 ) start = 0;
if ( end === void 0 ) end = this.original.length;
while (start < 0) { start += this.original.length; }
while (end < 0) { end += this.original.length; }
var result = '';
// find start chunk
var chunk = this.firstChunk;
while (chunk && (chunk.start > start || chunk.end <= start)) {
// found end chunk before start
if (chunk.start < end && chunk.end >= end) {
return result;
}
chunk = chunk.next;
}
if (chunk && chunk.edited && chunk.start !== start)
{ throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
var startChunk = chunk;

@@ -951,27 +757,18 @@ while (chunk) {

}
var containsEnd = chunk.start < end && chunk.end >= end;
if (containsEnd && chunk.edited && chunk.end !== end)
{ throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
var sliceStart = startChunk === chunk ? start - chunk.start : 0;
var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
result += chunk.content.slice(sliceStart, sliceEnd);
if (chunk.outro && (!containsEnd || chunk.end === end)) {
result += chunk.outro;
}
if (containsEnd) {
break;
}
chunk = chunk.next;
}
return result;
};
// TODO deprecate this? not really very useful
MagicString.prototype.snip = function snip (start, end) {

@@ -981,22 +778,15 @@ var clone = this.clone();

clone.remove(end, clone.original.length);
return clone;
};
MagicString.prototype._split = function _split (index) {
if (this.byStart[index] || this.byEnd[index]) { return; }
var chunk = this.lastSearchedChunk;
var searchForward = index > chunk.end;
while (chunk) {
if (chunk.contains(index)) { return this._splitChunk(chunk, index); }
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
}
};
MagicString.prototype._splitChunk = function _splitChunk (chunk, index) {
if (chunk.edited && chunk.content.length) {
// zero-length edited chunks are a special case (overlapping replacements)
var loc = getLocator(this.original)(index);

@@ -1007,18 +797,12 @@ throw new Error(

}
var newChunk = chunk.split(index);
this.byEnd[index] = chunk;
this.byStart[index] = newChunk;
this.byEnd[newChunk.end] = newChunk;
if (chunk === this.lastChunk) { this.lastChunk = newChunk; }
this.lastSearchedChunk = chunk;
return true;
};
MagicString.prototype.toString = function toString () {
var str = this.intro;
var chunk = this.firstChunk;

@@ -1029,6 +813,4 @@ while (chunk) {

}
return str + this.outro;
};
MagicString.prototype.isEmpty = function isEmpty () {

@@ -1046,3 +828,2 @@ var chunk = this.firstChunk;

};
MagicString.prototype.length = function length () {

@@ -1056,24 +837,16 @@ var chunk = this.firstChunk;

};
MagicString.prototype.trimLines = function trimLines () {
return this.trim('[\\r\\n]');
};
MagicString.prototype.trim = function trim (charType) {
return this.trimStart(charType).trimEnd(charType);
};
MagicString.prototype.trimEndAborted = function trimEndAborted (charType) {
var rx = new RegExp((charType || '\\s') + '+$');
this.outro = this.outro.replace(rx, '');
if (this.outro.length) { return true; }
var chunk = this.lastChunk;
do {
var end = chunk.end;
var aborted = chunk.trimEnd(rx);
// if chunk was trimmed, we have a new lastChunk
if (chunk.end !== end) {

@@ -1083,3 +856,2 @@ if (this.lastChunk === chunk) {

}
this.byEnd[chunk.end] = chunk;

@@ -1089,10 +861,7 @@ this.byStart[chunk.next.start] = chunk.next;

}
if (aborted) { return true; }
chunk = chunk.previous;
} while (chunk);
return false;
};
MagicString.prototype.trimEnd = function trimEnd (charType) {

@@ -1104,16 +873,10 @@ this.trimEndAborted(charType);

var rx = new RegExp('^' + (charType || '\\s') + '+');
this.intro = this.intro.replace(rx, '');
if (this.intro.length) { return true; }
var chunk = this.firstChunk;
do {
var end = chunk.end;
var aborted = chunk.trimStart(rx);
if (chunk.end !== end) {
// special case...
if (chunk === this.lastChunk) { this.lastChunk = chunk.next; }
this.byEnd[chunk.end] = chunk;

@@ -1123,10 +886,7 @@ this.byStart[chunk.next.start] = chunk.next;

}
if (aborted) { return true; }
chunk = chunk.next;
} while (chunk);
return false;
};
MagicString.prototype.trimStart = function trimStart (charType) {

@@ -1146,4 +906,2 @@ this.trimStartAborted(charType);

}
// Need to mock this rather than rely on JavaScript String.prototype.padEnd() as it doesn't always
// exists in the build / test infrastructure
function padEnd(input, len, fill) {

@@ -1165,8 +923,2 @@ var value = input || "";

}
/**
* Simple Rush plugin to remove code that is wrapped between specific comments, this is used to
* remove the boilerplate code require by typescript to define methods as prototype level while
* using @ms-dynamicProto project to support minification. This can also be used to remove "debug"
* functions from the production code.
*/
function dynamicRemove(options) {

@@ -1178,3 +930,2 @@ if (options === void 0) { options = {}; }

var funcNameGroup = 6;
// Because of the test infrastructure (PhamtonJS) the RegEx can't use the "s" flag (gis vs gi) or named groups
var pattern = new RegExp("([\\t ]*\\/\\*\\*((?!\\*\\/)(.|\\r|\\n))*\\*\\/[\\s]*)*(\\/\\/[\\t ]*" + escape(token) + "[^\\r\\n]*(\\r\\n|\\n\\r|\\r|\\n))*[\\t ]*([\\w]*\\.prototype(\\.|\\[\\\"|\\[\\')[\\w]*(\\\"\\]|\\'\\])?)[\\t ]*=[\\t ]*function[\\t ]*\\([^\\{]*\\{[^\\/\\}\\{]*(\\{[^\\}]*\\}[^\\/\\}\\{]*)*(\\/[\\*\\/][\\t ]*" + escape(token) + "[^\\*\\r\\n]*(\\*\\/)?(\\r\\n|\\n\\r|\\r|\\n))*[^\\}]*\\};([\\t ]*\\/\\/[\\t ]*" + escape(token) + "[^\\r\\n]*)*", 'gi');

@@ -1253,3 +1004,2 @@ function formatError(token, code, pos, id) {

if (!isNullOrWhitespace(funcName)) {
// Only remove matches that contain a tag and function
var hasToken = false;

@@ -1294,7 +1044,5 @@ for (var lp = 0; lp < tokenGroups.length; lp++) {

if (result) {
// Do a final check of the string
checkResult(result.code, id);
}
else {
// Check that the raw input doesn't include the tag
checkResult(code, id);

@@ -1301,0 +1049,0 @@ }

@@ -13,6 +13,6 @@ /*!

function encode(decoded) {
var sourceFileIndex = 0; // second field
var sourceCodeLine = 0; // third field
var sourceCodeColumn = 0; // fourth field
var nameIndex = 0; // fifth field
var sourceFileIndex = 0;
var sourceCodeLine = 0;
var sourceCodeColumn = 0;
var nameIndex = 0;
var mappings = '';

@@ -25,3 +25,3 @@ for (var i = 0; i < decoded.length; i++) {

continue;
var generatedCodeColumn = 0; // first field
var generatedCodeColumn = 0;
var lineMappings = [];

@@ -68,11 +68,8 @@ for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {

};
BitSet.prototype.add = function add (n) {
this.bits[n >> 5] |= 1 << (n & 31);
};
BitSet.prototype.has = function has (n) {
return !!(this.bits[n >> 5] & (1 << (n & 31)));
};
var Chunk = function Chunk(start, end, content) {

@@ -82,11 +79,7 @@ this.start = start;

this.original = content;
this.intro = '';
this.outro = '';
this.content = content;
this.storeName = false;
this.edited = false;
// we make these non-enumerable, for sanity while debugging
Object.defineProperties(this, {

@@ -97,14 +90,10 @@ previous: { writable: true, value: null },

};
Chunk.prototype.appendLeft = function appendLeft (content) {
this.outro += content;
};
Chunk.prototype.appendRight = function appendRight (content) {
this.intro = this.intro + content;
};
Chunk.prototype.clone = function clone () {
var chunk = new Chunk(this.start, this.end, this.original);
chunk.intro = this.intro;

@@ -115,10 +104,7 @@ chunk.outro = this.outro;

chunk.edited = this.edited;
return chunk;
};
Chunk.prototype.contains = function contains (index) {
return this.start < index && index < this.end;
};
Chunk.prototype.eachNext = function eachNext (fn) {

@@ -131,3 +117,2 @@ var chunk = this;

};
Chunk.prototype.eachPrevious = function eachPrevious (fn) {

@@ -140,3 +125,2 @@ var chunk = this;

};
Chunk.prototype.edit = function edit (content, storeName, contentOnly) {

@@ -149,32 +133,21 @@ this.content = content;

this.storeName = storeName;
this.edited = true;
return this;
};
Chunk.prototype.prependLeft = function prependLeft (content) {
this.outro = content + this.outro;
};
Chunk.prototype.prependRight = function prependRight (content) {
this.intro = content + this.intro;
};
Chunk.prototype.split = function split (index) {
var sliceIndex = index - this.start;
var originalBefore = this.original.slice(0, sliceIndex);
var originalAfter = this.original.slice(sliceIndex);
this.original = originalBefore;
var newChunk = new Chunk(index, this.end, originalAfter);
newChunk.outro = this.outro;
this.outro = '';
this.end = index;
if (this.edited) {
// TODO is this block necessary?...
newChunk.edit('', false);

@@ -185,3 +158,2 @@ this.content = '';

}
newChunk.next = this.next;

@@ -191,16 +163,11 @@ if (newChunk.next) { newChunk.next.previous = newChunk; }

this.next = newChunk;
return newChunk;
};
Chunk.prototype.toString = function toString () {
return this.intro + this.content + this.outro;
};
Chunk.prototype.trimEnd = function trimEnd (rx) {
this.outro = this.outro.replace(rx, '');
if (this.outro.length) { return true; }
var trimmed = this.content.replace(rx, '');
if (trimmed.length) {

@@ -213,3 +180,2 @@ if (trimmed !== this.content) {

this.edit('', undefined, true);
this.intro = this.intro.replace(rx, '');

@@ -219,9 +185,6 @@ if (this.intro.length) { return true; }

};
Chunk.prototype.trimStart = function trimStart (rx) {
this.intro = this.intro.replace(rx, '');
if (this.intro.length) { return true; }
var trimmed = this.content.replace(rx, '');
if (trimmed.length) {

@@ -235,3 +198,2 @@ if (trimmed !== this.content) {

this.edit('', undefined, true);
this.outro = this.outro.replace(rx, '');

@@ -241,3 +203,2 @@ if (this.outro.length) { return true; }

};
var btoa = function () {

@@ -251,3 +212,2 @@ throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');

}
var SourceMap = function SourceMap(properties) {

@@ -261,29 +221,18 @@ this.version = 3;

};
SourceMap.prototype.toString = function toString () {
return JSON.stringify(this);
};
SourceMap.prototype.toUrl = function toUrl () {
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
};
function guessIndent(code) {
var lines = code.split('\n');
var tabbed = lines.filter(function (line) { return /^\t+/.test(line); });
var spaced = lines.filter(function (line) { return /^ {2,}/.test(line); });
if (tabbed.length === 0 && spaced.length === 0) {
return null;
}
// More lines tabbed than spaced? Assume tabs, and
// default to tabs in the case of a tie (or nothing
// to go on)
if (tabbed.length >= spaced.length) {
return '\t';
}
// Otherwise, we need to guess the multiple
var min = spaced.reduce(function (previous, current) {

@@ -293,12 +242,8 @@ var numSpaces = /^ +/.exec(current)[0].length;

}, Infinity);
return new Array(min + 1).join(' ');
}
function getRelativePath(from, to) {
var fromParts = from.split(/[/\\]/);
var toParts = to.split(/[/\\]/);
fromParts.pop(); // get dirname
fromParts.pop();
while (fromParts[0] === toParts[0]) {

@@ -308,3 +253,2 @@ fromParts.shift();

}
if (fromParts.length) {

@@ -314,16 +258,11 @@ var i = fromParts.length;

}
return fromParts.concat(toParts).join('/');
}
var toString = Object.prototype.toString;
function isObject(thing) {
return toString.call(thing) === '[object Object]';
}
function getLocator(source) {
var originalLines = source.split('\n');
var lineOffsets = [];
for (var i = 0, pos = 0; i < originalLines.length; i++) {

@@ -333,3 +272,2 @@ lineOffsets.push(pos);

}
return function locate(index) {

@@ -351,3 +289,2 @@ var i = 0;

}
var Mappings = function Mappings(hires) {

@@ -361,3 +298,2 @@ this.hires = hires;

};
Mappings.prototype.addEdit = function addEdit (sourceIndex, content, loc, nameIndex) {

@@ -373,11 +309,8 @@ if (content.length) {

}
this.advance(content);
this.pending = null;
};
Mappings.prototype.addUneditedChunk = function addUneditedChunk (sourceIndex, chunk, original, loc, sourcemapLocations) {
var originalCharIndex = chunk.start;
var first = true;
while (originalCharIndex < chunk.end) {

@@ -387,3 +320,2 @@ if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {

}
if (original[originalCharIndex] === '\n') {

@@ -401,14 +333,9 @@ loc.line += 1;

}
originalCharIndex += 1;
}
this.pending = null;
};
Mappings.prototype.advance = function advance (str) {
if (!str) { return; }
var lines = str.split('\n');
if (lines.length > 1) {

@@ -421,8 +348,5 @@ for (var i = 0; i < lines.length - 1; i++) {

}
this.generatedCodeColumn += lines[lines.length - 1].length;
};
var n = '\n';
var warned = {

@@ -433,8 +357,5 @@ insertLeft: false,

};
var MagicString = function MagicString(string, options) {
if ( options === void 0 ) options = {};
var chunk = new Chunk(0, string.length, string);
Object.defineProperties(this, {

@@ -455,25 +376,17 @@ original: { writable: true, value: string },

});
this.byStart[0] = chunk;
this.byEnd[string.length] = chunk;
};
MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) {
this.sourcemapLocations.add(char);
};
MagicString.prototype.append = function append (content) {
if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
this.outro += content;
return this;
};
MagicString.prototype.appendLeft = function appendLeft (index, content) {
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
this._split(index);
var chunk = this.byEnd[index];
if (chunk) {

@@ -486,10 +399,6 @@ chunk.appendLeft(content);

};
MagicString.prototype.appendRight = function appendRight (index, content) {
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
this._split(index);
var chunk = this.byStart[index];
if (chunk) {

@@ -502,60 +411,40 @@ chunk.appendRight(content);

};
MagicString.prototype.clone = function clone () {
var cloned = new MagicString(this.original, { filename: this.filename });
var originalChunk = this.firstChunk;
var clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
while (originalChunk) {
cloned.byStart[clonedChunk.start] = clonedChunk;
cloned.byEnd[clonedChunk.end] = clonedChunk;
var nextOriginalChunk = originalChunk.next;
var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
if (nextClonedChunk) {
clonedChunk.next = nextClonedChunk;
nextClonedChunk.previous = clonedChunk;
clonedChunk = nextClonedChunk;
}
originalChunk = nextOriginalChunk;
}
cloned.lastChunk = clonedChunk;
if (this.indentExclusionRanges) {
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
}
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
cloned.intro = this.intro;
cloned.outro = this.outro;
return cloned;
};
MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
var this$1$1 = this;
options = options || {};
var sourceIndex = 0;
var names = Object.keys(this.storedNames);
var mappings = new Mappings(options.hires);
var locate = getLocator(this.original);
if (this.intro) {
mappings.advance(this.intro);
}
this.firstChunk.eachNext(function (chunk) {
var loc = locate(chunk.start);
if (chunk.intro.length) { mappings.advance(chunk.intro); }
if (chunk.edited) {

@@ -571,6 +460,4 @@ mappings.addEdit(

}
if (chunk.outro.length) { mappings.advance(chunk.outro); }
});
return {

@@ -584,14 +471,10 @@ file: options.file ? options.file.split(/[/\\]/).pop() : null,

};
MagicString.prototype.generateMap = function generateMap (options) {
return new SourceMap(this.generateDecodedMap(options));
};
MagicString.prototype.getIndentString = function getIndentString () {
return this.indentStr === null ? '\t' : this.indentStr;
};
MagicString.prototype.indent = function indent (indentStr, options) {
var pattern = /^[^\r\n]/gm;
if (isObject(indentStr)) {

@@ -601,12 +484,6 @@ options = indentStr;

}
indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
if (indentStr === '') { return this; } // noop
if (indentStr === '') { return this; }
options = options || {};
// Process exclusion ranges
var isExcluded = {};
if (options.exclude) {

@@ -621,3 +498,2 @@ var exclusions =

}
var shouldIndentNextCharacter = options.indentStart !== false;

@@ -629,15 +505,10 @@ var replacer = function (match) {

};
this.intro = this.intro.replace(pattern, replacer);
var charIndex = 0;
var chunk = this.firstChunk;
while (chunk) {
var end = chunk.end;
if (chunk.edited) {
if (!isExcluded[charIndex]) {
chunk.content = chunk.content.replace(pattern, replacer);
if (chunk.content.length) {

@@ -649,7 +520,5 @@ shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';

charIndex = chunk.start;
while (charIndex < end) {
if (!isExcluded[charIndex]) {
var char = this.original[charIndex];
if (char === '\n') {

@@ -659,3 +528,2 @@ shouldIndentNextCharacter = true;

shouldIndentNextCharacter = false;
if (charIndex === chunk.start) {

@@ -670,16 +538,11 @@ chunk.prependRight(indentStr);

}
charIndex += 1;
}
}
charIndex = chunk.end;
chunk = chunk.next;
}
this.outro = this.outro.replace(pattern, replacer);
return this;
};
MagicString.prototype.insert = function insert () {

@@ -690,3 +553,2 @@ throw new Error(

};
MagicString.prototype.insertLeft = function insertLeft (index, content) {

@@ -696,9 +558,7 @@ if (!warned.insertLeft) {

'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
); // eslint-disable-line no-console
);
warned.insertLeft = true;
}
return this.appendLeft(index, content);
};
MagicString.prototype.insertRight = function insertRight (index, content) {

@@ -708,32 +568,23 @@ if (!warned.insertRight) {

'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
); // eslint-disable-line no-console
);
warned.insertRight = true;
}
return this.prependRight(index, content);
};
MagicString.prototype.move = function move (start, end, index) {
if (index >= start && index <= end) { throw new Error('Cannot move a selection inside itself'); }
this._split(start);
this._split(end);
this._split(index);
var first = this.byStart[start];
var last = this.byEnd[end];
var oldLeft = first.previous;
var oldRight = last.next;
var newRight = this.byStart[index];
if (!newRight && last === this.lastChunk) { return this; }
var newLeft = newRight ? newRight.previous : this.lastChunk;
if (oldLeft) { oldLeft.next = oldRight; }
if (oldRight) { oldRight.previous = oldLeft; }
if (newLeft) { newLeft.next = first; }
if (newRight) { newRight.previous = last; }
if (!first.previous) { this.firstChunk = last.next; }

@@ -744,6 +595,4 @@ if (!last.next) {

}
first.previous = newLeft;
last.next = newRight || null;
if (!newLeft) { this.firstChunk = first; }

@@ -753,9 +602,6 @@ if (!newRight) { this.lastChunk = last; }

};
MagicString.prototype.overwrite = function overwrite (start, end, content, options) {
if (typeof content !== 'string') { throw new TypeError('replacement content must be a string'); }
while (start < 0) { start += this.original.length; }
while (end < 0) { end += this.original.length; }
if (end > this.original.length) { throw new Error('end is out of bounds'); }

@@ -766,6 +612,4 @@ if (start === end)

); }
this._split(start);
this._split(end);
if (options === true) {

@@ -775,6 +619,5 @@ if (!warned.storeName) {

'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
); // eslint-disable-line no-console
);
warned.storeName = true;
}
options = { storeName: true };

@@ -784,3 +627,2 @@ }

var contentOnly = options !== undefined ? options.contentOnly : false;
if (storeName) {

@@ -790,6 +632,4 @@ var original = this.original.slice(start, end);

}
var first = this.byStart[start];
var last = this.byEnd[end];
if (first) {

@@ -804,9 +644,5 @@ var chunk = first;

}
first.edit(content, storeName, contentOnly);
} else {
// must be inserting at the end
var newChunk = new Chunk(start, end, '').edit(content, storeName);
// TODO last chunk in the array may not be the last chunk, if it's moved...
last.next = newChunk;

@@ -817,17 +653,11 @@ newChunk.previous = last;

};
MagicString.prototype.prepend = function prepend (content) {
if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
this.intro = content + this.intro;
return this;
};
MagicString.prototype.prependLeft = function prependLeft (index, content) {
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
this._split(index);
var chunk = this.byEnd[index];
if (chunk) {

@@ -840,10 +670,6 @@ chunk.prependLeft(content);

};
MagicString.prototype.prependRight = function prependRight (index, content) {
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
this._split(index);
var chunk = this.byStart[index];
if (chunk) {

@@ -856,17 +682,11 @@ chunk.prependRight(content);

};
MagicString.prototype.remove = function remove (start, end) {
while (start < 0) { start += this.original.length; }
while (end < 0) { end += this.original.length; }
if (start === end) { return this; }
if (start < 0 || end > this.original.length) { throw new Error('Character is out of bounds'); }
if (start > end) { throw new Error('end must be greater than start'); }
this._split(start);
this._split(end);
var chunk = this.byStart[start];
while (chunk) {

@@ -876,3 +696,2 @@ chunk.intro = '';

chunk.edit('');
chunk = end > chunk.end ? this.byStart[chunk.end] : null;

@@ -882,3 +701,2 @@ }

};
MagicString.prototype.lastChar = function lastChar () {

@@ -895,3 +713,2 @@ if (this.outro.length) { return this.outro[this.outro.length - 1]; }

};
MagicString.prototype.lastLine = function lastLine () {

@@ -908,3 +725,2 @@ var lineIndex = this.outro.lastIndexOf(n);

}
if (chunk.content.length > 0) {

@@ -915,3 +731,2 @@ lineIndex = chunk.content.lastIndexOf(n);

}
if (chunk.intro.length > 0) {

@@ -927,26 +742,17 @@ lineIndex = chunk.intro.lastIndexOf(n);

};
MagicString.prototype.slice = function slice (start, end) {
if ( start === void 0 ) start = 0;
if ( end === void 0 ) end = this.original.length;
while (start < 0) { start += this.original.length; }
while (end < 0) { end += this.original.length; }
var result = '';
// find start chunk
var chunk = this.firstChunk;
while (chunk && (chunk.start > start || chunk.end <= start)) {
// found end chunk before start
if (chunk.start < end && chunk.end >= end) {
return result;
}
chunk = chunk.next;
}
if (chunk && chunk.edited && chunk.start !== start)
{ throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
var startChunk = chunk;

@@ -957,27 +763,18 @@ while (chunk) {

}
var containsEnd = chunk.start < end && chunk.end >= end;
if (containsEnd && chunk.edited && chunk.end !== end)
{ throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
var sliceStart = startChunk === chunk ? start - chunk.start : 0;
var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
result += chunk.content.slice(sliceStart, sliceEnd);
if (chunk.outro && (!containsEnd || chunk.end === end)) {
result += chunk.outro;
}
if (containsEnd) {
break;
}
chunk = chunk.next;
}
return result;
};
// TODO deprecate this? not really very useful
MagicString.prototype.snip = function snip (start, end) {

@@ -987,22 +784,15 @@ var clone = this.clone();

clone.remove(end, clone.original.length);
return clone;
};
MagicString.prototype._split = function _split (index) {
if (this.byStart[index] || this.byEnd[index]) { return; }
var chunk = this.lastSearchedChunk;
var searchForward = index > chunk.end;
while (chunk) {
if (chunk.contains(index)) { return this._splitChunk(chunk, index); }
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
}
};
MagicString.prototype._splitChunk = function _splitChunk (chunk, index) {
if (chunk.edited && chunk.content.length) {
// zero-length edited chunks are a special case (overlapping replacements)
var loc = getLocator(this.original)(index);

@@ -1013,18 +803,12 @@ throw new Error(

}
var newChunk = chunk.split(index);
this.byEnd[index] = chunk;
this.byStart[index] = newChunk;
this.byEnd[newChunk.end] = newChunk;
if (chunk === this.lastChunk) { this.lastChunk = newChunk; }
this.lastSearchedChunk = chunk;
return true;
};
MagicString.prototype.toString = function toString () {
var str = this.intro;
var chunk = this.firstChunk;

@@ -1035,6 +819,4 @@ while (chunk) {

}
return str + this.outro;
};
MagicString.prototype.isEmpty = function isEmpty () {

@@ -1052,3 +834,2 @@ var chunk = this.firstChunk;

};
MagicString.prototype.length = function length () {

@@ -1062,24 +843,16 @@ var chunk = this.firstChunk;

};
MagicString.prototype.trimLines = function trimLines () {
return this.trim('[\\r\\n]');
};
MagicString.prototype.trim = function trim (charType) {
return this.trimStart(charType).trimEnd(charType);
};
MagicString.prototype.trimEndAborted = function trimEndAborted (charType) {
var rx = new RegExp((charType || '\\s') + '+$');
this.outro = this.outro.replace(rx, '');
if (this.outro.length) { return true; }
var chunk = this.lastChunk;
do {
var end = chunk.end;
var aborted = chunk.trimEnd(rx);
// if chunk was trimmed, we have a new lastChunk
if (chunk.end !== end) {

@@ -1089,3 +862,2 @@ if (this.lastChunk === chunk) {

}
this.byEnd[chunk.end] = chunk;

@@ -1095,10 +867,7 @@ this.byStart[chunk.next.start] = chunk.next;

}
if (aborted) { return true; }
chunk = chunk.previous;
} while (chunk);
return false;
};
MagicString.prototype.trimEnd = function trimEnd (charType) {

@@ -1110,16 +879,10 @@ this.trimEndAborted(charType);

var rx = new RegExp('^' + (charType || '\\s') + '+');
this.intro = this.intro.replace(rx, '');
if (this.intro.length) { return true; }
var chunk = this.firstChunk;
do {
var end = chunk.end;
var aborted = chunk.trimStart(rx);
if (chunk.end !== end) {
// special case...
if (chunk === this.lastChunk) { this.lastChunk = chunk.next; }
this.byEnd[chunk.end] = chunk;

@@ -1129,10 +892,7 @@ this.byStart[chunk.next.start] = chunk.next;

}
if (aborted) { return true; }
chunk = chunk.next;
} while (chunk);
return false;
};
MagicString.prototype.trimStart = function trimStart (charType) {

@@ -1152,4 +912,2 @@ this.trimStartAborted(charType);

}
// Need to mock this rather than rely on JavaScript String.prototype.padEnd() as it doesn't always
// exists in the build / test infrastructure
function padEnd(input, len, fill) {

@@ -1171,8 +929,2 @@ var value = input || "";

}
/**
* Simple Rush plugin to remove code that is wrapped between specific comments, this is used to
* remove the boilerplate code require by typescript to define methods as prototype level while
* using @ms-dynamicProto project to support minification. This can also be used to remove "debug"
* functions from the production code.
*/
function dynamicRemove(options) {

@@ -1184,3 +936,2 @@ if (options === void 0) { options = {}; }

var funcNameGroup = 6;
// Because of the test infrastructure (PhamtonJS) the RegEx can't use the "s" flag (gis vs gi) or named groups
var pattern = new RegExp("([\\t ]*\\/\\*\\*((?!\\*\\/)(.|\\r|\\n))*\\*\\/[\\s]*)*(\\/\\/[\\t ]*" + escape(token) + "[^\\r\\n]*(\\r\\n|\\n\\r|\\r|\\n))*[\\t ]*([\\w]*\\.prototype(\\.|\\[\\\"|\\[\\')[\\w]*(\\\"\\]|\\'\\])?)[\\t ]*=[\\t ]*function[\\t ]*\\([^\\{]*\\{[^\\/\\}\\{]*(\\{[^\\}]*\\}[^\\/\\}\\{]*)*(\\/[\\*\\/][\\t ]*" + escape(token) + "[^\\*\\r\\n]*(\\*\\/)?(\\r\\n|\\n\\r|\\r|\\n))*[^\\}]*\\};([\\t ]*\\/\\/[\\t ]*" + escape(token) + "[^\\r\\n]*)*", 'gi');

@@ -1259,3 +1010,2 @@ function formatError(token, code, pos, id) {

if (!isNullOrWhitespace(funcName)) {
// Only remove matches that contain a tag and function
var hasToken = false;

@@ -1300,7 +1050,5 @@ for (var lp = 0; lp < tokenGroups.length; lp++) {

if (result) {
// Do a final check of the string
checkResult(result.code, id);
}
else {
// Check that the raw input doesn't include the tag
checkResult(code, id);

@@ -1307,0 +1055,0 @@ }

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