ISSUE DESCRIPTION unused-class-members FP: methods called only from Svelte <template>…
- User
ISSUE DESCRIPTION
unused-class-members FP: methods called only from Svelte member expressions False positive on 2.84.0. Class methods called only from a Svelte
<template>via a member expression (for exampleresultState.pin(...)in markup) are reported asunused-class-member. Fallow tracks template-visible identifiers but not member-expression method calls on a bound instance inside Svelte markup.Repro (2.84.0): asciimoo/hister.
ResultState.onOpen,.pin,.updateLabel, and.addSkipRuleare each invoked from.sveltetemplates (resultState.pin(...)inResultActionsMenu.svelte) yet reported unused. The repo currently setsrules.unused-class-members: "off"to work around it.Expected: credit a method called as
<local>.<method>(...)inside a Svelte<template>when<local>resolves to an instance of the class, parallel to the existing Vue/Angular template member-access tracking.Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- Assistant
I'll start by exploring the repository structure and understanding how unused-class-members and Svelte template tracking currently work.
- Assistant
Let me explore the crates and search for unused-class-members and Svelte-related code.
- Assistant
rg is not available, let me use grep instead.
- Assistant
Let me look at the unused_members code and Svelte/Vue template member tracking.
- Assistant
I need to look at how Vue/Angular template member access tracking works.
- Assistant
Let me look at the unused_members.rs around Angular template bridging and the extract crate for Svelte template parsing.
- Assistant
There's an sfc_template directory and template_usage.rs - those look relevant.
- Assistant
Let me look at the Svelte template scanner specifically and compare it with Vue.
- Assistant
I need more detail on how bound targets and member-access chains are wired for Svelte vs Vue.
- Assistant
Looking at the existing unit tests and how bound_targets are populated for Svelte SFCs.
- Assistant
Looking at how SFC parsing builds bound targets for Svelte and how template usage is merged.
- Assistant
Let me look at how template_visible_bound_targets are populated, particularly around line 376.
- Assistant
Let me look at merge_script_into_module and how expected bound targets are recorded.
- Assistant
I need to understand binding_target_names and any related integration tests for Svelte member methods.
- Assistant
There's an sfc_parsing.rs integration test - let me look at that and binding_target_names.
- Assistant
There's already a svelte class-members test. Let me find decisions/changelog and the fixture that matches the issue more closely.
- Assistant
Let me inspect the svelte-project fixture and craft a repro that matches the reported hister pattern.
- Assistant
Let me read the svelte project files and the CHANGELOG for anything about svelte template member access.
- Assistant
Let me search for gaps around Svelte bound instances,
$state, and method-reference patterns. - Assistant
Let me look at analyze_template_snippet_with_bound_targets and how bound_targets remap member accesses.
- Assistant
Let me continue reading the rest of the file.
- Assistant
Looking at how typed local bindings populate binding_target_names—the issue may require type annotations, not just
new Class(). - Assistant
Let me look more carefully at variable declarations which create binding targets - probably around line 1990-2500.
- Assistant
Let me continue further to see more patterns for binding targets.
- Assistant
Let me check version history and try building a minimal repro that matches the issue pattern more closely.
- Assistant
The member-accesser reports
Counter.bumpfrom the Svelte file; I'll check whether unused_members correctly balances that against the class export path. - Assistant
There's INSTANCE_EXPORT_SENTINEL - the hister case may be an imported instance (
export const resultState = new ResultState()), not a locally constructed one. - Assistant
Let me look at how INSTANCE_EXPORT_SENTINEL is emitted in the visitor.
- Assistant
So exported instances work within that file for crediting from accesses on the exported instance. But when suck instance is imported into a Svelte template, does
resultState.pin()get credited? - Assistant
For Svelte templates: When
resultStateis imported and used asresultState.pin(): - Assistant
Checking whether bare member expressions like
resultState.pin(method references) are recorded as well as calls. - Assistant
Looking for TODOs and recently touched related code that may indicate the unfinished fix.
- Assistant
There's already a plx: "fix(svelte): credit@attach directives and script-instance member access" and vue version.` Theissue claims FPstill on 2.84.0. Let me check if2.84 is after or before those fixes.
- Assistant
Let me try fetching the hister repro repository to inspect the exact pattern.
- Assistant
I'll clone hister shallowly and inspect the ResultState pattern.
- Assistant
Interesting! The ResultState is in a
.svelte.tsrune module. Inspecting that pattern next. - Assistant
The gap is a
$props()destructured prop typed via a Props interface with a type-only import. Checking how those typed patterns are handled. - Assistant
I need to go back to the fallow repo.
- Assistant
Look at record_typed_binding fully and how Nested type bindings work for interface Props.
- Assistant
I'll check type-only imports in local_to_export_keys and Vue-style typed prop handling for a parallel pattern.
- Assistant
Let me look atuest build_local_to_export_keys and whether type-only imports are included.
- Assistant
Type-only imports are included if all_resolved_imports includes them. Let me check.
- Assistant
Let me dig into ResolvedModule::all_resolved_imports
- Assistant
Let meread that.
- Assistant
Checking how local type declarations are tracked so we can resolve named Props interfaces.
- Assistant
I'll verify type-only import extraction and then sketch a formula fix.
- Assistant
Let me check how URL import type is handled and also whether
.svelte.tsParsing is special. - Assistant
Looking at resolve_bound_member_accesses and how to store property types for named interfaces.
- Assistant
Checking how type annotations attach on destructured variable declarators in this codebase.
- Assistant
There's
declarator.type_annotation- oxc might have a convenience field. Let me check the oxc API via cargo doc or source in target. - Assistant
Looking for oxc types in the local environment.
- Assistant
Found it.
- Assistant
There's already extract_object_pattern_bindings - look at it.
- Assistant
Looking at how interface/Type alias visits work so I can collect property shapes.
- Assistant
I'll also check ModuleInfoExtractor's field definition and finalize/into.
- Assistant
I notice
playwright_fixture_typesis exactly a map of type alias name -> property types. I can reuse similar pattern for general type property bindings, or expand the playwright map for general pr... - Assistant
There's
collect_fixture_type_bindings_from_typethat already walks Type aliases and type literals. I can leverage similar infrastructure. - Assistant
Checking into_module_info finalize order.
- Assistant
Looking at into_module_info around 789-820.
- Assistant
Note that for SFC, merge_into runs finalize including resolve_bound_member_accesses, THEN apply_template_usage uses binding_target_names() - but wait, after into_module_info/merge_into the extractor is c...
- Assistant
Implementing the fix. First checking CACHE_VERSION and drafting a minimal repro.
- Assistant
Let me find CACHE_VERSION
- Assistant
Maybe extract cache version is elsewhere
- Assistant
Implementing support for typed object-pattern props (Svelte
$props) and named interface/type-alias property binding. - Assistant
I'll look for where ObjectBindingCandidate is defined to follow the same pattern.
- Assistant
Let me read those structures and then implement.
- Assistant
I'll implement the core visitor changes now.
- Assistant
Need to check if FxHashMap is imported in mod.rs
- Assistant
Good, FxHashMap is imported. Now add the field to the struct.
- Assistant
Need to goto the right line.
- Assistant
Now I can replace the field.
- Assistant
I'll make
binding_target_names()resolve pending expansions so SFC can pick them up, and wire finalize the same way. - Assistant
I'll change binding_target_names to take &mut and resolve, or add a separate pubpolysil method resolve that must bes called. Changing signature of binding_target_names to &mut self is cleaner挂 for SFC.
- Assistant
Need to call resolve_typed_type_expansions in into_module_infoPE and merge_into before resolve_bound_member_accesses.
- Assistant
I'll update both finalize paths.
- Assistant
resolve_class_type_paramis private to visit_impl, so I'll clone type names directly in the expansion. - Assistant
Need to goto line 319 first.
- Assistant
Now I can replace.
- Assistant
Now add calls Empresa in into_module_info and merge_into.
- Assistant
Updating visit_impl to record interface shapes and handle typed object patterns.
- Assistant
I'll update record_typed_binding and شمالی add record_typed_object_pattern_binding and record_interface_type_shape.
- Assistant
I need to make PendingTypedTypeExpansion visible from visit_impl (it's private in parent - child can access private items of parent? In Rust, child modules can access parent's private items. Yes - `supe...
- Assistant
Next I'll wire the variable declaration and interface visits.
- Assistant
Look at visit_variable_declaration around 2070 and interface around 1679.
- Assistant
I'll add record_interface_type_shape to the interface visit.
- Assistant
Now update visit_variable_declaration to handle ObjectPattern.
- Assistant
In oxc, BindingPattern is used as enum-like with BindingIdentifier directly -
declarator.idis BindingPattern kind. Let me check - the code uses `BindingPattern::BindingIdentifier(id) = &declarator.... - Assistant
Checking that type annotations on destructuring bind to VariableDeclarator as expected in oxc.
- Assistant
There might be an issue - oxc has type_annotation on bothVariableDeclarator and BindingPattern. The ESTree viaVariableDeclaratorId might put type on id. Let me check if Declarator.type_annotation is p...
- Assistant
Let me find BindingPattern definition
- Assistant
Hmm empty? Maybe it's in a different file
- Assistant
Maybe it's generated differently. Looking at how BindingPattern is matched -they use BindingPattern::BindingIdentifier which suggests BindingPattern is an enum (maybe type aliasrévél for Kind).
- Assistant
Let me read the BindingPattern enum and VariableDeclarator type_annotation handling
- Assistant
Type annotation is on VariableDeclarator and merged into id for ESTree. Our access ofdeclarator.type_annotation should work.
- Assistant
Bump CACHE_VERSION to 103. Wire shape of cached data mighteness be the same (member_accesses contentocks changes) - still need bump for re-extraction.
- Assistant
Adding a unit test and extending the svelte fixture. First, checking how visitor tests parse sources.
- Assistant
I'll add a unit test near other member access tests and an SFC integration fixture update.
- Assistant
I'll insert a test after assigned_nested_object_member_access_mapped_to_class.
- Assistant
I accidentally left Arabic text in the test message - fixing that.
- Assistant
goto and fix
- Assistant
fix the Arabic text
- Assistant
Now add SFC full pipeline test and update svelte fixture. Let me look at how sfc tests work.
- Assistant
Look at that SFC test around 494 to add a sibling for $props.
- Assistant
Add SFC test after the existing event handler test.
- Assistant
The instructions ban adding or modifying tests. Reverting those test changes and using a temporary script instead.
- Assistant
Building the extract crate and running a temporary reproduction next.
- Assistant
Need fallow-extract package name. The tests I removed won't exist - I need to compile and write temp test.
- Assistant
Creating a temporary repro to verify the fix.
- Assistant
Script unit test works. Meanwhile SFC test:
- Assistant
SFC extraction works. Now verifying end-to-end with a mini project and the fallow CLI.
- Assistant
Need to check fallow CLIusage for root path.
- Assistant
Need to check for --directory or cwd
- Assistant
Only unusedMethod is reported. pin, onOpen, updateLabel, addSkipRule, and labelMessage are credited. Cleaning up temporary tests.
- Assistant
Running related Svelte and class-member tests to ensure nothing broke.
- Assistant
All sfc integration tests pass. Running member_detection as well.
- Assistant
All good. Verifying extractor is mut in sfc.rs, then submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.