Skip to content

Compiler emit changes#67729

Merged
mattrbeck merged 5 commits intoangular:mainfrom
crisbeto:ignore-factories
Mar 18, 2026
Merged

Compiler emit changes#67729
mattrbeck merged 5 commits intoangular:mainfrom
crisbeto:ignore-factories

Conversation

@crisbeto
Copy link
Member

Fixes an issue where the factories we generate might not be able to compile, based on the level of analysis.

Also expands and reworks the base abstract emitter so we can reuse it in other contexts.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Mar 18, 2026
@angular-robot angular-robot bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Mar 18, 2026
@crisbeto crisbeto added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Mar 18, 2026
@ngbot ngbot bot modified the milestone: Backlog Mar 18, 2026
Adds a `ts-ignore` comment to thew instantiation expressions in factories, because in some compilation modes we can't guarantee that they'll compile.
Cleans up the `escapeDollarInStrings` parameter in various places since it isn't passed anywhere.
Allows for consumers of the `AbstractEmitterVisitor` to determine whether comments should be printed.
@crisbeto crisbeto requested review from atscott and mattrbeck March 18, 2026 12:11
@crisbeto crisbeto marked this pull request as ready for review March 18, 2026 12:11

switch (type.name) {
case o.BuiltinTypeName.Bool:
ctx.print(null, ': boolean');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a little funny to me that we're printing the : with the type rather than in the parent. Ditto for other places like visitExpressionType. Does it need to be printed here?

Copy link
Member Author

@crisbeto crisbeto Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of reasons I did it this way:

  1. We have the BuiltinTypeName.Inferred which basically outputs an empty type annotation. By baking in the : we can avoid having to check for it everywhere.
  2. This is a bit more convenient because we can just visit types without having to insert : conditionally.

this.printLeadingComments(stmt, ctx);
ctx.print(stmt, `function ${stmt.name}(`);
this.visitParams(stmt.params, ctx);
ctx.println(stmt, `)`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want newlines between the closing paren and the return type? Ditto for visitFunctionExpr

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This visitor doesn't really focus on making the output readable, e.g. object literals are all on one line.

Moves the logic for constructing more AST nodes into the `AbstractEmitterVisitor` so it's easier to implement.

Also cleans up the visitor a bit.
Adds an opt-in flag to emit type information through the base abstract emitter.
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 18, 2026
@crisbeto
Copy link
Member Author

Caretaker note: the presubmit failures are pre-existing and unrelated.

@mattrbeck mattrbeck merged commit 468874d into angular:main Mar 18, 2026
21 of 23 checks passed
@mattrbeck
Copy link
Member

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants