fix(ngcc): use annotateForClosureCompiler option#36652
Conversation
JoostK
left a comment
There was a problem hiding this comment.
Thanks for looking into this and opening a PR to resolve the issue! 🎉
It looks to me like we don't have to make the changes to TraitCompiler, CompileResult, WritePropExpr and ExpressionTranslatorVisitor, instead keeping the necessary changes local to ngcc's renderer.
My idea is to only change Renderer.renderDefinitions/Renderer.renderStatements such that the @nocollapse comment is added there, if annotateForClosureCompiler is enabled. This is similar to ngtsc's approach of adding the comment in a TypeScript transformer, which would be the renderer in ngcc's case.
Thanks for the quick feedback @JoostK! this.srcFormatter.printStatement(stmt, sourceFile, imports);Which goes all the way from if (this.annotateForClosureCompiler && stmt.expr instanceof WritePropExpr && someEsotericCheckThatThisIsAStaticPropertyAndNotAnyOtherKind(stmt)) {
stmt.expr.leadingComment = '* @nocollapse ';
}
this.srcFormatter.printStatement(stmt, sourceFile, imports);Which still requires the changes in While writing the above I tried implementing it and was unsuccessful. I'm happy to be convinced that there is a better way, I'm just not sure I'm knowledgeable enough already to be able to implement that way. |
|
Thanks for the reply. I agree that tacking on the comment to a string would be a hack, but I see some other ways:
export type EmitStatement {
stmt: o.Statement;
comments: string[];
}I'm not sold on the name but I can't think of something better
My personal preference would be in the order as presented above. If you run into problems feel free to follow up here. |
|
I should be able to get to this toward the end of next week. |
|
@DavidANeil - do you still have time to work on this? |
|
Yup sorry for the radio silence, my plan was to come back to it as soon as I enabled Ivy for our code base, and I thought that "the end of next week" would be a good estimate for when that would be done, but it turns out "the end of next month" was probably a more accurate estimate. I think I am about 3/4 done with enabling Ivy, so I should be circling back to this in a week or so? Sorry I can't get to it sooner. |
|
No problem. Good luck with your ivy-ifying of your code. |
645d7e8 to
cab05e3
Compare
|
Let's discuss the overall "Angular + Closure Compiler outside of google3" story before we start adding more flags and closure support into ngc and especially ngcc. I have a meeting with @DavidANeil scheduled for next week, so I'll bring up this PR there and will post an update on this PR afterwards. |
|
Sounds good, that's what I was thinking too. I just wanted to get this PR into a better state before I entirely forgot my mental model of the ngcc renderer. |
There was a problem hiding this comment.
After discussing the build setup with @DavidANeil I think that this is a reasonable change to make.
@DavidANeil can you please update this PR with:
- updat the commit message to explain "The Why" - the motivation behind this change
- rebase the PR (it should make the saucelabs flake go away)
LGTM otherwise. Thanks!
The rationale behind this decision is concistency. ngc already supports the flag, and ngcc exists only to convert code from VE to Ivy, so there is no good reason for ngcc not to support this flag - it doesn't increase our support burden or feature set. In fact one could argue that this change fixes a regression caused by the Ivy and ngcc rollout in v9.
There was a problem hiding this comment.
I had completely missed the refactored commit, thanks for the cleanup!
Also, the linter is complaining about the commit message being too short (needs to be 100 chars at least). Could you also change Resolves #36618 into Closes #36618, that's the term we typically use.
One small nit about an import, otherwise LGTM!
There was a problem hiding this comment.
Can you move this import to @angular/compiler above?
Adds @nocollapse to static properties added by ngcc iff annotateForClosureCompiler is true. The Closure Compiler will collapse static properties into the global namespace. Adding this annotation keeps the properties attached to their respective object, which allows them to be referenced via a class's constructor. The annotation is already added by ngtsc and ngc under the same option, this commit extends the functionality to ngcc. Closes angular#36618.
cab05e3 to
fe84683
Compare
Adds @nocollapse to static properties added by ngcc iff annotateForClosureCompiler is true. The Closure Compiler will collapse static properties into the global namespace. Adding this annotation keeps the properties attached to their respective object, which allows them to be referenced via a class's constructor. The annotation is already added by ngtsc and ngc under the same option, this commit extends the functionality to ngcc. Closes #36618. PR Close #36652
Adds @nocollapse to static properties added by ngcc iff annotateForClosureCompiler is true. The Closure Compiler will collapse static properties into the global namespace. Adding this annotation keeps the properties attached to their respective object, which allows them to be referenced via a class's constructor. The annotation is already added by ngtsc and ngc under the same option, this commit extends the functionality to ngcc. Closes angular#36618. PR Close angular#36652
|
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. |
Adds @nocollapse to static properties added by ngcc iff annotateForClosureCompiler is true. The Closure Compiler will collapse static properties into the global namespace. Adding this annotation keeps the properties attached to their respective object, which allows them to be referenced via a class's constructor. The annotation is already added by ngtsc and ngc under the same option, this commit extends the functionality to ngcc. Closes angular#36618. PR Close angular#36652
Adds @nocollapse to static properties added by ngcc iff annotateForClosureCompiler is true.
Resolves #36618.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #36618
What is the new behavior?
When
ngccis invoked with a tsconfig that contains the option"annotateForClosureCompiler": truethenngccwill output closure compatible javascript.Does this PR introduce a breaking change?