Skip to content

Fix nested member access and ImageResource pattern detection#96

Closed
adamlaw-oe wants to merge 1 commit intoonevcat:masterfrom
adamlaw-oe:fix/nested-member-access-support
Closed

Fix nested member access and ImageResource pattern detection#96
adamlaw-oe wants to merge 1 commit intoonevcat:masterfrom
adamlaw-oe:fix/nested-member-access-support

Conversation

@adamlaw-oe
Copy link
Copy Markdown

Fixes incomplete detection of Xcode-generated asset symbols for:

  1. Folder-organized assets (nested member access)
  2. ImageResource dot notation references
  3. Asset names containing dots

Problems Fixed:

  1. Nested Member Access (Issue Add check unuse for Xcode generated asset symbols #83 follow-up) PR Handle generated asset symbols via member access scanning #84 added support for simple patterns like .icFlag, but didn't handle nested patterns like Image(.Icons.Settings.logo) that Xcode generates for folder-structured asset catalogs.

  2. ImageResource Pattern ImageResource.homeIcon and ImageResource.Icons.Settings.logo patterns were not detected at all.

  3. Dots in Asset Names Asset names like "empty.icon" or "navigation-menu.row.icon" were incorrectly converted to .empty.icon instead of .emptyIcon. The generatedAssetSymbolKey function didn't treat dots as word boundaries like Xcode does.

Solution:

  1. Added regex pattern for nested member access inside Image() calls
  2. Added regex pattern for ImageResource dot notation
  3. Track ranges to exclude nested patterns from simple matching
  4. Updated suffix matching logic for namespaced symbols
  5. Fixed generatedAssetSymbolKey to treat dots as word boundaries
  6. Added comprehensive tests for all patterns

Testing:

  • New tests cover: deeply nested patterns (4+ levels), ImageResource notation, whitespace handling, dots in filenames, and mixed usage
  • Verified on real iOS project with folder-organized assets

Impact:
This fix makes FengNiao work correctly with modern Xcode projects that organize assets in folders and use type-safe asset symbols.

Fixes incomplete detection of Xcode-generated asset symbols for:
1. Folder-organized assets (nested member access)
2. ImageResource dot notation references
3. Asset names containing dots

**Problems Fixed:**

1. **Nested Member Access (Issue onevcat#83 follow-up)**
   PR onevcat#84 added support for simple patterns like `.icFlag`, but didn't
   handle nested patterns like `Image(.Icons.Settings.logo)` that Xcode
   generates for folder-structured asset catalogs.

2. **ImageResource Pattern**
   `ImageResource.homeIcon` and `ImageResource.Icons.Settings.logo`
   patterns were not detected at all.

3. **Dots in Asset Names**
   Asset names like "empty.icon" or "navigation-menu.row.icon" were
   incorrectly converted to `.empty.icon` instead of `.emptyIcon`.
   The generatedAssetSymbolKey function didn't treat dots as word
   boundaries like Xcode does.

**Solution:**

1. Added regex pattern for nested member access inside Image() calls
2. Added regex pattern for ImageResource dot notation
3. Track ranges to exclude nested patterns from simple matching
4. Updated suffix matching logic for namespaced symbols
5. Fixed generatedAssetSymbolKey to treat dots as word boundaries
6. Added comprehensive tests for all patterns

**Testing:**
- New tests cover: deeply nested patterns (4+ levels), ImageResource
  notation, whitespace handling, dots in filenames, and mixed usage
- Verified on real iOS project with folder-organized assets

**Impact:**
This fix makes FengNiao work correctly with modern Xcode projects
that organize assets in folders and use type-safe asset symbols.
@onevcat
Copy link
Copy Markdown
Owner

onevcat commented Apr 21, 2026

Thanks for the detailed investigation and tests here. The problem is real: folder-organized asset symbols, nested member access, and asset names containing dots do expose gaps in the current detection logic.

I am not going to merge this PR directly because the branch is now behind master and conflicts with follow-up work that already landed, especially around generated symbol handling. Merging it as-is would risk regressing the newer behavior on master.

I will take the confirmed problem forward from current master, add proper fixture-based coverage for the real asset-catalog cases, and land a follow-up fix there. Thanks again for surfacing and narrowing this down.

@onevcat
Copy link
Copy Markdown
Owner

onevcat commented Apr 21, 2026

Closing this PR in favor of a follow-up fix based on current master, so we can preserve the newer generated-symbol support and add stronger fixture coverage for the nested asset cases.

@onevcat onevcat closed this Apr 21, 2026
@onevcat
Copy link
Copy Markdown
Owner

onevcat commented Apr 21, 2026

Thanks again for the investigation here.

I carried the fix forward from current master and opened a follow-up PR with fixture-backed coverage for the nested asset catalog cases: #98

That follow-up keeps the newer generated-symbol support already on master, adds a real .xcassets regression fixture, and addresses the nested member-access / dotted asset-name cases discussed here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants