Comparing version 2.5.3 to 2.6.0
@@ -34,3 +34,5 @@ // Note: named reexports are used instead of `export *` because | ||
__createBinding, | ||
__addDisposableResource, | ||
__disposeResources, | ||
} from '../tslib.js'; | ||
export * as default from '../tslib.js'; |
@@ -32,2 +32,4 @@ import tslib from '../tslib.js'; | ||
__classPrivateFieldIn, | ||
__addDisposableResource, | ||
__disposeResources, | ||
} = tslib; | ||
@@ -64,3 +66,5 @@ export { | ||
__classPrivateFieldIn, | ||
__addDisposableResource, | ||
__disposeResources, | ||
}; | ||
export default tslib; |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://www.typescriptlang.org/", | ||
"version": "2.5.3", | ||
"version": "2.6.0", | ||
"license": "0BSD", | ||
@@ -8,0 +8,0 @@ "description": "Runtime library for TypeScript helper functions", |
@@ -431,1 +431,24 @@ /****************************************************************************** | ||
export declare function __createBinding(object: object, target: object, key: PropertyKey, objectKey?: PropertyKey): void; | ||
/** | ||
* Adds a disposable resource to a resource-tracking environment object. | ||
* @param env A resource-tracking environment object. | ||
* @param value Either a Disposable or AsyncDisposable object, `null`, or `undefined`. | ||
* @param async When `true`, `AsyncDisposable` resources can be added. When `false`, `AsyncDisposable` resources cannot be added. | ||
* @returns The {@link value} argument. | ||
* | ||
* @throws {TypeError} If {@link value} is not an object, or if either `Symbol.dispose` or `Symbol.asyncDispose` are not | ||
* defined, or if {@link value} does not have an appropriate `Symbol.dispose` or `Symbol.asyncDispose` method. | ||
*/ | ||
export declare function __addDisposableResource<T>(env: { stack: { value?: unknown, dispose?: Function, async: boolean }[]; error: unknown; hasError: boolean; }, value: T, async: boolean): T; | ||
/** | ||
* Disposes all resources in a resource-tracking environment object. | ||
* @param env A resource-tracking environment object. | ||
* @returns A {@link Promise} if any resources in the environment were marked as `async` when added; otherwise, `void`. | ||
* | ||
* @throws {SuppressedError} if an error thrown during disposal would have suppressed a prior error from disposal or the | ||
* error recorded in the resource-tracking environment object. | ||
* @seealso {@link __addDisposableResource} | ||
*/ | ||
export declare function __disposeResources(env: { stack: { value?: unknown, dispose?: Function, async: boolean }[]; error: unknown; hasError: boolean; }): any; |
@@ -15,3 +15,3 @@ /****************************************************************************** | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
/* global Reflect, Promise, SuppressedError, Symbol */ | ||
@@ -296,2 +296,49 @@ var extendStatics = function(d, b) { | ||
export function __addDisposableResource(env, value, async) { | ||
if (value !== null && value !== void 0) { | ||
if (typeof value !== "object") throw new TypeError("Object expected."); | ||
var dispose; | ||
if (async) { | ||
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); | ||
dispose = value[Symbol.asyncDispose]; | ||
} | ||
if (dispose === void 0) { | ||
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); | ||
dispose = value[Symbol.dispose]; | ||
} | ||
if (typeof dispose !== "function") throw new TypeError("Object not disposable."); | ||
env.stack.push({ value: value, dispose: dispose, async: async }); | ||
} | ||
else if (async) { | ||
env.stack.push({ async: true }); | ||
} | ||
return value; | ||
} | ||
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { | ||
var e = new Error(message); | ||
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; | ||
}; | ||
export function __disposeResources(env) { | ||
function fail(e) { | ||
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; | ||
env.hasError = true; | ||
} | ||
function next() { | ||
while (env.stack.length) { | ||
var rec = env.stack.pop(); | ||
try { | ||
var result = rec.dispose && rec.dispose.call(rec.value); | ||
if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); | ||
} | ||
catch (e) { | ||
fail(e); | ||
} | ||
} | ||
if (env.hasError) throw env.error; | ||
} | ||
return next(); | ||
} | ||
export default { | ||
@@ -323,2 +370,4 @@ __extends, | ||
__classPrivateFieldIn, | ||
__addDisposableResource, | ||
__disposeResources, | ||
}; |
53
tslib.js
@@ -15,3 +15,3 @@ /****************************************************************************** | ||
***************************************************************************** */ | ||
/* global global, define, System, Reflect, Promise */ | ||
/* global global, define, Symbol, Reflect, Promise, SuppressedError */ | ||
var __extends; | ||
@@ -46,2 +46,4 @@ var __assign; | ||
var __createBinding; | ||
var __addDisposableResource; | ||
var __disposeResources; | ||
(function (factory) { | ||
@@ -343,2 +345,49 @@ var root = typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : {}; | ||
__addDisposableResource = function (env, value, async) { | ||
if (value !== null && value !== void 0) { | ||
if (typeof value !== "object") throw new TypeError("Object expected."); | ||
var dispose; | ||
if (async) { | ||
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); | ||
dispose = value[Symbol.asyncDispose]; | ||
} | ||
if (dispose === void 0) { | ||
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); | ||
dispose = value[Symbol.dispose]; | ||
} | ||
if (typeof dispose !== "function") throw new TypeError("Object not disposable."); | ||
env.stack.push({ value: value, dispose: dispose, async: async }); | ||
} | ||
else if (async) { | ||
env.stack.push({ async: true }); | ||
} | ||
return value; | ||
}; | ||
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { | ||
var e = new Error(message); | ||
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; | ||
}; | ||
__disposeResources = function (env) { | ||
function fail(e) { | ||
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; | ||
env.hasError = true; | ||
} | ||
function next() { | ||
while (env.stack.length) { | ||
var rec = env.stack.pop(); | ||
try { | ||
var result = rec.dispose && rec.dispose.call(rec.value); | ||
if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); | ||
} | ||
catch (e) { | ||
fail(e); | ||
} | ||
} | ||
if (env.hasError) throw env.error; | ||
} | ||
return next(); | ||
}; | ||
exporter("__extends", __extends); | ||
@@ -373,2 +422,4 @@ exporter("__assign", __assign); | ||
exporter("__classPrivateFieldIn", __classPrivateFieldIn); | ||
exporter("__addDisposableResource", __addDisposableResource); | ||
exporter("__disposeResources", __disposeResources); | ||
}); |
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
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
83488
1568