Skip to content

Missing error if ClassDeclaration is used in Statement position #22682

@ajafff

Description

@ajafff

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: ParserThe parser didn't handle the syntax correctlyEffort: CasualGood issue if you're already used to contributing to the codebase. Harder than "good first issue".Help WantedYou can do this

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions