-
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
fix(ivy): ngcc - recognize synthesized constructors #27897
Conversation
@petebacondarwin I have updated the code with some more documentation and added ES2015 support. For the ES2015 tests I choose to include them in the existing file, whereas I split out the ES5 constructor tests into a separate file. I am now wondering which is better 🤔 Regarding the tests, I feel it's a bit overkill to add tests that verify all possible mismatches in AST structure. How do you feel about that? Are the current tests sufficient or do you see some additional ones that should be added? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I would be tempted to keep the tests in the files rather than splitting them out. It makes the git history a bit simpler. |
57f95b9
to
2c9df97
Compare
I added an integration test in b29dd5c only to find that ES5 didn't actually work :-) I added fixup commit 2c9df97 in which
EDIT: Discussed offline that emitting |
2c9df97
to
d50197d
Compare
@JoostK Can you rebase this one? (ping me when you're ready and I'll merge) |
@kara I can't at the moment, I'm on holiday this week. Will rebase coming weekend if none of you have beaten me to it (the conflict is trivial to resolve, only a Js docblock was added) |
A constructor function may have been "synthesized" by TypeScript during JavaScript emit, in the case no user-defined constructor exists and e.g. property initializers are used. Those initializers need to be emitted into a constructor in JavaScript, so the TypeScript compiler generates a synthetic constructor. This commit adds identification of such constructors as ngcc needs to be able to tell if a class did originally have a constructor in the TypeScript source. When a class has a superclass, a synthesized constructor must not be considered as a user-defined constructor as that prevents a base factory call from being created by ngtsc, resulting in a factory function that does not inject the dependencies of the superclass. Hence, we identify a default synthesized super call in the constructor body, according to the structure that TypeScript emits.
d50197d
to
4c0ca3d
Compare
I have rebased on master. This has triggered the code-owners approval process. |
A constructor function may have been "synthesized" by TypeScript during JavaScript emit, in the case no user-defined constructor exists and e.g. property initializers are used. Those initializers need to be emitted into a constructor in JavaScript, so the TypeScript compiler generates a synthetic constructor. This commit adds identification of such constructors as ngcc needs to be able to tell if a class did originally have a constructor in the TypeScript source. When a class has a superclass, a synthesized constructor must not be considered as a user-defined constructor as that prevents a base factory call from being created by ngtsc, resulting in a factory function that does not inject the dependencies of the superclass. Hence, we identify a default synthesized super call in the constructor body, according to the structure that TypeScript emits. PR Close angular#27897
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. |
ngcc needs to be able to identify synthesized constructors in order to let ngtsc create a base factory call, instead of assuming a no-args constructor.
This is important for Material, e.g. the following code (source):
is compiled to ES2015 (source):
and downleveled to ES5 (source):
Currently, ngcc reports the
MatTable
class to have a no-args constructor, resulting in a factory function that doesn't inject the dependencies ofCdkTable
.PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?