; TypeScript pattern detection queries
; Captures: @node (pattern site), @name (identifier or function name)

; === Singleton: private constructor or cached instances ===

; class Foo { private constructor() {} }
(class_declaration
  name: (type_identifier) @name
  body: (class_body
    (method_definition
      (accessibility_modifier) @_access
      name: (property_identifier) @_ctor)
    (#eq? @_access "private")
    (#eq? @_ctor "constructor"))) @node

; === Factory: export function create*() ===

(export_statement
  (function_declaration
    name: (identifier) @name
    (#match? @name "^create[A-Z]"))) @node

; === Dependency Injection markers ===

; container.register(...) / container.bind(...)
(call_expression
  function: (member_expression
    object: (identifier) @_obj
    property: (property_identifier) @_method)
  (#eq? @_obj "container")
  (#match? @_method "^(register|bind)$")) @node

; === Decorator patterns ===
; @Injectable() / @Component() etc.
(decorator
  (call_expression
    function: (identifier) @name
    (#match? @name "^(Injectable|Component|Service|Controller|Module)$"))) @node

; === Cached instance: new Map() / new WeakMap() ===

(lexical_declaration
  (variable_declarator
    name: (identifier) @name
    value: (new_expression
      constructor: (identifier) @_cls
      (#match? @_cls "^(Map|WeakMap|Set)$")))) @node
