Skip to content

Start decoupling TCB generation from TypeScript factory APIs#67381

Merged
thePunderWoman merged 5 commits intoangular:mainfrom
crisbeto:tcb-strings-2
Mar 3, 2026
Merged

Start decoupling TCB generation from TypeScript factory APIs#67381
thePunderWoman merged 5 commits intoangular:mainfrom
crisbeto:tcb-strings-2

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Mar 2, 2026

Starts the process of decoupling our TCB generation from TypeScript's factory APIs which might not be available in TypeScript 7. These changes try to cover the majority of TCB use cases, but we still have some where we print through ts.Printer. I aim to address those in a follow-up PR.

crisbeto added 3 commits March 2, 2026 10:36
Introduces the `TcbExpr` class that will be used to generate TCB code without going through TypeScript's factory APIs.
Initial pass to move usages of TS `factory` APIs to the new `TcbExpr`.
Deletes utilities that we no longer use.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Mar 2, 2026
@angular-robot angular-robot bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Mar 2, 2026
@ngbot ngbot bot added this to the Backlog milestone Mar 2, 2026
*
* @deprecated This is a temporary method until all code generation code has been migrated.
*/
export function tempPrint(node: ts.Node, sourceFile: ts.SourceFile): string {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm using this function in the cases where we convert some arbitrary nodes to strings. In follow-up changes I'll try to get rid of all call sites.

TypeScript has functionality that automatically escapes quotes in string literals. These changes update the places where we may need to do the same ourselves.
@crisbeto crisbeto force-pushed the tcb-strings-2 branch 2 times, most recently from 1f44053 to fa9fd4c Compare March 2, 2026 15:39
@crisbeto crisbeto requested review from atscott and mattrbeck March 2, 2026 16:18
@crisbeto crisbeto marked this pull request as ready for review March 2, 2026 16:18
expect(result).toContain(`if ((((this).expr)) === (0)) { (this).zero(); }`);
expect(result).toContain(
`if (!((((this).expr)) === (0)) && (((this).expr)) === (1)) { (this).one(); }`,
`if ((!((((this).expr)) === (0))) && ((((this).expr)) === (1))) { (this).one(); }`,
Copy link
Member Author

Choose a reason for hiding this comment

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

The context for the additional parens is that TS is a bit smarter about only inserting them when necessary whereas we do it for all instances.

Resolves issues caught during the presubmit.
@crisbeto
Copy link
Member Author

crisbeto commented Mar 3, 2026

Passing TGP

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 3, 2026
@crisbeto crisbeto removed the request for review from mattrbeck March 3, 2026 18:46
@thePunderWoman thePunderWoman merged commit f28b8f6 into angular:main Mar 3, 2026
21 checks passed
crisbeto added a commit to crisbeto/angular that referenced this pull request Mar 4, 2026
This is a follow-up to angular#67381 which introduced a subtle bug where depending on the type checking configuration, we may put an object literal directly in the TCB body which the TS compiler ends up interpreting as a block. These changes resolve the issue by always wrapping the literal in parentheses.
crisbeto added a commit to crisbeto/angular that referenced this pull request Mar 4, 2026
This is a follow-up to angular#67381 which introduced a subtle bug where depending on the type checking configuration, we may put an object literal directly in the TCB body which the TS compiler ends up interpreting as a block. These changes resolve the issue by always wrapping the literal in parentheses.
thePunderWoman pushed a commit that referenced this pull request Mar 4, 2026
This is a follow-up to #67381 which introduced a subtle bug where depending on the type checking configuration, we may put an object literal directly in the TCB body which the TS compiler ends up interpreting as a block. These changes resolve the issue by always wrapping the literal in parentheses.
crisbeto added a commit to crisbeto/angular that referenced this pull request Mar 5, 2026
This is a follow-up to angular#67381 which introduced a subtle bug where depending on the type checking configuration, we may put an object literal directly in the TCB body which the TS compiler ends up interpreting as a block. These changes resolve the issue by always wrapping the literal in parentheses.
atscott pushed a commit that referenced this pull request Mar 5, 2026
This is a follow-up to #67381 which introduced a subtle bug where depending on the type checking configuration, we may put an object literal directly in the TCB body which the TS compiler ends up interpreting as a block. These changes resolve the issue by always wrapping the literal in parentheses.
crisbeto added a commit to crisbeto/angular that referenced this pull request Mar 13, 2026
Fixes a regression introduced by angular#67381 where we weren't escaping backticks in template literals.

Fixes angular#67675.
crisbeto added a commit to crisbeto/angular that referenced this pull request Mar 15, 2026
Fixes a regression introduced by angular#67381 where we weren't escaping backticks in template literals.

Fixes angular#67675.
mattrbeck pushed a commit that referenced this pull request Mar 16, 2026
Fixes a regression introduced by #67381 where we weren't escaping backticks in template literals.

Fixes #67675.
mattrbeck pushed a commit that referenced this pull request Mar 16, 2026
Fixes a regression introduced by #67381 where we weren't escaping backticks in template literals.

Fixes #67675.

(cherry picked from commit 2bd708f)
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 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