fix(extract): count method calls on instanceof-narrowed values as class-member uses#855
Open
BartWaardenburg wants to merge 2 commits into
Open
fix(extract): count method calls on instanceof-narrowed values as class-member uses#855BartWaardenburg wants to merge 2 commits into
BartWaardenburg wants to merge 2 commits into
Conversation
…ss-member uses Fixes #845
- Bump extract CACHE_VERSION 107 -> 108: instanceof narrowing populates binding_target_names, changing the cached member_accesses for any instanceof-bearing file (structurally identical to the #752 precedent). - Add an analyze-layer regression test + fixture proving the unused-class-member false positive is gone end-to-end while genuinely unused members on the same class still report. - Document the detection in .claude/rules/detection.md and CHANGELOG.md.
df1f7a2 to
e551df3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
visit_if_statementto the Oxc AST visitor incrates/extract/src/visitor/visit_impl.rs. When anifstatement's test containsx instanceof ClassName(or&&-chained variants), the narrowingx -> ClassNameis inserted intobinding_target_namesbefore the body is walked. The existingresolve_bound_member_accessesfinalization pass then re-emits anyx.method()call asClassName.method, crediting the method as used. A standalonecollect_instanceof_narrowingshelper recurses throughLogicalExpression(&&)andParenthesizedExpressionnodes. Two regression tests are added tocrates/extract/src/tests/js_ts/member_access.rs.Review
Verdict: FIX
CACHE_VERSIONbump. The fix changes emittedmember_accessesfor any file containing aninstanceofguard, andmember_accessesis serialized intoCachedModule(crates/extract/src/cache/types.rs:203). The cache-version doc comment attypes.rs:89-92records the exact precedent: issue unused-class-members FP: methods called only from Svelte <template> member expressions #752 bumped the version for the structurally identical change. With a warm cache, users upgrading will continue to see the false positive until an unrelated edit forces re-extraction. Bump to 108 with a doc-comment paragraph referencing Method call throughinstanceofnarrowing not counted as a class-member use #845.getMessage(used only via instanceof-narrowed call) is credited and not reported, while a genuinely-unused sibling method (unusedOne) still reports.member_access.rsfail before the visitor change and pass after.Closes #845