You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe that this is the correct behavior @FlorianDold. When you do export class MyClass { } you are using a class expression instead of a regular class declaration. (Edit: my reasoning here doesn't make any sense, because exporting arbitrary expressions, like export 5, is obviously invalid. There must be an identifier or it must be a default export.) In class expressions, the BindingIdentifier portion (i.e. MyClass) is optional. If provided, as you did, it is only available for use inside of the class body. (See bullet point #2 here).
Your original TS code should generate an error, as return new MyClass(); is invalid because MyClass isn't available there. If there's no error, that is a bug most likely.
export class MyClass { } is still a class declaration (with an export modifier). Our emit is probably wrong - the declaration within the execute function behaves as block scoped (which is normal), but we need to hoist it so its binding is available in the initialization block above. This is probably best done by rewriting the class as a class expression which is assigned to the var made above. (or leaving it as a declaration, but mangling the hoisted name and assigning it to the mangled name)
Thanks for the correction @weswigham. If you did want to export a named class expression in one statement for some reason, assuming you could do something like export default (class SomeName { });?
The following code
is compiled (with
tsc test.ts -m system --target es2015
) towhich is wrong, since the actual definition of
MyClass
is not in scope ofmyFunction
anymore.Compiling down to es5 works as expected with respect to the scope of the class.
The text was updated successfully, but these errors were encountered: