-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: nightly (2.3.0-dev.20170314)
The use of yield* emits __asyncDelegator(), and the __asyncDelegator() calls __asyncValues() but __asyncValues() isn't emitted unless you use for-await-of in the same file.
Code
require("./polyfill.min.js");
export async function* useYield():AsyncIterable<string> {
yield* ["hello","world"]
};which emits:
"use strict";
var __asyncDelegator = (this && this.__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 }; }) };
// ####
// #### uses __asyncValues, which doesn't get emitted unless you do a for-await-of
// ####
return o = __asyncValues(o), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { return function (v) { return { value: ["delegate", (o[n] || f).call(o, v)], done: false }; }; }
};
var __asyncGenerator = (this && this.__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) : r.value[0] === "yield" ? settle(c[2], { value: r.value[1], done: false }) : Promise.resolve(r.value[1]).then(r.value[0] === "delegate" ? delegate : fulfill, reject); }
function delegate(r) { step(r.done ? r : { value: ["yield", r.value], done: false }); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { c = void 0, f(v), next(); }
};
Object.defineProperty(exports, "__esModule", { value: true });
require("./polyfill.min.js");
function yieldFromMap() {
return __asyncGenerator(this, arguments, function* yieldFromMap_1() {
//let m = new Map<string,string>([['name1', 'value1'], ['name2', 'value2']]);
yield* __asyncDelegator(["hello", "world"]);
});
}
exports.yieldFromMap = yieldFromMap;
;
//# sourceMappingURL=test-async.js.mapExpected behavior:
When __asyncDelegator() is emitted, emit the __asyncValues() implementation too.
Actual behavior:
Doesn't emit __asyncValues() and __asyncDelegator() will fail when called.
** My Guess **
I figure this has to be fixed somewhere around here:
https://github.com/Microsoft/TypeScript/blob/master/src/compiler/transformers/esnext.ts#L923
But I'm not familiar enough with what's going on to write a proper fix and test. Sorry 😞
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue