Coverage for metrics / halstead / typescript.py: 100%
7 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-08 15:04 -0800
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-08 15:04 -0800
1"""Halstead complexity measures for TypeScript."""
3from __future__ import annotations
5from metrics.halstead.common import make_compute_halstead
7_TS_OPERATOR_TOKENS = {
8 # Arithmetic
9 "+",
10 "-",
11 "*",
12 "/",
13 "%",
14 "**",
15 # Comparison / equality
16 "==",
17 "!=",
18 "===",
19 "!==",
20 "<",
21 ">",
22 "<=",
23 ">=",
24 # Bitwise
25 "&",
26 "|",
27 "^",
28 "~",
29 "<<",
30 ">>",
31 ">>>",
32 # Logical (leaf tokens)
33 "&&",
34 "||",
35 "!",
36 # Assignment
37 "=",
38 "+=",
39 "-=",
40 "*=",
41 "/=",
42 "%=",
43 "**=",
44 "&=",
45 "|=",
46 "^=",
47 "<<=",
48 ">>=",
49 ">>>=",
50 "&&=",
51 "||=",
52 "??=",
53 # Other symbols
54 ".",
55 ",",
56 ":",
57 ";",
58 "(",
59 ")",
60 "[",
61 "]",
62 "{",
63 "}",
64 "=>",
65 "?.",
66 "??",
67 # Unary / misc
68 "++",
69 "--",
70 "typeof",
71 "instanceof",
72 "in",
73 "void",
74 "delete",
75 "...",
76}
78_TS_KEYWORD_OPERATORS = {
79 "if_statement",
80 "else_clause",
81 "for_statement",
82 "for_in_statement",
83 "while_statement",
84 "do_statement",
85 "return_statement",
86 "throw_statement",
87 "function_declaration",
88 "generator_function_declaration",
89 "class_declaration",
90 "abstract_class_declaration",
91 "method_definition",
92 "arrow_function",
93 "import_statement",
94 "export_statement",
95 "try_statement",
96 "catch_clause",
97 "finally_clause",
98 "switch_statement",
99 "switch_case",
100 "switch_default",
101 "variable_declaration",
102 "lexical_declaration",
103 "type_alias_declaration",
104 "interface_declaration",
105 "enum_declaration",
106 "break_statement",
107 "continue_statement",
108 "labeled_statement",
109 "with_statement",
110 "debugger_statement",
111 "new_expression",
112}
114_TS_OPERAND_TYPES = {
115 "identifier",
116 "property_identifier",
117 "shorthand_property_identifier",
118 "number",
119 "string",
120 "template_string",
121 "template_substitution",
122 "regex",
123 "true",
124 "false",
125 "null",
126 "undefined",
127 "this",
128 "super",
129 "type_identifier",
130}
132_TS_COMMENT_TYPES = {"comment"}
135compute_halstead_ts = make_compute_halstead(
136 _TS_COMMENT_TYPES, _TS_KEYWORD_OPERATORS, _TS_OPERAND_TYPES, _TS_OPERATOR_TOKENS
137)