Microsoft/TypeScript

Missing error if ClassDeclaration is used in Statement position

開放

#22,682 建立於 2018年3月18日

 (4 則留言) (0 個反應) (0 位負責人)TypeScript (13,395 個分叉)batch import
BugDomain: ParserEffort: CasualHelp Wanted

倉庫指標

星標
 (108,860 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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:

貢獻者指南