Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiled generators does not have correct constructor name #15088

Closed
paldepind opened this issue Apr 9, 2017 · 5 comments
Closed

Compiled generators does not have correct constructor name #15088

paldepind opened this issue Apr 9, 2017 · 5 comments
Labels
ES6 Relates to the ES6 Spec Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it
Milestone

Comments

@paldepind
Copy link

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.

@KatSick
Copy link

KatSick commented Jul 31, 2017

Is there any updates ?

@paldepind
Copy link
Author

@KatSick I am not aware of any updates. Previously it was tagged for the 2.4 release but now it's just tagged as future. I still really hope it'll be fixed as it's quite problematic for a project I'm working on.

@rbuckton is assigned to this issue. Do you have any idea about a timeline for this?

@nickbreaton
Copy link

This also applies to async functions:

TypeScript:

async function a() {}

a.constructor.name // "Function"

Latest version of Chrome:

async function a() {}

a.constructor.name // "AsyncFunction"

@rotu
Copy link

rotu commented Sep 22, 2023

I think this is resolved.

@RyanCavanaugh RyanCavanaugh added Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it and removed Bug A bug in TypeScript labels Feb 23, 2024
@RyanCavanaugh
Copy link
Member

This doesn't seem like an important scenario for modern JS development - folks can either target ES6 which is supported basically everywhere, or use an alternate transpiler with stricter adherence semantics if this is important for their scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ES6 Relates to the ES6 Spec Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it
Projects
None yet
Development

No branches or pull requests

7 participants