-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Angular Compiler messes up return statement and duplicates comment in some arrow functions #23829
Comments
Can you please provide a reproduction? We generally don't mess around with the function body of app code so I'm not sure how could we be responsible for this but maybe there is some kind of odd interaction that is not obvious. A repro would help. |
Sure, I can provide a more detailed reproduction. Since this deals with library compilation, I can't figure out a way to get it into a StackBlitz. However, here's how to reproduce it in a more realistic situation:
dist/my-lib/bundles/my-lib.umd.js
dist/my-lib/bundles/my-lib.umd.min.js
dist/my-lib/esm5/lib/my-lib.service.js
dist/my-lib/fesm5/my-lib.js
If you'd like to further see how this will effect an app at runtime, you'll need to create a second app and reference the packaged output (simulating as if you had published the package to npm and somebody else is using it):
|
Could reproduce by |
Good find, @trotyl! Looks like this might be related to tsickle issue 57. I'll create a specific issue for this one as well and file it on there. |
Filed as tsickle issue 802. |
The original tsickle issue has been fixed; it's kind of related in that it's about arrow function emit being a bit fickle. I've sent out a PR to fix angular/tsickle#802, it's caused by the source map transformer synthesizing comments in a way that breaks TS emit (maybe TS emit is also slightly wrong here, see microsoft/TypeScript#24096). |
Closing as resolved in angular/tsickle#802 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a...
Current behavior
When targeting es5, the Angular Compiler (
ngc
) produces incorrect JavaScript when it encounters a single statement arrow function with a line comment between the arrow and the statement. This bug prevents the body of the arrow function from executing. For example, this:compiles into this, when using
ngc
:Not only did it duplicate the comment, but it put the duplicated comment on its own line after
return
, which causes the function to return before the actual code is run.Expected behavior
The Angular Compiler should produce the same JavaScript that the TypeScript compiler does with this code:
Minimal reproduction of the problem with instructions
Compile the above TypeScript with
ngc
. For reference, here is thetsconfig.json
I used:EDIT: More detailed reproduction here
What is the motivation / use case for changing the behavior?
This bug creates unwanted behavior that is very difficult to trace, especially when creating an Angular library. For example, it can make arrow functions used with an array
forEach
orfilter
return nothing.Environment
The text was updated successfully, but these errors were encountered: