@gedit/utils
Advanced tools
Comparing version 0.1.69 to 0.1.70
@@ -23,3 +23,3 @@ "use strict"; | ||
exports.preventNavigation = exports.parseCssTime = exports.parseCssMagnitude = exports.animationFrame = exports.isBasicWasmSupported = exports.isNative = exports.isIPad = exports.isSafari = exports.isChrome = exports.isWebKit = exports.isFirefox = exports.isOpera = exports.isEdgeOrIE = exports.isEdge = exports.isIE = void 0; | ||
var userAgent = typeof navigator !== 'undefined' ? navigator.userAgent : ''; | ||
const userAgent = typeof navigator !== 'undefined' ? navigator.userAgent : ''; | ||
exports.isIE = (userAgent.indexOf('Trident') >= 0); | ||
@@ -42,5 +42,4 @@ exports.isEdge = (userAgent.indexOf('Edge/') >= 0); | ||
*/ | ||
function animationFrame(n) { | ||
if (n === void 0) { n = 1; } | ||
return new Promise(function (resolve) { | ||
function animationFrame(n = 1) { | ||
return new Promise(resolve => { | ||
function frameFunc() { | ||
@@ -61,3 +60,3 @@ if (n <= 0) { | ||
if (value) { | ||
var parsed = void 0; | ||
let parsed; | ||
if (value.endsWith('px')) { | ||
@@ -78,3 +77,3 @@ parsed = parseFloat(value.substring(0, value.length - 2)); | ||
if (time) { | ||
var parsed = void 0; | ||
let parsed; | ||
if (time.endsWith('ms')) { | ||
@@ -97,4 +96,4 @@ parsed = parseFloat(time.substring(0, time.length - 2)); | ||
function getMonacoEditorScroll(elem) { | ||
var linesContent = elem.querySelector('.lines-content'); | ||
var viewLines = elem.querySelector('.view-lines'); | ||
const linesContent = elem.querySelector('.lines-content'); | ||
const viewLines = elem.querySelector('.view-lines'); | ||
// eslint-disable-next-line no-null/no-null | ||
@@ -104,5 +103,5 @@ if (linesContent === null || viewLines === null) { | ||
} | ||
var linesContentStyle = linesContent.style; | ||
var elemStyle = elem.style; | ||
var viewLinesStyle = viewLines.style; | ||
const linesContentStyle = linesContent.style; | ||
const elemStyle = elem.style; | ||
const viewLinesStyle = viewLines.style; | ||
return { | ||
@@ -119,13 +118,13 @@ left: -parseCssMagnitude(linesContentStyle.left, 0), | ||
function preventNavigation(event) { | ||
var currentTarget = event.currentTarget, deltaX = event.deltaX, deltaY = event.deltaY; | ||
var absDeltaX = Math.abs(deltaX); | ||
var absDeltaY = Math.abs(deltaY); | ||
var elem = event.target; | ||
const { currentTarget, deltaX, deltaY } = event; | ||
const absDeltaX = Math.abs(deltaX); | ||
const absDeltaY = Math.abs(deltaY); | ||
let elem = event.target; | ||
while (elem && elem !== currentTarget) { | ||
var scroll_1 = void 0; | ||
let scroll; | ||
if (elem.classList.contains('monaco-scrollable-element')) { | ||
scroll_1 = getMonacoEditorScroll(elem); | ||
scroll = getMonacoEditorScroll(elem); | ||
} | ||
else { | ||
scroll_1 = { | ||
scroll = { | ||
left: elem.scrollLeft, | ||
@@ -137,5 +136,5 @@ top: elem.scrollTop, | ||
} | ||
if (scroll_1) { | ||
var scrollH = scroll_1.maxLeft > 0 && (deltaX < 0 && scroll_1.left > 0 || deltaX > 0 && scroll_1.left < scroll_1.maxLeft); | ||
var scrollV = scroll_1.maxTop > 0 && (deltaY < 0 && scroll_1.top > 0 || deltaY > 0 && scroll_1.top < scroll_1.maxTop); | ||
if (scroll) { | ||
const scrollH = scroll.maxLeft > 0 && (deltaX < 0 && scroll.left > 0 || deltaX > 0 && scroll.left < scroll.maxLeft); | ||
const scrollV = scroll.maxTop > 0 && (deltaY < 0 && scroll.top > 0 || deltaY > 0 && scroll.top < scroll.maxTop); | ||
if (scrollH && scrollV || scrollH && absDeltaX > absDeltaY || scrollV && absDeltaY > absDeltaX) { | ||
@@ -142,0 +141,0 @@ // The event is consumed by the scrollable child element |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.domUtils = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
var clsx_1 = require("clsx"); | ||
var common_1 = require("../common"); | ||
var toStyleKey = function (key) { return key.replace(/([A-Z])/, function (k) { return "-".concat(k.toLowerCase()); }); }; | ||
const clsx_1 = require("clsx"); | ||
const common_1 = require("../common"); | ||
const toStyleKey = (key) => key.replace(/([A-Z])/, k => `-${k.toLowerCase()}`); | ||
var domUtils; | ||
(function (domUtils) { | ||
function toPixel(num) { | ||
return "".concat(num, "px"); | ||
return `${num}px`; | ||
} | ||
@@ -48,3 +23,3 @@ domUtils.toPixel = toPixel; | ||
function toPercent(percent) { | ||
return "".concat(percent, "%"); | ||
return `${percent}%`; | ||
} | ||
@@ -60,8 +35,4 @@ domUtils.toPercent = toPercent; | ||
domUtils.disableEvent = disableEvent; | ||
function createElement(ele) { | ||
var classNames = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
classNames[_i - 1] = arguments[_i]; | ||
} | ||
var element = document.createElement(ele); | ||
function createElement(ele, ...classNames) { | ||
const element = document.createElement(ele); | ||
if (classNames.length > 0) { | ||
@@ -74,24 +45,12 @@ element.className = (0, clsx_1.default)(classNames); | ||
domUtils.createElement = createElement; | ||
function createDivWithClass() { | ||
var classNames = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
classNames[_i] = arguments[_i]; | ||
} | ||
return createElement.apply(void 0, __spreadArray(['div'], __read(classNames), false)); | ||
function createDivWithClass(...classNames) { | ||
return createElement('div', ...classNames); | ||
} | ||
domUtils.createDivWithClass = createDivWithClass; | ||
function addClass(element) { | ||
var classNames = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
classNames[_i - 1] = arguments[_i]; | ||
} | ||
function addClass(element, ...classNames) { | ||
element.className = (0, clsx_1.default)(classNames.concat(element.className.split(' '))); | ||
} | ||
domUtils.addClass = addClass; | ||
function delClass(element) { | ||
var classNames = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
classNames[_i - 1] = arguments[_i]; | ||
} | ||
classNames.forEach(function (name) { | ||
function delClass(element, ...classNames) { | ||
classNames.forEach(name => { | ||
element.classList.remove(name); | ||
@@ -102,7 +61,3 @@ }); | ||
domUtils.delClass = delClass; | ||
function coverClass(element) { | ||
var classNames = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
classNames[_i - 1] = arguments[_i]; | ||
} | ||
function coverClass(element, ...classNames) { | ||
element.className = (0, clsx_1.default)(classNames); | ||
@@ -116,16 +71,16 @@ } | ||
function translatePercent(node, x, y) { | ||
node.style.transform = "translate(".concat(x, "%, ").concat(y, "%)"); | ||
node.style.transform = `translate(${x}%, ${y}%)`; | ||
} | ||
domUtils.translatePercent = translatePercent; | ||
function translateXPercent(node, x) { | ||
node.style.transform = "translateX(".concat(x, "%)"); | ||
node.style.transform = `translateX(${x}%)`; | ||
} | ||
domUtils.translateXPercent = translateXPercent; | ||
function translateYPercent(node, y) { | ||
node.style.transform = "translateY(".concat(y, "%)"); | ||
node.style.transform = `translateY(${y}%)`; | ||
} | ||
domUtils.translateYPercent = translateYPercent; | ||
function setStyle(node, styles) { | ||
var styleStrs = []; | ||
(0, common_1.each)(styles, function (value, key) { | ||
const styleStrs = []; | ||
(0, common_1.each)(styles, (value, key) => { | ||
if (value === undefined) | ||
@@ -136,6 +91,6 @@ return; | ||
} | ||
styleStrs.push("".concat(toStyleKey(key), ":").concat(value)); | ||
styleStrs.push(`${toStyleKey(key)}:${value}`); | ||
}); | ||
var oldStyle = node.getAttribute('style'); | ||
var newStyle = styleStrs.join(';'); | ||
const oldStyle = node.getAttribute('style'); | ||
const newStyle = styleStrs.join(';'); | ||
if (oldStyle !== newStyle) { | ||
@@ -147,3 +102,3 @@ node.setAttribute('style', newStyle); | ||
function classNameWithPrefix(prefix) { | ||
return function (key, opts) { return (0, clsx_1.default)(key.split(/\s+/).map(function (s) { return "".concat(prefix, "-").concat(s); }).join(' '), opts); }; | ||
return (key, opts) => (0, clsx_1.default)(key.split(/\s+/).map(s => `${prefix}-${s}`).join(' '), opts); | ||
} | ||
@@ -153,3 +108,3 @@ domUtils.classNameWithPrefix = classNameWithPrefix; | ||
dom.addEventListener(type, listener, options); | ||
return common_1.Disposable.create(function () { | ||
return common_1.Disposable.create(() => { | ||
dom.removeEventListener(type, listener); | ||
@@ -165,4 +120,4 @@ }); | ||
function createDOMCache(parent, className, children) { | ||
return common_1.Cache.create(function (item) { | ||
var dom = typeof className === 'string' ? domUtils.createDivWithClass(className) : className(); | ||
return common_1.Cache.create(item => { | ||
const dom = typeof className === 'string' ? domUtils.createDivWithClass(className) : className(); | ||
if (children) { | ||
@@ -174,4 +129,4 @@ dom.innerHTML = children; | ||
key: item ? item.key : undefined, | ||
dispose: function () { | ||
var parentNode = dom.parentNode; | ||
dispose: () => { | ||
const parentNode = dom.parentNode; | ||
if (parentNode) { | ||
@@ -181,3 +136,3 @@ parentNode.removeChild(dom); | ||
}, | ||
setStyle: function (style) { | ||
setStyle: (style) => { | ||
domUtils.setStyle(dom, style); | ||
@@ -184,0 +139,0 @@ } |
@@ -19,100 +19,74 @@ "use strict"; | ||
exports.Endpoint = void 0; | ||
var uri_1 = require("../common/uri"); | ||
const uri_1 = require("../common/uri"); | ||
/** | ||
* An endpoint provides URLs for http and ws, based on configuration and defaults. | ||
*/ | ||
var Endpoint = /** @class */ (function () { | ||
function Endpoint(options, location) { | ||
if (options === void 0) { options = {}; } | ||
if (location === void 0) { location = window.location; } | ||
class Endpoint { | ||
constructor(options = {}, location = window.location) { | ||
this.options = options; | ||
this.location = location; | ||
} | ||
Object.defineProperty(Endpoint.prototype, "host", { | ||
get: function () { | ||
if (this.options.host) { | ||
return this.options.host; | ||
get host() { | ||
if (this.options.host) { | ||
return this.options.host; | ||
} | ||
if (this.location.host) { | ||
return this.location.host; | ||
} | ||
return 'localhost:' + this.port; | ||
} | ||
/** | ||
* The HTTP/HTTPS scheme of the endpoint, or the user defined one. | ||
* See: `Endpoint.Options.httpScheme`. | ||
*/ | ||
get httpScheme() { | ||
if (this.options.httpScheme) { | ||
return this.options.httpScheme; | ||
} | ||
if (this.location.protocol === Endpoint.PROTO_HTTP || | ||
this.location.protocol === Endpoint.PROTO_HTTPS) { | ||
return this.location.protocol; | ||
} | ||
return Endpoint.PROTO_HTTP; | ||
} | ||
get pathname() { | ||
if (this.location.protocol === Endpoint.PROTO_FILE) { | ||
return ''; | ||
} | ||
if (this.location.pathname === '/') { | ||
return ''; | ||
} | ||
if (this.location.pathname.endsWith('/')) { | ||
return this.location.pathname.substr(0, this.location.pathname.length - 1); | ||
} | ||
return this.location.pathname; | ||
} | ||
get port() { | ||
return this.getSearchParam('port', '3000'); | ||
} | ||
get wsScheme() { | ||
if (this.options.wsScheme) { | ||
return this.options.wsScheme; | ||
} | ||
return this.httpScheme === Endpoint.PROTO_HTTPS ? Endpoint.PROTO_WSS : Endpoint.PROTO_WS; | ||
} | ||
get path() { | ||
if (this.options.path) { | ||
if (this.options.path.startsWith('/')) { | ||
return this.options.path; | ||
} | ||
if (this.location.host) { | ||
return this.location.host; | ||
else { | ||
return '/' + this.options.path; | ||
} | ||
return 'localhost:' + this.port; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Endpoint.prototype, "httpScheme", { | ||
/** | ||
* The HTTP/HTTPS scheme of the endpoint, or the user defined one. | ||
* See: `Endpoint.Options.httpScheme`. | ||
*/ | ||
get: function () { | ||
if (this.options.httpScheme) { | ||
return this.options.httpScheme; | ||
} | ||
if (this.location.protocol === Endpoint.PROTO_HTTP || | ||
this.location.protocol === Endpoint.PROTO_HTTPS) { | ||
return this.location.protocol; | ||
} | ||
return Endpoint.PROTO_HTTP; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Endpoint.prototype, "pathname", { | ||
get: function () { | ||
if (this.location.protocol === Endpoint.PROTO_FILE) { | ||
return ''; | ||
} | ||
if (this.location.pathname === '/') { | ||
return ''; | ||
} | ||
if (this.location.pathname.endsWith('/')) { | ||
return this.location.pathname.substr(0, this.location.pathname.length - 1); | ||
} | ||
return this.location.pathname; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Endpoint.prototype, "port", { | ||
get: function () { | ||
return this.getSearchParam('port', '3000'); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Endpoint.prototype, "wsScheme", { | ||
get: function () { | ||
if (this.options.wsScheme) { | ||
return this.options.wsScheme; | ||
} | ||
return this.httpScheme === Endpoint.PROTO_HTTPS ? Endpoint.PROTO_WSS : Endpoint.PROTO_WS; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Endpoint.prototype, "path", { | ||
get: function () { | ||
if (this.options.path) { | ||
if (this.options.path.startsWith('/')) { | ||
return this.options.path; | ||
} | ||
else { | ||
return '/' + this.options.path; | ||
} | ||
} | ||
return this.options.path || ''; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Endpoint.prototype.getWebSocketUrl = function () { | ||
return new uri_1.URI("".concat(this.wsScheme, "//").concat(this.host).concat(this.pathname).concat(this.path)); | ||
}; | ||
Endpoint.prototype.getRestUrl = function () { | ||
return new uri_1.URI("".concat(this.httpScheme, "//").concat(this.host).concat(this.pathname).concat(this.path)); | ||
}; | ||
Endpoint.prototype.getSearchParam = function (name, defaultValue) { | ||
var search = this.location.search; | ||
} | ||
return this.options.path || ''; | ||
} | ||
getWebSocketUrl() { | ||
return new uri_1.URI(`${this.wsScheme}//${this.host}${this.pathname}${this.path}`); | ||
} | ||
getRestUrl() { | ||
return new uri_1.URI(`${this.httpScheme}//${this.host}${this.pathname}${this.path}`); | ||
} | ||
getSearchParam(name, defaultValue) { | ||
const search = this.location.search; | ||
if (!search) { | ||
@@ -122,33 +96,25 @@ return defaultValue; | ||
return search.substr(1).split('&') | ||
.filter(function (value) { return value.startsWith(name + '='); }) | ||
.map(function (value) { | ||
var encoded = value.substr(name.length + 1); | ||
.filter(value => value.startsWith(name + '=')) | ||
.map(value => { | ||
const encoded = value.substr(name.length + 1); | ||
return decodeURIComponent(encoded); | ||
})[0] || defaultValue; | ||
}; | ||
Endpoint.PROTO_HTTPS = 'https:'; | ||
Endpoint.PROTO_HTTP = 'http:'; | ||
Endpoint.PROTO_WS = 'ws:'; | ||
Endpoint.PROTO_WSS = 'wss:'; | ||
Endpoint.PROTO_FILE = 'file:'; | ||
return Endpoint; | ||
}()); | ||
} | ||
} | ||
exports.Endpoint = Endpoint; | ||
Endpoint.PROTO_HTTPS = 'https:'; | ||
Endpoint.PROTO_HTTP = 'http:'; | ||
Endpoint.PROTO_WS = 'ws:'; | ||
Endpoint.PROTO_WSS = 'wss:'; | ||
Endpoint.PROTO_FILE = 'file:'; | ||
(function (Endpoint) { | ||
var Options = /** @class */ (function () { | ||
function Options() { | ||
} | ||
return Options; | ||
}()); | ||
class Options { | ||
} | ||
Endpoint.Options = Options; | ||
// Necessary for running tests with dependency on TS lib on node | ||
// FIXME figure out how to mock with ts-node | ||
var Location = /** @class */ (function () { | ||
function Location() { | ||
} | ||
return Location; | ||
}()); | ||
class Location { | ||
} | ||
Endpoint.Location = Location; | ||
})(Endpoint = exports.Endpoint || (exports.Endpoint = {})); | ||
exports.Endpoint = Endpoint; | ||
//# sourceMappingURL=endpoint.js.map |
@@ -18,8 +18,8 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chai = require("chai"); | ||
var endpoint_1 = require("./endpoint"); | ||
var expect = chai.expect; | ||
describe('Endpoint', function () { | ||
describe('01 #getWebSocketUrl', function () { | ||
it('Should correctly join root pathname', function () { | ||
const chai = require("chai"); | ||
const endpoint_1 = require("./endpoint"); | ||
const expect = chai.expect; | ||
describe('Endpoint', () => { | ||
describe('01 #getWebSocketUrl', () => { | ||
it('Should correctly join root pathname', () => { | ||
expectWsUri({ | ||
@@ -35,3 +35,3 @@ httpScheme: 'ws', | ||
}); | ||
it('Should correctly join pathname and path', function () { | ||
it('Should correctly join pathname and path', () => { | ||
expectWsUri({ | ||
@@ -47,3 +47,3 @@ httpScheme: 'ws', | ||
}); | ||
it('Should correctly join pathname and path, ignoring double slash in between', function () { | ||
it('Should correctly join pathname and path, ignoring double slash in between', () => { | ||
expectWsUri({ | ||
@@ -59,3 +59,3 @@ httpScheme: 'ws', | ||
}); | ||
it('Should correctly join pathname and path, without trailing slash', function () { | ||
it('Should correctly join pathname and path, without trailing slash', () => { | ||
expectWsUri({ | ||
@@ -72,4 +72,4 @@ httpScheme: 'ws', | ||
}); | ||
describe('02 #httpScheme', function () { | ||
it('Should choose https:// if location protocol is https://', function () { | ||
describe('02 #httpScheme', () => { | ||
it('Should choose https:// if location protocol is https://', () => { | ||
expectRestUri({ | ||
@@ -84,3 +84,3 @@ path: '/' | ||
}); | ||
it("should return with the 'options.httpScheme' if defined", function () { | ||
it("should return with the 'options.httpScheme' if defined", () => { | ||
expect(new endpoint_1.Endpoint({ httpScheme: 'foo:' }, { | ||
@@ -93,3 +93,3 @@ host: 'example.org', | ||
}); | ||
it('should return with the HTTP if the protocol is HTTP.', function () { | ||
it('should return with the HTTP if the protocol is HTTP.', () => { | ||
expect(new endpoint_1.Endpoint({}, { | ||
@@ -102,3 +102,3 @@ host: 'example.org', | ||
}); | ||
it('should return with the HTTPS if the protocol is HTTPS.', function () { | ||
it('should return with the HTTPS if the protocol is HTTPS.', () => { | ||
expect(new endpoint_1.Endpoint({}, { | ||
@@ -111,3 +111,3 @@ host: 'example.org', | ||
}); | ||
it('should return with the HTTP if the protocol is *not* HTTP or HTTPS.', function () { | ||
it('should return with the HTTP if the protocol is *not* HTTP or HTTPS.', () => { | ||
expect(new endpoint_1.Endpoint({}, { | ||
@@ -123,11 +123,11 @@ host: 'example.org', | ||
function expectWsUri(options, mockLocation, expectedUri) { | ||
var cut = new endpoint_1.Endpoint(options, mockLocation); | ||
var uri = cut.getWebSocketUrl(); | ||
const cut = new endpoint_1.Endpoint(options, mockLocation); | ||
const uri = cut.getWebSocketUrl(); | ||
expect(uri.toString()).to.eq(expectedUri); | ||
} | ||
function expectRestUri(options, mockLocation, expectedUri) { | ||
var cut = new endpoint_1.Endpoint(options, mockLocation); | ||
var uri = cut.getRestUrl(); | ||
const cut = new endpoint_1.Endpoint(options, mockLocation); | ||
const uri = cut.getRestUrl(); | ||
expect(uri.toString()).to.eq(expectedUri); | ||
} | ||
//# sourceMappingURL=endpoint.spec.js.map |
"use strict"; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sortArrayWithTypeAndName = exports.sortArrayByCharCode = exports.moveSourceToDest = exports.deleteElement = exports.moveBackward = exports.moveForward = exports.updateArrayItem = exports.arrayUnion = exports.arrayToSet = exports.iterToArray = void 0; | ||
function iterToArray(iter) { | ||
var e_1, _a; | ||
var result = []; | ||
try { | ||
for (var iter_1 = __values(iter), iter_1_1 = iter_1.next(); !iter_1_1.done; iter_1_1 = iter_1.next()) { | ||
var v = iter_1_1.value; | ||
result.push(v); | ||
} | ||
const result = []; | ||
for (const v of iter) { | ||
result.push(v); | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (iter_1_1 && !iter_1_1.done && (_a = iter_1.return)) _a.call(iter_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return result; | ||
@@ -36,4 +14,4 @@ } | ||
function arrayToSet(arr) { | ||
var set = new Set; | ||
for (var i = 0, len = arr.length; i < len; i++) { | ||
const set = new Set; | ||
for (let i = 0, len = arr.length; i < len; i++) { | ||
set.add(arr[i]); | ||
@@ -45,4 +23,4 @@ } | ||
function arrayUnion(arr) { | ||
var result = []; | ||
for (var i = 0, len = arr.length; i < len; i++) { | ||
const result = []; | ||
for (let i = 0, len = arr.length; i < len; i++) { | ||
if (!result.includes(arr[i])) | ||
@@ -55,6 +33,6 @@ result.push(arr[i]); | ||
function updateArrayItem(arr, itemFinder, updater) { | ||
var item = arr.find(itemFinder); | ||
const item = arr.find(itemFinder); | ||
if (item) { | ||
var index = arr.indexOf(item); | ||
var newItem = updater(item); | ||
const index = arr.indexOf(item); | ||
const newItem = updater(item); | ||
arr.splice(index, 1, newItem); | ||
@@ -107,3 +85,3 @@ return true; | ||
function moveSourceToDest(arr, sourceIndex, destIndex) { | ||
var element = arr.splice(sourceIndex, 1)[0]; | ||
const element = arr.splice(sourceIndex, 1)[0]; | ||
arr.splice(destIndex, 0, element); | ||
@@ -121,7 +99,6 @@ return arr; | ||
*/ | ||
function sortArrayByCharCode(targetArr, getter) { | ||
if (targetArr === void 0) { targetArr = []; } | ||
return targetArr.sort(function (obj1, obj2) { | ||
var str1 = obj1; | ||
var str2 = obj2; | ||
function sortArrayByCharCode(targetArr = [], getter) { | ||
return targetArr.sort((obj1, obj2) => { | ||
let str1 = obj1; | ||
let str2 = obj2; | ||
if (getter) { | ||
@@ -131,3 +108,3 @@ str1 = getter(obj1); | ||
} | ||
var cursor = 0; | ||
let cursor = 0; | ||
if (typeof str1 === 'number' || typeof str2 === 'number') { | ||
@@ -139,4 +116,4 @@ if (str1 === str2) | ||
// 过滤掉后缀名,如 xxxx0001.jpg 取 0001 | ||
var match1 = str1.match(/([0-9]+)\.*[^0-9]*$/); | ||
var match2 = str2.match(/([0-9]+)\.*[^0-9]*$/); | ||
const match1 = str1.match(/([0-9]+)\.*[^0-9]*$/); | ||
const match2 = str2.match(/([0-9]+)\.*[^0-9]*$/); | ||
// 使用最后一排的数字进行排序 | ||
@@ -147,6 +124,6 @@ if (match1 && match2 && str1.slice(0, match1.index) === str2.slice(0, match2.index)) { | ||
for (; cursor <= str1.length; cursor++) { | ||
var A = str1.charCodeAt(cursor); | ||
var B = str2.charCodeAt(cursor); | ||
var a = str1.toLowerCase().charCodeAt(cursor); | ||
var b = str2.toLowerCase().charCodeAt(cursor); | ||
const A = str1.charCodeAt(cursor); | ||
const B = str2.charCodeAt(cursor); | ||
const a = str1.toLowerCase().charCodeAt(cursor); | ||
const b = str2.toLowerCase().charCodeAt(cursor); | ||
if (isNaN(b)) | ||
@@ -173,10 +150,10 @@ return -1; | ||
function sortArrayWithTypeAndName(items, getName, getType, types) { | ||
var typeSorts = types.reduce(function (res, item, i) { | ||
const typeSorts = types.reduce((res, item, i) => { | ||
res[item] = i; | ||
return res; | ||
}, {}); | ||
var data = []; | ||
items.forEach(function (item) { | ||
var type = getType(item); | ||
var arr = data[typeSorts[type]]; | ||
const data = []; | ||
items.forEach(item => { | ||
const type = getType(item); | ||
let arr = data[typeSorts[type]]; | ||
if (!arr) { | ||
@@ -187,5 +164,5 @@ arr = data[typeSorts[type]] = []; | ||
}); | ||
return data.map(function (i) { return sortArrayByCharCode(i, getName); }).flat(); | ||
return data.map(i => sortArrayByCharCode(i, getName)).flat(); | ||
} | ||
exports.sortArrayWithTypeAndName = sortArrayWithTypeAndName; | ||
//# sourceMappingURL=array.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Cache = void 0; | ||
var compare_1 = require("./compare"); | ||
const compare_1 = require("./compare"); | ||
/** | ||
@@ -23,12 +23,10 @@ * 缓存工具: | ||
(function (Cache) { | ||
function create(cacheFactory, opts) { | ||
if (opts === void 0) { opts = {}; } | ||
var cache = []; | ||
function create(cacheFactory, opts = {}) { | ||
let cache = []; | ||
return { | ||
getMore: function (count, autoDelete) { | ||
if (autoDelete === void 0) { autoDelete = true; } | ||
getMore(count, autoDelete = true) { | ||
if (count === cache.length) | ||
return cache; | ||
if (count > cache.length) { | ||
var added = count - cache.length; | ||
let added = count - cache.length; | ||
while (added > 0) { | ||
@@ -45,4 +43,4 @@ cache.push(cacheFactory()); | ||
} | ||
var deleted = cache.splice(count, cache.length - count); | ||
deleted.forEach(function (el) { return el.dispose && el.dispose(); }); | ||
const deleted = cache.splice(count, cache.length - count); | ||
deleted.forEach(el => el.dispose && el.dispose()); | ||
} | ||
@@ -59,6 +57,6 @@ else { | ||
*/ | ||
getMoreByItemKeys: function (items) { | ||
var newCache = []; | ||
var findedKeys = []; | ||
cache.forEach(function (item) { | ||
getMoreByItemKeys(items) { | ||
const newCache = []; | ||
const findedKeys = []; | ||
cache.forEach(item => { | ||
if (item.key === undefined) { | ||
@@ -70,3 +68,3 @@ console.error('Cache object miss key: ', item); | ||
} | ||
if (items.find(function (i) { return i.key === item.key; })) { | ||
if (items.find(i => i.key === item.key)) { | ||
findedKeys.push(item.key); | ||
@@ -80,3 +78,3 @@ newCache.push(item); | ||
}); | ||
items.forEach(function (item) { | ||
items.forEach(item => { | ||
if (!findedKeys.includes(item.key)) { | ||
@@ -89,3 +87,3 @@ newCache.push(cacheFactory(item)); | ||
}, | ||
get: function () { | ||
get() { | ||
if (cache.length > 0) | ||
@@ -96,11 +94,11 @@ return cache[0]; | ||
}, | ||
getFromCacheByKey: function (key) { | ||
return cache.find(function (item) { return item.key === key; }); | ||
getFromCacheByKey(key) { | ||
return cache.find(item => item.key === key); | ||
}, | ||
dispose: function () { | ||
cache.forEach(function (item) { return item.dispose && item.dispose(); }); | ||
dispose() { | ||
cache.forEach(item => item.dispose && item.dispose()); | ||
cache.length = 0; | ||
}, | ||
clear: function () { | ||
cache.forEach(function (item) { return item.dispose && item.dispose(); }); | ||
clear() { | ||
cache.forEach(item => item.dispose && item.dispose()); | ||
cache.length = 0; | ||
@@ -119,10 +117,9 @@ } | ||
*/ | ||
function createShortCache(timeout) { | ||
if (timeout === void 0) { timeout = 1000; } | ||
var cache; | ||
var timeoutId; | ||
function createShortCache(timeout = 1000) { | ||
let cache; | ||
let timeoutId; | ||
function updateTimeout() { | ||
if (timeoutId) | ||
clearTimeout(timeoutId); | ||
timeoutId = setTimeout(function () { | ||
timeoutId = setTimeout(() => { | ||
timeoutId = undefined; | ||
@@ -133,3 +130,3 @@ cache = undefined; | ||
return { | ||
get: function (getValue) { | ||
get(getValue) { | ||
if (cache) { | ||
@@ -147,7 +144,7 @@ updateTimeout(); | ||
function createWeakCache() { | ||
var weakCache = new WeakMap; | ||
const weakCache = new WeakMap; | ||
return { | ||
get: function (key) { return weakCache.get(key); }, | ||
save: function (key, value) { return weakCache.set(key, value); }, | ||
isChanged: function (key, value) { return compare_1.Compare.isChanged(weakCache.get(key), value); } | ||
get: key => weakCache.get(key), | ||
save: (key, value) => weakCache.set(key, value), | ||
isChanged: (key, value) => compare_1.Compare.isChanged(weakCache.get(key), value) | ||
}; | ||
@@ -154,0 +151,0 @@ } |
@@ -23,8 +23,8 @@ "use strict"; | ||
exports.checkCancelled = exports.isCancelled = exports.cancelled = exports.CancellationTokenSource = exports.CancellationToken = void 0; | ||
var event_1 = require("./event"); | ||
const event_1 = require("./event"); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
var shortcutEvent = Object.freeze(Object.assign(function (callback, context) { | ||
var handle = setTimeout(callback.bind(context), 0); | ||
const shortcutEvent = Object.freeze(Object.assign(function (callback, context) { | ||
const handle = setTimeout(callback.bind(context), 0); | ||
return { | ||
dispose: function () { | ||
dispose() { | ||
clearTimeout(handle); | ||
@@ -45,27 +45,19 @@ } | ||
})(CancellationToken = exports.CancellationToken || (exports.CancellationToken = {})); | ||
var MutableToken = /** @class */ (function () { | ||
function MutableToken() { | ||
class MutableToken { | ||
constructor() { | ||
this._isCancelled = false; | ||
} | ||
Object.defineProperty(MutableToken.prototype, "isCancellationRequested", { | ||
get: function () { | ||
return this._isCancelled; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(MutableToken.prototype, "onCancellationRequested", { | ||
get: function () { | ||
if (this._isCancelled) { | ||
return shortcutEvent; | ||
} | ||
if (!this._emitter) { | ||
this._emitter = new event_1.Emitter(); | ||
} | ||
return this._emitter.event; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
MutableToken.prototype.cancel = function () { | ||
get isCancellationRequested() { | ||
return this._isCancelled; | ||
} | ||
get onCancellationRequested() { | ||
if (this._isCancelled) { | ||
return shortcutEvent; | ||
} | ||
if (!this._emitter) { | ||
this._emitter = new event_1.Emitter(); | ||
} | ||
return this._emitter.event; | ||
} | ||
cancel() { | ||
if (!this._isCancelled) { | ||
@@ -78,22 +70,15 @@ this._isCancelled = true; | ||
} | ||
}; | ||
return MutableToken; | ||
}()); | ||
var CancellationTokenSource = /** @class */ (function () { | ||
function CancellationTokenSource() { | ||
} | ||
Object.defineProperty(CancellationTokenSource.prototype, "token", { | ||
get: function () { | ||
if (!this._token) { | ||
// be lazy and create the token only when | ||
// actually needed | ||
this._token = new MutableToken(); | ||
} | ||
return this._token; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
CancellationTokenSource.prototype.cancel = function () { | ||
} | ||
class CancellationTokenSource { | ||
get token() { | ||
if (!this._token) { | ||
// be lazy and create the token only when | ||
// actually needed | ||
this._token = new MutableToken(); | ||
} | ||
return this._token; | ||
} | ||
cancel() { | ||
if (!this._token) { | ||
// save an object by returning the default | ||
@@ -107,10 +92,9 @@ // cancelled token when cancellation happens | ||
} | ||
}; | ||
CancellationTokenSource.prototype.dispose = function () { | ||
} | ||
dispose() { | ||
this.cancel(); | ||
}; | ||
return CancellationTokenSource; | ||
}()); | ||
} | ||
} | ||
exports.CancellationTokenSource = CancellationTokenSource; | ||
var cancelledMessage = 'Cancelled'; | ||
const cancelledMessage = 'Cancelled'; | ||
function cancelled() { | ||
@@ -117,0 +101,0 @@ return new Error(cancelledMessage); |
@@ -14,5 +14,3 @@ "use strict"; | ||
*/ | ||
function isChanged(oldProps, newProps, depth, partial) { | ||
if (depth === void 0) { depth = 1; } | ||
if (partial === void 0) { partial = true; } | ||
function isChanged(oldProps, newProps, depth = 1, partial = true) { | ||
if (oldProps === newProps) | ||
@@ -23,10 +21,10 @@ return false; | ||
} | ||
var keys = Object.keys(newProps); | ||
const keys = Object.keys(newProps); | ||
if (!partial) { | ||
var oldKeys = Object.keys(oldProps); | ||
const oldKeys = Object.keys(oldProps); | ||
if (keys.length !== oldKeys.length) | ||
return true; | ||
} | ||
for (var i = 0, len = keys.length; i < len; i++) { | ||
var key = keys[i]; | ||
for (let i = 0, len = keys.length; i < len; i++) { | ||
const key = keys[i]; | ||
if (isChanged(oldProps[key], newProps[key], depth - 1, partial)) | ||
@@ -33,0 +31,0 @@ return true; |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.compose = void 0; | ||
// tslint:disable:no-unused-expression typedef | ||
function compose() { | ||
var funcs = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
funcs[_i] = arguments[_i]; | ||
} | ||
function compose(...funcs) { | ||
if (funcs.length === 0) { | ||
// infer the argument type so it is usable in inference down the line | ||
return function (arg) { return arg; }; | ||
return (arg) => arg; | ||
} | ||
@@ -42,11 +13,5 @@ if (funcs.length === 1) { | ||
} | ||
return funcs.reduce(function (a, b) { return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return a(b.apply(void 0, __spreadArray([], __read(args), false))); | ||
}; }); | ||
return funcs.reduce((a, b) => (...args) => a(b(...args))); | ||
} | ||
exports.compose = compose; | ||
//# sourceMappingURL=compose.js.map |
@@ -17,39 +17,14 @@ "use strict"; | ||
********************************************************************************/ | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.bindContributionProvider = exports.Bindable = exports.ContributionProvider = void 0; | ||
exports.ContributionProvider = Symbol('ContributionProvider'); | ||
var ContainerBasedContributionProvider = /** @class */ (function () { | ||
function ContainerBasedContributionProvider(serviceIdentifier, container) { | ||
class ContainerBasedContributionProvider { | ||
constructor(serviceIdentifier, container) { | ||
this.serviceIdentifier = serviceIdentifier; | ||
this.container = container; | ||
} | ||
ContainerBasedContributionProvider.prototype.getContributions = function (recursive) { | ||
getContributions(recursive) { | ||
if (this.services === undefined) { | ||
var currentServices = []; | ||
var currentContainer = this.container; | ||
const currentServices = []; | ||
let currentContainer = this.container; | ||
// eslint-disable-next-line no-null/no-null | ||
@@ -59,3 +34,3 @@ while (currentContainer !== null) { | ||
try { | ||
currentServices.push.apply(currentServices, __spreadArray([], __read(currentContainer.getAll(this.serviceIdentifier)), false)); | ||
currentServices.push(...currentContainer.getAll(this.serviceIdentifier)); | ||
} | ||
@@ -72,5 +47,4 @@ catch (error) { | ||
return this.services; | ||
}; | ||
return ContainerBasedContributionProvider; | ||
}()); | ||
} | ||
} | ||
var Bindable; | ||
@@ -87,5 +61,5 @@ (function (Bindable) { | ||
function bindContributionProvider(bindable, id) { | ||
var bindingToSyntax = (Bindable.isContainer(bindable) ? bindable.bind(exports.ContributionProvider) : bindable(exports.ContributionProvider)); | ||
const bindingToSyntax = (Bindable.isContainer(bindable) ? bindable.bind(exports.ContributionProvider) : bindable(exports.ContributionProvider)); | ||
bindingToSyntax | ||
.toDynamicValue(function (ctx) { return new ContainerBasedContributionProvider(id, ctx.container); }) | ||
.toDynamicValue(ctx => new ContainerBasedContributionProvider(id, ctx.container)) | ||
.inSingletonScope().whenTargetNamed(id); | ||
@@ -92,0 +66,0 @@ } |
@@ -19,3 +19,3 @@ "use strict"; | ||
********************************************************************************/ | ||
var event_1 = require("./event"); | ||
const event_1 = require("./event"); | ||
var Disposable; | ||
@@ -34,60 +34,38 @@ (function (Disposable) { | ||
Disposable.create = create; | ||
Disposable.NULL = create(function () { | ||
Disposable.NULL = create(() => { | ||
}); | ||
})(Disposable = exports.Disposable || (exports.Disposable = {})); | ||
var DisposableImpl = /** @class */ (function () { | ||
function DisposableImpl() { | ||
class DisposableImpl { | ||
constructor() { | ||
this.toDispose = new DisposableCollection(); | ||
} | ||
DisposableImpl.prototype.dispose = function () { | ||
dispose() { | ||
this.toDispose.dispose(); | ||
}; | ||
Object.defineProperty(DisposableImpl.prototype, "disposed", { | ||
get: function () { | ||
return this.toDispose.disposed; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(DisposableImpl.prototype, "onDispose", { | ||
get: function () { | ||
return this.toDispose.onDispose; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return DisposableImpl; | ||
}()); | ||
} | ||
get disposed() { | ||
return this.toDispose.disposed; | ||
} | ||
get onDispose() { | ||
return this.toDispose.onDispose; | ||
} | ||
} | ||
exports.DisposableImpl = DisposableImpl; | ||
var DisposableCollection = /** @class */ (function () { | ||
function DisposableCollection() { | ||
var toDispose = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
toDispose[_i] = arguments[_i]; | ||
} | ||
var _this = this; | ||
class DisposableCollection { | ||
constructor(...toDispose) { | ||
this.disposables = []; | ||
this.onDisposeEmitter = new event_1.Emitter(); | ||
this.disposingElements = false; | ||
toDispose.forEach(function (d) { return _this.push(d); }); | ||
toDispose.forEach(d => this.push(d)); | ||
} | ||
Object.defineProperty(DisposableCollection.prototype, "onDispose", { | ||
/** | ||
* This event is fired only once | ||
* on first dispose of not empty collection. | ||
*/ | ||
get: function () { | ||
return this.onDisposeEmitter.event; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(DisposableCollection.prototype, "disposed", { | ||
get: function () { | ||
return this.disposables.length === 0; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
DisposableCollection.prototype.dispose = function () { | ||
/** | ||
* This event is fired only once | ||
* on first dispose of not empty collection. | ||
*/ | ||
get onDispose() { | ||
return this.onDisposeEmitter.event; | ||
} | ||
get disposed() { | ||
return this.disposables.length === 0; | ||
} | ||
dispose() { | ||
if (this.disposed || this.disposingElements) { | ||
@@ -107,16 +85,15 @@ return; | ||
this.checkDisposed(); | ||
}; | ||
DisposableCollection.prototype.push = function (disposable) { | ||
var _this = this; | ||
var disposables = this.disposables; | ||
} | ||
push(disposable) { | ||
const disposables = this.disposables; | ||
disposables.push(disposable); | ||
var originalDispose = disposable.dispose.bind(disposable); | ||
var toRemove = Disposable.create(function () { | ||
var index = disposables.indexOf(disposable); | ||
const originalDispose = disposable.dispose.bind(disposable); | ||
const toRemove = Disposable.create(() => { | ||
const index = disposables.indexOf(disposable); | ||
if (index !== -1) { | ||
disposables.splice(index, 1); | ||
} | ||
_this.checkDisposed(); | ||
this.checkDisposed(); | ||
}); | ||
disposable.dispose = function () { | ||
disposable.dispose = () => { | ||
toRemove.dispose(); | ||
@@ -126,10 +103,7 @@ originalDispose(); | ||
return toRemove; | ||
}; | ||
DisposableCollection.prototype.pushAll = function (disposables) { | ||
var _this = this; | ||
return disposables.map(function (disposable) { | ||
return _this.push(disposable); | ||
}); | ||
}; | ||
DisposableCollection.prototype.checkDisposed = function () { | ||
} | ||
pushAll(disposables) { | ||
return disposables.map(disposable => this.push(disposable)); | ||
} | ||
checkDisposed() { | ||
if (this.disposed && !this.disposingElements) { | ||
@@ -139,5 +113,4 @@ this.onDisposeEmitter.fire(undefined); | ||
} | ||
}; | ||
return DisposableCollection; | ||
}()); | ||
} | ||
} | ||
exports.DisposableCollection = DisposableCollection; | ||
@@ -147,30 +120,24 @@ /** | ||
*/ | ||
var EmitterProxy = /** @class */ (function () { | ||
function EmitterProxy(originEvent) { | ||
class EmitterProxy { | ||
constructor(originEvent) { | ||
this.originEvent = originEvent; | ||
this.toDispose = new DisposableCollection(); | ||
} | ||
Object.defineProperty(EmitterProxy.prototype, "event", { | ||
get: function () { | ||
var _this = this; | ||
if (!this._event) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
this._event = Object.assign(function (listener, thisArgs, disposables) { | ||
var originDisposable = _this.originEvent(listener, thisArgs, disposables); | ||
return _this.toDispose.push(originDisposable); | ||
}, { | ||
maxListeners: this.originEvent.maxListeners | ||
}); | ||
} | ||
return this._event; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
EmitterProxy.prototype.dispose = function () { | ||
get event() { | ||
if (!this._event) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
this._event = Object.assign((listener, thisArgs, disposables) => { | ||
const originDisposable = this.originEvent(listener, thisArgs, disposables); | ||
return this.toDispose.push(originDisposable); | ||
}, { | ||
maxListeners: this.originEvent.maxListeners | ||
}); | ||
} | ||
return this._event; | ||
} | ||
dispose() { | ||
this.toDispose.dispose(); | ||
}; | ||
return EmitterProxy; | ||
}()); | ||
} | ||
} | ||
exports.EmitterProxy = EmitterProxy; | ||
//# sourceMappingURL=disposable.js.map |
@@ -17,21 +17,10 @@ "use strict"; | ||
********************************************************************************/ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.environment = void 0; | ||
var isElectron = require('is-electron'); | ||
const isElectron = require('is-electron'); | ||
/** | ||
* The electron specific environment. | ||
*/ | ||
var ElectronEnv = /** @class */ (function () { | ||
function ElectronEnv() { | ||
class ElectronEnv { | ||
constructor() { | ||
/** | ||
@@ -47,5 +36,5 @@ * Environment variable that can be accessed on the `process` to check if running in electron or not. | ||
*/ | ||
ElectronEnv.prototype.is = function () { | ||
is() { | ||
return isElectron(); | ||
}; | ||
} | ||
/** | ||
@@ -56,3 +45,3 @@ * `true` if running in Electron in development mode. Otherwise, `false`. | ||
*/ | ||
ElectronEnv.prototype.isDevMode = function () { | ||
isDevMode() { | ||
return this.is() | ||
@@ -62,3 +51,3 @@ && typeof process !== 'undefined' | ||
&& (process.defaultApp || /node_modules[/]electron[/]/.test(process.execPath)); // eslint-disable-line @typescript-eslint/no-explicit-any | ||
}; | ||
} | ||
/** | ||
@@ -76,13 +65,12 @@ * Creates and return with a new environment object which always contains the `ELECTRON_RUN_AS_NODE: 1` property pair. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
ElectronEnv.prototype.runAsNodeEnv = function (env) { | ||
runAsNodeEnv(env) { | ||
if (typeof process === 'undefined') { | ||
throw new Error("'process' cannot be undefined."); | ||
} | ||
return __assign(__assign({}, (env === undefined ? process.env : env)), { ELECTRON_RUN_AS_NODE: 1 }); | ||
}; | ||
return ElectronEnv; | ||
}()); | ||
var electron = new ElectronEnv(); | ||
var environment = { electron: electron }; | ||
return Object.assign(Object.assign({}, (env === undefined ? process.env : env)), { ELECTRON_RUN_AS_NODE: 1 }); | ||
} | ||
} | ||
const electron = new ElectronEnv(); | ||
const environment = { electron }; | ||
exports.environment = environment; | ||
//# sourceMappingURL=environment.js.map |
@@ -17,74 +17,2 @@ "use strict"; | ||
********************************************************************************/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -94,4 +22,4 @@ exports.WaitUntilEvent = exports.Emitter = exports.Event = void 0; | ||
(function (Event) { | ||
var _disposable = { | ||
dispose: function () { | ||
const _disposable = { | ||
dispose() { | ||
} | ||
@@ -113,3 +41,3 @@ }; | ||
function map(event, mapFunc) { | ||
return Object.assign(function (listener, thisArgs, disposables) { return event(function (i) { return listener.call(thisArgs, mapFunc(i)); }, undefined, disposables); }, { | ||
return Object.assign((listener, thisArgs, disposables) => event(i => listener.call(thisArgs, mapFunc(i)), undefined, disposables), { | ||
maxListeners: 0, | ||
@@ -120,15 +48,7 @@ }); | ||
})(Event = exports.Event || (exports.Event = {})); | ||
var CallbackList = /** @class */ (function () { | ||
function CallbackList() { | ||
class CallbackList { | ||
get length() { | ||
return this._callbacks && this._callbacks.length || 0; | ||
} | ||
Object.defineProperty(CallbackList.prototype, "length", { | ||
get: function () { | ||
return this._callbacks && this._callbacks.length || 0; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
CallbackList.prototype.add = function (callback, context, bucket) { | ||
var _this = this; | ||
if (context === void 0) { context = undefined; } | ||
add(callback, context = undefined, bucket) { | ||
if (!this._callbacks) { | ||
@@ -141,12 +61,11 @@ this._callbacks = []; | ||
if (Array.isArray(bucket)) { | ||
bucket.push({ dispose: function () { return _this.remove(callback, context); } }); | ||
bucket.push({ dispose: () => this.remove(callback, context) }); | ||
} | ||
}; | ||
CallbackList.prototype.remove = function (callback, context) { | ||
if (context === void 0) { context = undefined; } | ||
} | ||
remove(callback, context = undefined) { | ||
if (!this._callbacks) { | ||
return; | ||
} | ||
var foundCallbackWithDifferentContext = false; | ||
for (var i = 0; i < this._callbacks.length; i++) { | ||
let foundCallbackWithDifferentContext = false; | ||
for (let i = 0; i < this._callbacks.length; i++) { | ||
if (this._callbacks[i] === callback) { | ||
@@ -167,58 +86,34 @@ if (this._contexts[i] === context) { | ||
} | ||
}; | ||
} | ||
// tslint:disable-next-line:typedef | ||
CallbackList.prototype[Symbol.iterator] = function () { | ||
[Symbol.iterator]() { | ||
if (!this._callbacks) { | ||
return [][Symbol.iterator](); | ||
} | ||
var callbacks = this._callbacks.slice(0); | ||
var contexts = this._contexts.slice(0); | ||
return callbacks.map(function (callback, i) { | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return callback.apply(contexts[i], args); | ||
}; | ||
})[Symbol.iterator](); | ||
}; | ||
CallbackList.prototype.invoke = function () { | ||
var e_1, _a; | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var ret = []; | ||
try { | ||
for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var callback = _c.value; | ||
try { | ||
ret.push(callback.apply(void 0, __spreadArray([], __read(args), false))); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
const callbacks = this._callbacks.slice(0); | ||
const contexts = this._contexts.slice(0); | ||
return callbacks.map((callback, i) => (...args) => callback.apply(contexts[i], args))[Symbol.iterator](); | ||
} | ||
invoke(...args) { | ||
const ret = []; | ||
for (const callback of this) { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
ret.push(callback(...args)); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
return ret; | ||
}; | ||
CallbackList.prototype.isEmpty = function () { | ||
} | ||
isEmpty() { | ||
return !this._callbacks || this._callbacks.length === 0; | ||
}; | ||
CallbackList.prototype.dispose = function () { | ||
} | ||
dispose() { | ||
this._callbacks = undefined; | ||
this._contexts = undefined; | ||
}; | ||
return CallbackList; | ||
}()); | ||
var Emitter = /** @class */ (function () { | ||
function Emitter(_options) { | ||
} | ||
} | ||
class Emitter { | ||
constructor(_options) { | ||
this._options = _options; | ||
@@ -228,47 +123,42 @@ this._disposed = false; | ||
} | ||
Object.defineProperty(Emitter.prototype, "event", { | ||
/** | ||
* For the public to allow to subscribe | ||
* to events from this Emitter | ||
*/ | ||
get: function () { | ||
var _this = this; | ||
if (!this._event) { | ||
this._event = Object.assign(function (listener, thisArgs, disposables) { | ||
if (!_this._callbacks) { | ||
_this._callbacks = new CallbackList(); | ||
} | ||
if (_this._options && _this._options.onFirstListenerAdd && _this._callbacks.isEmpty()) { | ||
_this._options.onFirstListenerAdd(_this); | ||
} | ||
_this._callbacks.add(listener, thisArgs); | ||
var removeMaxListenersCheck = _this.checkMaxListeners(_this._event.maxListeners); | ||
var result = { | ||
dispose: function () { | ||
if (removeMaxListenersCheck) { | ||
removeMaxListenersCheck(); | ||
} | ||
/** | ||
* For the public to allow to subscribe | ||
* to events from this Emitter | ||
*/ | ||
get event() { | ||
if (!this._event) { | ||
this._event = Object.assign((listener, thisArgs, disposables) => { | ||
if (!this._callbacks) { | ||
this._callbacks = new CallbackList(); | ||
} | ||
if (this._options && this._options.onFirstListenerAdd && this._callbacks.isEmpty()) { | ||
this._options.onFirstListenerAdd(this); | ||
} | ||
this._callbacks.add(listener, thisArgs); | ||
const removeMaxListenersCheck = this.checkMaxListeners(this._event.maxListeners); | ||
const result = { | ||
dispose: () => { | ||
if (removeMaxListenersCheck) { | ||
removeMaxListenersCheck(); | ||
} | ||
result.dispose = Emitter._noop; | ||
if (!this._disposed) { | ||
this._callbacks.remove(listener, thisArgs); | ||
result.dispose = Emitter._noop; | ||
if (!_this._disposed) { | ||
_this._callbacks.remove(listener, thisArgs); | ||
result.dispose = Emitter._noop; | ||
if (_this._options && _this._options.onLastListenerRemove && _this._callbacks.isEmpty()) { | ||
_this._options.onLastListenerRemove(_this); | ||
} | ||
if (this._options && this._options.onLastListenerRemove && this._callbacks.isEmpty()) { | ||
this._options.onLastListenerRemove(this); | ||
} | ||
} | ||
}; | ||
if (Array.isArray(disposables)) { | ||
disposables.push(result); | ||
} | ||
return result; | ||
}, { | ||
maxListeners: Emitter.LEAK_WARNING_THRESHHOLD | ||
}); | ||
} | ||
return this._event; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
}; | ||
if (Array.isArray(disposables)) { | ||
disposables.push(result); | ||
} | ||
return result; | ||
}, { | ||
maxListeners: Emitter.LEAK_WARNING_THRESHHOLD | ||
}); | ||
} | ||
return this._event; | ||
} | ||
/** | ||
@@ -278,7 +168,7 @@ * To be kept private to fire an event to | ||
*/ | ||
Emitter.prototype.fire = function (event) { | ||
fire(event) { | ||
if (this._callbacks) { | ||
this._callbacks.invoke(event); | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -288,44 +178,12 @@ * Process each listener one by one. | ||
*/ | ||
Emitter.prototype.sequence = function (processor) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, _b, listener, e_2_1; | ||
var e_2, _c; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
if (!this._callbacks) return [3 /*break*/, 8]; | ||
_d.label = 1; | ||
case 1: | ||
_d.trys.push([1, 6, 7, 8]); | ||
_a = __values(this._callbacks), _b = _a.next(); | ||
_d.label = 2; | ||
case 2: | ||
if (!!_b.done) return [3 /*break*/, 5]; | ||
listener = _b.value; | ||
return [4 /*yield*/, processor(listener)]; | ||
case 3: | ||
if (!(_d.sent())) { | ||
return [3 /*break*/, 5]; | ||
} | ||
_d.label = 4; | ||
case 4: | ||
_b = _a.next(); | ||
return [3 /*break*/, 2]; | ||
case 5: return [3 /*break*/, 8]; | ||
case 6: | ||
e_2_1 = _d.sent(); | ||
e_2 = { error: e_2_1 }; | ||
return [3 /*break*/, 8]; | ||
case 7: | ||
try { | ||
if (_b && !_b.done && (_c = _a.return)) _c.call(_a); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
return [7 /*endfinally*/]; | ||
case 8: return [2 /*return*/]; | ||
async sequence(processor) { | ||
if (this._callbacks) { | ||
for (const listener of this._callbacks) { | ||
if (!await processor(listener)) { | ||
break; | ||
} | ||
}); | ||
}); | ||
}; | ||
Emitter.prototype.dispose = function () { | ||
} | ||
} | ||
} | ||
dispose() { | ||
if (this._leakingStacks) { | ||
@@ -340,12 +198,12 @@ this._leakingStacks.clear(); | ||
this._disposed = true; | ||
}; | ||
Emitter.prototype.checkMaxListeners = function (maxListeners) { | ||
} | ||
checkMaxListeners(maxListeners) { | ||
if (maxListeners === 0 || !this._callbacks) { | ||
return undefined; | ||
} | ||
var listenerCount = this._callbacks.length; | ||
const listenerCount = this._callbacks.length; | ||
if (listenerCount <= maxListeners) { | ||
return undefined; | ||
} | ||
var popStack = this.pushLeakingStack(); | ||
const popStack = this.pushLeakingStack(); | ||
this._leakWarnCountdown -= 1; | ||
@@ -356,83 +214,68 @@ if (this._leakWarnCountdown <= 0) { | ||
this._leakWarnCountdown = maxListeners * 0.5; | ||
var topStack_1; | ||
var topCount_1 = 0; | ||
this._leakingStacks.forEach(function (stackCount, stack) { | ||
if (!topStack_1 || topCount_1 < stackCount) { | ||
topStack_1 = stack; | ||
topCount_1 = stackCount; | ||
let topStack; | ||
let topCount = 0; | ||
this._leakingStacks.forEach((stackCount, stack) => { | ||
if (!topStack || topCount < stackCount) { | ||
topStack = stack; | ||
topCount = stackCount; | ||
} | ||
}); | ||
// eslint-disable-next-line max-len | ||
console.warn("Possible Emitter memory leak detected. ".concat(listenerCount, " listeners added. Use event.maxListeners to increase the limit (").concat(maxListeners, "). MOST frequent listener (").concat(topCount_1, "):")); | ||
console.warn(topStack_1); | ||
console.warn(`Possible Emitter memory leak detected. ${listenerCount} listeners added. Use event.maxListeners to increase the limit (${maxListeners}). MOST frequent listener (${topCount}):`); | ||
console.warn(topStack); | ||
} | ||
return popStack; | ||
}; | ||
Emitter.prototype.pushLeakingStack = function () { | ||
var _this = this; | ||
} | ||
pushLeakingStack() { | ||
if (!this._leakingStacks) { | ||
this._leakingStacks = new Map(); | ||
} | ||
var stack = new Error().stack.split('\n').slice(3).join('\n'); | ||
var count = (this._leakingStacks.get(stack) || 0); | ||
const stack = new Error().stack.split('\n').slice(3).join('\n'); | ||
const count = (this._leakingStacks.get(stack) || 0); | ||
this._leakingStacks.set(stack, count + 1); | ||
return function () { return _this.popLeakingStack(stack); }; | ||
}; | ||
Emitter.prototype.popLeakingStack = function (stack) { | ||
return () => this.popLeakingStack(stack); | ||
} | ||
popLeakingStack(stack) { | ||
if (!this._leakingStacks) { | ||
return; | ||
} | ||
var count = (this._leakingStacks.get(stack) || 0); | ||
const count = (this._leakingStacks.get(stack) || 0); | ||
this._leakingStacks.set(stack, count - 1); | ||
}; | ||
Emitter.LEAK_WARNING_THRESHHOLD = 175; | ||
Emitter._noop = function () { | ||
}; | ||
return Emitter; | ||
}()); | ||
} | ||
} | ||
exports.Emitter = Emitter; | ||
Emitter.LEAK_WARNING_THRESHHOLD = 175; | ||
Emitter._noop = function () { | ||
}; | ||
var WaitUntilEvent; | ||
(function (WaitUntilEvent) { | ||
function fire(emitter, event, timeout) { | ||
if (timeout === void 0) { timeout = undefined; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var waitables, asyncEvent; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
waitables = []; | ||
asyncEvent = Object.assign(event, { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
waitUntil: function (thenable) { | ||
if (Object.isFrozen(waitables)) { | ||
throw new Error('waitUntil cannot be called asynchronously.'); | ||
} | ||
waitables.push(thenable); | ||
} | ||
}); | ||
try { | ||
emitter.fire(asyncEvent); | ||
// Asynchronous calls to `waitUntil` should fail. | ||
Object.freeze(waitables); | ||
} | ||
finally { | ||
// @ts-ignore | ||
delete asyncEvent['waitUntil']; | ||
} | ||
if (!waitables.length) { | ||
return [2 /*return*/]; | ||
} | ||
if (!(timeout !== undefined)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, Promise.race([Promise.all(waitables), new Promise(function (resolve) { return setTimeout(resolve, timeout); })])]; | ||
case 1: | ||
_a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 2: return [4 /*yield*/, Promise.all(waitables)]; | ||
case 3: | ||
_a.sent(); | ||
_a.label = 4; | ||
case 4: return [2 /*return*/]; | ||
async function fire(emitter, event, timeout = undefined) { | ||
const waitables = []; | ||
const asyncEvent = Object.assign(event, { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
waitUntil: (thenable) => { | ||
if (Object.isFrozen(waitables)) { | ||
throw new Error('waitUntil cannot be called asynchronously.'); | ||
} | ||
}); | ||
waitables.push(thenable); | ||
} | ||
}); | ||
try { | ||
emitter.fire(asyncEvent); | ||
// Asynchronous calls to `waitUntil` should fail. | ||
Object.freeze(waitables); | ||
} | ||
finally { | ||
// @ts-ignore | ||
delete asyncEvent['waitUntil']; | ||
} | ||
if (!waitables.length) { | ||
return; | ||
} | ||
if (timeout !== undefined) { | ||
await Promise.race([Promise.all(waitables), new Promise(resolve => setTimeout(resolve, timeout))]); | ||
} | ||
else { | ||
await Promise.all(waitables); | ||
} | ||
} | ||
@@ -439,0 +282,0 @@ WaitUntilEvent.fire = fire; |
@@ -18,9 +18,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chai_1 = require("chai"); | ||
var event_1 = require("./event"); | ||
describe('Event Objects', function () { | ||
it('Emitter firing should be synchronous', function () { | ||
var emitter = new event_1.Emitter(); | ||
var counter = 0; | ||
emitter.event(function () { return counter++; }); | ||
const chai_1 = require("chai"); | ||
const event_1 = require("./event"); | ||
describe('Event Objects', () => { | ||
it('Emitter firing should be synchronous', () => { | ||
const emitter = new event_1.Emitter(); | ||
let counter = 0; | ||
emitter.event(() => counter++); | ||
(0, chai_1.expect)(counter).eq(0); | ||
@@ -27,0 +27,0 @@ emitter.fire(undefined); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateLocalId = void 0; | ||
var idx = 0; | ||
let idx = 0; | ||
function generateLocalId() { | ||
@@ -6,0 +6,0 @@ idx++; |
@@ -18,3 +18,3 @@ "use strict"; | ||
exports.debounce = void 0; | ||
var debounce = require("lodash.debounce"); | ||
const debounce = require("lodash.debounce"); | ||
exports.debounce = debounce; | ||
@@ -21,0 +21,0 @@ __exportStar(require("./id"), exports); |
@@ -6,3 +6,3 @@ "use strict"; | ||
function bindInSingletonScope(bind, identifiers) { | ||
identifiers.forEach(function (binder) { return bind(binder).toSelf().inSingletonScope(); }); | ||
identifiers.forEach(binder => bind(binder).toSelf().inSingletonScope()); | ||
return bind; | ||
@@ -13,3 +13,3 @@ } | ||
function bindContributions(bind, target, contributions) { | ||
contributions.forEach(function (contrib) { return bind(contrib).toService(target); }); | ||
contributions.forEach(contrib => bind(contrib).toService(target)); | ||
return bind; | ||
@@ -16,0 +16,0 @@ } |
@@ -12,3 +12,3 @@ "use strict"; | ||
return false; | ||
var proto = obj; | ||
let proto = obj; | ||
while (Object.getPrototypeOf(proto) !== null) { | ||
@@ -15,0 +15,0 @@ proto = Object.getPrototypeOf(proto); |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -31,3 +20,3 @@ exports.NOOP = exports.setByKey = exports.getByKey = exports.mapKeys = exports.mapValues = exports.reduce = exports.omit = exports.pick = exports.filter = exports.values = exports.each = exports.isEmpty = exports.notEmpty = exports.deepFreeze = exports.deepClone = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
var keys = Object.keys; | ||
const keys = Object.keys; | ||
exports.deepClone = require('lodash.clonedeep'); | ||
@@ -59,9 +48,9 @@ /* export function deepClone<T>(obj: T): T { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
var stack = [obj]; | ||
const stack = [obj]; | ||
while (stack.length > 0) { | ||
var objectToFreeze = stack.shift(); | ||
const objectToFreeze = stack.shift(); | ||
Object.freeze(objectToFreeze); | ||
for (var key in objectToFreeze) { | ||
for (const key in objectToFreeze) { | ||
if (_hasOwnProperty.call(objectToFreeze, key)) { | ||
var prop = objectToFreeze[key]; | ||
const prop = objectToFreeze[key]; | ||
if (typeof prop === 'object' && !Object.isFrozen(prop)) { | ||
@@ -76,3 +65,3 @@ stack.push(prop); | ||
exports.deepFreeze = deepFreeze; | ||
var _hasOwnProperty = Object.prototype.hasOwnProperty; | ||
const _hasOwnProperty = Object.prototype.hasOwnProperty; | ||
function notEmpty(arg) { | ||
@@ -90,31 +79,17 @@ // eslint-disable-next-line no-null/no-null | ||
exports.isEmpty = isEmpty; | ||
var each = function (obj, fn) { return keys(obj).forEach(function (key) { return fn(obj[key], key); }); }; | ||
const each = (obj, fn) => keys(obj).forEach(key => fn(obj[key], key)); | ||
exports.each = each; | ||
var values = function (obj) { return Object.values ? Object.values(obj) : keys(obj).map(function (k) { return obj[k]; }); }; | ||
const values = (obj) => Object.values ? Object.values(obj) : keys(obj).map(k => obj[k]); | ||
exports.values = values; | ||
var filter = function (obj, fn, dest) { | ||
return keys(obj).reduce(function (output, key) { | ||
var _a; | ||
return fn(obj[key], key) ? Object.assign(output, (_a = {}, _a[key] = obj[key], _a)) : output; | ||
}, dest || {}); | ||
}; | ||
const filter = (obj, fn, dest) => keys(obj).reduce((output, key) => fn(obj[key], key) ? Object.assign(output, { [key]: obj[key] }) : output, dest || {}); | ||
exports.filter = filter; | ||
var pick = function (obj, fields, dest) { return (0, exports.filter)(obj, function (n, k) { return fields.indexOf(k) !== -1; }, dest); }; | ||
const pick = (obj, fields, dest) => (0, exports.filter)(obj, (n, k) => fields.indexOf(k) !== -1, dest); | ||
exports.pick = pick; | ||
var omit = function (obj, fields, dest) { return (0, exports.filter)(obj, function (n, k) { return fields.indexOf(k) === -1; }, dest); }; | ||
const omit = (obj, fields, dest) => (0, exports.filter)(obj, (n, k) => fields.indexOf(k) === -1, dest); | ||
exports.omit = omit; | ||
var reduce = function (obj, fn, res) { | ||
if (res === void 0) { res = {}; } | ||
return keys(obj).reduce(function (r, k) { return fn(r, obj[k], k); }, res); | ||
}; | ||
const reduce = (obj, fn, res = {}) => keys(obj).reduce((r, k) => fn(r, obj[k], k), res); | ||
exports.reduce = reduce; | ||
var mapValues = function (obj, fn) { return (0, exports.reduce)(obj, function (res, value, key) { | ||
var _a; | ||
return Object.assign(res, (_a = {}, _a[key] = fn(value, key), _a)); | ||
}); }; | ||
const mapValues = (obj, fn) => (0, exports.reduce)(obj, (res, value, key) => Object.assign(res, { [key]: fn(value, key) })); | ||
exports.mapValues = mapValues; | ||
var mapKeys = function (obj, fn) { return (0, exports.reduce)(obj, function (res, value, key) { | ||
var _a; | ||
return Object.assign(res, (_a = {}, _a[fn(value, key)] = value, _a)); | ||
}); }; | ||
const mapKeys = (obj, fn) => (0, exports.reduce)(obj, (res, value, key) => Object.assign(res, { [fn(value, key)]: value })); | ||
exports.mapKeys = mapKeys; | ||
@@ -136,3 +111,3 @@ /** | ||
return undefined; | ||
return key.split('.').reduce(function (v, k) { | ||
return key.split('.').reduce((v, k) => { | ||
if (typeof v !== 'object') | ||
@@ -160,11 +135,10 @@ return undefined; | ||
*/ | ||
function setByKey(target, key, newValue, autoCreateObject, clone) { | ||
if (autoCreateObject === void 0) { autoCreateObject = true; } | ||
function setByKey(target, key, newValue, autoCreateObject = true, clone) { | ||
if (typeof target !== 'object' || !key) | ||
return target; | ||
if (clone) { | ||
target = __assign({}, target); | ||
target = Object.assign({}, target); | ||
} | ||
var originTarget = target; | ||
var targetKeys = key.split('.'); | ||
const originTarget = target; | ||
const targetKeys = key.split('.'); | ||
while (targetKeys.length > 0) { | ||
@@ -182,3 +156,3 @@ key = targetKeys.shift(); | ||
if (clone) { | ||
target[key] = __assign({}, target[key]); | ||
target[key] = Object.assign({}, target[key]); | ||
} | ||
@@ -190,4 +164,4 @@ target = target[key]; | ||
exports.setByKey = setByKey; | ||
var NOOP = function () { }; | ||
const NOOP = () => { }; | ||
exports.NOOP = NOOP; | ||
//# sourceMappingURL=objects.js.map |
@@ -17,27 +17,2 @@ "use strict"; | ||
********************************************************************************/ | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -60,10 +35,6 @@ exports.OS = exports.isOSX = exports.isWindows = void 0; | ||
(function (OS) { | ||
function cmd(command) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
function cmd(command, ...args) { | ||
return [ | ||
exports.isWindows ? 'cmd' : command, | ||
exports.isWindows ? __spreadArray(['/c', command], __read(args), false) : args | ||
exports.isWindows ? ['/c', command, ...args] : args | ||
]; | ||
@@ -75,3 +46,3 @@ } | ||
*/ | ||
var Type; | ||
let Type; | ||
(function (Type) { | ||
@@ -78,0 +49,0 @@ Type["Windows"] = "Windows"; |
@@ -36,10 +36,10 @@ "use strict"; | ||
*/ | ||
var Path = /** @class */ (function () { | ||
class Path { | ||
/** | ||
* The raw should be normalized, meaning that only '/' is allowed as a path separator. | ||
*/ | ||
function Path(raw) { | ||
constructor(raw) { | ||
this.raw = Path.normalizeDrive(raw); | ||
var firstIndex = raw.indexOf(Path.separator); | ||
var lastIndex = raw.lastIndexOf(Path.separator); | ||
const firstIndex = raw.indexOf(Path.separator); | ||
const lastIndex = raw.lastIndexOf(Path.separator); | ||
this.isAbsolute = firstIndex === 0; | ||
@@ -49,35 +49,27 @@ this.base = lastIndex === -1 ? raw : raw.substr(lastIndex + 1); | ||
this.root = this.computeRoot(); | ||
var extIndex = this.base.lastIndexOf('.'); | ||
const extIndex = this.base.lastIndexOf('.'); | ||
this.name = extIndex === -1 ? this.base : this.base.substr(0, extIndex); | ||
this.ext = extIndex === -1 ? '' : this.base.substr(extIndex); | ||
} | ||
Object.defineProperty(Path.prototype, "dir", { | ||
/** | ||
* Returns the parent directory if it exists (`hasDir === true`) or `this` otherwise. | ||
*/ | ||
get: function () { | ||
if (this._dir === undefined) { | ||
this._dir = this.computeDir(); | ||
} | ||
return this._dir; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Path.prototype, "hasDir", { | ||
/** | ||
* Returns `true` if this has a parent directory, `false` otherwise. | ||
* | ||
* _This implementation returns `true` if and only if this is not the root dir and | ||
* there is a path separator in the raw path._ | ||
*/ | ||
get: function () { | ||
return !this.isRoot && this.raw.lastIndexOf(Path.separator) !== -1; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Path.isDrive = function (segment) { | ||
/** | ||
* Returns the parent directory if it exists (`hasDir === true`) or `this` otherwise. | ||
*/ | ||
get dir() { | ||
if (this._dir === undefined) { | ||
this._dir = this.computeDir(); | ||
} | ||
return this._dir; | ||
} | ||
/** | ||
* Returns `true` if this has a parent directory, `false` otherwise. | ||
* | ||
* _This implementation returns `true` if and only if this is not the root dir and | ||
* there is a path separator in the raw path._ | ||
*/ | ||
get hasDir() { | ||
return !this.isRoot && this.raw.lastIndexOf(Path.separator) !== -1; | ||
} | ||
static isDrive(segment) { | ||
return segment.endsWith(':'); | ||
}; | ||
} | ||
/** | ||
@@ -88,24 +80,20 @@ * vscode-uri always normalizes drive letters to lower case: | ||
*/ | ||
Path.normalizeDrive = function (path) { | ||
static normalizeDrive(path) { | ||
// lower-case windows drive letters in /C:/fff or C:/fff | ||
if (path.length >= 3 && path.charCodeAt(0) === 47 /* '/' */ && path.charCodeAt(2) === 58 /* ':' */) { | ||
var code = path.charCodeAt(1); | ||
const code = path.charCodeAt(1); | ||
if (code >= 65 /* A */ && code <= 90 /* Z */) { | ||
path = "/".concat(String.fromCharCode(code + 32), ":").concat(path.substr(3)); // "/c:".length === 3 | ||
path = `/${String.fromCharCode(code + 32)}:${path.substr(3)}`; // "/c:".length === 3 | ||
} | ||
} | ||
else if (path.length >= 2 && path.charCodeAt(1) === 58 /* ':' */) { | ||
var code = path.charCodeAt(0); | ||
const code = path.charCodeAt(0); | ||
if (code >= 65 /* A */ && code <= 90 /* Z */) { | ||
path = "".concat(String.fromCharCode(code + 32), ":").concat(path.substr(2)); // "/c:".length === 3 | ||
path = `${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "/c:".length === 3 | ||
} | ||
} | ||
return path; | ||
}; | ||
Path.prototype.join = function () { | ||
var paths = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
paths[_i] = arguments[_i]; | ||
} | ||
var relativePath = paths.filter(function (s) { return !!s; }).join(Path.separator); | ||
} | ||
join(...paths) { | ||
const relativePath = paths.filter(s => !!s).join(Path.separator); | ||
if (!relativePath) { | ||
@@ -118,7 +106,7 @@ return this; | ||
return new Path(this.raw + Path.separator + relativePath); | ||
}; | ||
Path.prototype.toString = function () { | ||
} | ||
toString() { | ||
return this.raw; | ||
}; | ||
Path.prototype.relative = function (path) { | ||
} | ||
relative(path) { | ||
if (this.raw === path.raw) { | ||
@@ -130,16 +118,16 @@ return new Path(''); | ||
} | ||
var raw = this.base ? this.raw + Path.separator : this.raw; | ||
const raw = this.base ? this.raw + Path.separator : this.raw; | ||
if (!path.raw.startsWith(raw)) { | ||
return undefined; | ||
} | ||
var relativePath = path.raw.substr(raw.length); | ||
const relativePath = path.raw.substr(raw.length); | ||
return new Path(relativePath); | ||
}; | ||
Path.prototype.isEqualOrParent = function (path) { | ||
} | ||
isEqualOrParent(path) { | ||
return !!this.relative(path); | ||
}; | ||
Path.prototype.relativity = function (path) { | ||
var relative = this.relative(path); | ||
} | ||
relativity(path) { | ||
const relative = this.relative(path); | ||
if (relative) { | ||
var relativeStr = relative.toString(); | ||
const relativeStr = relative.toString(); | ||
if (relativeStr === '') { | ||
@@ -151,12 +139,11 @@ return 0; | ||
return -1; | ||
}; | ||
} | ||
/* | ||
* return a normalized Path, resolving '..' and '.' segments | ||
*/ | ||
Path.prototype.normalize = function () { | ||
var _this = this; | ||
var trailingSlash = this.raw.endsWith('/'); | ||
var pathArray = this.toString().split('/'); | ||
var resultArray = []; | ||
pathArray.forEach(function (value, index) { | ||
normalize() { | ||
const trailingSlash = this.raw.endsWith('/'); | ||
const pathArray = this.toString().split('/'); | ||
const resultArray = []; | ||
pathArray.forEach((value, index) => { | ||
if (!value || value === '.') { | ||
@@ -169,3 +156,3 @@ return; | ||
} | ||
else if (!_this.isAbsolute) { | ||
else if (!this.isAbsolute) { | ||
resultArray.push('..'); | ||
@@ -187,4 +174,4 @@ } | ||
return new Path((this.isAbsolute ? '/' : '') + resultArray.join('/') + (trailingSlash ? '/' : '')); | ||
}; | ||
Path.prototype.computeRoot = function () { | ||
} | ||
computeRoot() { | ||
// '/' -> '/' | ||
@@ -199,3 +186,3 @@ // '/c:' -> '/c:' | ||
} | ||
var index = this.raw.indexOf(Path.separator, Path.separator.length); | ||
const index = this.raw.indexOf(Path.separator, Path.separator.length); | ||
if (index === -1) { | ||
@@ -208,10 +195,10 @@ // '/foo/bar' -> '/' | ||
return new Path(this.raw.substr(0, index)).root; | ||
}; | ||
Path.prototype.computeDir = function () { | ||
} | ||
computeDir() { | ||
if (!this.hasDir) { | ||
return this; | ||
} | ||
var lastIndex = this.raw.lastIndexOf(Path.separator); | ||
const lastIndex = this.raw.lastIndexOf(Path.separator); | ||
if (this.isAbsolute) { | ||
var firstIndex = this.raw.indexOf(Path.separator); | ||
const firstIndex = this.raw.indexOf(Path.separator); | ||
if (firstIndex === lastIndex) { | ||
@@ -222,7 +209,6 @@ return new Path(this.raw.substr(0, firstIndex + 1)); | ||
return new Path(this.raw.substr(0, lastIndex)); | ||
}; | ||
Path.separator = '/'; | ||
return Path; | ||
}()); | ||
} | ||
} | ||
exports.Path = Path; | ||
Path.separator = '/'; | ||
//# sourceMappingURL=path.js.map |
@@ -18,7 +18,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var assert = require("assert"); | ||
var path_1 = require("./path"); | ||
describe('Path', function () { | ||
it('new from /foo/bar/file.txt', function () { | ||
var path = new path_1.Path('/foo/bar/file.txt'); | ||
const assert = require("assert"); | ||
const path_1 = require("./path"); | ||
describe('Path', () => { | ||
it('new from /foo/bar/file.txt', () => { | ||
const path = new path_1.Path('/foo/bar/file.txt'); | ||
assert.deepEqual(path.isRoot, false); | ||
@@ -33,4 +33,4 @@ assert.deepEqual(path.isAbsolute, true); | ||
}); | ||
it('new from foo/bar/file.txt', function () { | ||
var path = new path_1.Path('foo/bar/file.txt'); | ||
it('new from foo/bar/file.txt', () => { | ||
const path = new path_1.Path('foo/bar/file.txt'); | ||
assert.deepEqual(path.isRoot, false); | ||
@@ -45,4 +45,4 @@ assert.deepEqual(path.isAbsolute, false); | ||
}); | ||
it('new from /foo', function () { | ||
var path = new path_1.Path('/foo'); | ||
it('new from /foo', () => { | ||
const path = new path_1.Path('/foo'); | ||
assert.deepEqual(path.isRoot, false); | ||
@@ -57,4 +57,4 @@ assert.deepEqual(path.isAbsolute, true); | ||
}); | ||
it('new from foo', function () { | ||
var path = new path_1.Path('foo'); | ||
it('new from foo', () => { | ||
const path = new path_1.Path('foo'); | ||
assert.deepEqual(path.isRoot, false); | ||
@@ -69,4 +69,4 @@ assert.deepEqual(path.isAbsolute, false); | ||
}); | ||
it('new from /', function () { | ||
var path = new path_1.Path('/'); | ||
it('new from /', () => { | ||
const path = new path_1.Path('/'); | ||
assert.deepEqual(path.isRoot, true); | ||
@@ -81,4 +81,4 @@ assert.deepEqual(path.isAbsolute, true); | ||
}); | ||
it('new from /c:/foo/bar/file.txt', function () { | ||
var path = new path_1.Path('/c:/foo/bar/file.txt'); | ||
it('new from /c:/foo/bar/file.txt', () => { | ||
const path = new path_1.Path('/c:/foo/bar/file.txt'); | ||
assert.deepEqual(path.isRoot, false); | ||
@@ -93,4 +93,4 @@ assert.deepEqual(path.isAbsolute, true); | ||
}); | ||
it('new from /c:/foo', function () { | ||
var path = new path_1.Path('/c:/foo'); | ||
it('new from /c:/foo', () => { | ||
const path = new path_1.Path('/c:/foo'); | ||
assert.deepEqual(path.isRoot, false); | ||
@@ -105,4 +105,4 @@ assert.deepEqual(path.isAbsolute, true); | ||
}); | ||
it('new from /c:/', function () { | ||
var path = new path_1.Path('/c:/'); | ||
it('new from /c:/', () => { | ||
const path = new path_1.Path('/c:/'); | ||
assert.deepEqual(path.isRoot, false); | ||
@@ -117,4 +117,4 @@ assert.deepEqual(path.isAbsolute, true); | ||
}); | ||
it('new from /c:', function () { | ||
var path = new path_1.Path('/c:'); | ||
it('new from /c:', () => { | ||
const path = new path_1.Path('/c:'); | ||
assert.deepEqual(path.isRoot, true); | ||
@@ -149,6 +149,5 @@ assert.deepEqual(path.isAbsolute, true); | ||
}); | ||
function assertRelative(_a) { | ||
var from = _a.from, to = _a.to, expectation = _a.expectation; | ||
it("the relative path from '".concat(from, "' to '").concat(to, "' should be '").concat(expectation, "'"), function () { | ||
var path = new path_1.Path(from).relative(new path_1.Path(to)); | ||
function assertRelative({ from, to, expectation }) { | ||
it(`the relative path from '${from}' to '${to}' should be '${expectation}'`, () => { | ||
const path = new path_1.Path(from).relative(new path_1.Path(to)); | ||
assert.deepEqual(expectation, path && path.toString()); | ||
@@ -225,5 +224,4 @@ }); | ||
}); | ||
function assertNormalize(_a) { | ||
var from = _a.from, expectation = _a.expectation; | ||
it("path ".concat(from, " should be normalized as ").concat(expectation), function () { | ||
function assertNormalize({ from, expectation }) { | ||
it(`path ${from} should be normalized as ${expectation}`, () => { | ||
assert.deepStrictEqual(new path_1.Path(from).normalize().toString(), expectation); | ||
@@ -230,0 +228,0 @@ }); |
@@ -17,52 +17,5 @@ "use strict"; | ||
********************************************************************************/ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PromisePool = exports.retry = exports.timeout = exports.Deferred = exports.PromiseDeferred = void 0; | ||
var cancellation_1 = require("./cancellation"); | ||
const cancellation_1 = require("./cancellation"); | ||
/** | ||
@@ -72,12 +25,10 @@ * Simple implementation of the deferred pattern. | ||
*/ | ||
var PromiseDeferred = /** @class */ (function () { | ||
function PromiseDeferred() { | ||
var _this = this; | ||
this.promise = new Promise(function (resolve, reject) { | ||
_this.resolve = resolve; | ||
_this.reject = reject; | ||
class PromiseDeferred { | ||
constructor() { | ||
this.promise = new Promise((resolve, reject) => { | ||
this.resolve = resolve; | ||
this.reject = reject; | ||
}); | ||
} | ||
return PromiseDeferred; | ||
}()); | ||
} | ||
exports.PromiseDeferred = PromiseDeferred; | ||
@@ -89,7 +40,6 @@ exports.Deferred = PromiseDeferred; | ||
*/ | ||
function timeout(ms, token) { | ||
if (token === void 0) { token = cancellation_1.CancellationToken.None; } | ||
var deferred = new PromiseDeferred(); | ||
var handle = setTimeout(function () { return deferred.resolve(); }, ms); | ||
token.onCancellationRequested(function () { | ||
function timeout(ms, token = cancellation_1.CancellationToken.None) { | ||
const deferred = new PromiseDeferred(); | ||
const handle = setTimeout(() => deferred.resolve(), ms); | ||
token.onCancellationRequested(() => { | ||
clearTimeout(handle); | ||
@@ -101,45 +51,26 @@ deferred.reject((0, cancellation_1.cancelled)()); | ||
exports.timeout = timeout; | ||
function retry(task, delay, retries, shouldRetry) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var lastError, result, i, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
i = 0; | ||
_a.label = 1; | ||
case 1: | ||
if (!(i < retries)) return [3 /*break*/, 9]; | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 6, , 8]); | ||
return [4 /*yield*/, task()]; | ||
case 3: | ||
result = _a.sent(); | ||
if (!(shouldRetry && shouldRetry(result))) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, timeout(delay)]; | ||
case 4: | ||
_a.sent(); | ||
return [3 /*break*/, 8]; | ||
case 5: return [2 /*return*/, result]; | ||
case 6: | ||
error_1 = _a.sent(); | ||
lastError = error_1; | ||
return [4 /*yield*/, timeout(delay)]; | ||
case 7: | ||
_a.sent(); | ||
return [3 /*break*/, 8]; | ||
case 8: | ||
i++; | ||
return [3 /*break*/, 1]; | ||
case 9: | ||
if (lastError) { | ||
throw lastError; | ||
} | ||
return [2 /*return*/, result]; | ||
async function retry(task, delay, retries, shouldRetry) { | ||
let lastError; | ||
let result; | ||
for (let i = 0; i < retries; i++) { | ||
try { | ||
result = await task(); | ||
if (shouldRetry && shouldRetry(result)) { | ||
await timeout(delay); | ||
continue; | ||
} | ||
}); | ||
}); | ||
return result; | ||
} | ||
catch (error) { | ||
lastError = error; | ||
await timeout(delay); | ||
} | ||
} | ||
if (lastError) { | ||
throw lastError; | ||
} | ||
return result; | ||
} | ||
exports.retry = retry; | ||
var PromisePoolOptsDefault = { | ||
const PromisePoolOptsDefault = { | ||
intervalCount: 10, | ||
@@ -150,16 +81,11 @@ intervalTime: 0, | ||
}; | ||
var PromisePool = /** @class */ (function () { | ||
function PromisePool(opts) { | ||
if (opts === void 0) { opts = PromisePoolOptsDefault; } | ||
this.opts = __assign(__assign({}, PromisePoolOptsDefault), opts); | ||
class PromisePool { | ||
constructor(opts = PromisePoolOptsDefault) { | ||
this.opts = Object.assign(Object.assign({}, PromisePoolOptsDefault), opts); | ||
} | ||
PromisePool.prototype.tryToExec = function (task, checkIfRetry) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
if (this.opts.retries === 0) | ||
return [2 /*return*/, task()]; | ||
return [2 /*return*/, retry(task, this.opts.retryDelay, this.opts.retries, checkIfRetry)]; | ||
}); | ||
}); | ||
}; | ||
async tryToExec(task, checkIfRetry) { | ||
if (this.opts.retries === 0) | ||
return task(); | ||
return retry(task, this.opts.retryDelay, this.opts.retries, checkIfRetry); | ||
} | ||
/** | ||
@@ -169,35 +95,17 @@ * @param tasks 执行任务 | ||
*/ | ||
PromisePool.prototype.run = function (tasks, checkIfRetry) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var curTasks, promises, result, nextTasks, _a, _b; | ||
var _this = this; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (tasks.length === 0) | ||
return [2 /*return*/, []]; | ||
curTasks = tasks.slice(0, this.opts.intervalCount); | ||
promises = curTasks.map(function (task) { return _this.tryToExec(task, checkIfRetry); }); | ||
return [4 /*yield*/, Promise.all(promises)]; | ||
case 1: | ||
result = _c.sent(); | ||
nextTasks = tasks.slice(this.opts.intervalCount); | ||
if (nextTasks.length === 0) | ||
return [2 /*return*/, result]; | ||
if (!(this.opts.intervalTime !== 0)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, timeout(this.opts.intervalTime)]; | ||
case 2: | ||
_c.sent(); | ||
_c.label = 3; | ||
case 3: | ||
_b = (_a = result).concat; | ||
return [4 /*yield*/, this.run(nextTasks, checkIfRetry)]; | ||
case 4: return [2 /*return*/, _b.apply(_a, [_c.sent()])]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return PromisePool; | ||
}()); | ||
async run(tasks, checkIfRetry) { | ||
if (tasks.length === 0) | ||
return []; | ||
const curTasks = tasks.slice(0, this.opts.intervalCount); | ||
const promises = curTasks.map(task => this.tryToExec(task, checkIfRetry)); | ||
const result = await Promise.all(promises); | ||
const nextTasks = tasks.slice(this.opts.intervalCount); | ||
if (nextTasks.length === 0) | ||
return result; | ||
if (this.opts.intervalTime !== 0) | ||
await timeout(this.opts.intervalTime); | ||
return result.concat(await this.run(nextTasks, checkIfRetry)); | ||
} | ||
} | ||
exports.PromisePool = PromisePool; | ||
//# sourceMappingURL=promise-util.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var promise_util_1 = require("./promise-util"); | ||
var assert = require("assert"); | ||
describe('promise utils', function () { | ||
var execTimes = 0; | ||
const promise_util_1 = require("./promise-util"); | ||
const assert = require("assert"); | ||
describe('promise utils', () => { | ||
let execTimes = 0; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
var tasks = Array(10).fill(0).map(function (t, i) { return function () { return new Promise(function (res) { return setTimeout(function () { | ||
const tasks = Array(10).fill(0).map((t, i) => () => new Promise(res => setTimeout(() => { | ||
console.log('>> run task ' + i); | ||
execTimes++; | ||
res(i); | ||
}, 10); }); }; }); | ||
}, 10))); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
it('PromisePool', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var pool, checkIfRetry, result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
pool = new promise_util_1.PromisePool({ | ||
intervalCount: 3, | ||
intervalTime: 100, | ||
retries: 3, // 尝试三次 | ||
}); | ||
checkIfRetry = function (res) { | ||
if (res === 8) | ||
return true; | ||
return false; | ||
}; | ||
return [4 /*yield*/, pool.run(tasks, checkIfRetry)]; | ||
case 1: | ||
result = _a.sent(); | ||
assert.equal(execTimes, 12); | ||
assert.deepEqual(result, Array(10).fill(0).map(function (t, i) { return i; })); | ||
return [2 /*return*/]; | ||
} | ||
it('PromisePool', async () => { | ||
const pool = new promise_util_1.PromisePool({ | ||
intervalCount: 3, | ||
intervalTime: 100, | ||
retries: 3, // 尝试三次 | ||
}); | ||
}); }); | ||
const checkIfRetry = (res) => { | ||
if (res === 8) | ||
return true; | ||
return false; | ||
}; | ||
const result = await pool.run(tasks, checkIfRetry); | ||
assert.equal(execTimes, 12); | ||
assert.deepEqual(result, Array(10).fill(0).map((t, i) => i)); | ||
}); | ||
}); | ||
//# sourceMappingURL=promise-util.spec.js.map |
@@ -17,96 +17,8 @@ "use strict"; | ||
********************************************************************************/ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SyncReferenceCollection = exports.ReferenceCollection = exports.AbstractReferenceCollection = void 0; | ||
var disposable_1 = require("./disposable"); | ||
var event_1 = require("./event"); | ||
var AbstractReferenceCollection = /** @class */ (function () { | ||
function AbstractReferenceCollection() { | ||
var _this = this; | ||
const disposable_1 = require("./disposable"); | ||
const event_1 = require("./event"); | ||
class AbstractReferenceCollection { | ||
constructor() { | ||
this._keys = new Map(); | ||
@@ -122,60 +34,40 @@ this._values = new Map(); | ||
this.toDispose.push(this.onWillDisposeEmitter); | ||
this.toDispose.push(disposable_1.Disposable.create(function () { return _this.clear(); })); | ||
this.toDispose.push(disposable_1.Disposable.create(() => this.clear())); | ||
} | ||
AbstractReferenceCollection.prototype.dispose = function () { | ||
dispose() { | ||
this.toDispose.dispose(); | ||
}; | ||
AbstractReferenceCollection.prototype.clear = function () { | ||
var e_1, _a; | ||
try { | ||
for (var _b = __values(this._values.values()), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var value = _c.value; | ||
try { | ||
value.dispose(); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
} | ||
clear() { | ||
for (const value of this._values.values()) { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
value.dispose(); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
}; | ||
AbstractReferenceCollection.prototype.has = function (args) { | ||
var key = this.toKey(args); | ||
} | ||
has(args) { | ||
const key = this.toKey(args); | ||
return this.references.has(key); | ||
}; | ||
AbstractReferenceCollection.prototype.keys = function () { | ||
return __spreadArray([], __read(this._keys.values()), false); | ||
}; | ||
AbstractReferenceCollection.prototype.values = function () { | ||
return __spreadArray([], __read(this._values.values()), false); | ||
}; | ||
AbstractReferenceCollection.prototype.get = function (args) { | ||
var key = this.toKey(args); | ||
} | ||
keys() { | ||
return [...this._keys.values()]; | ||
} | ||
values() { | ||
return [...this._values.values()]; | ||
} | ||
get(args) { | ||
const key = this.toKey(args); | ||
return this._values.get(key); | ||
}; | ||
AbstractReferenceCollection.prototype.getOrCreate = function (args) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var ref; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.acquire(args)]; | ||
case 1: | ||
ref = _a.sent(); | ||
return [2 /*return*/, ref.object]; | ||
} | ||
}); | ||
}); | ||
}; | ||
AbstractReferenceCollection.prototype.doAcquire = function (key, object) { | ||
var references = this.references.get(key) || this.createReferences(key, object); | ||
var reference = { | ||
object: object, | ||
dispose: function () { | ||
} | ||
async getOrCreate(args) { | ||
const ref = await this.acquire(args); | ||
return ref.object; | ||
} | ||
doAcquire(key, object) { | ||
const references = this.references.get(key) || this.createReferences(key, object); | ||
const reference = { | ||
object, | ||
dispose: () => { | ||
} | ||
@@ -185,17 +77,16 @@ }; | ||
return reference; | ||
}; | ||
AbstractReferenceCollection.prototype.toKey = function (args) { | ||
} | ||
toKey(args) { | ||
return JSON.stringify(args); | ||
}; | ||
AbstractReferenceCollection.prototype.createReferences = function (key, value) { | ||
var _this = this; | ||
var references = new disposable_1.DisposableCollection(); | ||
references.onDispose(function () { return value.dispose(); }); | ||
var disposeObject = value.dispose.bind(value); | ||
value.dispose = function () { | ||
_this.onWillDisposeEmitter.fire(value); | ||
} | ||
createReferences(key, value) { | ||
const references = new disposable_1.DisposableCollection(); | ||
references.onDispose(() => value.dispose()); | ||
const disposeObject = value.dispose.bind(value); | ||
value.dispose = () => { | ||
this.onWillDisposeEmitter.fire(value); | ||
disposeObject(); | ||
_this._values.delete(key); | ||
_this._keys.delete(key); | ||
_this.references.delete(key); | ||
this._values.delete(key); | ||
this._keys.delete(key); | ||
this.references.delete(key); | ||
references.dispose(); | ||
@@ -205,5 +96,4 @@ }; | ||
return references; | ||
}; | ||
return AbstractReferenceCollection; | ||
}()); | ||
} | ||
} | ||
exports.AbstractReferenceCollection = AbstractReferenceCollection; | ||
@@ -213,87 +103,60 @@ /** | ||
*/ | ||
var ReferenceCollection = /** @class */ (function (_super) { | ||
__extends(ReferenceCollection, _super); | ||
function ReferenceCollection(factory, toKey) { | ||
var _this = _super.call(this) || this; | ||
_this.factory = factory; | ||
_this.pendingValues = new Map(); | ||
class ReferenceCollection extends AbstractReferenceCollection { | ||
constructor(factory, toKey) { | ||
super(); | ||
this.factory = factory; | ||
this.pendingValues = new Map(); | ||
if (toKey) { | ||
_this.toKey = toKey; | ||
this.toKey = toKey; | ||
} | ||
return _this; | ||
} | ||
ReferenceCollection.prototype.acquire = function (args) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var key, existing, object; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
key = this.toKey(args); | ||
existing = this._values.get(key); | ||
if (existing) { | ||
return [2 /*return*/, this.doAcquire(key, existing)]; | ||
} | ||
return [4 /*yield*/, this.getOrCreateValue(key, args)]; | ||
case 1: | ||
object = _a.sent(); | ||
return [2 /*return*/, this.doAcquire(key, object)]; | ||
} | ||
}); | ||
}); | ||
}; | ||
ReferenceCollection.prototype.getOrCreateValue = function (key, args) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var existing, pending, value, e_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
existing = this.pendingValues.get(key); | ||
if (existing) { | ||
return [2 /*return*/, existing]; | ||
} | ||
pending = this.factory(args); | ||
this._keys.set(key, args); | ||
this.pendingValues.set(key, pending); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, 4, 5]); | ||
return [4 /*yield*/, pending]; | ||
case 2: | ||
value = _a.sent(); | ||
this._values.set(key, value); | ||
this.onDidCreateEmitter.fire(value); | ||
return [2 /*return*/, value]; | ||
case 3: | ||
e_2 = _a.sent(); | ||
this._keys.delete(key); | ||
throw e_2; | ||
case 4: | ||
this.pendingValues.delete(key); | ||
return [7 /*endfinally*/]; | ||
case 5: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return ReferenceCollection; | ||
}(AbstractReferenceCollection)); | ||
async acquire(args) { | ||
const key = this.toKey(args); | ||
const existing = this._values.get(key); | ||
if (existing) { | ||
return this.doAcquire(key, existing); | ||
} | ||
const object = await this.getOrCreateValue(key, args); | ||
return this.doAcquire(key, object); | ||
} | ||
async getOrCreateValue(key, args) { | ||
const existing = this.pendingValues.get(key); | ||
if (existing) { | ||
return existing; | ||
} | ||
const pending = this.factory(args); | ||
this._keys.set(key, args); | ||
this.pendingValues.set(key, pending); | ||
try { | ||
const value = await pending; | ||
this._values.set(key, value); | ||
this.onDidCreateEmitter.fire(value); | ||
return value; | ||
} | ||
catch (e) { | ||
this._keys.delete(key); | ||
throw e; | ||
} | ||
finally { | ||
this.pendingValues.delete(key); | ||
} | ||
} | ||
} | ||
exports.ReferenceCollection = ReferenceCollection; | ||
var SyncReferenceCollection = /** @class */ (function (_super) { | ||
__extends(SyncReferenceCollection, _super); | ||
function SyncReferenceCollection(factory) { | ||
var _this = _super.call(this) || this; | ||
_this.factory = factory; | ||
return _this; | ||
class SyncReferenceCollection extends AbstractReferenceCollection { | ||
constructor(factory) { | ||
super(); | ||
this.factory = factory; | ||
} | ||
SyncReferenceCollection.prototype.acquire = function (args) { | ||
var key = this.toKey(args); | ||
var object = this.getOrCreateValue(key, args); | ||
acquire(args) { | ||
const key = this.toKey(args); | ||
const object = this.getOrCreateValue(key, args); | ||
return this.doAcquire(key, object); | ||
}; | ||
SyncReferenceCollection.prototype.getOrCreateValue = function (key, args) { | ||
var existing = this._values.get(key); | ||
} | ||
getOrCreateValue(key, args) { | ||
const existing = this._values.get(key); | ||
if (existing) { | ||
return existing; | ||
} | ||
var value = this.factory(args); | ||
const value = this.factory(args); | ||
this._keys.set(key, args); | ||
@@ -303,6 +166,5 @@ this._values.set(key, value); | ||
return value; | ||
}; | ||
return SyncReferenceCollection; | ||
}(AbstractReferenceCollection)); | ||
} | ||
} | ||
exports.SyncReferenceCollection = SyncReferenceCollection; | ||
//# sourceMappingURL=reference.js.map |
@@ -17,248 +17,111 @@ "use strict"; | ||
********************************************************************************/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var assert = require("assert"); | ||
var reference_1 = require("./reference"); | ||
describe('reference', function () { | ||
it('dispose a single reference', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectation, references, reference; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
expectation = { disposed: false }; | ||
references = new reference_1.ReferenceCollection(function (key) { return ({ | ||
key: key, | ||
dispose: function () { | ||
expectation.disposed = true; | ||
} | ||
}); }); | ||
assert.ok(!references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), []); | ||
return [4 /*yield*/, references.acquire('a')]; | ||
case 1: | ||
reference = _a.sent(); | ||
assert.ok(references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), ['a']); | ||
reference.dispose(); | ||
assert.ok(!references.has('a')); | ||
assert.ok(expectation.disposed); | ||
assert.deepEqual(references.keys(), []); | ||
return [2 /*return*/]; | ||
const assert = require("assert"); | ||
const reference_1 = require("./reference"); | ||
describe('reference', () => { | ||
it('dispose a single reference', async () => { | ||
const expectation = { disposed: false }; | ||
const references = new reference_1.ReferenceCollection(key => ({ | ||
key, dispose: () => { | ||
expectation.disposed = true; | ||
} | ||
}); | ||
}); }); | ||
it('dispose 2 references', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectation, references, reference, reference2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
expectation = { disposed: false }; | ||
references = new reference_1.ReferenceCollection(function (key) { return ({ | ||
key: key, | ||
dispose: function () { | ||
expectation.disposed = true; | ||
} | ||
}); }); | ||
assert.ok(!references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), []); | ||
return [4 /*yield*/, references.acquire('a')]; | ||
case 1: | ||
reference = _a.sent(); | ||
return [4 /*yield*/, references.acquire('a')]; | ||
case 2: | ||
reference2 = _a.sent(); | ||
assert.ok(references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), ['a']); | ||
reference.dispose(); | ||
assert.ok(references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), ['a']); | ||
reference2.dispose(); | ||
assert.ok(!references.has('a')); | ||
assert.ok(expectation.disposed); | ||
assert.deepEqual(references.keys(), []); | ||
return [2 /*return*/]; | ||
})); | ||
assert.ok(!references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), []); | ||
const reference = await references.acquire('a'); | ||
assert.ok(references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), ['a']); | ||
reference.dispose(); | ||
assert.ok(!references.has('a')); | ||
assert.ok(expectation.disposed); | ||
assert.deepEqual(references.keys(), []); | ||
}); | ||
it('dispose 2 references', async () => { | ||
const expectation = { disposed: false }; | ||
const references = new reference_1.ReferenceCollection(key => ({ | ||
key, dispose: () => { | ||
expectation.disposed = true; | ||
} | ||
}); | ||
}); }); | ||
it('dispose an object with 2 references', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectation, references, reference; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
expectation = { disposed: false }; | ||
references = new reference_1.ReferenceCollection(function (key) { return ({ | ||
key: key, | ||
dispose: function () { | ||
expectation.disposed = true; | ||
} | ||
}); }); | ||
assert.ok(!references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), []); | ||
return [4 /*yield*/, references.acquire('a')]; | ||
case 1: | ||
_a.sent(); | ||
return [4 /*yield*/, references.acquire('a')]; | ||
case 2: | ||
reference = _a.sent(); | ||
assert.ok(references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), ['a']); | ||
reference.object.dispose(); | ||
assert.ok(!references.has('a')); | ||
assert.ok(expectation.disposed); | ||
assert.deepEqual(references.keys(), []); | ||
return [2 /*return*/]; | ||
})); | ||
assert.ok(!references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), []); | ||
const reference = await references.acquire('a'); | ||
const reference2 = await references.acquire('a'); | ||
assert.ok(references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), ['a']); | ||
reference.dispose(); | ||
assert.ok(references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), ['a']); | ||
reference2.dispose(); | ||
assert.ok(!references.has('a')); | ||
assert.ok(expectation.disposed); | ||
assert.deepEqual(references.keys(), []); | ||
}); | ||
it('dispose an object with 2 references', async () => { | ||
const expectation = { disposed: false }; | ||
const references = new reference_1.ReferenceCollection(key => ({ | ||
key, dispose: () => { | ||
expectation.disposed = true; | ||
} | ||
}); | ||
}); }); | ||
it("shouldn't call onWillDispose event on create", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectation, references, reference; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
expectation = { disposed: false }; | ||
references = new reference_1.ReferenceCollection(function (key) { return ({ | ||
key: key, | ||
dispose: function () { | ||
} | ||
}); }); | ||
assert.ok(!references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
references.onWillDispose(function (e) { | ||
expectation.disposed = true; | ||
}); | ||
return [4 /*yield*/, references.acquire('a')]; | ||
case 1: | ||
_a.sent(); | ||
assert.ok(!expectation.disposed); | ||
return [4 /*yield*/, references.acquire('a')]; | ||
case 2: | ||
reference = _a.sent(); | ||
reference.object.dispose(); | ||
assert.ok(expectation.disposed); | ||
return [2 /*return*/]; | ||
})); | ||
assert.ok(!references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), []); | ||
await references.acquire('a'); | ||
const reference = await references.acquire('a'); | ||
assert.ok(references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
assert.deepEqual(references.keys(), ['a']); | ||
reference.object.dispose(); | ||
assert.ok(!references.has('a')); | ||
assert.ok(expectation.disposed); | ||
assert.deepEqual(references.keys(), []); | ||
}); | ||
it("shouldn't call onWillDispose event on create", async () => { | ||
const expectation = { disposed: false }; | ||
const references = new reference_1.ReferenceCollection(key => ({ | ||
key, dispose: () => { | ||
} | ||
})); | ||
assert.ok(!references.has('a')); | ||
assert.ok(!expectation.disposed); | ||
references.onWillDispose(e => { | ||
expectation.disposed = true; | ||
}); | ||
}); }); | ||
it('the same object should be provided by an async factory for the same key', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var references, result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
references = new reference_1.ReferenceCollection(function (key) { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, ({ | ||
key: key, | ||
dispose: function () { | ||
} | ||
})]; | ||
}); | ||
}); }); | ||
return [4 /*yield*/, Promise.all(__spreadArray([], __read(Array(10).keys()), false).map(function () { return references.acquire('a'); }))]; | ||
case 1: | ||
result = _a.sent(); | ||
result.forEach(function (v) { return assert.ok(result[0].object === v.object); }); | ||
return [2 /*return*/]; | ||
await references.acquire('a'); | ||
assert.ok(!expectation.disposed); | ||
const reference = await references.acquire('a'); | ||
reference.object.dispose(); | ||
assert.ok(expectation.disposed); | ||
}); | ||
it('the same object should be provided by an async factory for the same key', async () => { | ||
const references = new reference_1.ReferenceCollection(async (key) => ({ | ||
key, dispose: () => { | ||
} | ||
}); | ||
}); }); | ||
it('should not dispose an object if a reference is pending', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var disposed, references, reference, pendingReference; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
disposed = false; | ||
references = new reference_1.ReferenceCollection(function (key) { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, ({ | ||
key: key, | ||
dispose: function () { | ||
disposed = true; | ||
} | ||
})]; | ||
}); | ||
}); }); | ||
assert.ok(!disposed); | ||
return [4 /*yield*/, references.acquire('a')]; | ||
case 1: | ||
reference = _a.sent(); | ||
pendingReference = references.acquire('a'); | ||
reference.dispose(); | ||
assert.ok(!disposed); | ||
return [4 /*yield*/, pendingReference]; | ||
case 2: | ||
reference = _a.sent(); | ||
reference.dispose(); | ||
assert.ok(disposed); | ||
return [2 /*return*/]; | ||
})); | ||
const result = await Promise.all([...Array(10).keys()].map(() => references.acquire('a'))); | ||
result.forEach(v => assert.ok(result[0].object === v.object)); | ||
}); | ||
it('should not dispose an object if a reference is pending', async () => { | ||
let disposed = false; | ||
const references = new reference_1.ReferenceCollection(async (key) => ({ | ||
key, dispose: () => { | ||
disposed = true; | ||
} | ||
}); | ||
}); }); | ||
})); | ||
assert.ok(!disposed); | ||
let reference = await references.acquire('a'); | ||
const pendingReference = references.acquire('a'); | ||
reference.dispose(); | ||
assert.ok(!disposed); | ||
reference = await pendingReference; | ||
reference.dispose(); | ||
assert.ok(disposed); | ||
}); | ||
}); | ||
//# sourceMappingURL=reference.spec.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SizeSchema = exports.TransformSchema = exports.TransformSchemaDecoration = exports.SkewSchemaDecoration = exports.ScaleSchemaDecoration = exports.RotationSchemaDecoration = exports.PositionSchemaDecoration = exports.OriginSchemaDecoration = exports.SizeSchemaDecoration = void 0; | ||
var schema_1 = require("./schema"); | ||
const schema_1 = require("./schema"); | ||
exports.SizeSchemaDecoration = { | ||
@@ -107,3 +107,3 @@ label: '大小', | ||
function mergeDelta(oldTransform, newTransformDelta, toFixedNum) { | ||
var toFixed = toFixedNum !== undefined ? function (v) { return Math.round(v * 100) / 100; } : function (v) { return v; }; | ||
const toFixed = toFixedNum !== undefined ? (v) => Math.round(v * 100) / 100 : (v) => v; | ||
return { | ||
@@ -155,5 +155,5 @@ position: { | ||
return 1; | ||
var wScale = currentSize.width / parentSize.width; | ||
var hScale = currentSize.height / parentSize.height; | ||
var scale = wScale > hScale ? wScale : hScale; | ||
const wScale = currentSize.width / parentSize.width; | ||
const hScale = currentSize.height / parentSize.height; | ||
const scale = wScale > hScale ? wScale : hScale; | ||
return 1 / scale; | ||
@@ -169,5 +169,5 @@ } | ||
function coverSize(currentSize, parentSize) { | ||
var wScale = currentSize.width / parentSize.width; | ||
var hScale = currentSize.height / parentSize.height; | ||
var scale = wScale < hScale ? wScale : hScale; | ||
const wScale = currentSize.width / parentSize.width; | ||
const hScale = currentSize.height / parentSize.height; | ||
const scale = wScale < hScale ? wScale : hScale; | ||
return 1 / scale; | ||
@@ -174,0 +174,0 @@ } |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Schema = exports.SchemaDecoration = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
var objects_1 = require("../objects"); | ||
const objects_1 = require("../objects"); | ||
var SchemaDecoration; | ||
@@ -36,4 +25,4 @@ (function (SchemaDecoration) { | ||
return { | ||
properties: __assign(__assign({}, extend === null || extend === void 0 ? void 0 : extend.properties), properties), | ||
mixinDefaults: __assign(__assign({}, extend === null || extend === void 0 ? void 0 : extend.mixinDefaults), mixinDefaults), | ||
properties: Object.assign(Object.assign({}, extend === null || extend === void 0 ? void 0 : extend.properties), properties), | ||
mixinDefaults: Object.assign(Object.assign({}, extend === null || extend === void 0 ? void 0 : extend.mixinDefaults), mixinDefaults), | ||
type: 'object' | ||
@@ -47,7 +36,7 @@ }; | ||
function createDefault(decoration, mixinDefaults, _key) { | ||
mixinDefaults = __assign(__assign({}, decoration.mixinDefaults), mixinDefaults); | ||
var prefixKey = _key ? _key + '.' : ''; | ||
mixinDefaults = Object.assign(Object.assign({}, decoration.mixinDefaults), mixinDefaults); | ||
const prefixKey = _key ? _key + '.' : ''; | ||
if (decoration.properties) { | ||
return (0, objects_1.mapValues)(decoration.properties, function (v, k) { | ||
var childKey = prefixKey + k; | ||
return (0, objects_1.mapValues)(decoration.properties, (v, k) => { | ||
const childKey = prefixKey + k; | ||
if (mixinDefaults && mixinDefaults[childKey] !== undefined) { | ||
@@ -54,0 +43,0 @@ return mixinDefaults[childKey]; |
"use strict"; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -46,24 +19,13 @@ exports.mnemonicButtonLabel = exports.format = exports.escapeRegExpCharacters = exports.unescapeInvisibleChars = exports.escapeInvisibleChars = exports.split = void 0; | ||
********************************************************************************/ | ||
var os_1 = require("./os"); | ||
function split(s, splitter) { | ||
var start, end; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
start = 0; | ||
_a.label = 1; | ||
case 1: | ||
if (!(start < s.length)) return [3 /*break*/, 3]; | ||
end = s.indexOf(splitter, start); | ||
if (end === -1) { | ||
end = s.length; | ||
} | ||
return [4 /*yield*/, s.substring(start, end)]; | ||
case 2: | ||
_a.sent(); | ||
start = end + splitter.length; | ||
return [3 /*break*/, 1]; | ||
case 3: return [2 /*return*/]; | ||
const os_1 = require("./os"); | ||
function* split(s, splitter) { | ||
let start = 0; | ||
while (start < s.length) { | ||
let end = s.indexOf(splitter, start); | ||
if (end === -1) { | ||
end = s.length; | ||
} | ||
}); | ||
yield s.substring(start, end); | ||
start = end + splitter.length; | ||
} | ||
} | ||
@@ -83,3 +45,3 @@ exports.split = split; | ||
exports.escapeRegExpCharacters = escapeRegExpCharacters; | ||
var formatRegexp = /{(\d+)}/g; | ||
const formatRegexp = /{(\d+)}/g; | ||
/** | ||
@@ -92,12 +54,8 @@ * Helper to produce a string with a variable number of arguments. Insert variable segments | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function format(value) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
function format(value, ...args) { | ||
if (args.length === 0) { | ||
return value; | ||
} | ||
return value.replace(formatRegexp, function (match, group) { | ||
var idx = parseInt(group, 10); | ||
return value.replace(formatRegexp, (match, group) => { | ||
const idx = parseInt(group, 10); | ||
return isNaN(idx) || idx < 0 || idx >= args.length ? | ||
@@ -120,3 +78,3 @@ match : | ||
if (os_1.isWindows) { | ||
return label.replace(/&&|&/g, function (m) { return m === '&' ? '&&' : '&'; }); | ||
return label.replace(/&&|&/g, m => m === '&' ? '&&' : '&'); | ||
} | ||
@@ -123,0 +81,0 @@ return label.replace(/&&/g, '_'); |
@@ -17,38 +17,2 @@ "use strict"; | ||
********************************************************************************/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -58,47 +22,26 @@ exports.Prioritizeable = void 0; | ||
(function (Prioritizeable) { | ||
function toPrioritizeable(rawValue, getPriority) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var value, priority; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (rawValue instanceof Array) { | ||
return [2 /*return*/, Promise.all(rawValue.map(function (v) { return toPrioritizeable(v, getPriority); }))]; | ||
} | ||
return [4 /*yield*/, rawValue]; | ||
case 1: | ||
value = _a.sent(); | ||
return [4 /*yield*/, getPriority(value)]; | ||
case 2: | ||
priority = _a.sent(); | ||
return [2 /*return*/, { priority: priority, value: value }]; | ||
} | ||
}); | ||
}); | ||
async function toPrioritizeable(rawValue, getPriority) { | ||
if (rawValue instanceof Array) { | ||
return Promise.all(rawValue.map(v => toPrioritizeable(v, getPriority))); | ||
} | ||
const value = await rawValue; | ||
const priority = await getPriority(value); | ||
return { priority, value }; | ||
} | ||
Prioritizeable.toPrioritizeable = toPrioritizeable; | ||
function toPrioritizeableSync(rawValue, getPriority) { | ||
return rawValue.map(function (v) { return ({ | ||
return rawValue.map(v => ({ | ||
value: v, | ||
priority: getPriority(v) | ||
}); }); | ||
})); | ||
} | ||
Prioritizeable.toPrioritizeableSync = toPrioritizeableSync; | ||
function prioritizeAllSync(values, getPriority) { | ||
var prioritizeable = toPrioritizeableSync(values, getPriority); | ||
const prioritizeable = toPrioritizeableSync(values, getPriority); | ||
return prioritizeable.filter(isValid).sort(compare); | ||
} | ||
Prioritizeable.prioritizeAllSync = prioritizeAllSync; | ||
function prioritizeAll(values, getPriority) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var prioritizeable; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, toPrioritizeable(values, getPriority)]; | ||
case 1: | ||
prioritizeable = _a.sent(); | ||
return [2 /*return*/, prioritizeable.filter(isValid).sort(compare)]; | ||
} | ||
}); | ||
}); | ||
async function prioritizeAll(values, getPriority) { | ||
const prioritizeable = await toPrioritizeable(values, getPriority); | ||
return prioritizeable.filter(isValid).sort(compare); | ||
} | ||
@@ -105,0 +48,0 @@ Prioritizeable.prioritizeAll = prioritizeAll; |
@@ -17,85 +17,56 @@ "use strict"; | ||
********************************************************************************/ | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var assert = require("assert"); | ||
var types_1 = require("./types"); | ||
describe('types', function () { | ||
describe('recursive-partial', function () { | ||
it('should handle nested arrays', function () { | ||
var myArr = []; | ||
var myFoo = {}; | ||
const assert = require("assert"); | ||
const types_1 = require("./types"); | ||
describe('types', () => { | ||
describe('recursive-partial', () => { | ||
it('should handle nested arrays', () => { | ||
const myArr = []; | ||
const myFoo = {}; | ||
if (myFoo.bar && myFoo.bar.arr) { | ||
var x = Array.from(new Set(myFoo.bar.arr)); | ||
myArr.push.apply(myArr, __spreadArray([], __read(x), false)); | ||
const x = Array.from(new Set(myFoo.bar.arr)); | ||
myArr.push(...x); | ||
} | ||
}); | ||
}); | ||
describe('Prioritizeable', function () { | ||
it('prioritizeAll #01', function () { | ||
var input = [-4, 4, -3, 3, -2, 2, -1, 1, 0, -0]; | ||
return types_1.Prioritizeable.prioritizeAll(input, function (value) { return -value; }) | ||
.then(function (values) { | ||
return assert.deepStrictEqual([ | ||
{ | ||
priority: 4, | ||
value: -4 | ||
}, | ||
{ | ||
priority: 3, | ||
value: -3 | ||
}, { | ||
priority: 2, | ||
value: -2 | ||
}, { | ||
priority: 1, | ||
value: -1 | ||
} | ||
], values); | ||
}); | ||
describe('Prioritizeable', () => { | ||
it('prioritizeAll #01', () => { | ||
const input = [-4, 4, -3, 3, -2, 2, -1, 1, 0, -0]; | ||
return types_1.Prioritizeable.prioritizeAll(input, value => -value) | ||
.then(values => assert.deepStrictEqual([ | ||
{ | ||
priority: 4, | ||
value: -4 | ||
}, | ||
{ | ||
priority: 3, | ||
value: -3 | ||
}, { | ||
priority: 2, | ||
value: -2 | ||
}, { | ||
priority: 1, | ||
value: -1 | ||
} | ||
], values)); | ||
}); | ||
it('prioritizeAll #02', function () { | ||
var input = [-4, 4, -3, 3, -2, 2, -1, 1, 0, -0].map(function (v) { return Promise.resolve(v); }); | ||
return types_1.Prioritizeable.prioritizeAll(input, function (value) { return -value; }) | ||
.then(function (values) { | ||
return assert.deepStrictEqual([ | ||
{ | ||
priority: 4, | ||
value: -4 | ||
}, | ||
{ | ||
priority: 3, | ||
value: -3 | ||
}, { | ||
priority: 2, | ||
value: -2 | ||
}, { | ||
priority: 1, | ||
value: -1 | ||
} | ||
], values); | ||
}); | ||
it('prioritizeAll #02', () => { | ||
const input = [-4, 4, -3, 3, -2, 2, -1, 1, 0, -0].map(v => Promise.resolve(v)); | ||
return types_1.Prioritizeable.prioritizeAll(input, value => -value) | ||
.then(values => assert.deepStrictEqual([ | ||
{ | ||
priority: 4, | ||
value: -4 | ||
}, | ||
{ | ||
priority: 3, | ||
value: -3 | ||
}, { | ||
priority: 2, | ||
value: -2 | ||
}, { | ||
priority: 1, | ||
value: -1 | ||
} | ||
], values)); | ||
}); | ||
@@ -102,0 +73,0 @@ }); |
@@ -17,36 +17,8 @@ "use strict"; | ||
********************************************************************************/ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.URI = void 0; | ||
var vscode_uri_1 = require("vscode-uri"); | ||
var path_1 = require("./path"); | ||
var URI = /** @class */ (function () { | ||
function URI(uri) { | ||
if (uri === void 0) { uri = ''; } | ||
const vscode_uri_1 = require("vscode-uri"); | ||
const path_1 = require("./path"); | ||
class URI { | ||
constructor(uri = '') { | ||
if (uri instanceof vscode_uri_1.URI) { | ||
@@ -59,92 +31,56 @@ this.codeUri = uri; | ||
} | ||
Object.defineProperty(URI.prototype, "path", { | ||
get: function () { | ||
if (this._path === undefined) { | ||
this._path = new path_1.Path(this.codeUri.path); | ||
} | ||
return this._path; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "displayName", { | ||
get: function () { | ||
var base = this.path.base; | ||
if (base) { | ||
return base; | ||
} | ||
if (this.path.isRoot) { | ||
return this.path.toString(); | ||
} | ||
return ''; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "allLocations", { | ||
/** | ||
* Return all uri from the current to the top most. | ||
*/ | ||
get: function () { | ||
var locations = []; | ||
var location = this; | ||
while (!location.path.isRoot && location.path.hasDir) { | ||
locations.push(location); | ||
location = location.parent; | ||
} | ||
get path() { | ||
if (this._path === undefined) { | ||
this._path = new path_1.Path(this.codeUri.path); | ||
} | ||
return this._path; | ||
} | ||
get displayName() { | ||
const base = this.path.base; | ||
if (base) { | ||
return base; | ||
} | ||
if (this.path.isRoot) { | ||
return this.path.toString(); | ||
} | ||
return ''; | ||
} | ||
/** | ||
* Return all uri from the current to the top most. | ||
*/ | ||
get allLocations() { | ||
const locations = []; | ||
let location = this; | ||
while (!location.path.isRoot && location.path.hasDir) { | ||
locations.push(location); | ||
return locations; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "parent", { | ||
get: function () { | ||
if (this.path.isRoot) { | ||
return this; | ||
} | ||
return this.withPath(this.path.dir); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "scheme", { | ||
get: function () { | ||
return this.codeUri.scheme; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "authority", { | ||
get: function () { | ||
return this.codeUri.authority; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "query", { | ||
get: function () { | ||
return this.codeUri.query; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "fragment", { | ||
get: function () { | ||
return this.codeUri.fragment; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(URI.prototype, "queryObject", { | ||
get: function () { | ||
return URI.queryStringToObject(this.query); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
URI.getDistinctParents = function (uris) { | ||
var result = []; | ||
uris.forEach(function (uri, i) { | ||
if (!uris.some(function (otherUri, index) { return index !== i && otherUri.isEqualOrParent(uri); })) { | ||
location = location.parent; | ||
} | ||
locations.push(location); | ||
return locations; | ||
} | ||
get parent() { | ||
if (this.path.isRoot) { | ||
return this; | ||
} | ||
return this.withPath(this.path.dir); | ||
} | ||
get scheme() { | ||
return this.codeUri.scheme; | ||
} | ||
get authority() { | ||
return this.codeUri.authority; | ||
} | ||
get query() { | ||
return this.codeUri.query; | ||
} | ||
get fragment() { | ||
return this.codeUri.fragment; | ||
} | ||
get queryObject() { | ||
return URI.queryStringToObject(this.query); | ||
} | ||
static getDistinctParents(uris) { | ||
const result = []; | ||
uris.forEach((uri, i) => { | ||
if (!uris.some((otherUri, index) => index !== i && otherUri.isEqualOrParent(uri))) { | ||
result.push(uri); | ||
@@ -154,4 +90,4 @@ } | ||
return result; | ||
}; | ||
URI.prototype.relative = function (uri) { | ||
} | ||
relative(uri) { | ||
if (this.authority !== uri.authority || this.scheme !== uri.scheme) { | ||
@@ -161,52 +97,52 @@ return undefined; | ||
return this.path.relative(uri.path); | ||
}; | ||
URI.prototype.resolve = function (path) { | ||
} | ||
resolve(path) { | ||
return this.withPath(this.path.join(path.toString())); | ||
}; | ||
} | ||
/** | ||
* return a new URI replacing the current with the given scheme | ||
*/ | ||
URI.prototype.withScheme = function (scheme) { | ||
var newCodeUri = vscode_uri_1.URI.from(__assign(__assign({}, this.codeUri.toJSON()), { scheme: scheme })); | ||
withScheme(scheme) { | ||
const newCodeUri = vscode_uri_1.URI.from(Object.assign(Object.assign({}, this.codeUri.toJSON()), { scheme })); | ||
return new URI(newCodeUri); | ||
}; | ||
} | ||
/** | ||
* return a new URI replacing the current with the given authority | ||
*/ | ||
URI.prototype.withAuthority = function (authority) { | ||
var newCodeUri = vscode_uri_1.URI.from(__assign(__assign({}, this.codeUri.toJSON()), { scheme: this.codeUri.scheme, authority: authority })); | ||
withAuthority(authority) { | ||
const newCodeUri = vscode_uri_1.URI.from(Object.assign(Object.assign({}, this.codeUri.toJSON()), { scheme: this.codeUri.scheme, authority })); | ||
return new URI(newCodeUri); | ||
}; | ||
} | ||
/** | ||
* return this URI without a authority | ||
*/ | ||
URI.prototype.withoutAuthority = function () { | ||
withoutAuthority() { | ||
return this.withAuthority(''); | ||
}; | ||
} | ||
/** | ||
* return a new URI replacing the current with the given path | ||
*/ | ||
URI.prototype.withPath = function (path) { | ||
var newCodeUri = vscode_uri_1.URI.from(__assign(__assign({}, this.codeUri.toJSON()), { scheme: this.codeUri.scheme, path: path.toString() })); | ||
withPath(path) { | ||
const newCodeUri = vscode_uri_1.URI.from(Object.assign(Object.assign({}, this.codeUri.toJSON()), { scheme: this.codeUri.scheme, path: path.toString() })); | ||
return new URI(newCodeUri); | ||
}; | ||
} | ||
/** | ||
* return this URI without a path | ||
*/ | ||
URI.prototype.withoutPath = function () { | ||
withoutPath() { | ||
return this.withPath(''); | ||
}; | ||
} | ||
/** | ||
* return a new URI replacing the current with the given query | ||
*/ | ||
URI.prototype.withQuery = function (query) { | ||
var newCodeUri = vscode_uri_1.URI.from(__assign(__assign({}, this.codeUri.toJSON()), { scheme: this.codeUri.scheme, query: query })); | ||
withQuery(query) { | ||
const newCodeUri = vscode_uri_1.URI.from(Object.assign(Object.assign({}, this.codeUri.toJSON()), { scheme: this.codeUri.scheme, query })); | ||
return new URI(newCodeUri); | ||
}; | ||
URI.prototype.addQueryObject = function (queryObj) { | ||
queryObj = __assign(__assign({}, this.queryObject), queryObj); | ||
} | ||
addQueryObject(queryObj) { | ||
queryObj = Object.assign(Object.assign({}, this.queryObject), queryObj); | ||
return this.withQuery(URI.objectToQueryString(queryObj)); | ||
}; | ||
URI.prototype.removeQueryObject = function (key) { | ||
var queryObj = __assign({}, this.queryObject); | ||
} | ||
removeQueryObject(key) { | ||
const queryObj = Object.assign({}, this.queryObject); | ||
if (key in queryObj) { | ||
@@ -216,36 +152,35 @@ delete queryObj[key]; | ||
return this.withQuery(URI.objectToQueryString(queryObj)); | ||
}; | ||
} | ||
/** | ||
* return this URI without a query | ||
*/ | ||
URI.prototype.withoutQuery = function () { | ||
withoutQuery() { | ||
return this.withQuery(''); | ||
}; | ||
} | ||
/** | ||
* return a new URI replacing the current with the given fragment | ||
*/ | ||
URI.prototype.withFragment = function (fragment) { | ||
var newCodeUri = vscode_uri_1.URI.from(__assign(__assign({}, this.codeUri.toJSON()), { scheme: this.codeUri.scheme, fragment: fragment })); | ||
withFragment(fragment) { | ||
const newCodeUri = vscode_uri_1.URI.from(Object.assign(Object.assign({}, this.codeUri.toJSON()), { scheme: this.codeUri.scheme, fragment })); | ||
return new URI(newCodeUri); | ||
}; | ||
} | ||
/** | ||
* return this URI without a fragment | ||
*/ | ||
URI.prototype.withoutFragment = function () { | ||
withoutFragment() { | ||
return this.withFragment(''); | ||
}; | ||
} | ||
/** | ||
* return a new URI replacing the current with its normalized path, resolving '..' and '.' segments | ||
*/ | ||
URI.prototype.normalizePath = function () { | ||
normalizePath() { | ||
return this.withPath(this.path.normalize()); | ||
}; | ||
URI.prototype.toString = function (skipEncoding) { | ||
} | ||
toString(skipEncoding) { | ||
return this.codeUri.toString(skipEncoding); | ||
}; | ||
URI.prototype.isEqualOrParent = function (uri) { | ||
} | ||
isEqualOrParent(uri) { | ||
return this.authority === uri.authority && this.scheme === uri.scheme && this.path.isEqualOrParent(uri.path); | ||
}; | ||
return URI; | ||
}()); | ||
} | ||
} | ||
exports.URI = URI; | ||
@@ -256,8 +191,8 @@ (function (URI) { | ||
return ''; | ||
return Object.keys(obj).map(function (key) { return "".concat(key, "=").concat(obj[key] || ''); }).join('&'); | ||
return Object.keys(obj).map(key => `${key}=${obj[key] || ''}`).join('&'); | ||
} | ||
URI.objectToQueryString = objectToQueryString; | ||
function queryStringToObject(queryString) { | ||
return queryString.split('&').reduce(function (obj, key) { | ||
var _a = __read(key.split('='), 2), k = _a[0], value = _a[1]; | ||
return queryString.split('&').reduce((obj, key) => { | ||
const [k, value] = key.split('='); | ||
obj[k] = value; | ||
@@ -270,3 +205,2 @@ return obj; | ||
})(URI = exports.URI || (exports.URI = {})); | ||
exports.URI = URI; | ||
//# sourceMappingURL=uri.js.map |
@@ -18,9 +18,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chai = require("chai"); | ||
var uri_1 = require("./uri"); | ||
var expect = chai.expect; | ||
describe('uri', function () { | ||
describe('#getAllLocations', function () { | ||
it('of /foo/bar/file.txt', function () { | ||
expect(new uri_1.URI('/foo/bar/file.txt').allLocations.map(function (x) { return x.toString(); })) | ||
const chai = require("chai"); | ||
const uri_1 = require("./uri"); | ||
const expect = chai.expect; | ||
describe('uri', () => { | ||
describe('#getAllLocations', () => { | ||
it('of /foo/bar/file.txt', () => { | ||
expect(new uri_1.URI('/foo/bar/file.txt').allLocations.map(x => x.toString())) | ||
.deep.equals([ | ||
@@ -33,4 +33,4 @@ new uri_1.URI('/foo/bar/file.txt').toString(), | ||
}); | ||
it('of foo', function () { | ||
expect(new uri_1.URI('foo').allLocations.map(function (x) { return x.toString(); })) | ||
it('of foo', () => { | ||
expect(new uri_1.URI('foo').allLocations.map(x => x.toString())) | ||
.deep.equals([ | ||
@@ -41,4 +41,4 @@ new uri_1.URI('foo').toString(), | ||
}); | ||
it('of foo:bar.txt', function () { | ||
expect(new uri_1.URI().withScheme('foo').withPath('bar.txt').allLocations.map(function (x) { return x.toString(); })) | ||
it('of foo:bar.txt', () => { | ||
expect(new uri_1.URI().withScheme('foo').withPath('bar.txt').allLocations.map(x => x.toString())) | ||
.deep.equals([ | ||
@@ -48,4 +48,4 @@ 'foo:bar.txt' | ||
}); | ||
it('of foo:bar/foobar.txt', function () { | ||
expect(new uri_1.URI().withScheme('foo').withPath('bar/foobar.txt').allLocations.map(function (x) { return x.toString(); })) | ||
it('of foo:bar/foobar.txt', () => { | ||
expect(new uri_1.URI().withScheme('foo').withPath('bar/foobar.txt').allLocations.map(x => x.toString())) | ||
.deep.equals([ | ||
@@ -57,74 +57,74 @@ new uri_1.URI().withScheme('foo').withPath('bar/foobar.txt').toString(), | ||
}); | ||
describe('#getParent', function () { | ||
it('of file:///foo/bar.txt', function () { | ||
describe('#getParent', () => { | ||
it('of file:///foo/bar.txt', () => { | ||
expect(new uri_1.URI('file:///foo/bar.txt').parent.toString()).equals('file:///foo'); | ||
}); | ||
it('of file:///foo/', function () { | ||
it('of file:///foo/', () => { | ||
expect(new uri_1.URI('file:///foo/').parent.toString()).equals('file:///foo'); | ||
}); | ||
it('of file:///foo', function () { | ||
it('of file:///foo', () => { | ||
expect(new uri_1.URI('file:///foo').parent.toString()).equals('file:///'); | ||
}); | ||
it('of file:///', function () { | ||
it('of file:///', () => { | ||
expect(new uri_1.URI('file:///').parent.toString()).equals('file:///'); | ||
}); | ||
it('of file://', function () { | ||
it('of file://', () => { | ||
expect(new uri_1.URI('file://').parent.toString()).equals('file:///'); | ||
}); | ||
}); | ||
describe('#lastSegment', function () { | ||
it('of file:///foo/bar.txt', function () { | ||
describe('#lastSegment', () => { | ||
it('of file:///foo/bar.txt', () => { | ||
expect(new uri_1.URI('file:///foo/bar.txt').path.base).equals('bar.txt'); | ||
}); | ||
it('of file:///foo', function () { | ||
it('of file:///foo', () => { | ||
expect(new uri_1.URI('file:///foo').path.base).equals('foo'); | ||
}); | ||
it('of file:///', function () { | ||
it('of file:///', () => { | ||
expect(new uri_1.URI('file:///').path.base).equals(''); | ||
}); | ||
it('of file://', function () { | ||
it('of file://', () => { | ||
expect(new uri_1.URI('file://').path.base).equals(''); | ||
}); | ||
}); | ||
describe('#appendPath', function () { | ||
it("'' to file:///foo", function () { | ||
var uri = new uri_1.URI('file:///foo'); | ||
describe('#appendPath', () => { | ||
it("'' to file:///foo", () => { | ||
const uri = new uri_1.URI('file:///foo'); | ||
expect(uri.resolve('').toString()).to.be.equal(uri.toString()); | ||
}); | ||
it('bar to file:///foo', function () { | ||
it('bar to file:///foo', () => { | ||
expect(new uri_1.URI('file:///foo').resolve('bar').toString()).to.be.equal('file:///foo/bar'); | ||
}); | ||
it('bar/baz to file:///foo', function () { | ||
it('bar/baz to file:///foo', () => { | ||
expect(new uri_1.URI('file:///foo').resolve('bar/baz').toString()).to.be.equal('file:///foo/bar/baz'); | ||
}); | ||
it("'' to file:///", function () { | ||
var uri = new uri_1.URI('file:///'); | ||
it("'' to file:///", () => { | ||
const uri = new uri_1.URI('file:///'); | ||
expect(uri.resolve('').toString()).to.be.equal(uri.toString()); | ||
}); | ||
it('bar to file:///', function () { | ||
it('bar to file:///', () => { | ||
expect(new uri_1.URI('file:///').resolve('bar').toString()).to.be.equal('file:///bar'); | ||
}); | ||
it('bar/baz to file:///', function () { | ||
it('bar/baz to file:///', () => { | ||
expect(new uri_1.URI('file:///').resolve('bar/baz').toString()).to.be.equal('file:///bar/baz'); | ||
}); | ||
}); | ||
describe('#path', function () { | ||
it('Should return with the FS path from the URI.', function () { | ||
describe('#path', () => { | ||
it('Should return with the FS path from the URI.', () => { | ||
expect(new uri_1.URI('file:///foo/bar/baz.txt').path.toString()).equals('/foo/bar/baz.txt'); | ||
}); | ||
it('Should not return the encoded path', function () { | ||
it('Should not return the encoded path', () => { | ||
expect(new uri_1.URI('file:///foo 3/bar 4/baz 4.txt').path.toString()).equals('/foo 3/bar 4/baz 4.txt'); | ||
}); | ||
}); | ||
describe('#withFragment', function () { | ||
it('Should replace the fragment.', function () { | ||
describe('#withFragment', () => { | ||
it('Should replace the fragment.', () => { | ||
expect(new uri_1.URI('file:///foo/bar/baz.txt#345345').withFragment('foo').toString()).equals('file:///foo/bar/baz.txt#foo'); | ||
expect(new uri_1.URI('file:///foo/bar/baz.txt?foo=2#345345').withFragment('foo').toString(true)).equals('file:///foo/bar/baz.txt?foo=2#foo'); | ||
}); | ||
it('Should remove the fragment.', function () { | ||
it('Should remove the fragment.', () => { | ||
expect(new uri_1.URI('file:///foo/bar/baz.txt#345345').withFragment('').toString()).equals('file:///foo/bar/baz.txt'); | ||
}); | ||
}); | ||
describe('#toString()', function () { | ||
it('should produce the non encoded string', function () { | ||
describe('#toString()', () => { | ||
it('should produce the non encoded string', () => { | ||
function check(uri) { | ||
@@ -138,5 +138,5 @@ expect(new uri_1.URI(uri).toString(true)).equals(uri); | ||
}); | ||
describe('#Uri.with...()', function () { | ||
it('produce proper URIs', function () { | ||
var uri = new uri_1.URI('').withScheme('file').withPath('/foo/bar.txt').withQuery('x=12').withFragment('baz'); | ||
describe('#Uri.with...()', () => { | ||
it('produce proper URIs', () => { | ||
const uri = new uri_1.URI('').withScheme('file').withPath('/foo/bar.txt').withQuery('x=12').withFragment('baz'); | ||
expect(uri.toString(true)).equals('file:///foo/bar.txt?x=12#baz'); | ||
@@ -149,6 +149,6 @@ expect(uri.withScheme('http').toString(true)).equals('http:/foo/bar.txt?x=12#baz'); | ||
}); | ||
describe('#relative()', function () { | ||
it('drive letters should be in lowercase', function () { | ||
var uri = new uri_1.URI('file:///C:/projects/theia'); | ||
var path = uri.relative(new uri_1.URI(uri.resolve('node_modules/typescript/lib').toString())); | ||
describe('#relative()', () => { | ||
it('drive letters should be in lowercase', () => { | ||
const uri = new uri_1.URI('file:///C:/projects/theia'); | ||
const path = uri.relative(new uri_1.URI(uri.resolve('node_modules/typescript/lib').toString())); | ||
expect(String(path)).equals('node_modules/typescript/lib'); | ||
@@ -155,0 +155,0 @@ }); |
@@ -9,3 +9,3 @@ "use strict"; | ||
require("./polyfill"); | ||
var _UUIDPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; | ||
const _UUIDPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; | ||
function isUUID(value) { | ||
@@ -16,5 +16,5 @@ return _UUIDPattern.test(value); | ||
// prep-work | ||
var _data = new Uint8Array(16); | ||
var _hex = []; | ||
for (var i = 0; i < 256; i++) { | ||
const _data = new Uint8Array(16); | ||
const _hex = []; | ||
for (let i = 0; i < 256; i++) { | ||
_hex.push(i.toString(16).padStart(2, '0')); | ||
@@ -24,4 +24,4 @@ } | ||
// todo@joh use browser-crypto | ||
var _fillRandomValues = function (bucket) { | ||
for (var i = 0; i < bucket.length; i++) { | ||
const _fillRandomValues = function (bucket) { | ||
for (let i = 0; i < bucket.length; i++) { | ||
bucket[i] = Math.floor(Math.random() * 256); | ||
@@ -38,4 +38,4 @@ } | ||
// print as string | ||
var i = 0; | ||
var result = ''; | ||
let i = 0; | ||
let result = ''; | ||
result += _hex[_data[i++]]; | ||
@@ -42,0 +42,0 @@ result += _hex[_data[i++]]; |
@@ -26,112 +26,81 @@ "use strict"; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
var inversify_1 = require("inversify"); | ||
var MockLogger = /** @class */ (function () { | ||
function MockLogger() { | ||
const inversify_1 = require("inversify"); | ||
let MockLogger = class MockLogger { | ||
setLogLevel(logLevel) { | ||
return Promise.resolve(); | ||
} | ||
MockLogger.prototype.setLogLevel = function (logLevel) { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.getLogLevel = function () { | ||
getLogLevel() { | ||
return Promise.resolve(0); | ||
}; | ||
MockLogger.prototype.isEnabled = function (logLevel) { | ||
} | ||
isEnabled(logLevel) { | ||
return Promise.resolve(true); | ||
}; | ||
MockLogger.prototype.ifEnabled = function (logLevel) { | ||
} | ||
ifEnabled(logLevel) { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.log = function (logLevel, arg2) { | ||
var params = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
params[_i - 2] = arguments[_i]; | ||
} | ||
} | ||
log(logLevel, arg2, ...params) { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.isTrace = function () { | ||
} | ||
isTrace() { | ||
return Promise.resolve(true); | ||
}; | ||
MockLogger.prototype.ifTrace = function () { | ||
} | ||
ifTrace() { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.trace = function (arg) { | ||
var params = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
params[_i - 1] = arguments[_i]; | ||
} | ||
} | ||
trace(arg, ...params) { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.isDebug = function () { | ||
} | ||
isDebug() { | ||
return Promise.resolve(true); | ||
}; | ||
MockLogger.prototype.ifDebug = function () { | ||
} | ||
ifDebug() { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.debug = function (arg) { | ||
var params = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
params[_i - 1] = arguments[_i]; | ||
} | ||
} | ||
debug(arg, ...params) { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.isInfo = function () { | ||
} | ||
isInfo() { | ||
return Promise.resolve(true); | ||
}; | ||
MockLogger.prototype.ifInfo = function () { | ||
} | ||
ifInfo() { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.info = function (arg) { | ||
var params = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
params[_i - 1] = arguments[_i]; | ||
} | ||
} | ||
info(arg, ...params) { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.isWarn = function () { | ||
} | ||
isWarn() { | ||
return Promise.resolve(true); | ||
}; | ||
MockLogger.prototype.ifWarn = function () { | ||
} | ||
ifWarn() { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.warn = function (arg) { | ||
var params = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
params[_i - 1] = arguments[_i]; | ||
} | ||
} | ||
warn(arg, ...params) { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.isError = function () { | ||
} | ||
isError() { | ||
return Promise.resolve(true); | ||
}; | ||
MockLogger.prototype.ifError = function () { | ||
} | ||
ifError() { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.error = function (arg) { | ||
var params = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
params[_i - 1] = arguments[_i]; | ||
} | ||
} | ||
error(arg, ...params) { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.isFatal = function () { | ||
} | ||
isFatal() { | ||
return Promise.resolve(true); | ||
}; | ||
MockLogger.prototype.ifFatal = function () { | ||
} | ||
ifFatal() { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.fatal = function (arg) { | ||
var params = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
params[_i - 1] = arguments[_i]; | ||
} | ||
} | ||
fatal(arg, ...params) { | ||
return Promise.resolve(); | ||
}; | ||
MockLogger.prototype.child = function (obj) { | ||
} | ||
child(obj) { | ||
return this; | ||
}; | ||
MockLogger = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], MockLogger); | ||
return MockLogger; | ||
}()); | ||
} | ||
}; | ||
MockLogger = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], MockLogger); | ||
exports.MockLogger = MockLogger; | ||
//# sourceMappingURL=mock-logger.js.map |
{ | ||
"name": "@gedit/utils", | ||
"version": "0.1.69", | ||
"version": "0.1.70", | ||
"license": "MIT", | ||
@@ -15,3 +15,3 @@ "main": "lib/common/index", | ||
"clsx": "^1.1.1", | ||
"inversify": "^5.0.1", | ||
"inversify": "^5.1.0", | ||
"is-electron": "^2.1.0", | ||
@@ -33,3 +33,3 @@ "lodash.clonedeep": "^4.5.0", | ||
}, | ||
"gitHead": "1bb1a2c9de07b987e6e1c15053e7278766cbe23c" | ||
"gitHead": "8bdf36b3a3898da871ec15be92760865fc6a182a" | ||
} |
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
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
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
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
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
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
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
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
499837
9501
Updatedinversify@^5.1.0