grepmax 0.17.9 → 0.17.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -553,8 +553,78 @@ class TreeSitterChunker {
|
|
|
553
553
|
referencedSymbols.push(name);
|
|
554
554
|
}
|
|
555
555
|
};
|
|
556
|
+
// Leaf identifier node types across grammars (a bare name with no
|
|
557
|
+
// named children — `ErrorCodes`, not `a.ErrorCodes`).
|
|
558
|
+
const LEAF_ID_TYPES = new Set([
|
|
559
|
+
"identifier",
|
|
560
|
+
"type_identifier",
|
|
561
|
+
"constant", // Ruby
|
|
562
|
+
"name", // PHP
|
|
563
|
+
"simple_identifier", // Kotlin, Swift
|
|
564
|
+
"property_identifier",
|
|
565
|
+
"field_identifier", // Go
|
|
566
|
+
]);
|
|
567
|
+
const isLeafId = (n) => {
|
|
568
|
+
var _a, _b;
|
|
569
|
+
return !!n &&
|
|
570
|
+
LEAF_ID_TYPES.has(n.type) &&
|
|
571
|
+
((_b = (_a = n.namedChildren) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 0;
|
|
572
|
+
};
|
|
573
|
+
const firstNamed = (n) => { var _a, _b; return (_b = ((_a = n.namedChildren) !== null && _a !== void 0 ? _a : [])[0]) !== null && _b !== void 0 ? _b : null; };
|
|
574
|
+
// Resolve the type name out of an instantiation node (`new Foo`,
|
|
575
|
+
// `Foo{}`, `new Foo()`), preferring an explicit `type` field and
|
|
576
|
+
// falling back to the first named child (qualified names reduce to
|
|
577
|
+
// their rightmost segment via simpleRefName).
|
|
578
|
+
const instantiatedTypeName = (n) => {
|
|
579
|
+
var _a;
|
|
580
|
+
const typed = (_a = (n.childForFieldName ? n.childForFieldName("type") : null)) !== null && _a !== void 0 ? _a : firstNamed(n);
|
|
581
|
+
if (!typed)
|
|
582
|
+
return null;
|
|
583
|
+
if (isLeafId(typed))
|
|
584
|
+
return typed.text;
|
|
585
|
+
return simpleRefName(typed);
|
|
586
|
+
};
|
|
587
|
+
// First `type_identifier` reachable directly or via a `user_type`
|
|
588
|
+
// wrapper — covers Java `instanceof_expression` and Kotlin/Swift
|
|
589
|
+
// `check_expression` (`x is T`).
|
|
590
|
+
const firstTypeIdent = (n) => {
|
|
591
|
+
var _a, _b;
|
|
592
|
+
for (const c of (_a = n.namedChildren) !== null && _a !== void 0 ? _a : []) {
|
|
593
|
+
if (c.type === "type_identifier")
|
|
594
|
+
return c.text;
|
|
595
|
+
if (c.type === "user_type") {
|
|
596
|
+
const t = ((_b = c.namedChildren) !== null && _b !== void 0 ? _b : []).find((x) => x.type === "type_identifier");
|
|
597
|
+
if (t === null || t === void 0 ? void 0 : t.text)
|
|
598
|
+
return t.text;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return null;
|
|
602
|
+
};
|
|
603
|
+
// Member / scope access node types, one per grammar. We capture the
|
|
604
|
+
// head (object/scope) only when it is a Capitalized leaf identifier,
|
|
605
|
+
// so `ErrorCodes.VALIDATION` / `ErrorCodes::NOT_FOUND` yield an edge
|
|
606
|
+
// to `ErrorCodes` while `this.x` / `req.body` / lowercase locals do not.
|
|
607
|
+
const MEMBER_ACCESS_TYPES = new Set([
|
|
608
|
+
"member_expression", // TS/JS
|
|
609
|
+
"attribute", // Python
|
|
610
|
+
"selector_expression", // Go
|
|
611
|
+
"field_access", // Java
|
|
612
|
+
"member_access_expression", // C#
|
|
613
|
+
"scoped_identifier", // Rust
|
|
614
|
+
"scope_resolution", // Ruby
|
|
615
|
+
"navigation_expression", // Kotlin, Swift
|
|
616
|
+
"field_expression", // Scala
|
|
617
|
+
"class_constant_access_expression", // PHP
|
|
618
|
+
]);
|
|
619
|
+
// Instantiation node types whose first/`type` child names a type.
|
|
620
|
+
const INSTANTIATION_TYPES = new Set([
|
|
621
|
+
"object_creation_expression", // Java, C#, PHP
|
|
622
|
+
"composite_literal", // Go
|
|
623
|
+
"struct_expression", // Rust
|
|
624
|
+
"instance_expression", // Scala
|
|
625
|
+
]);
|
|
556
626
|
const extractRefs = (n) => {
|
|
557
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
627
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
558
628
|
// Handle JS/TS (call_expression), Python (call), Lua (function_call)
|
|
559
629
|
if (n.type === "call_expression" ||
|
|
560
630
|
n.type === "call" ||
|
|
@@ -617,19 +687,26 @@ class TreeSitterChunker {
|
|
|
617
687
|
}
|
|
618
688
|
}
|
|
619
689
|
}
|
|
620
|
-
// Identifier-as-value references
|
|
621
|
-
//
|
|
690
|
+
// Identifier-as-value references: edges the call-expression capture
|
|
691
|
+
// above misses. These feed the graph-walk consumers (PPR,
|
|
622
692
|
// `gmax dead <ClassName>`, audit) that need class/enum references,
|
|
623
|
-
// not just method-call names.
|
|
693
|
+
// not just method-call names. Node types are grammar-specific but
|
|
694
|
+
// each falls into one of three shapes — instantiation, type-test, or
|
|
695
|
+
// member/scope access — handled uniformly across the 14 grammars.
|
|
696
|
+
// Shape 1 — instantiation: `new ClassName(...)`, `ClassName{...}`.
|
|
624
697
|
if (n.type === "new_expression") {
|
|
625
|
-
//
|
|
698
|
+
// TS/JS — constructor may be qualified (`ns.ClassName`).
|
|
626
699
|
const ctor = n.childForFieldName
|
|
627
700
|
? n.childForFieldName("constructor")
|
|
628
701
|
: null;
|
|
629
702
|
addRef(simpleRefName(ctor));
|
|
630
703
|
}
|
|
631
|
-
else if (n.type
|
|
632
|
-
|
|
704
|
+
else if (INSTANTIATION_TYPES.has(n.type)) {
|
|
705
|
+
addRef(instantiatedTypeName(n));
|
|
706
|
+
}
|
|
707
|
+
// Shape 2 — type-test: `x instanceof T`, `x is T`.
|
|
708
|
+
if (n.type === "binary_expression") {
|
|
709
|
+
// TS/JS, PHP — instanceof is a binary operator.
|
|
633
710
|
const op = n.childForFieldName
|
|
634
711
|
? n.childForFieldName("operator")
|
|
635
712
|
: null;
|
|
@@ -640,19 +717,27 @@ class TreeSitterChunker {
|
|
|
640
717
|
addRef(simpleRefName(right));
|
|
641
718
|
}
|
|
642
719
|
}
|
|
643
|
-
else if (n.type === "
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
720
|
+
else if (n.type === "instanceof_expression" || // Java
|
|
721
|
+
n.type === "check_expression" // Kotlin, Swift (`x is T`)
|
|
722
|
+
) {
|
|
723
|
+
addRef(firstTypeIdent(n));
|
|
724
|
+
}
|
|
725
|
+
else if (n.type === "is_pattern_expression") {
|
|
726
|
+
// C# — `x is BeyondError`: the type sits in a constant_pattern.
|
|
727
|
+
const cp = ((_h = n.namedChildren) !== null && _h !== void 0 ? _h : []).find((c) => c.type === "constant_pattern");
|
|
728
|
+
const id = cp ? firstNamed(cp) : null;
|
|
729
|
+
if (isLeafId(id) && id && /^[A-Z]/.test(id.text))
|
|
730
|
+
addRef(id.text);
|
|
731
|
+
}
|
|
732
|
+
// Shape 3 — member / scope access: `ErrorCodes.MEMBER`,
|
|
733
|
+
// `ErrorCodes::MEMBER`. Capitalized head only (skip `this.x`).
|
|
734
|
+
if (MEMBER_ACCESS_TYPES.has(n.type)) {
|
|
735
|
+
const head = firstNamed(n);
|
|
736
|
+
if (head && isLeafId(head) && /^[A-Z]/.test(head.text)) {
|
|
737
|
+
addRef(head.text);
|
|
653
738
|
}
|
|
654
739
|
}
|
|
655
|
-
for (const child of (
|
|
740
|
+
for (const child of (_j = n.namedChildren) !== null && _j !== void 0 ? _j : []) {
|
|
656
741
|
extractRefs(child);
|
|
657
742
|
}
|
|
658
743
|
};
|
package/package.json
CHANGED