Skip to content

Conversation

@rbuckton
Copy link
Contributor

This fixes an issue where we do not implicitly await the operand to yield or the iterated elements of the operand to yield* as per https://tc39.github.io/proposal-async-iteration/#sec-asyncgenerator-definitions-evaluation.

Fixes #15205

@rbuckton
Copy link
Contributor Author

I will also need to patch tslib.

@rbuckton rbuckton merged commit 2ca1de5 into master Apr 18, 2017
@rbuckton rbuckton deleted the fix15205 branch September 23, 2017 01:46
@ComFreek
Copy link

ComFreek commented Mar 5, 2018

I can still reproduce this issue with TypeScript 2.9.0-dev.20180422 on Windows 10 Pro 64-bit.

// Run with "tsc && node --harmony test.js"
// Node.js version: 9.7.1

declare const console: any;

async function *asyncGenerator(): AsyncIterable<number> {
  yield 1;
  yield Promise.resolve(2);
}

(async function() {
	const iterator: AsyncIterator<number> = asyncGenerator()[Symbol.asyncIterator]();

	// Should be {value: 1, done: false}
	console.log(await iterator.next());

	// Should be {value: 2, done: false}
	//
	// But actually is { value: Promise { 2 }, done: false } with the
	// following targets: es5, es6, es20{15, 16, 17, 18}.
	// The target "esnext" prevents any downcompilation and therefore
	// works natively on Node.js/V8 as intended.
	console.log(await iterator.next());

	// Should be {value: undefined, done: true}
	console.log(await iterator.next());
})();

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "lib": [
      "es6",
      "esnext.asynciterable",
    ],

    "importHelpers": true,
    "downlevelIteration": true,

    "strict": true,
  }
}

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Async generator function does not flatten yielded promises

5 participants