fix(extract): emit inherits edge for JavaScript class extends#1790
Open
Synvoya wants to merge 1 commit into
Open
fix(extract): emit inherits edge for JavaScript class extends#1790Synvoya wants to merge 1 commit into
Synvoya wants to merge 1 commit into
Conversation
The JavaScript tree-sitter grammar stores a class's base type directly
under the class_heritage node (`extends Base` -> [extends, identifier]),
whereas the TypeScript grammar wraps it in an extends_clause child.
_ts_walk_class_members only handled the extends_clause/implements_clause
shape, so `class Derived extends Base {}` in a .js file emitted no
inherits edge even though the equivalent .ts file worked.
When class_heritage has no extends_clause/implements_clause child, treat
the heritage node itself as the extends clause and emit an inherits edge,
mirroring the existing extends_type_clause branch used for interface
heritage.
Adds a regression test alongside the existing TS inheritance tests.
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.
Bug
class Derived extends Base {}in a plain.jsfile produces noinheritsedge, while the identical code in a.tsfile works.Root cause
The two tree-sitter grammars shape class heritage differently:
class_heritage→extends_clause→identifier(base wrapped in a clause node)class_heritage→extends,identifier(base held directly, noextends_clausewrapper)_ts_walk_class_members(graphify/extractors/resolution.py) only iteratedclass_heritagechildren looking forextends_clause/implements_clause. For.jsclasses neither exists, so the heritage entry was silently dropped.Minimal repro
extract(["a.js"])yields noDog --inherits--> Animaledge. The equivalenta.tsalready emits it.Fix
When a
class_heritagenode has noextends_clause/implements_clausechild, treat the heritage node itself as the extends clause and emit aninheritsedge — mirroring the existingextends_type_clausebranch used for interface heritage (#1095). TypeScript files are unaffected (they still take the clause branch, guarded by asaw_clauseflag, so there is no double emission).Testing
test_js_class_extends_same_filetotests/test_ts_inheritance.py, mirroring the existingtest_class_extends_same_file(.ts) test but with a.jsfile. It fails before the change and passes after.tests/test_ts_inheritance.py: 8 passed.tests/test_languages.py: 314 passed, 13 skipped (unchanged).