Microsoft/TypeScript

Missing error if ClassDeclaration is used in Statement position

Open

#22 682 ouverte le 18 mars 2018

Voir sur GitHub
 (4 commentaires) (0 réactions) (0 assignés)TypeScript (6 726 forks)batch import
BugDomain: ParserEffort: CasualHelp Wanted

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

Description

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:

Guide contributeur