mirror of
https://github.com/safishamsi/graphify.git
synced 2026-09-25 06:55:43 +00:00
fix(powershell): emit inherits/implements edges for class base types
The `class_statement` handler read only the first `simple_name` child —
the class name — and never inspected the base type(s) after the `:`
token. As a result `class Dog : Animal` dropped the Dog->Animal
inheritance edge entirely; derived classes appeared as isolated nodes.
Walk the class_statement children, and once the `:` token is seen treat
each following `simple_name` as a base type. Matching the C# convention
(PowerShell has no syntactic base-vs-interface split), the first base is
emitted as `inherits` and the rest as `implements`, resolved via
ensure_named_node.
Adds a Shape/Circle inheritance pair to tests/fixtures/sample.ps1 and a
regression test asserting ("Circle","Shape") in the inherits edges.
This commit is contained in:
Vendored
+16
@@ -30,3 +30,19 @@ class DataProcessor {
|
||||
Set-Content -Path $path -Value $this.Source
|
||||
}
|
||||
}
|
||||
|
||||
class Shape {
|
||||
[string]$Kind
|
||||
|
||||
[double] Area() {
|
||||
return 0.0
|
||||
}
|
||||
}
|
||||
|
||||
class Circle : Shape {
|
||||
[double]$Radius
|
||||
|
||||
[double] Area() {
|
||||
return 3.14159 * $this.Radius * $this.Radius
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1631,6 +1631,13 @@ def test_powershell_finds_class_and_method():
|
||||
assert any("Transform" in l for l in labels)
|
||||
|
||||
|
||||
def test_powershell_class_base_type_emits_inherits_edge():
|
||||
# `class Circle : Shape` — the base type after ':' was previously dropped
|
||||
# because the handler only read the first simple_name (the class name).
|
||||
r = extract_powershell(FIXTURES / "sample.ps1")
|
||||
assert ("Circle", "Shape") in _edge_labels(r, "inherits")
|
||||
|
||||
|
||||
def test_powershell_property_field_type_context():
|
||||
r = extract_powershell(FIXTURES / "sample.ps1")
|
||||
assert ("DataProcessor", "string") in _edge_labels(r, "references", "field")
|
||||
|
||||
Reference in New Issue
Block a user