Skip to content

Commit

Permalink
Merge pull request #30 from Microsoft/updateAsyncGeneratorHelpers
Browse files Browse the repository at this point in the history
Update async generator helpers
  • Loading branch information
rbuckton authored May 4, 2017
2 parents b687af3 + 13a29ac commit 0cadbd0
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 32 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,31 @@ For the latest stable version:
## npm

```sh
# TypeScript 2.3.3 or later
npm install tslib

# TypeScript 2.3.2 or earlier
npm install tslib@1.6.1
```

## bower

```sh
# TypeScript 2.3.3 or later
bower install tslib

# TypeScript 2.3.2 or earlier
bower install tslib@1.6.1
```

## JSPM

```sh
# TypeScript 2.3.3 or later
jspm install npm:tslib

# TypeScript 2.3.2 or earlier
jspm install npm:tslib@1.6.1
```

# Usage
Expand Down Expand Up @@ -68,7 +80,7 @@ For JSPM users:
"importHelpers": true,
"baseUrl": "./",
"paths": {
"tslib" : ["jspm_packages/npm/tslib@1.6.1/tslib.d.ts"]
"tslib" : ["jspm_packages/npm/tslib@1.7.0/tslib.d.ts"]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Microsoft Corp."
],
"homepage": "http://typescriptlang.org/",
"version": "1.6.0",
"version": "1.7.0",
"license": "Apache-2.0",
"description": "Runtime library for TypeScript helper functions",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tslib",
"author": "Microsoft Corp.",
"homepage": "http://typescriptlang.org/",
"version": "1.6.1",
"version": "1.7.0",
"license": "Apache-2.0",
"description": "Runtime library for TypeScript helper functions",
"keywords": [
Expand Down
1 change: 1 addition & 0 deletions tslib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export declare function __exportStar(m: any, exports: any): void;
export declare function __values(o: any): any;
export declare function __read(o: any, n?: number): any[];
export declare function __spread(...args: any[]): any[];
export declare function __await(v: any): any;
export declare function __asyncGenerator(thisArg: any, _arguments: any, generator: Function): any;
export declare function __asyncDelegator(o: any): any;
export declare function __asyncValues(o: any): any;
38 changes: 20 additions & 18 deletions tslib.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export var __assign = Object.assign || function __assign(t) {
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
}

export function __rest(s, e) {
var t = {};
Expand Down Expand Up @@ -107,7 +107,7 @@ export function __values(o) {
return { value: o && o[i++], done: !o };
}
};
};
}

export function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
Expand All @@ -124,36 +124,38 @@ export function __read(o, n) {
finally { if (e) throw e.error; }
}
return ar;
};
}

export function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
};
}

export function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}

export function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), q = [], c, i;
return i = { next: verb("next"), "throw": verb("throw"), "return": verb("return") }, i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { return function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]), next(); }); }; }
function next() { if (!c && q.length) resume((c = q.shift())[0], c[1]); }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(c[3], e); } }
function step(r) { r.done ? settle(c[2], r) : Promise.resolve(r.value[1]).then(r.value[0] === "yield" ? send : fulfill, reject); }
function send(value) { settle(c[2], { value: value, done: false }); }
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { c = void 0, f(v), next(); }
};
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}

export function __asyncDelegator(o) {
var i = { next: verb("next"), "throw": verb("throw", function (e) { throw e; }), "return": verb("return", function (v) { return { value: v, done: true }; }) }, p;
return o = __asyncValues(o), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { return function (v) { return v = p && n === "throw" ? f(v) : p && v.done ? v : { value: p ? ["yield", v.value] : ["await", (o[n] || f).call(o, v)], done: false }, p = !p, v; }; }
};
var i, p;
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n) { if (o[n]) i[n] = function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : v; }; }
}

export function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator];
return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator]();
};
}
26 changes: 15 additions & 11 deletions tslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var __exportStar;
var __values;
var __read;
var __spread;
var __await;
var __asyncGenerator;
var __asyncDelegator;
var __asyncValues;
Expand Down Expand Up @@ -162,24 +163,26 @@ var __asyncValues;
return ar;
};

__await = function (v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
};

__asyncGenerator = function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), q = [], c, i;
return i = { next: verb("next"), "throw": verb("throw"), "return": verb("return") }, i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { return function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]), next(); }); }; }
function next() { if (!c && q.length) resume((c = q.shift())[0], c[1]); }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(c[3], e); } }
function step(r) { r.done ? settle(c[2], r) : Promise.resolve(r.value[1]).then(r.value[0] === "yield" ? send : fulfill, reject); }
function send(value) { settle(c[2], { value: value, done: false }); }
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { c = void 0, f(v), next(); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};

__asyncDelegator = function (o) {
var i = { next: verb("next"), "throw": verb("throw", function (e) { throw e; }), "return": verb("return", function (v) { return { value: v, done: true }; }) }, p;
return o = __asyncValues(o), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { return function (v) { return v = p && n === "throw" ? f(v) : p && v.done ? v : { value: p ? ["yield", v.value] : ["await", (o[n] || f).call(o, v)], done: false }, p = !p, v; }; }
var i, p;
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n) { if (o[n]) i[n] = function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : v; }; }
};

__asyncValues = function (o) {
Expand All @@ -200,6 +203,7 @@ var __asyncValues;
exporter("__values", __values);
exporter("__read", __read);
exporter("__spread", __spread);
exporter("__await", __await);
exporter("__asyncGenerator", __asyncGenerator);
exporter("__asyncDelegator", __asyncDelegator);
exporter("__asyncValues", __asyncValues);
Expand Down

0 comments on commit 0cadbd0

Please sign in to comment.