Sitelet https://github.com/Graphify-Labs/graphify/issues/3064
Skip to content

TypeScript: enum members are not nodes, so a string enum's type is a leaf and the values are unsearchable #3064

Description

@durmazoguzhan

Environment

  • graphify 0.9.49 (PyPI graphifyy), Linux, Python 3.12
  • graphify.extract.extract([...])

Summary

TypeScript enum members are not extracted as nodes. enum_declaration is in _TS_CONFIG.class_types and the comment there reads # parity with Java/C#, but only the container half of that parity is implemented: the enum type gets a node, its members do not, and the type sits in the graph as a leaf.

This is the same gap #1700 reported for Kotlin/Java, fixed for Java in #1719 and Kotlin in #1738. Swift emits case_of for enum_entry, and PowerShell enum members landed in 0.9.49 via #3002.

Reproducer

// color.ts
export enum Direction {
    Up = "UP",
    Down = "DOWN"
}

Current behavior (0.9.49)

color_ts           color.ts
color_direction    Direction     (no children)

Up and Down are not in the node table, and Direction has no outgoing edges. String enums like this are the common TS spelling, so the members carry the meaning and the type name alone carries very little.

Expected

The Java shape:

color_direction --case_of--> color_direction_up
color_direction --case_of--> color_direction_down

Grammar notes

The walk already reaches the members: enum_declaration's body field resolves to enum_body, and the class handler descends into its children with the enum as parent_class_nid. There is no handler for the member node types.

TS spells a member two ways, and both need covering:

  • a bare Red is a property_identifier
  • Green = 5 is an enum_assignment whose name field is a property_identifier, or a string when the member is quoted ("Odd Name" = 7), where the label wants the string_fragment rather than the quoted literal

property_identifier also appears all over a normal TS file, so a handler has to be scoped to nodes whose parent is enum_body rather than matching the type alone.

One more wrinkle shared with C#: TS is case-sensitive while normalize_id casefolds, so enum E { Value, value } puts two legal members on one id.

I have a patch and will open it against this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions