Commit fd59f88
committed
fix(resolver): scope this.prop typeMap key to enclosing class to prevent false edges in multi-class files (#1382)
* fix(resolver): scope this.prop typeMap key to class to prevent false edges in multi-class files
When a file defines two or more classes that both assign `this.service = new X()` in
their constructors, `handlePropWriteTypeMap` previously stored all entries under the
unqualified key `this.service`. `setTypeMapEntry` discards equal-confidence duplicates,
so only one class's entry survived, causing the other class's `this.service.method()`
calls to resolve against the wrong type and producing spurious call-graph edges.
Fix: extractTypeMapWalk now threads a `currentClass: string | null` parameter through
its inner walk. When a `class_declaration` node is encountered, the class name is
extracted and passed down to all children. `handlePropWriteTypeMap` uses this to key
`this.prop = new Ctor()` writes as `ClassName.prop` (e.g. `ClassA.service`) instead
of `this.prop`, so two classes with the same property name no longer collide in the
typeMap.
The call resolver gains a symmetric fallback: when a `this.X` receiver isn't found via
`effectiveReceiver` / `this.X` lookups, it also tries `CallerClass.X` where the caller
class is extracted from `callerName` (e.g. `ClassA.runA` → `ClassA`). This correctly
resolves the class-scoped key while leaving all other resolution paths untouched.
Also adds: `multi-class.js` fixture, four expected edges, driver exercise, and three
unit tests covering the new scoping, fallback when there is no enclosing class, and the
absence of false entries.
Closes #1323
* fix(extractor): use this.prop fallback for named class expressions in typeMap
Named class expressions (`const Foo = class Bar { ... }`) store the key as
`Bar.x` using the expression-internal name, but the resolver derives callerClass
from the binding name `Foo`, so it looks up `Foo.x` and misses `Bar.x`.
Walk class expression children with null so the pre-fix `this.prop` fallback
is preserved and the second lookup in resolveByMethodOrGlobal still finds the
entry. Only class_declaration and abstract_class_declaration receive the
class-scoped key treatment.
Add a unit test asserting `this.x` is stored (not `Bar.x`) for named class
expressions.
Fixes a silent regression identified by Greptile in PR #1382 review.1 parent 19bec64 commit fd59f88
6 files changed
Lines changed: 158 additions & 10 deletions
File tree
- src
- domain/graph/builder
- extractors
- tests
- benchmarks/resolution/fixtures/javascript
- parsers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
76 | 79 | | |
77 | 80 | | |
| 81 | + | |
| 82 | + | |
78 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
79 | 91 | | |
80 | 92 | | |
81 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1741 | 1741 | | |
1742 | 1742 | | |
1743 | 1743 | | |
1744 | | - | |
| 1744 | + | |
1745 | 1745 | | |
1746 | 1746 | | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
1747 | 1765 | | |
1748 | 1766 | | |
1749 | 1767 | | |
1750 | 1768 | | |
1751 | 1769 | | |
1752 | | - | |
| 1770 | + | |
1753 | 1771 | | |
1754 | 1772 | | |
1755 | 1773 | | |
1756 | 1774 | | |
1757 | | - | |
| 1775 | + | |
1758 | 1776 | | |
1759 | 1777 | | |
1760 | | - | |
| 1778 | + | |
1761 | 1779 | | |
1762 | 1780 | | |
1763 | 1781 | | |
| |||
1957 | 1975 | | |
1958 | 1976 | | |
1959 | 1977 | | |
1960 | | - | |
| 1978 | + | |
| 1979 | + | |
1961 | 1980 | | |
1962 | 1981 | | |
1963 | 1982 | | |
1964 | 1983 | | |
1965 | | - | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
1966 | 1989 | | |
1967 | 1990 | | |
1968 | 1991 | | |
| |||
1975 | 1998 | | |
1976 | 1999 | | |
1977 | 2000 | | |
1978 | | - | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
1979 | 2004 | | |
1980 | 2005 | | |
1981 | | - | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
1982 | 2010 | | |
1983 | 2011 | | |
1984 | 2012 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
| |||
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
250 | 278 | | |
251 | 279 | | |
252 | 280 | | |
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
363 | | - | |
| 363 | + | |
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
371 | 384 | | |
372 | 385 | | |
373 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
374 | 414 | | |
375 | 415 | | |
376 | 416 | | |
377 | 417 | | |
378 | 418 | | |
379 | 419 | | |
380 | 420 | | |
| 421 | + | |
381 | 422 | | |
382 | 423 | | |
383 | 424 | | |
| |||
0 commit comments