Skip to content

fix(angular-compiler): skip arrow fn types when finding assignment = …#2274

Merged
brandonroberts merged 1 commit into
analogjs:betafrom
ashley-hunter:fix/arrow-fn-type-class-field-lowering
Apr 10, 2026
Merged

fix(angular-compiler): skip arrow fn types when finding assignment = …#2274
brandonroberts merged 1 commit into
analogjs:betafrom
ashley-hunter:fix/arrow-fn-type-class-field-lowering

Conversation

@ashley-hunter

@ashley-hunter ashley-hunter commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

findEqualsSign() in class field lowering scanned from key.end to value.start for the assignment =, but for private
fields with arrow function type annotations (e.g. #cb: (() => void) | null = null) it matched the = inside => first,
removing part of the type annotation and producing invalid output like #cb: (() ;.

Fix: when a type annotation is present, start scanning from typeAnnotation.end instead of key.end.

PR Checklist

Closes #

Affected scope

  • Primary scope: angular-compiler
  • Secondary scopes:

Recommended merge strategy for maintainer [optional]

  • Squash merge
  • Rebase merge
  • Other

Commit preservation note [optional]

What is the new behavior?

When a private class field has a type annotation, findEqualsSign() now starts scanning from typeAnnotation.end instead of key.end, skipping past any = characters inside arrow function type annotations (=>). This ensures only the actual assignment = is matched.

// Previously mangled output:
#registeredClearUserData: (() ;
#onChange: (value: string) ;                                                                                                  
 
// Now correctly preserved:                                                                                                   
#registeredClearUserData: (() => void) | null;                  
#onChange: (value: string) => void;    

Test plan

  • nx format:check
  • pnpm build
  • pnpm test
  • Manual verification

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

[optional] What gif best describes this PR or how it makes you feel?

…in field lowering

findEqualsSign() scanned from key.end to value.start for the
assignment `=`, but for private fields with arrow function type
annotations (e.g. `#cb: (() => void) | null = null`) it matched
the `=` inside `=>` first, removing part of the type annotation
and producing invalid output like `#cb: (() ;`.

Fix: when a type annotation is present, start scanning from
typeAnnotation.end instead of key.end.
@netlify

netlify Bot commented Apr 10, 2026

Copy link
Copy Markdown

Deploy Preview for analog-blog ready!

Name Link
🔨 Latest commit c965f89
🔍 Latest deploy log https://app.netlify.com/projects/analog-blog/deploys/69d8d78ec31a8500089dd48b
😎 Deploy Preview https://deploy-preview-2274--analog-blog.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Apr 10, 2026

Copy link
Copy Markdown

Deploy Preview for analog-docs ready!

Name Link
🔨 Latest commit c965f89
🔍 Latest deploy log https://app.netlify.com/projects/analog-docs/deploys/69d8d78e2934de0008805ad4
😎 Deploy Preview https://deploy-preview-2274--analog-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Apr 10, 2026

Copy link
Copy Markdown

Deploy Preview for analog-app ready!

Name Link
🔨 Latest commit c965f89
🔍 Latest deploy log https://app.netlify.com/projects/analog-app/deploys/69d8d78eca4ab9000882401a
😎 Deploy Preview https://deploy-preview-2274--analog-app.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Apr 10, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f486e7c5-06af-4445-ae56-d043b21787ec

📥 Commits

Reviewing files that changed from the base of the PR and between 75786d1 and c965f89.

📒 Files selected for processing (2)
  • packages/angular-compiler/src/lib/class-field-lowering.spec.ts
  • packages/angular-compiler/src/lib/class-field-lowering.ts

📝 Walkthrough

Walkthrough

This PR fixes a bug in private class field lowering where the = character detection logic incorrectly identified equality symbols within type annotations (particularly arrow function types) instead of locating the actual initializer assignment. The implementation adjusts the scan start position to begin from the end of the field's type annotation when present, rather than always from the field key's end. Four new test cases validate the fix handles private fields with complex TypeScript type annotations and arrow/function initializer expressions correctly, ensuring type syntax is preserved without mangling and initializer assignments appear in the constructor.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title follows Conventional Commit style with the 'fix' type and 'angular-compiler' scope, and accurately summarizes the main change of fixing arrow function type handling in class field lowering.
Description check ✅ Passed The PR description is detailed and directly related to the changeset, explaining the bug, the fix, expected vs. actual behavior, and test results.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the scope:angular-compiler Changes in @analogjs/angular-compiler label Apr 10, 2026

@brandonroberts brandonroberts left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@brandonroberts brandonroberts merged commit 992e180 into analogjs:beta Apr 10, 2026
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:angular-compiler Changes in @analogjs/angular-compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants