code-gauge 1.8.0 → 1.10.0

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.
package/dist/metrics.js CHANGED
@@ -1,2 +1,3 @@
1
- import e from"tree-sitter";import{createLanguageRegistry as t}from"./languages.js";const n=new Set(["&&","||","and","or"]),r=new Set(["+","-","*","/","%","**","=","+=","-=","*=","/=","%=","==","!=","===","!==","<","<=",">",">=","!","~","&","|","^","<<",">>","=>","return","throw","yield","await","break","continue"]),i=new Set(["identifier","property_identifier","field_identifier","type_identifier","number","integer","float","integer_literal","float_literal","int_literal","rune_literal","imaginary_literal","string","string_literal","template_string","character_literal","char_literal","true","false","null","undefined","nil"]);class o{registry=t();registerLanguage(e){this.registry.set(e.name,e);for(const t of e.aliases??[])this.registry.set(t,e)}getSupportedLanguages(){return[...new Set([...this.registry.values()].map(e=>e.name))]}measure(t,n){const o=this.registry.get(n.language);if(!o)throw new Error(`Unsupported language: ${n.language}`);const a=new e;a.setLanguage(o.parserLanguage);const s=a.parse(t,void 0,{bufferSize:t.length+1}).rootNode,d=function(e,t,n){const r=t.map((e,t)=>function(e,t,n){const r=u(e,t,0,!0),i=function(e,t){const n=new Set,r=new Set(t.functionNodeTypes);let i=0;function o(e,t){if(t||!r.has(e.type)){if(A(e)){i+=1;const t=function(e){const t=e.childForFieldName("function")??e.namedChild(0);if(!t)return;return O(t)}(e);t&&n.add(t)}for(const t of e.namedChildren)o(t,!1)}}return o(e,!0),{callCount:i,callees:n}}(e,t);return{index:n,name:$(e),startLine:e.startPosition.row+1,startColumn:e.startPosition.column,endLine:e.endPosition.row+1,returnsJsx:p(e,t),cyclomaticComplexity:r.cyclomaticComplexity,cognitiveComplexity:r.cognitiveComplexity,callCount:i.callCount,parameterCount:c(e),callees:i.callees,identifiers:l(e)}}(e,n,t)),i=function(e){const t=function(e){const t=new Map;for(const n of e)n.name&&t.set(n.name,t.has(n.name)?void 0:n.index);return new Map([...t.entries()].filter(e=>void 0!==e[1]))}(e),n=new Set(t.keys()),r=new Map,i=new Map,o=new Map;let a=0,s=0;const c=new Set;for(const u of e){a+=u.callCount;for(const e of u.callees)c.add(e);const e=new Set([...u.callees].filter(e=>n.has(e))),l=new Set;for(const n of e){const e=t.get(n);void 0!==e&&l.add(e)}o.set(u.index,l),i.set(u.index,e.size),s+=e.size;for(const e of l)r.set(e,(r.get(e)??0)+1)}const u=function(e){const t=new Set;for(const n of e.keys())Z(n,n,e,new Set)&&t.add(n);return t}(o);return{fanInByIndex:r,fanOutByIndex:i,recursiveIndexes:u,metrics:{callCount:a,uniqueCalleeCount:c.size,internalCallCount:s,internalEdgeCount:se([...o.values()].map(e=>e.size)),recursiveFunctionCount:u.size,maxFanIn:ae(r),maxFanOut:ae(i),maxCallDepth:ee(o)}}}(r);return{functions:r.map(e=>({name:e.name,startLine:e.startLine,startColumn:e.startColumn,endLine:e.endLine,returnsJsx:e.returnsJsx,cyclomaticComplexity:e.cyclomaticComplexity,cognitiveComplexity:e.cognitiveComplexity,callCount:e.callCount,uniqueCalleeCount:e.callees.size,fanIn:i.fanInByIndex.get(e.index)??0,fanOut:i.fanOutByIndex.get(e.index)??0,parameterCount:e.parameterCount,recursive:i.recursiveIndexes.has(e.index)})),callGraph:i.metrics,coupling:v(e,n),module:C(e,n),cohesion:N(r),syntaxFeatures:S(e),typeComplexity:b(e)}}(s,f(s,new Set(o.functionNodeTypes)),o),m=d.functions,y=u(s,o,0,!1),h=function(e,t){const n=0===e.length?[]:e.split(/\r\n|\n|\r/),r=function(e){const t=[];function n(e){if("comment"===e.type||"line_comment"===e.type||"block_comment"===e.type)for(let n=e.startPosition.row;n<=e.endPosition.row;n+=1)t.push({line:n,startColumn:n===e.startPosition.row?e.startPosition.column:0,endColumn:n===e.endPosition.row?e.endPosition.column:Number.POSITIVE_INFINITY});for(const t of e.namedChildren)n(t)}return n(e),t}(t);let i=0,o=0;for(const[e,t]of n.entries())""!==t.trim()?P(t,e,r)&&(o+=1):i+=1;return{total:n.length,code:n.length-i-o,comment:o,blank:i}}(t,s),_=function(e,t){const n=new Map,o=new Map;function a(e){if("comment"!==e.type){if(0===e.childCount){const a=t.slice(e.startIndex,e.endIndex);return void(r.has(a)||r.has(e.type)?ie(n,a||e.type):i.has(e.type)&&ie(o,a))}r.has(e.type)&&ie(n,e.type);for(const t of e.children)a(t)}}a(e);const s=n.size,c=o.size,u=se(n.values()),l=se(o.values()),f=s+c,p=u+l,d=0===f?0:p*Math.log2(f),m=0===c?0:s/2*(l/c),y=m*d;return{distinctOperators:s,distinctOperands:c,totalOperators:u,totalOperands:l,vocabulary:f,length:p,volume:d,difficulty:m,effort:y,time:y/18,bugs:d/3e3}}(s,t);return{language:o.name,bytes:Buffer.byteLength(t),lines:h,functions:m,classCount:f(s,new Set(o.classNodeTypes)).length,functionCount:m.length,cyclomaticComplexity:y.cyclomaticComplexity,maxCyclomaticComplexity:oe(m,"cyclomaticComplexity"),cognitiveComplexity:y.cognitiveComplexity,maxCognitiveComplexity:oe(m,"cognitiveComplexity"),nestingDepth:y.nestingDepth,callGraph:d.callGraph,coupling:d.coupling,module:d.module,cohesion:d.cohesion,syntaxFeatures:d.syntaxFeatures,typeComplexity:d.typeComplexity,duplication:I(s),halstead:_,maintainabilityIndex:re(_.volume,y.cyclomaticComplexity,h.code),syntaxTree:n.includeSyntaxTree?s.toString():void 0}}}const a=new o;function s(e,t){return a.measure(e,t)}function c(e){const t=e.childForFieldName("parameters")??e.namedChildren.find(e=>"formal_parameters"===e.type||"parameter_list"===e.type);return t?t.namedChildren.filter(e=>"comment"!==e.type&&"self_parameter"!==e.type).length:0}function u(e,t,r,i){let o=1,a=0,s=r;const c=new Set(t.functionNodeTypes),u=new Set(t.decisionNodeTypes),l=new Set(t.nestingNodeTypes);function f(e,t,r){if(i&&c.has(e.type))return;const p=u.has(e.type),d=l.has(e.type);p&&(o+=1,a+=1+t),function(e){if(e.isNamed)return!1;return n.has(e.text)}(e)&&(o+=1,a+=1);const m=d?t+1:t;s=Math.max(s,m);for(const t of e.children)f(t,m)}for(const t of e.children)f(t,r);return{cyclomaticComplexity:o,cognitiveComplexity:a,nestingDepth:s}}function l(e){const t=new Set;return function e(n){"identifier"!==n.type&&"property_identifier"!==n.type&&"field_identifier"!==n.type||t.add(n.text);for(const t of n.namedChildren)e(t)}(e),t}function f(e,t){const n=[];return function e(r){t.has(r.type)&&n.push(r);for(const t of r.namedChildren)e(t)}(e),n}function p(e,t){const n=new Set(t.functionNodeTypes);return function t(r,i){if(!i&&n.has(r.type))return!1;if("return_statement"===r.type)return m(r,n)||y(r,n);if("arrow_function"===e.type&&r===d(e)&&"statement_block"!==r.type&&!n.has(r.type))return m(r,n)||y(r,n);for(const e of r.namedChildren)if(t(e,!1))return!0;return!1}(e,!0)}function d(e){return e.childForFieldName("body")??e.namedChild(e.namedChildCount-1)??void 0}function m(e,t){return h(e,t,e=>e.type.startsWith("jsx_")||function(e,t){if(!A(e)||!function(e){if(!e)return!1;const t=O(e);return"map"===t||"flatMap"===t}(e.childForFieldName("function")??e.namedChild(0)))return!1;return e.namedChildren.some(e=>_(e,t))}(e,t))}function y(e,t){return h(e,t,B)}function h(e,t,n){return function e(r,i){if(!i&&t.has(r.type))return!1;if(n(r))return!0;for(const t of r.namedChildren)if(e(t,!1))return!0;return!1}(e,!0)}function _(e,t){return t.has(e.type)?function(e,t){const n="arrow_function"===e.type?d(e):void 0;if(n&&"statement_block"!==n.type&&!t.has(n.type))return m(n,t)||y(n,t);return function(e,t,n){function r(e,i){if(!i&&t.has(e.type))return!1;if("return_statement"===e.type&&n(e))return!0;for(const t of e.namedChildren)if(r(t,!1))return!0;return!1}return r(e,!0)}(e,t,e=>m(e,t)||y(e,t))}(e,t):e.namedChildren.some(e=>_(e,t))}function C(e,t){const n=new Set;return function e(r){if(j(r))for(const e of R(r,t,{expandPythonSubmodules:!0}))n.add(e);for(const t of r.namedChildren)e(t)}(e),{declarations:x(e),importSources:[...n]}}function x(e){const t=function(e){const t=new Set;function n(e,r){if(!r&&function(e){return"export_specifier"===e.type||"namespace_export"===e.type}(e)){const n=function(e){const t=e.childForFieldName("name")??e.childForFieldName("alias")??e.namedChildren.find(F);return t&&F(t)?t.text:void 0}(e);n&&t.add(n)}const i=r||w(e)&&null!==e.childForFieldName("source");for(const t of e.namedChildren)n(t,i)}return n(e,!1),t}(e);return e.namedChildren.flatMap(e=>g(e,!1)).map(e=>t.has(e.name)?{...e,exported:!0}:e)}function g(e,t){return w(e)?e.namedChildren.flatMap(e=>g(e,!0)):function(e){return"lexical_declaration"===e.type||"variable_declaration"===e.type||"decorated_definition"===e.type||"type_declaration"===e.type||"const_declaration"===e.type||"var_declaration"===e.type||"var_spec_list"===e.type}(e)?e.namedChildren.flatMap(e=>g(e,t)):function(e,t){if(!function(e){return"function_declaration"===e.type||"function_definition"===e.type||"function_item"===e.type||"method_declaration"===e.type||"class_declaration"===e.type||"class_definition"===e.type||"interface_declaration"===e.type||"type_alias_declaration"===e.type||"type_declaration"===e.type||"type_spec"===e.type||"const_spec"===e.type||"var_spec"===e.type||"variable_declarator"===e.type||"struct_item"===e.type||"enum_item"===e.type||"union_item"===e.type||"trait_item"===e.type||"type_item"===e.type||"const_item"===e.type||"static_item"===e.type||"mod_item"===e.type}(e))return[];const n=function(e){if("method_declaration"===e.type)return function(e){const t=e.childForFieldName("name"),n=e.childForFieldName("receiver")?.namedChildren[0]?.childForFieldName("type");if(!t||!F(t)||!n)return t&&F(t)?t.text:void 0;return`${r=n.text,r.replaceAll(/\s+/gu,"").replace(/^\*+/u,"")}.${t.text}`;var r}(e);const t=e.childForFieldName("name");if(t)return F(t)?t.text:void 0;return e.namedChildren.find(F)?.text}(e);return n?[{exported:t,name:n,startLine:e.startPosition.row+1}]:[]}(e,t)}function w(e){return"export_statement"===e.type||"export_declaration"===e.type}function F(e){return"identifier"===e.type||"type_identifier"===e.type||"property_identifier"===e.type||"field_identifier"===e.type}function v(e,t){const n=new Set;let r=0,i=0;!function e(o){if((E(o)||D(o))&&(r+=1),j(o))for(const e of R(o,t,{expandPythonSubmodules:!1}))n.add(e);X(o)&&(i+=1);for(const t of o.namedChildren)e(t)}(e);const o=[...n].filter(e=>function(e,t){if(e.startsWith(".")||e.startsWith("/"))return!0;return"rust"===t&&function(e){return/^(?:crate|self|super)(?:::|$)/u.test(e)}(e)}(e,t.name)).length;return{importCount:r,importSourceCount:n.size,relativeImportCount:o,externalImportCount:n.size-o,exportCount:i}}function S(e){const t={assignmentCount:0,awaitExpressionCount:0,loopStatementCount:0,mutableBindingCount:0,returnStatementCount:0,throwStatementCount:0,tryStatementCount:0};return function e(n){(function(e){return"assignment_expression"===e.type||"augmented_assignment_expression"===e.type||"assignment_statement"===e.type||"assignment"===e.type||"augmented_assignment"===e.type||"short_var_declaration"===e.type||"compound_assignment_expr"===e.type})(n)&&(t.assignmentCount+=1),function(e){return"await_expression"===e.type||"await"===e.type}(n)&&(t.awaitExpressionCount+=1),function(e){return"for_statement"===e.type||"for_in_statement"===e.type||"while_statement"===e.type||"do_statement"===e.type||"for_expression"===e.type||"while_expression"===e.type||"loop_expression"===e.type}(n)&&(t.loopStatementCount+=1),function(e){return"lexical_declaration"===e.type&&"let"===e.firstChild?.text||"variable_declaration"===e.type&&"var"===e.firstChild?.text||"var_declaration"===e.type||"let_declaration"===e.type&&function(e){if(e.children.some(e=>"mutable_specifier"===e.type))return!0;const t=e.childForFieldName("pattern");if(!t)return!1;return t.descendantsOfType("mutable_specifier").some(e=>"reference_pattern"!==e.parent?.type)}(e)}(n)&&(t.mutableBindingCount+=1),function(e){return"return_statement"===e.type||"return_expression"===e.type}(n)&&(t.returnStatementCount+=1),function(e){return"throw_statement"===e.type||"raise_statement"===e.type}(n)&&(t.throwStatementCount+=1),function(e){return"try_statement"===e.type}(n)&&(t.tryStatementCount+=1);for(const t of n.namedChildren)e(t)}(e),t}function N(e){const t=new Set,n=new Set;let r=0,i=0;for(const n of e)for(const e of n.identifiers)t.add(e);for(let t=0;t<e.length;t+=1)for(let o=t+1;o<e.length;o+=1){const a=e[t],s=e[o];if(!a||!s)continue;const c=ne(a.identifiers,s.identifiers),u=new Set([...a.identifiers,...s.identifiers]).size;for(const e of c)n.add(e);r+=0===u?0:c.size/u,i+=1}return{averageFunctionIdentifierOverlap:0===i?1:r/i,sharedIdentifierCount:n.size,uniqueIdentifierCount:t.size}}function b(e){const t={typeAnnotationCount:0,typeAliasCount:0,interfaceCount:0,genericParameterCount:0,unionTypeCount:0,intersectionTypeCount:0,conditionalTypeCount:0,typeAssertionCount:0,nonNullAssertionCount:0,satisfiesExpressionCount:0};return function e(n){switch(n.type){case"type_annotation":t.typeAnnotationCount+=1;break;case"type_alias_declaration":t.typeAliasCount+=1;break;case"interface_declaration":t.interfaceCount+=1;break;case"type_parameters":case"type_parameter":t.genericParameterCount+="type_parameter"===n.type?1:0;break;case"union_type":t.unionTypeCount+=1;break;case"intersection_type":t.intersectionTypeCount+=1;break;case"conditional_type":t.conditionalTypeCount+=1;break;case"as_expression":case"type_assertion":t.typeAssertionCount+=1;break;case"non_null_expression":t.nonNullAssertionCount+=1;break;case"satisfies_expression":t.satisfiesExpressionCount+=1}for(const t of n.namedChildren)e(t)}(e),t}const M=new Set(["statement_block","block","if_statement","for_statement","for_in_statement","while_statement","do_statement","try_statement","with_statement","switch_statement","switch_case","case_clause","match_statement","match_arm","except_clause","catch_clause","finally_clause","elif_clause","expression_statement","return_statement","return_expression","if_expression","for_expression","while_expression","loop_expression","match_expression","jsx_element","jsx_self_closing_element"]),z=24;function I(e){const t=[],n=new Map;!function e(r){if(M.has(r.type)){const{size:e}=k(r,n);if(e>=z){const{shape:i}=k(r,n);t.push({node:r,shape:i,size:e})}}for(const t of r.namedChildren)e(t)}(e);const r=new Map;for(const e of t){const t=r.get(e.shape)??[];t.push(e),r.set(e.shape,t)}const i=[];let o=0,a=0;const s=new Map;for(const[e,t]of r)if(!(t.length<2))for(const n of t.toSorted((e,t)=>t.size-e.size))i.some(e=>T(e,n.node))||(i.push(n.node),s.set(e,(s.get(e)??0)+1),a=Math.max(a,n.size));let c=0;for(const e of s.values())e>=2&&(o+=e-1,c+=1);return{duplicateBlockCount:o,duplicateBlockGroupCount:c,maxDuplicateBlockSize:a}}function k(e,t){const n=t.get(e.id);if(n)return n;let r=e.type,i=1;if(e.namedChildCount>0){const n=[];for(const r of e.namedChildren){const e=k(r,t);n.push(e.shape),i+=e.size}r=`${e.type}(${n.join(",")})`}const o={shape:r,size:i};return t.set(e.id,o),o}function T(e,t){let n=t.parent;for(;n;){if(n.id===e.id)return!0;n=n.parent}return!1}function P(e,t,n){const r=n.filter(e=>e.line===t);if(0===r.length)return!1;const i=e.search(/\S/),o=e.trimEnd().length;return r.some(e=>e.startColumn<=i&&e.endColumn>=o)}function $(e){const t=function(e){let t=e;for(;t;){const e=t.parent,n=e?.parent;if("arguments"!==e?.type||"call_expression"!==n?.type)return;if(!L(n))return;const r=n.parent;if("variable_declarator"===r?.type)return r.childForFieldName("name")?.text;t=n}return}(e);if(t)return t;const n=e.childForFieldName("name");if(n)return n.text;const r=e.parent;if(!r)return;if("closure_expression"===e.type&&"let_declaration"===r.type){const e=r.childForFieldName("pattern");return"identifier"===e?.type?e.text:void 0}const i=r.childForFieldName("name");return i?.text}function L(e){const t=e.childForFieldName("function")??e.namedChild(0);return"memo"===t?.text||"React.memo"===t?.text||"forwardRef"===t?.text||"React.forwardRef"===t?.text}function A(e){return"call_expression"===e.type||"call"===e.type||"macro_invocation"===e.type}function O(e){if("identifier"===e.type||"property_identifier"===e.type||"field_identifier"===e.type||"attribute"===e.type)return e.text;for(let t=e.namedChildCount-1;t>=0;t-=1){const n=e.namedChild(t);if(!n)continue;const r=O(n);if(r)return r}}function B(e){if(!A(e))return!1;const t=e.childForFieldName("function")??e.namedChild(0);return"React.createElement"===t?.text||"createElement"===t?.text}function E(e){return"import_statement"===e.type||"import_declaration"===e.type||"import_from_statement"===e.type||"import_spec"===e.type||"import_spec_list"===e.type||"use_declaration"===e.type||"extern_crate_declaration"===e.type}function j(e){return E(e)||D(e)||X(e)&&null!==e.childForFieldName("source")}function D(e){if(!A(e))return!1;const t=e.childForFieldName("function")??e.namedChild(0);return"import"===t?.text}function R(e,t,n){if("python"===t.name){const t=function(e,t){if("import_from_statement"===e.type){const n=e.childForFieldName("module_name");if(!n)return[];const r=Y(n.text),i=function(e,t){const n=[];for(let r=0;r<e.childCount;r+=1){const i=e.child(r);i&&e.fieldNameForChild(r)===t&&n.push(i)}return n}(e,"name");if(!t.expandPythonSubmodules||!r.startsWith("."))return[r];if(/^\.+$/u.test(r)&&i.length>0)return i.flatMap(U).map(e=>`${r}${e}`);const o=i.flatMap(U).map(e=>`${r}.${e}`);return o.length>0?[r,...o]:[r]}if("import_statement"!==e.type)return[];return e.namedChildren.map(e=>V(e)).filter(e=>void 0!==e)}(e,n);if(t.length>0)return t}if("rust"===t.name)return function(e){if("extern_crate_declaration"===e.type){const t=e.childForFieldName("name");return t?[Y(t.text)]:[]}const t=e.childForFieldName("argument");return t?W(t,""):[]}(e);if(D(e))return function(e){const t=e.childForFieldName("arguments"),n=t?.namedChild(0);return n&&K(n)?[Q(n.text)]:[]}(e);const r=e.childForFieldName("source")??H(e);return r?[Q(r.text)]:[]}function W(e,t){switch(e.type){case"use_list":return e.namedChildren.flatMap(e=>W(e,t));case"scoped_use_list":{const n=e.childForFieldName("list"),r=q(t,G(e.childForFieldName("path")));return n?W(n,r):J(r)}case"scoped_identifier":return J(q(t,G(e.childForFieldName("path"))));case"use_wildcard":return J(q(t,G(e.namedChild(0))));case"use_as_clause":{const n=e.childForFieldName("path");return n?W(n,t):[]}case"self":return J(t);case"identifier":case"crate":case"super":return J(""===t?Y(e.text):t);default:return[]}}function G(e){return e?Y(e.text):""}function q(e,t){return t?e?`${e}::${t}`:t:e}function J(e){return e?[e]:[]}function U(e){if("aliased_import"===e.type){const t=e.childForFieldName("name");return t?U(t):[]}return"identifier"===e.type?[e.text]:"dotted_name"===e.type?[Y(e.text)]:e.namedChildren.flatMap(U)}function V(e){if("dotted_name"===e.type||"relative_import"===e.type)return Y(e.text);const t=e.childForFieldName("name");if(t)return Y(t.text);for(const t of e.namedChildren){const e=V(t);if(e)return e}}function Y(e){return e.replaceAll(/\s+/gu,"")}function H(e){if(K(e))return e;for(const t of e.namedChildren){const e=H(t);if(e)return e}}function K(e){return"string"===e.type||"string_literal"===e.type||"interpreted_string_literal"===e.type}function Q(e){return e.replaceAll(/^['"`]|['"`]$/gu,"")}function X(e){return e.type.startsWith("export")||"public_field_definition"===e.type}function Z(e,t,n,r){const i=n.get(e);if(!i)return!1;for(const e of i){if(e===t)return!0;if(!r.has(e)&&(r.add(e),Z(e,t,n,r)))return!0}return!1}function ee(e){let t=0;for(const n of e.keys())t=Math.max(t,te(n,e,new Set));return t}function te(e,t,n){const r=t.get(e);if(!r||0===r.size||n.has(e))return 0;n.add(e);let i=0;for(const e of r)i=Math.max(i,1+te(e,t,new Set(n)));return i}function ne(e,t){const n=new Set;for(const r of e)t.has(r)&&n.add(r);return n}function re(e,t,n){if(0===n)return 100;const r=171-5.2*Math.log(Math.max(e,1))-.23*t-16.2*Math.log(n);return Math.max(0,Math.min(100,100*r/171))}function ie(e,t){e.set(t,(e.get(t)??0)+1)}function oe(e,t){return 0===e.length?0:Math.max(...e.map(e=>e[t]))}function ae(e){let t=0;for(const n of e.values())t=Math.max(t,n);return t}function se(e){let t=0;for(const n of e)t+=n;return t}export{o as TreeMeasurer,a as defaultMeasurer,s as measureCode};
2
- //# sourceMappingURL=metrics.js.map
1
+ import{createLanguageRegistry as e}from"./languages.js";import{measureDuplication as t}from"./duplication.js";import n from"tree-sitter";const r=new Set([`&&`,`||`,`and`,`or`]),i=new Set(`+,-,*,/,%,**,=,+=,-=,*=,/=,%=,==,!=,===,!==,<,<=,>,>=,!,~,&,|,^,++,--,<<,>>,>>>,=>,**=,<<=,>>=,>>>=,&=,|=,^=,&&=,||=,??=,??,?.,?,//,//=,@,@=,:=,<-,<=>,=~,..,...,..=,&&,||,!~,&^,&^=,&.,.,->,::,->*,.*,sizeof,alignof,defined?,as,bitand,bitor,xor,compl,and_eq,or_eq,xor_eq,not_eq,and,or,not,in,is,instanceof,typeof,new,delete,return,throw,raise,yield,await,co_await,co_yield,co_return,break,continue`.split(`,`)),a=new Set(`identifier.property_identifier.field_identifier.type_identifier.constant.instance_variable.class_variable.global_variable.simple_symbol.self.this.super.primitive_type.boolean_type.void_type.auto.number.integer.float.integer_literal.float_literal.int_literal.rune_literal.imaginary_literal.number_literal.decimal_integer_literal.hex_integer_literal.octal_integer_literal.binary_integer_literal.decimal_floating_point_literal.hex_floating_point_literal.string.string_literal.raw_string_literal.string_fragment.multiline_string_fragment.string_content.raw_string_content.template_string.character_literal.char_literal.character.true.false.null.null_literal.undefined.nil.none`.split(`.`)),o=new Set([`interpreted_string_literal`,`regex`,`user_defined_literal`,`integral_type`,`floating_point_type`,`sized_type_specifier`,`placeholder_type_specifier`]);var s=class{registry=e();registerLanguage(e){this.registry.set(e.name,e);for(let t of e.aliases??[])this.registry.set(t,e)}getSupportedLanguages(){return[...new Set([...this.registry.values()].map(e=>e.name))]}measure(e,r){let i=this.registry.get(r.language);if(!i)throw Error(`Unsupported language: ${r.language}`);let a=new n;a.setLanguage(i.parserLanguage);let o=a.parse(e,void 0,{bufferSize:e.length+1}).rootNode,s=u(o,b(o,new Set(i.functionNodeTypes)).filter(e=>!_(e)&&te(e)),i),c=s.functions,l=ne(o,i,0,!1),{lines:d,codeLineNumbers:f}=lt(e,o),p=ft(o,e);return{language:i.name,bytes:Buffer.byteLength(e),lines:d,functions:c,classCount:ge(o,i),functionCount:c.length,cyclomaticComplexity:l.cyclomaticComplexity,maxCyclomaticComplexity:Xt(c,`cyclomaticComplexity`),cognitiveComplexity:l.cognitiveComplexity,maxCognitiveComplexity:Xt(c,`cognitiveComplexity`),nestingDepth:l.nestingDepth,callGraph:s.callGraph,coupling:s.coupling,module:s.module,cohesion:s.cohesion,syntaxFeatures:s.syntaxFeatures,typeComplexity:s.typeComplexity,duplication:t(o,f),halstead:p,maintainabilityIndex:Yt(p.volume,l.cyclomaticComplexity,d.code),syntaxTree:r.includeSyntaxTree?o.toString():void 0}}};const c=new s;function l(e,t){return c.measure(e,t)}function u(e,t,n){let r=pe(e,n),i=t.map((e,t)=>d(e,n,t,r)),a=h(i);return{functions:i.map(e=>({name:e.name,startLine:e.startLine,startColumn:e.startColumn,endLine:e.endLine,returnsJsx:e.returnsJsx,cyclomaticComplexity:e.cyclomaticComplexity,cognitiveComplexity:e.cognitiveComplexity,nestingDepth:e.nestingDepth,callCount:e.callCount,uniqueCalleeCount:e.callees.size,fanIn:a.fanInByIndex.get(e.index)??0,fanOut:a.fanOutByIndex.get(e.index)??0,parameterCount:e.parameterCount,recursive:a.recursiveIndexes.has(e.index)})),callGraph:a.metrics,coupling:qe(e,n),module:Ee(e,n),cohesion:st(i),syntaxFeatures:Je(e,n.name),typeComplexity:ct(e)}}function d(e,t,n,r){let i=ne(e,t,0,!0),a=ce(e,t,r);return{index:n,name:pt(e),startLine:e.startPosition.row+1,startColumn:e.startPosition.column,endLine:e.endPosition.row+1,returnsJsx:ve(e,t),cyclomaticComplexity:i.cyclomaticComplexity,cognitiveComplexity:i.cognitiveComplexity,nestingDepth:i.nestingDepth,callCount:a.callCount,parameterCount:f(e),callees:a.callees,identifiers:he(e)}}function f(e){if(e.childForFieldName(`parameter`))return 1;let t=m(e);if(!t)return 0;if(t.type===`identifier`)return 1;let n=new Set(J(t,`locals`).map(e=>e.id));return $(t.namedChildren.filter(e=>e.type!==`comment`&&e.type!==`self_parameter`&&e.type!==`receiver_parameter`&&e.type!==`positional_separator`&&e.type!==`keyword_separator`&&!n.has(e.id)&&!p(e)).map(e=>e.type===`parameter_declaration`?Math.max(1,J(e,`name`).length):1))+t.children.filter(e=>!e.isNamed&&e.text===`...`).length}function p(e){return e.type===`parameter_declaration`&&e.childForFieldName(`declarator`)===null&&e.childForFieldName(`type`)?.text===`void`}function m(e){let t=e.childForFieldName(`parameters`);if(t)return t;if(e.type===`compact_constructor_declaration`)return e.parent?.parent?.childForFieldName(`parameters`)??void 0;let n=e.childForFieldName(`declarator`);for(;n;){let e=n.childForFieldName(`parameters`);if(e)return e;n=I(n)}return e.namedChildren.find(e=>e.type===`formal_parameters`||e.type===`parameter_list`)}function h(e){let t=g(e),n=new Set(t.keys()),r=new Map,i=new Map,a=new Map,o=0,s=0,c=new Set;for(let l of e){o+=l.callCount;for(let e of l.callees)c.add(e);let e=new Set([...l.callees].filter(e=>n.has(e))),u=new Set;for(let n of e){let e=t.get(n);e!==void 0&&u.add(e)}a.set(l.index,u),i.set(l.index,e.size),s+=e.size;for(let e of u)r.set(e,(r.get(e)??0)+1)}let l=Wt(a);return{fanInByIndex:r,fanOutByIndex:i,recursiveIndexes:l,metrics:{callCount:o,uniqueCalleeCount:c.size,internalCallCount:s,internalEdgeCount:$([...a.values()].map(e=>e.size)),recursiveFunctionCount:l.size,maxFanIn:Q(r),maxFanOut:Q(i),maxCallDepth:Kt(a)}}}function g(e){let t=new Map;for(let n of e)n.name&&t.set(n.name,t.has(n.name)?void 0:n.index);return new Map([...t.entries()].filter(e=>e[1]!==void 0))}const ee=new Set([`function_definition`,`method_declaration`,`constructor_declaration`,`compact_constructor_declaration`,`function_signature_item`]);function te(e){return!ee.has(e.type)||e.childForFieldName(`body`)!==null?!0:e.namedChildren.some(e=>e.type===`try_statement`)}function _(e){return(e.type===`block`||e.type===`do_block`)&&e.parent?.type===`lambda`}function v(e,t){return t.has(e.type)&&!_(e)}function ne(e,t,n,r){let i=1,a=0,o=n,s=new Set(t.functionNodeTypes),c=new Set(t.decisionNodeTypes),l=new Set(t.nestingNodeTypes);function u(e,t,n){if(r&&!n&&v(e,s))return;let d=e.isNamed&&c.has(e.type)&&!ae(e),f=e.isNamed&&l.has(e.type)&&!ae(e),p=d&&ie(e);d&&(i+=1,a+=p?1:1+t),se(e)&&(i+=1,a+=1),re(e)&&(i+=1,a+=1);let m=f&&!p?t+1:t;o=Math.max(o,m);for(let t of e.children)u(t,m,!1)}for(let t of e.children)u(t,n,!1);return{cyclomaticComplexity:i,cognitiveComplexity:a,nestingDepth:o}}function re(e){return e.isNamed?e.type===`guard`||e.type===`if_guard`||e.type===`unless_guard`||e.type===`if_clause`?!0:e.type===`match_pattern`&&e.children.some(e=>!e.isNamed&&e.type===`if`):!1}function ie(e){if(e.type===`elsif`||e.type===`elif_clause`)return!0;if(e.type!==`if_statement`&&e.type!==`if_expression`&&e.type!==`if`)return!1;let t=e.parent;return t?t.type===`else_clause`||t.childForFieldName(`alternative`)?.id===e.id:!1}function ae(e){if(e.type===`case_statement`)return e.childForFieldName(`value`)===null;if(e.type===`switch_block_statement_group`||e.type===`switch_rule`){let t=e.namedChildren.find(e=>e.type===`switch_label`);return t!==void 0&&t.namedChildCount===0}if(e.type===`case_clause`||e.type===`match_arm`){let t=e.namedChildren.find(e=>e.type===`case_pattern`||e.type===`match_pattern`);if(!t)return!1;if(t.child(0)?.type===`_`&&(t.childCount===1||t.child(1)?.type===`if`))return!0;let n=t.namedChildCount===1?t.namedChild(0):void 0;return e.type===`case_clause`&&n?.type===`dotted_name`&&n.namedChildCount===1&&n.namedChild(0)?.type===`identifier`}return e.type===`in_clause`?e.namedChild(0)?.type===`identifier`:!1}const oe=new Set([`binary_expression`,`binary`,`boolean_operator`]);function se(e){if(e.isNamed||!r.has(e.text))return!1;let t=e.parent;return t!==null&&oe.has(t.type)}function ce(e,t,n=new Set){let r=new Set,i=new Set(t.functionNodeTypes),a=0;function o(e,s){if(!(!s&&v(e,i))){if(!(t.name===`cpp`&&ue(e)))if(L(e)){a+=1;let i=t.name===`cpp`&&(e.type===`new_expression`||e.type===`call_expression`&&n.has(y(e.childForFieldName(`function`))??``))?void 0:Ct(e);if(i&&r.add(i),t.name===`ruby`&&e.type===`call`&&e.parent?.type===`operator_assignment`&&e.parent.childForFieldName(`left`)?.id===e.id){a+=1;let t=e.childForFieldName(`method`);t&&r.add(`${t.text}=`)}}else(me(e,t)||de(e,n))&&(a+=1);for(let t of e.namedChildren)o(t,!1)}}return o(e,!0),{callCount:a,callees:r}}const le=new Set([`static_cast`,`dynamic_cast`,`const_cast`,`reinterpret_cast`]);function ue(e){if(e.type!==`call_expression`)return!1;let t=e.childForFieldName(`function`);if(t?.type===`primitive_type`)return!0;let n=t?.type===`template_function`?t.childForFieldName(`name`)?.text:t?.text;return n!==void 0&&le.has(n)}function de(e,t){if(t.size===0)return!1;if(e.type===`compound_literal_expression`)return t.has(y(e.childForFieldName(`type`))??``);if(e.type===`init_declarator`){let n=e.childForFieldName(`value`);return n?.type!==`argument_list`&&n?.type!==`initializer_list`?!1:t.has(y(e.parent?.childForFieldName(`type`))??``)}if((e.type===`identifier`||e.type===`array_declarator`)&&e.parent?.type===`declaration`&&J(e.parent,`declarator`).some(t=>t.id===e.id)&&!E(e.parent,`extern`)){let n=e;for(;n?.type===`array_declarator`;)n=n.childForFieldName(`declarator`);return n?.type===`identifier`&&t.has(y(e.parent.childForFieldName(`type`))??``)}if(e.type===`field_initializer`){let n=e.namedChild(0),r=n?.type===`field_identifier`?n.text:y(n);return t.has(r??``)}return!1}function y(e){let t=e;for(;t;){if(t.type===`type_identifier`||t.type===`identifier`)return t.text;if(t.type===`qualified_identifier`||t.type===`scoped_identifier`||t.type===`template_type`||t.type===`template_function`){t=t.childForFieldName(`name`);continue}return}}const fe=new Set([`class_specifier`,`struct_specifier`,`union_specifier`]);function pe(e,t){let n=new Set;if(t.name!==`cpp`)return n;for(let t of b(e,fe)){let e=t.childForFieldName(`name`)?.text;e&&t.childForFieldName(`body`)&&n.add(e)}return n}function me(e,t){return t.name===`ruby`?e.type===`yield`||e.type===`super`&&e.parent?.type!==`call`:!1}function he(e){let t=new Set;function n(e){(e.type===`identifier`||e.type===`property_identifier`||e.type===`field_identifier`||e.type===`constant`||e.type===`instance_variable`||e.type===`class_variable`||e.type===`global_variable`)&&t.add(e.text);for(let t of e.namedChildren)n(t)}return n(e),t}function ge(e,t){return b(e,new Set(t.classNodeTypes)).filter(_e).length}function _e(e){return e.type===`object_creation_expression`||e.type===`enum_constant`?e.namedChildren.some(e=>e.type===`class_body`):!e.type.endsWith(`_specifier`)||e.childForFieldName(`body`)!==null}function b(e,t){let n=[];function r(e){t.has(e.type)&&n.push(e);for(let t of e.namedChildren)r(t)}return r(e),n}function ve(e,t){let n=new Set(t.functionNodeTypes);function r(t,i){if(!i&&n.has(t.type))return!1;if(t.type===`return_statement`||e.type===`arrow_function`&&t===ye(e)&&t.type!==`statement_block`&&!n.has(t.type))return x(t,n)||S(t,n);for(let e of t.namedChildren)if(r(e,!1))return!0;return!1}return r(e,!0)}function ye(e){return e.childForFieldName(`body`)??e.namedChild(e.namedChildCount-1)??void 0}function x(e,t){return be(e,t,e=>e.type.startsWith(`jsx_`)||xe(e,t))}function S(e,t){return be(e,t,Dt)}function be(e,t,n){function r(e,i){if(!i&&t.has(e.type))return!1;if(n(e))return!0;for(let t of e.namedChildren)if(r(t,!1))return!0;return!1}return r(e,!0)}function xe(e,t){return!L(e)||!Se(e.childForFieldName(`function`)??e.namedChild(0))?!1:e.namedChildren.some(e=>Ce(e,t))}function Se(e){if(!e)return!1;let t=R(e);return t===`map`||t===`flatMap`}function Ce(e,t){return t.has(e.type)?we(e,t):e.namedChildren.some(e=>Ce(e,t))}function we(e,t){let n=e.type===`arrow_function`?ye(e):void 0;return n&&n.type!==`statement_block`&&!t.has(n.type)?x(n,t)||S(n,t):Te(e,t,e=>x(e,t)||S(e,t))}function Te(e,t,n){function r(e,i){if(!i&&t.has(e.type))return!1;if(e.type===`return_statement`&&n(e))return!0;for(let t of e.namedChildren)if(r(t,!1))return!0;return!1}return r(e,!0)}function Ee(e,t){let n=new Set;function r(e){if(kt(e,t))for(let r of jt(e,t,{expandPythonSubmodules:!0}))n.add(r);for(let t of e.namedChildren)r(t)}return r(e),{declarations:De(e,t),importSources:[...n]}}function De(e,t){let n=He(e),r=t.name===`java`?Oe(e):``;return e.namedChildren.flatMap(e=>w(e,!1,r,t.name===`cpp`)).map(e=>n.has(e.name)?{...e,exported:!0}:e)}function Oe(e){let t=e.namedChildren.find(e=>e.type===`package_declaration`)?.namedChildren.find(e=>e.type===`scoped_identifier`||e.type===`identifier`);return t?`${t.text}::`:``}const C=new Set([`module`,`class`,`singleton_class`]);function w(e,t,n=``,r=!1){if(O(e))return e.namedChildren.flatMap(e=>w(e,!0,n,r));if(e.type===`namespace_definition`){let i=e.childForFieldName(`name`)?.text;return i?(e.childForFieldName(`body`)?.namedChildren??[]).flatMap(e=>w(e,t,`${n}${i}::`,r)):[]}return Be(e)?e.namedChildren.flatMap(e=>w(e,t,n,r)):e.type===`declaration`?T(Ie(e,t,r),n):e.type===`type_definition`?T(je(e,t),n):C.has(e.type)?ke(e,t,n):e.type===`assignment`||e.type===`operator_assignment`?T(Ae(e,t),n,!0):T(D(e,t),n)}function T(e,t,n=!1){return t?e.map(e=>n&&e.name.includes(`::`)?e:{...e,name:`${t}${e.name}`}):e}function ke(e,t,n=``){let r=T(D(e,t),n,!0),i=r[0]?`${r[0].name}::`:n,a=e.childForFieldName(`body`);for(let e of a?.namedChildren??[])C.has(e.type)?r.push(...ke(e,t,i)):(e.type===`assignment`||e.type===`operator_assignment`)&&r.push(...T(Ae(e,t),i,!0));return r}function Ae(e,t){if(e.type===`operator_assignment`&&!e.children.some(e=>!e.isNamed&&e.text===`||=`))return[];let n=e.childForFieldName(`left`);return n?(n.type===`left_assignment_list`?n.namedChildren:[n]).filter(e=>e.type===`constant`||e.type===`scope_resolution`&&e.childForFieldName(`name`)?.type===`constant`).map(e=>({exported:t,name:e.text,startLine:e.startPosition.row+1})):[]}function je(e,t){let n=e.childForFieldName(`type`),r=n?D(n,t):[],i=n?.type.endsWith(`_specifier`)&&!n.childForFieldName(`body`)?n.childForFieldName(`name`)?.text:void 0,a=new Set(r.map(e=>e.name));for(let n of J(e,`declarator`)){let e=n.type===`type_identifier`?n.text:F(n);e&&e!==i&&!a.has(e)&&(a.add(e),r.push({exported:t,name:e,startLine:n.startPosition.row+1}))}return r}const Me=new Set([`init_declarator`,`pointer_declarator`,`array_declarator`,`reference_declarator`,`identifier`,`field_identifier`]);function Ne(e){if(e.type===`pointer_declarator`||e.type===`reference_declarator`){let t=e;for(;t&&(t.type===`pointer_declarator`||t.type===`reference_declarator`||t.type===`array_declarator`);)t=I(t);return t?.type===`function_declarator`?t.childForFieldName(`declarator`)?.type===`parenthesized_declarator`:!0}return Me.has(e.type)?!0:e.type===`function_declarator`&&e.childForFieldName(`declarator`)?.type===`parenthesized_declarator`}function E(e,t){return e.children.some(e=>e.type===`storage_class_specifier`&&e.text===t)}function Pe(e){let t=e.childForFieldName(`type`);return t?.type!==`type_identifier`||t.text!==`import`&&t.text!==`export`&&t.text!==`module`?!1:!Fe(e,t.text)}function Fe(e,t){let n=e;for(;n.parent;)n=n.parent;return b(n,new Set([`type_definition`,`alias_declaration`])).some(e=>(e.childForFieldName(`declarator`)??e.childForFieldName(`name`))?.text===t)}function Ie(e,t,n=!1){if(n&&Pe(e)||E(e,`static`))return[];let r=e.childForFieldName(`type`),i=r?D(r,t):[],a=new Set(i.map(e=>e.name)),o=E(e,`extern`);for(let r of e.namedChildren.filter(Ne)){if(o&&r.type!==`init_declarator`||n&&!o&&!E(e,`inline`)&&!Le(r)&&!N(e,r))continue;let s=F(r);s&&!a.has(s)&&(a.add(s),i.push({exported:t,name:s,startLine:r.startPosition.row+1}))}return i}function Le(e){let t=e.type===`init_declarator`?e.childForFieldName(`declarator`)??e:e;for(;t;){if(t.type===`reference_declarator`)return!0;t=I(t)}return!1}function D(e,t){if(!Ve(e)||e.type.endsWith(`_specifier`)&&!e.childForFieldName(`body`)||E(e,`static`))return[];if(e.type===`enum_specifier`)return Re(e,t);let n=ze(e);return n?[{exported:t,name:n,startLine:e.startPosition.row+1}]:[]}function Re(e,t){let n=[],r=e.childForFieldName(`name`)?.text;r&&n.push({exported:t,name:r,startLine:e.startPosition.row+1});let i=e.children.some(e=>!e.isNamed&&(e.text===`class`||e.text===`struct`));for(let a of e.childForFieldName(`body`)?.namedChildren??[]){if(a.type!==`enumerator`)continue;let e=a.childForFieldName(`name`)?.text;e&&n.push({exported:t,name:i&&r?`${r}::${e}`:e,startLine:a.startPosition.row+1})}return n}function ze(e){if(e.type===`method_declaration`&&e.childForFieldName(`receiver`))return Ge(e);let t=e.childForFieldName(`name`);return t?.type===`template_type`&&(t=t.childForFieldName(`name`)),t?.type===`scope_resolution`?t.text:t?k(t)?t.text:void 0:F(e.childForFieldName(`declarator`),!0)||e.namedChildren.find(k)?.text}function O(e){return e.type===`export_statement`||e.type===`export_declaration`}function Be(e){return e.type===`lexical_declaration`||e.type===`variable_declaration`||e.type===`decorated_definition`||e.type===`type_declaration`||e.type===`const_declaration`||e.type===`var_declaration`||e.type===`var_spec_list`||e.type===`linkage_specification`||e.type===`template_declaration`||e.type===`declaration_list`||e.type===`preproc_ifdef`||e.type===`preproc_if`||e.type===`preproc_else`||e.type===`preproc_elif`}function Ve(e){return e.type===`function_declaration`||e.type===`function_definition`||e.type===`function_item`||e.type===`method_declaration`||e.type===`class_declaration`||e.type===`class_definition`||e.type===`interface_declaration`||e.type===`type_alias_declaration`||e.type===`type_declaration`||e.type===`type_spec`||e.type===`const_spec`||e.type===`var_spec`||e.type===`variable_declarator`||e.type===`struct_item`||e.type===`enum_item`||e.type===`union_item`||e.type===`trait_item`||e.type===`type_item`||e.type===`const_item`||e.type===`static_item`||e.type===`mod_item`||e.type===`enum_declaration`||e.type===`record_declaration`||e.type===`annotation_type_declaration`||e.type===`method`||e.type===`singleton_method`||e.type===`class`||e.type===`module`||e.type===`alias_declaration`||e.type===`struct_specifier`||e.type===`class_specifier`||e.type===`enum_specifier`||e.type===`union_specifier`}function k(e){return e.type===`identifier`||e.type===`type_identifier`||e.type===`property_identifier`||e.type===`field_identifier`||e.type===`constant`}function He(e){let t=new Set;function n(e,r){if(!r&&Ue(e)){let n=We(e);n&&t.add(n)}let i=r||O(e)&&e.childForFieldName(`source`)!==null;for(let t of e.namedChildren)n(t,i)}return n(e,!1),t}function Ue(e){return e.type===`export_specifier`||e.type===`namespace_export`}function We(e){let t=e.childForFieldName(`name`)??e.childForFieldName(`alias`)??e.namedChildren.find(k);return t&&k(t)?t.text:void 0}function Ge(e){let t=e.childForFieldName(`name`),n=e.childForFieldName(`receiver`)?.namedChildren[0]?.childForFieldName(`type`);return!t||!k(t)||!n?t&&k(t)?t.text:void 0:`${Ke(n.text)}.${t.text}`}function Ke(e){return e.replaceAll(/\s+/gu,``).replace(/^\*+/u,``)}function qe(e,t){let n=new Set,r=0,i=0;function a(e){if(!(t.name===`go`&&(e.type===`import_declaration`||e.type===`import_spec_list`))&&(Ot(e)||At(e,t)||z(e,t)||B(e)||V(e,t))&&(r+=1),kt(e,t))for(let r of jt(e,t,{expandPythonSubmodules:!1}))n.add(r);Ut(e)&&(i+=1);for(let t of e.namedChildren)a(t)}a(e);let o=[...n].filter(e=>Lt(e,t.name)).length;return{importCount:r,importSourceCount:n.size,relativeImportCount:o,externalImportCount:n.size-o,exportCount:i}}function Je(e,t){let n={assignmentCount:0,awaitExpressionCount:0,loopStatementCount:0,mutableBindingCount:0,returnStatementCount:0,throwStatementCount:0,tryStatementCount:0};function r(e){Ye(e)&&(n.assignmentCount+=1),Xe(e)&&(n.awaitExpressionCount+=1),Ze(e)&&(n.loopStatementCount+=1),n.mutableBindingCount+=Qe(e,t),nt(e)&&(n.returnStatementCount+=1),rt(e)&&(n.throwStatementCount+=1),at(e)&&(n.tryStatementCount+=1);for(let t of e.namedChildren)r(t)}return r(e),n}function Ye(e){return e.type===`assignment_expression`||e.type===`augmented_assignment_expression`||e.type===`assignment_statement`||e.type===`assignment`||e.type===`augmented_assignment`||e.type===`operator_assignment`||e.type===`short_var_declaration`||e.type===`compound_assignment_expr`||e.type===`named_expression`||e.type===`update_expression`||e.type===`inc_statement`||e.type===`dec_statement`}function Xe(e){return e.type===`await_expression`||e.type===`await`||e.type===`co_await_expression`}function Ze(e){return e.type===`for_statement`||e.type===`for_in_statement`||e.type===`enhanced_for_statement`||e.type===`for_range_loop`||e.type===`while_statement`||e.type===`do_statement`||e.type===`for_expression`||e.type===`while_expression`||e.type===`loop_expression`||e.type===`while`||e.type===`until`||e.type===`for`||e.type===`while_modifier`||e.type===`until_modifier`}function Qe(e,t){let n=t===`c`||t===`cpp`;if(e.type===`local_variable_declaration`||e.type===`field_declaration`&&t===`java`){let t=e.namedChildren.filter(e=>e.type===`variable_declarator`);return M(e)?t.length:0}if(n&&(e.type===`declaration`||e.type===`field_declaration`))return A(e,t===`cpp`);if(n&&e.type===`function_definition`){let n=e.childForFieldName(`declarator`);return n?.type===`field_identifier`||n?.type===`identifier`?A(e,t===`cpp`):0}if(e.type===`enhanced_for_statement`)return+!!M(e);if(t===`java`&&(e.type===`instanceof_expression`||e.type===`type_pattern`||e.type===`record_pattern_component`)){let t=e.type===`instanceof_expression`?e.childForFieldName(`name`)!==null:e.namedChildren.some(e=>e.type===`identifier`),n=e.children.some(e=>!e.isNamed&&e.text===`final`);return t&&!n?1:0}if(n&&e.type===`for_range_loop`){let t=e.childForFieldName(`declarator`);return t&&N(e,t)?j(t):0}return+!!$e(e)}function A(e,t){return t&&Pe(e)?0:$(e.namedChildren.filter(t=>Ne(t)&&N(e,t)).map(j))}function j(e){let t=e.type===`init_declarator`?e.childForFieldName(`declarator`)??e:e;return t.type===`structured_binding_declarator`?Math.max(1,t.namedChildren.filter(e=>e.type===`identifier`).length):1}function $e(e){return e.type===`lexical_declaration`&&e.firstChild?.text===`let`||e.type===`variable_declaration`&&e.firstChild?.text===`var`||e.type===`var_declaration`||e.type===`let_declaration`&&tt(e)}function M(e){return!e.namedChildren.find(e=>e.type===`modifiers`)?.children.some(e=>e.text===`final`)}function N(e,t){let n=t.type===`init_declarator`?t.childForFieldName(`declarator`)??t:t,r=!1;for(;n.type===`reference_declarator`||n.type===`pointer_declarator`||n.type===`array_declarator`||n.type===`parenthesized_declarator`||n.type===`function_declarator`;){if(n.type===`reference_declarator`)return!1;let e=I(n);if(!e)break;if(n.type===`pointer_declarator`&&(r=!0,P(n)&&!et(e)))return!1;n=e}return r||!P(e)}function et(e){let t=e;for(;t;){if(t.type===`pointer_declarator`)return!0;t=I(t)}return!1}function P(e){return e.namedChildren.some(e=>e.type===`type_qualifier`&&(e.text===`const`||e.text===`constexpr`))}function tt(e){if(e.children.some(e=>e.type===`mutable_specifier`))return!0;let t=e.childForFieldName(`pattern`);return t?t.descendantsOfType(`mutable_specifier`).some(e=>e.parent?.type!==`reference_pattern`):!1}function nt(e){return e.type===`return_statement`||e.type===`return_expression`||e.type===`return`||e.type===`co_return_statement`}function rt(e){return e.type===`throw_statement`||e.type===`raise_statement`||it(e)}function it(e){if(e.type!==`call`||e.childForFieldName(`receiver`))return!1;let t=e.childForFieldName(`method`);return t?.type===`identifier`&&(t.text===`raise`||t.text===`fail`)}function at(e){return e.type===`try_statement`||e.type===`try_with_resources_statement`||e.type===`rescue_modifier`||ot(e)}function ot(e){return(e.type===`begin`||e.type===`body_statement`)&&e.namedChildren.some(e=>e.type===`rescue`||e.type===`ensure`)}function st(e){let t=new Map;for(let n of e)for(let e of n.identifiers)t.set(e,(t.get(e)??0)+1);let n=0;for(let e of t.values())e>=2&&(n+=1);let r=e.length,i=r*(r-1)/2,a=Math.max(1,Math.ceil(i/25e4)),o=0,s=0,c=0,l=0,u=r-1;for(let t=0;t<i;t+=a){for(;t>=l+u;)l+=u,c+=1,u=r-1-c;let n=c+1+(t-l),i=e[c],a=e[n];if(!i||!a)continue;let d=Jt(i.identifiers,a.identifiers),f=i.identifiers.size+a.identifiers.size-d;o+=f===0?0:d/f,s+=1}return{averageFunctionIdentifierOverlap:s===0?1:o/s,sharedIdentifierCount:n,uniqueIdentifierCount:t.size}}function ct(e){let t={typeAnnotationCount:0,typeAliasCount:0,interfaceCount:0,genericParameterCount:0,unionTypeCount:0,intersectionTypeCount:0,conditionalTypeCount:0,typeAssertionCount:0,nonNullAssertionCount:0,satisfiesExpressionCount:0};function n(e){switch(e.type){case`type_annotation`:t.typeAnnotationCount+=1;break;case`type_alias_declaration`:t.typeAliasCount+=1;break;case`interface_declaration`:t.interfaceCount+=1;break;case`type_parameters`:case`type_parameter`:t.genericParameterCount+=+(e.type===`type_parameter`);break;case`union_type`:t.unionTypeCount+=1;break;case`intersection_type`:t.intersectionTypeCount+=1;break;case`conditional_type`:t.conditionalTypeCount+=1;break;case`as_expression`:case`type_assertion`:t.typeAssertionCount+=1;break;case`non_null_expression`:t.nonNullAssertionCount+=1;break;case`satisfies_expression`:t.satisfiesExpressionCount+=1;break}for(let t of e.namedChildren)n(t)}return n(e),t}function lt(e,t){let n=e.length===0?[]:e.split(/\r\n|\n|\r/),r=new Map;for(let e of ut(t)){let t=r.get(e.line)??[];t.push(e),r.set(e.line,t)}let i=0,a=0,o=new Set;for(let[e,t]of n.entries()){if(t.trim()===``){i+=1;continue}dt(t,r.get(e)??[])?a+=1:o.add(e+1)}return{lines:{total:n.length,code:o.size,comment:a,blank:i},codeLineNumbers:o}}function ut(e){let t=[];function n(e){if(e.type===`comment`||e.type===`line_comment`||e.type===`block_comment`)for(let n=e.startPosition.row;n<=e.endPosition.row;n+=1)t.push({line:n,startColumn:n===e.startPosition.row?e.startPosition.column:0,endColumn:n===e.endPosition.row?e.endPosition.column:1/0});for(let t of e.namedChildren)n(t)}return n(e),t}function dt(e,t){if(t.length===0)return!1;for(let n=0;n<e.length;n+=1)if(!/\s/u.test(e[n]??` `)&&!t.some(e=>e.startColumn<=n&&n<e.endColumn))return!1;return!0}function ft(e,t){let n=new Map,r=new Map;function s(e){if(!(e.type===`comment`||e.type===`line_comment`||e.type===`block_comment`)){if(o.has(e.type)){Z(r,t.slice(e.startIndex,e.endIndex));return}if(e.childCount===0){let o=t.slice(e.startIndex,e.endIndex);a.has(e.type)?Z(r,o):(i.has(o)||i.has(e.type))&&Et(e,o)&&Z(n,o||e.type);return}for(let t of e.children)s(t)}}s(e);let c=n.size,l=r.size,u=$(n.values()),d=$(r.values()),f=c+l,p=u+d,m=f===0?0:p*Math.log2(f),h=l===0?0:c/2*(d/l),g=h*m;return{distinctOperators:c,distinctOperands:l,totalOperators:u,totalOperands:d,vocabulary:f,length:p,volume:m,difficulty:h,effort:g,time:g/18,bugs:m/3e3}}function pt(e){let t=yt(e);if(t)return t;let n=e.childForFieldName(`name`);if(n)return n.text;let r=mt(e);if(r)return r;let i=e.parent;if(i){if(e.type===`closure_expression`&&i.type===`let_declaration`){let e=i.childForFieldName(`pattern`);return e?.type===`identifier`?e.text:void 0}return e.type===`lambda_expression`&&i.type===`init_declarator`?F(i.childForFieldName(`declarator`)):e.type===`func_literal`&&i.type===`expression_list`?_t(e,i):e.type===`lambda`&&i.type===`assignment`?ht(i):(e.type===`block`||e.type===`do_block`)&&gt(i)?i.parent?.type===`assignment`?ht(i.parent):void 0:i.childForFieldName(`name`)?.text}}function mt(e){return F(e.childForFieldName(`declarator`))}function F(e,t=!1){let n=e,r=``;for(;n;)switch(n.type){case`identifier`:case`field_identifier`:case`type_identifier`:case`destructor_name`:case`operator_name`:return r?`${r}::${n.text}`:n.text;case`operator_cast`:{let e=`operator ${n.childForFieldName(`type`)?.text??``}`.trimEnd();return r?`${r}::${e}`:e}case`template_function`:n=n.childForFieldName(`name`);break;case`qualified_identifier`:if(t){let e=n.childForFieldName(`scope`)?.text.replaceAll(/\s+/gu,``);e&&(r=r?`${r}::${e}`:e)}n=n.childForFieldName(`name`);break;default:n=I(n)}}function I(e){let t=e.childForFieldName(`declarator`);if(t)return t;if(e.type===`reference_declarator`||e.type===`parenthesized_declarator`)return e.namedChild(0)??void 0}function ht(e){let t=e.childForFieldName(`left`);return t?.type===`identifier`||t?.type===`constant`?t.text:void 0}function gt(e){if(e.type!==`call`||e.childForFieldName(`receiver`))return!1;let t=e.childForFieldName(`method`);return t?.type===`identifier`&&(t.text===`lambda`||t.text===`proc`)}function _t(e,t){let n=t.parent,r=t.namedChildren.filter(e=>e.type!==`comment`).findIndex(t=>t.id===e.id);if(!(!n||r===-1)){if(n.type===`short_var_declaration`){let e=n.childForFieldName(`left`)?.namedChildren.filter(e=>e.type!==`comment`);return vt(e?.[r])}if(n.type===`var_spec`){let e=J(n,`name`)[r];return vt(e)}}}function vt(e){return e?.type===`identifier`&&e.text!==`_`?e.text:void 0}function yt(e){let t=e;for(;t;){let e=t.parent,n=e?.parent;if(e?.type!==`arguments`||n?.type!==`call_expression`||!bt(n))return;let r=n.parent;if(r?.type===`variable_declarator`)return r.childForFieldName(`name`)?.text;t=n}}function bt(e){let t=e.childForFieldName(`function`)??e.namedChild(0);return t?.text===`memo`||t?.text===`React.memo`||t?.text===`forwardRef`||t?.text===`React.forwardRef`}function L(e){return e.type===`call_expression`||e.type===`call`||e.type===`method_invocation`||e.type===`macro_invocation`||e.type===`new_expression`||e.type===`object_creation_expression`||e.type===`explicit_constructor_invocation`}function xt(e){for(let t of e.children)if(t.type===`ERROR`){let e=t.children.find(e=>e.type===`operator_name`);if(e)return e.text}let t=e.childForFieldName(`function`);if(t?.type===`field_expression`){let e=t.children.findIndex(e=>e.type===`ERROR`&&e.text===`operator`),n=e===-1?void 0:t.children[e+1];if(n?.type===`field_identifier`||n?.type===`primitive_type`)return`operator ${n.text}`}}const St=new Set([`arrow_function`,`function_expression`,`function`,`lambda`,`lambda_expression`,`closure_expression`,`func_literal`,`anonymous_function`]);function Ct(e){if(e.type===`call`){let t=e.childForFieldName(`method`),n=e.childForFieldName(`receiver`);if(t?.text===`call`&&n?.type===`identifier`)return n.text;if(t&&e.parent?.type===`assignment`&&e.parent.childForFieldName(`left`)?.id===e.id)return`${t.text}=`;if(t?.type===`operator`)return t.text}if(e.type===`call_expression`){let t=xt(e);if(t)return t}let t=e.childForFieldName(`function`)??e.childForFieldName(`name`)??e.childForFieldName(`method`)??e.childForFieldName(`constructor`)??e.childForFieldName(`type`)??e.namedChild(0);if(!t)return;let n=wt(t);if(!St.has(n.type))return R(n)}function wt(e){let t=e;for(;t.type===`parenthesized_expression`&&t.namedChildCount===1;){let e=t.namedChild(0);if(!e)break;t=e}return t}const Tt=new Set([`ternary_expression`,`conditional_expression`,`conditional`,`try_expression`,`conditional_type`]);function Et(e,t){if(t===`@`){let t=e.parent?.type;return t===`binary_operator`||t===`augmented_assignment`}if(t!==`?`)return!0;let n=e.parent?.type;return n!==void 0&&Tt.has(n)}function R(e){if(e.type===`generic_function`||e.type===`template_function`||e.type===`template_method`){let t=e.childForFieldName(`function`)??e.childForFieldName(`name`);if(t)return R(t)}if(e.type===`destructor_name`)return e.text;if(e.type===`generic_type`){let t=e.namedChildren.find(e=>e.type===`type_identifier`||e.type===`scoped_type_identifier`);if(t)return R(t)}if(e.type===`identifier`||e.type===`property_identifier`||e.type===`field_identifier`||e.type===`type_identifier`||e.type===`attribute`)return e.text;for(let t=e.namedChildCount-1;t>=0;--t){let n=e.namedChild(t);if(!n)continue;let r=R(n);if(r)return r}}function Dt(e){if(!L(e))return!1;let t=e.childForFieldName(`function`)??e.namedChild(0);return t?.text===`React.createElement`||t?.text===`createElement`}function Ot(e){return e.type===`import_statement`||e.type===`import_declaration`||e.type===`import_from_statement`||e.type===`import_spec`||e.type===`import_spec_list`||e.type===`use_declaration`||e.type===`extern_crate_declaration`||e.type===`requires_module_directive`||e.type===`preproc_include`}function kt(e,t){return Ot(e)||At(e,t)||z(e,t)||B(e)||V(e,t)||Ut(e)&&e.childForFieldName(`source`)!==null}function z(e,t){if(t.name!==`cpp`)return!1;if(e.type===`declaration`){let t=e.childForFieldName(`type`);return t?.type===`type_identifier`?t.text===`import`?!Fe(e,`import`):t.text===`export`&&/^export\s+import\b/u.test(e.text):!1}return e.type===`labeled_statement`||e.type===`expression_statement`?e.parent?.type===`translation_unit`&&/^import\s+[:"<]/u.test(e.text):!1}function At(e,t){return t.name===`rust`&&e.type===`mod_item`&&!e.childForFieldName(`body`)}function B(e){return L(e)?(e.childForFieldName(`function`)??e.namedChild(0))?.text===`import`:!1}function jt(e,t,n){if(t.name===`python`){let t=zt(e,n);if(t.length>0)return t}if(t.name===`rust`)return Rt(e);if(t.name===`java`&&e.type===`requires_module_directive`){let t=e.childForFieldName(`module`);return t?[Y(t.text)]:[]}if(t.name===`java`&&e.type===`import_declaration`){let t=e.namedChild(0);if(!t)return[];let n=e.children.some(e=>e.type===`static`),r=e.namedChildren.some(e=>e.type===`asterisk`),i=Y(t.text);return[r&&!n?`${i}.*`:i]}if(z(e,t)){let t=/^(?:export\s+)?import\s+([\w.:]+|"[^"]+"|<[^>]+>)/u.exec(e.text)?.[1];return t?t.startsWith(`"`)?[`./${X(t)}`]:[t]:[]}if(V(e,t))return Nt(e);if(e.type===`preproc_include`){let t=e.childForFieldName(`path`);if(!t)return[];let n=X(t.text);return[t.type===`string_literal`&&!n.startsWith(`.`)&&!n.startsWith(`/`)?`./${n}`:n]}if(B(e))return It(e);let r=e.childForFieldName(`source`)??Vt(e);return r?[X(r.text)]:[]}const Mt=new Set([`require`,`require_relative`,`load`]);function V(e,t){if(t.name!==`ruby`||e.type!==`call`)return!1;let n=e.childForFieldName(`method`);if(n?.type!==`identifier`)return!1;if(n.text===`autoload`){let t=e.childForFieldName(`receiver`);return t===null||t.type===`constant`||t.type===`scope_resolution`}return e.childForFieldName(`receiver`)===null&&Mt.has(n.text)}function Nt(e){let t=e.childForFieldName(`arguments`),n=e.childForFieldName(`method`)?.text===`autoload`,r=t?.namedChild(+!!n);if(!r||r.type!==`string`||r.namedChildren.some(e=>e.type===`interpolation`))return[];let i=r.namedChildren.filter(e=>e.type===`string_content`||e.type===`escape_sequence`),a=i.length>0?i.map(e=>e.type===`escape_sequence`?Ft(e.text):e.text).join(``):X(r.text);return e.childForFieldName(`method`)?.text===`require_relative`?[a.startsWith(`.`)?a:`./${a}`]:[a.replace(/^(?:\.\.?\/)+/u,``)]}const Pt=new Map([[`n`,`
2
+ `],[`t`,` `],[`r`,`\r`],[`s`,` `],[`0`,`\0`]]);function Ft(e){let t=e.slice(1);return Pt.get(t)??t}function It(e){let t=e.childForFieldName(`arguments`)?.namedChild(0);return t&&Ht(t)?[X(t.text)]:[]}function Lt(e,t){return e.startsWith(`.`)||e.startsWith(`/`)?!0:t===`rust`&&H(e)}function H(e){return/^(?:crate|self|super)(?:::|$)/u.test(e)}function Rt(e){if(e.type===`mod_item`){let t=e.childForFieldName(`name`);return t?[`self::${Y(t.text)}`]:[]}if(e.type===`extern_crate_declaration`){let t=e.childForFieldName(`name`);return t?[Y(t.text)]:[]}let t=e.childForFieldName(`argument`);return t?U(t,``):[]}function U(e,t){switch(e.type){case`use_list`:return e.namedChildren.flatMap(e=>U(e,t));case`scoped_use_list`:{let n=e.childForFieldName(`list`),r=G(t,W(e.childForFieldName(`path`)));return n?U(n,r):K(r)}case`scoped_identifier`:{let n=G(t,Y(e.text));return H(n)?K(n):K(G(t,W(e.childForFieldName(`path`))))}case`use_wildcard`:return K(G(t,W(e.namedChild(0))));case`use_as_clause`:{let n=e.childForFieldName(`path`);return n?U(n,t):[]}case`self`:return K(t);case`identifier`:case`crate`:case`super`:return e.type===`identifier`&&H(t)?K(G(t,Y(e.text))):K(t===``?Y(e.text):t);default:return[]}}function W(e){return e?Y(e.text):``}function G(e,t){return t?e?`${e}::${t}`:t:e}function K(e){return e?[e]:[]}function zt(e,t){if(e.type===`import_from_statement`){let n=e.childForFieldName(`module_name`);if(!n)return[];let r=Y(n.text),i=J(e,`name`);if(!t.expandPythonSubmodules||!r.startsWith(`.`))return[r];if(/^\.+$/u.test(r)&&i.length>0)return i.flatMap(q).map(e=>`${r}${e}`);let a=i.flatMap(q).map(e=>`${r}.${e}`);return a.length>0?[r,...a]:[r]}return e.type===`import_statement`?e.namedChildren.map(e=>Bt(e)).filter(e=>e!==void 0):[]}function q(e){if(e.type===`aliased_import`){let t=e.childForFieldName(`name`);return t?q(t):[]}return e.type===`identifier`?[e.text]:e.type===`dotted_name`?[Y(e.text)]:e.namedChildren.flatMap(q)}function J(e,t){let n=[];for(let r=0;r<e.childCount;r+=1){let i=e.child(r);i&&e.fieldNameForChild(r)===t&&n.push(i)}return n}function Bt(e){if(e.type===`dotted_name`||e.type===`relative_import`)return Y(e.text);let t=e.childForFieldName(`name`);if(t)return Y(t.text);for(let t of e.namedChildren){let e=Bt(t);if(e)return e}}function Y(e){return e.replaceAll(/\s+/gu,``)}function Vt(e){if(Ht(e))return e;for(let t of e.namedChildren){let e=Vt(t);if(e)return e}}function Ht(e){return e.type===`string`||e.type===`string_literal`||e.type===`interpreted_string_literal`}function X(e){return e.replaceAll(/^['"`<]|['"`>]$/gu,``)}function Ut(e){return e.type.startsWith(`export`)&&e.type!==`exports_module_directive`||e.type===`public_field_definition`}function Wt(e){let t=new Set;for(let n of e.keys())Gt(n,n,e,new Set)&&t.add(n);return t}function Gt(e,t,n,r){let i=n.get(e);if(!i)return!1;for(let e of i)if(e===t||!r.has(e)&&(r.add(e),Gt(e,t,n,r)))return!0;return!1}function Kt(e){let t=new Map,n=0;for(let r of e.keys())n=Math.max(n,qt(r,e,new Set,t).depth);return n}function qt(e,t,n,r){let i=r.get(e);if(i!==void 0)return{depth:i,tainted:!1};let a=t.get(e);if(!a||a.size===0)return{depth:0,tainted:!1};if(n.has(e))return{depth:0,tainted:!0};n.add(e);let o=0,s=!1;for(let e of a){let i=qt(e,t,n,r);o=Math.max(o,1+i.depth),s||=i.tainted}return n.delete(e),s||r.set(e,o),{depth:o,tainted:s}}function Jt(e,t){let[n,r]=e.size<=t.size?[e,t]:[t,e],i=0;for(let e of n)r.has(e)&&(i+=1);return i}function Yt(e,t,n){if(n===0)return 100;let r=171-5.2*Math.log(Math.max(e,1))-.23*t-16.2*Math.log(n);return Math.max(0,Math.min(100,r*100/171))}function Z(e,t){e.set(t,(e.get(t)??0)+1)}function Xt(e,t){return e.length===0?0:Math.max(...e.map(e=>e[t]))}function Q(e){let t=0;for(let n of e.values())t=Math.max(t,n);return t}function $(e){let t=0;for(let n of e)t+=n;return t}export{s as TreeMeasurer,c as defaultMeasurer,l as measureCode};
3
+ //# sourceMappingURL=metrics.js.map