-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Do not warn unreachable code for variable declarations #2240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@mprobst do you have tools that shift things around so that the |
@evmar any intuition on how hard this'd be to solve in tsickle (e.g. assuming we generate a duplicate declarations at the top of the file)? |
I experimented a bit. Even this code:
is transpiled as
We currently do a pass over the compilation output (to rewrite |
Cross referencing microsoft/TypeScript#7017 I thought TypeScript fixed this in 2.0 but apparently not. |
I would prefer we NOT accept such code. Encouraging users to take advantage of hoisting with variables and functions defined after an exit point is not something I want to see. |
From https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/var :
If there is a return statement in a function, variable declarations written after should not warn for unreachable code.
I did not intentionnally write a statement like that, it's from typescript transpilation:
Is transpiled in:
The text was updated successfully, but these errors were encountered: