Skip to content

Compiled generators does not have correct constructor name #15088

Closed
@paldepind

Description

@paldepind

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ES6Relates to the ES6 SpecWon't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix it

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions