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

Missing error if ClassDeclaration is used in Statement position #22682

Open
ajafff opened this issue Mar 18, 2018 · 3 comments · May be fixed by #47216
Open

Missing error if ClassDeclaration is used in Statement position #22682

ajafff opened this issue Mar 18, 2018 · 3 comments · May be fixed by #47216
Labels
Bug A bug in TypeScript Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". Help Wanted You can do this
Milestone

Comments

@ajafff
Copy link
Contributor

ajafff commented Mar 18, 2018

TypeScript Version: 2.8.0-dev.20180318

Search Terms: class statement

Code

let codition = false as boolean;

if (condition)
    class C {} // runtime error if transpiled to ES2015 or above: Unexpected token class
if (condition)
    enum E { Foo } // should probably be an error?

new C(); // runtime error if transpiled to ES5, because 'C' is undefined
E.Foo; // runtime error: cannot read property 'Foo' of 'E'

Expected behavior:

Expected a compile error on class C and maybe on enum E

Actual behavior:
no error for these declarations, instead I get a runtime error when targeting ES2015 or above.

Playground Link:

Related Issues:

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 19, 2018
@RyanCavanaugh
Copy link
Member

Locally-scoped enums are valid so the code isn't technically wrong but I can't see anyone doing that on purpose either

@ajafff
Copy link
Contributor Author

ajafff commented Mar 19, 2018

@RyanCavanaugh

the code isn't technically wrong

If that's the case, I would expect that enum E is not visible outside of IfStatement.thenStatement. Otherwise this can cause hard to diagnose bugs.
And if the enum is not visible outside of its own declaration, there's no point in declaring it at all.

@mhegazy mhegazy added this to the Future milestone Mar 26, 2018
@RyanCavanaugh RyanCavanaugh added Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". Help Wanted You can do this labels Dec 15, 2021
@nicdard
Copy link
Contributor

nicdard commented Dec 22, 2021

I would like to try to help with this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants