Closed
Description
TypeScript Version: 2.3.0-dev.20170407
function* myGeneratorFunction() {
yield 1;
return 2;
}
console.log(myGeneratorFunction.constructor.name);
Expected behavior:
Code logs "GeneratorFunction" when compiled to ES5.
Actual behavior:
Code logs "Function" when compiled to ES5.
Description:
Babel compiles this code so that the constructor name is set correctly. They do that by including a small run-time function that marks all generator functions as such. The source code for the marking function can be found here.
Compiling this per the specification is important since using the constructor name is the only way to check if a certain function is a generator function or not. See for instance this SO question and answer.