Skip to content

Report use before definitely defined errors #5207

Closed
@falsandtru

Description

@falsandtru

This compiled code will throw a ReferenceError exception by native javascript engine if Class syntax is implemented. It means that TS compiler generate the invalid code. Should be disallow the use of a class before definition like a Let and Const Declaration because Class Declaration does not specified as hoisting target by es6 spec.

a; // ts: pass.
   // js: pass.
var a;
b; // ts: compile error
   // js: runtime error(ReferenceError).
let b;
c; // ts: compile error
   // js: runtime error(ReferenceError).
const c = void 0;
f(); // ts: pass.
     // js: pass.
function f(){}

new Foo(); // ts: pass.
           // js: runtime error(ReferenceError)!
           // Class Declaration is not hoistable.
           // should be a compile error before throw a runtime error.
class Foo {}

http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-statements-and-declarations
http://www.ecma-international.org/ecma-262/6.0/#sec-variable-statement
http://www.2ality.com/2015/02/es6-classes-final.html

I think, this issue is different from #2854 because this issue is based on spec.

Metadata

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions