code-gauge 1.11.0 → 1.12.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/README.md +4 -1
- package/dist/cli.cjs +3 -3
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/cliConfig.cjs +1 -1
- package/dist/cliConfig.js +1 -1
- package/dist/languages.cjs +1 -1
- package/dist/languages.cjs.map +1 -1
- package/dist/languages.js +1 -1
- package/dist/languages.js.map +1 -1
- package/dist/metrics.cjs +2 -2
- package/dist/metrics.cjs.map +1 -1
- package/dist/metrics.js +2 -2
- package/dist/metrics.js.map +1 -1
- package/dist/ncss.cjs +2 -0
- package/dist/ncss.cjs.map +1 -0
- package/dist/ncss.d.ts +11 -0
- package/dist/ncss.js +2 -0
- package/dist/ncss.js.map +1 -0
- package/dist/types.d.ts +22 -0
- package/package.json +20 -19
package/dist/metrics.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{createLanguageRegistry as e}from"./languages.js";import{measureDuplication as t}from"./duplication.js";import{measureWithNativeBackend as n}from"./nativeMetrics.js";import r from"tree-sitter";const i=new Set([`&&`,`||`,`and`,`or`]),a=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(`,`)),o=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(`.`)),s=new Set([`interpreted_string_literal`,`regex`,`user_defined_literal`,`integral_type`,`floating_point_type`,`sized_type_specifier`,`placeholder_type_specifier`]);var c=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,i){let a=this.registry.get(i.language);if(!a)throw Error(`Unsupported language: ${i.language}`);let o=n(e,a,i.includeSyntaxTree??!1);if(o)return d(o,i.includeSyntaxTree??!1);let s=new r;s.setLanguage(a.parserLanguage);let c=s.parse(e,void 0,{bufferSize:e.length+1}).rootNode,l=f(c,y(c,new Set(a.functionNodeTypes)).filter(e=>!g(e)&&ie(e)),a),u=l.functions,p=ae(c,a,0,!1),{lines:m,codeLineNumbers:ee}=dt(e,c),h=mt(c,e);return{language:a.name,bytes:Buffer.byteLength(e),lines:m,functions:u,classCount:ye(c,a),functionCount:u.length,cyclomaticComplexity:p.cyclomaticComplexity,maxCyclomaticComplexity:Qt(u,`cyclomaticComplexity`),cognitiveComplexity:p.cognitiveComplexity,maxCognitiveComplexity:Qt(u,`cognitiveComplexity`),nestingDepth:p.nestingDepth,callGraph:l.callGraph,coupling:l.coupling,module:l.module,cohesion:l.cohesion,syntaxFeatures:l.syntaxFeatures,typeComplexity:l.typeComplexity,duplication:t(c,ee),halstead:h,maintainabilityIndex:Zt(h.volume,p.cyclomaticComplexity,m.code),syntaxTree:i.includeSyntaxTree?c.toString():void 0}}};const l=new c;function u(e,t){return l.measure(e,t)}function d(e,t){let n=ht(e.halsteadCounts);return{language:e.language,bytes:e.bytes,lines:e.lines,functions:e.functions.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.uniqueCalleeCount,fanIn:e.fanIn,fanOut:e.fanOut,parameterCount:e.parameterCount,recursive:e.recursive})),classCount:e.classCount,functionCount:e.functionCount,cyclomaticComplexity:e.cyclomaticComplexity,maxCyclomaticComplexity:e.maxCyclomaticComplexity,cognitiveComplexity:e.cognitiveComplexity,maxCognitiveComplexity:e.maxCognitiveComplexity,nestingDepth:e.nestingDepth,callGraph:e.callGraph,coupling:e.coupling,module:e.module,cohesion:e.cohesion,syntaxFeatures:e.syntaxFeatures,typeComplexity:e.typeComplexity,duplication:e.duplication,halstead:n,maintainabilityIndex:Zt(n.volume,e.cyclomaticComplexity,e.lines.code),syntaxTree:t?e.syntaxTree:void 0}}function f(e,t,n){let r=ge(e,n),i=t.map((e,t)=>p(e,n,t,r)),a=te(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:Ge(e,n),module:Oe(e,n),cohesion:lt(i),syntaxFeatures:Ke(e,n.name),typeComplexity:ut(e)}}function p(e,t,n,r){let i=ae(e,t,0,!0),a=de(e,t,r);return{index:n,name:gt(e),startLine:e.startPosition.row+1,startColumn:e.startPosition.column,endLine:e.endPosition.row+1,returnsJsx:xe(e,t),cyclomaticComplexity:i.cyclomaticComplexity,cognitiveComplexity:i.cognitiveComplexity,nestingDepth:i.nestingDepth,callCount:a.callCount,parameterCount:m(e),callees:a.callees,identifiers:ve(e)}}function m(e){if(e.childForFieldName(`parameter`))return 1;let t=h(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)&&!ee(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 ee(e){return e.type===`parameter_declaration`&&e.childForFieldName(`declarator`)===null&&e.childForFieldName(`type`)?.text===`void`}function h(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 te(e){let t=ne(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=Kt(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:$t(r),maxFanOut:$t(i),maxCallDepth:Jt(a)}}}function ne(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 re=new Set([`function_definition`,`method_declaration`,`constructor_declaration`,`compact_constructor_declaration`,`function_signature_item`]);function ie(e){return!re.has(e.type)||e.childForFieldName(`body`)!==null?!0:e.namedChildren.some(e=>e.type===`try_statement`)}function g(e){return(e.type===`block`||e.type===`do_block`)&&e.parent?.type===`lambda`}function _(e,t){return t.has(e.type)&&!g(e)}function ae(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&&_(e,s))return;let d=e.isNamed&&c.has(e.type)&&!ce(e),f=e.isNamed&&l.has(e.type)&&!ce(e),p=d&&se(e);d&&(i+=1,a+=p?1:1+t),ue(e)&&(i+=1,a+=1),oe(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 oe(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 se(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 ce(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 le=new Set([`binary_expression`,`binary`,`boolean_operator`]);function ue(e){if(e.isNamed||!i.has(e.text))return!1;let t=e.parent;return t!==null&&le.has(t.type)}function de(e,t,n=new Set){let r=new Set,i=new Set(t.functionNodeTypes),a=0;function o(e,s){if(!(!s&&_(e,i))){if(!(t.name===`cpp`&&pe(e)))if(L(e)){a+=1;let i=t.name===`cpp`&&(e.type===`new_expression`||e.type===`call_expression`&&n.has(v(e.childForFieldName(`function`))??``))?void 0:Et(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(_e(e,t)||me(e,n))&&(a+=1);for(let t of e.namedChildren)o(t,!1)}}return o(e,!0),{callCount:a,callees:r}}const fe=new Set([`static_cast`,`dynamic_cast`,`const_cast`,`reinterpret_cast`]);function pe(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&&fe.has(n)}function me(e,t){if(t.size===0)return!1;if(e.type===`compound_literal_expression`)return t.has(v(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(v(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)&&!k(e.parent,`extern`)){let n=e;for(;n?.type===`array_declarator`;)n=n.childForFieldName(`declarator`);return n?.type===`identifier`&&t.has(v(e.parent.childForFieldName(`type`))??``)}if(e.type===`field_initializer`){let n=e.namedChild(0),r=n?.type===`field_identifier`?n.text:v(n);return t.has(r??``)}return!1}function v(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 he=new Set([`class_specifier`,`struct_specifier`,`union_specifier`]);function ge(e,t){let n=new Set;if(t.name!==`cpp`)return n;for(let t of y(e,he)){let e=t.childForFieldName(`name`)?.text;e&&t.childForFieldName(`body`)&&n.add(e)}return n}function _e(e,t){return t.name===`ruby`?e.type===`yield`||e.type===`super`&&e.parent?.type!==`call`:!1}function ve(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 ye(e,t){return y(e,new Set(t.classNodeTypes)).filter(be).length}function be(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 y(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 xe(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.id===Se(e)?.id&&t.type!==`statement_block`&&!n.has(t.type))return b(t,n)||x(t,n);for(let e of t.namedChildren)if(r(e,!1))return!0;return!1}return r(e,!0)}function Se(e){return e.childForFieldName(`body`)??e.namedChild(e.namedChildCount-1)??void 0}function b(e,t){return Ce(e,t,e=>e.type.startsWith(`jsx_`)||we(e,t))}function x(e,t){return Ce(e,t,At)}function Ce(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 we(e,t){return!L(e)||!Te(e.childForFieldName(`function`)??e.namedChild(0))?!1:e.namedChildren.some(e=>S(e,t))}function Te(e){if(!e)return!1;let t=R(e);return t===`map`||t===`flatMap`}function S(e,t){return t.has(e.type)?Ee(e,t):e.namedChildren.some(e=>S(e,t))}function Ee(e,t){let n=e.type===`arrow_function`?Se(e):void 0;return n&&n.type!==`statement_block`&&!t.has(n.type)?b(n,t)||x(n,t):De(e,t,e=>b(e,t)||x(e,t))}function De(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 Oe(e,t){let n=new Set;function r(e){if(Mt(e,t))for(let r of Pt(e,t,{expandPythonSubmodules:!0}))n.add(r);for(let t of e.namedChildren)r(t)}return r(e),{declarations:ke(e,t),importSources:[...n]}}function ke(e,t){let n=Be(e),r=t.name===`java`?Ae(e):``;return e.namedChildren.flatMap(e=>w(e,!1,r,t.name===`cpp`)).map(e=>n.has(e.name)?{...e,exported:!0}:e)}function Ae(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(Le(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 Re(e)?e.namedChildren.flatMap(e=>w(e,t,n,r)):e.type===`declaration`?T(Ne(e,t,r),n):e.type===`type_definition`?T(je(e,t),n):C.has(e.type)?E(e,t,n):e.type===`assignment`||e.type===`operator_assignment`?T(D(e,t),n,!0):T(M(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 E(e,t,n=``){let r=T(M(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(...E(e,t,i)):(e.type===`assignment`||e.type===`operator_assignment`)&&r.push(...T(D(e,t),i,!0));return r}function D(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?M(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 O(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 k(e,t){return e.children.some(e=>e.type===`storage_class_specifier`&&e.text===t)}function A(e){let t=e.childForFieldName(`type`);return t?.type!==`type_identifier`||t.text!==`import`&&t.text!==`export`&&t.text!==`module`?!1:!j(e,t.text)}function j(e,t){let n=e;for(;n.parent;)n=n.parent;return y(n,new Set([`type_definition`,`alias_declaration`])).some(e=>(e.childForFieldName(`declarator`)??e.childForFieldName(`name`))?.text===t)}function Ne(e,t,n=!1){if(n&&A(e)||k(e,`static`))return[];let r=e.childForFieldName(`type`),i=r?M(r,t):[],a=new Set(i.map(e=>e.name)),o=k(e,`extern`);for(let r of e.namedChildren.filter(O)){if(o&&r.type!==`init_declarator`||n&&!o&&!k(e,`inline`)&&!Pe(r)&&!P(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 Pe(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 M(e,t){if(!ze(e)||e.type.endsWith(`_specifier`)&&!e.childForFieldName(`body`)||k(e,`static`))return[];if(e.type===`enum_specifier`)return Fe(e,t);let n=Ie(e);return n?[{exported:t,name:n,startLine:e.startPosition.row+1}]:[]}function Fe(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 Ie(e){if(e.type===`method_declaration`&&e.childForFieldName(`receiver`))return Ue(e);let t=e.childForFieldName(`name`);return t?.type===`template_type`&&(t=t.childForFieldName(`name`)),t?.type===`scope_resolution`?t.text:t?N(t)?t.text:void 0:F(e.childForFieldName(`declarator`),!0)||e.namedChildren.find(N)?.text}function Le(e){return e.type===`export_statement`||e.type===`export_declaration`}function Re(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 ze(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 N(e){return e.type===`identifier`||e.type===`type_identifier`||e.type===`property_identifier`||e.type===`field_identifier`||e.type===`constant`}function Be(e){let t=new Set;function n(e,r){if(!r&&Ve(e)){let n=He(e);n&&t.add(n)}let i=r||Le(e)&&e.childForFieldName(`source`)!==null;for(let t of e.namedChildren)n(t,i)}return n(e,!1),t}function Ve(e){return e.type===`export_specifier`||e.type===`namespace_export`}function He(e){let t=e.childForFieldName(`name`)??e.childForFieldName(`alias`)??e.namedChildren.find(N);return t&&N(t)?t.text:void 0}function Ue(e){let t=e.childForFieldName(`name`),n=e.childForFieldName(`receiver`)?.namedChildren[0]?.childForFieldName(`type`);return!t||!N(t)||!n?t&&N(t)?t.text:void 0:`${We(n.text)}.${t.text}`}function We(e){return e.replaceAll(/\s+/gu,``).replace(/^\*+/u,``)}function Ge(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`))&&(jt(e)||Nt(e,t)||z(e,t)||B(e)||V(e,t))&&(r+=1),Mt(e,t))for(let r of Pt(e,t,{expandPythonSubmodules:!1}))n.add(r);Gt(e)&&(i+=1);for(let t of e.namedChildren)a(t)}a(e);let o=[...n].filter(e=>Bt(e,t.name)).length;return{importCount:r,importSourceCount:n.size,relativeImportCount:o,externalImportCount:n.size-o,exportCount:i}}function Ke(e,t){let n={assignmentCount:0,awaitExpressionCount:0,loopStatementCount:0,mutableBindingCount:0,returnStatementCount:0,throwStatementCount:0,tryStatementCount:0};function r(e){qe(e)&&(n.assignmentCount+=1),Je(e)&&(n.awaitExpressionCount+=1),Ye(e)&&(n.loopStatementCount+=1),n.mutableBindingCount+=Xe(e,t),it(e)&&(n.returnStatementCount+=1),at(e)&&(n.throwStatementCount+=1),st(e)&&(n.tryStatementCount+=1);for(let t of e.namedChildren)r(t)}return r(e),n}function qe(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 Je(e){return e.type===`await_expression`||e.type===`await`||e.type===`co_await_expression`}function Ye(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 Xe(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 et(e)?t.length:0}if(n&&(e.type===`declaration`||e.type===`field_declaration`))return Ze(e,t===`cpp`);if(n&&e.type===`function_definition`){let n=e.childForFieldName(`declarator`);return n?.type===`field_identifier`||n?.type===`identifier`?Ze(e,t===`cpp`):0}if(e.type===`enhanced_for_statement`)return+!!et(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&&P(e,t)?Qe(t):0}return+!!$e(e)}function Ze(e,t){return t&&A(e)?0:$(e.namedChildren.filter(t=>O(t)&&P(e,t)).map(Qe))}function Qe(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`&&rt(e)}function et(e){return!e.namedChildren.find(e=>e.type===`modifiers`)?.children.some(e=>e.text===`final`)}function P(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,nt(n)&&!tt(e)))return!1;n=e}return r||!nt(e)}function tt(e){let t=e;for(;t;){if(t.type===`pointer_declarator`)return!0;t=I(t)}return!1}function nt(e){return e.namedChildren.some(e=>e.type===`type_qualifier`&&(e.text===`const`||e.text===`constexpr`))}function rt(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 it(e){return e.type===`return_statement`||e.type===`return_expression`||e.type===`return`||e.type===`co_return_statement`}function at(e){return e.type===`throw_statement`||e.type===`raise_statement`||ot(e)}function ot(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 st(e){return e.type===`try_statement`||e.type===`try_with_resources_statement`||e.type===`rescue_modifier`||ct(e)}function ct(e){return(e.type===`begin`||e.type===`body_statement`)&&e.namedChildren.some(e=>e.type===`rescue`||e.type===`ensure`)}function lt(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=Xt(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 ut(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 dt(e,t){let n=e.length===0?[]:e.split(/\r\n|\n|\r/),r=new Map;for(let e of ft(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}pt(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 ft(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 pt(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 mt(e,t){let n=new Map,r=new Map;function i(e){if(!(e.type===`comment`||e.type===`line_comment`||e.type===`block_comment`)){if(s.has(e.type)){Q(r,t.slice(e.startIndex,e.endIndex));return}if(e.childCount===0){let i=t.slice(e.startIndex,e.endIndex);o.has(e.type)?Q(r,i):(a.has(i)||a.has(e.type))&&kt(e,i)&&Q(n,i||e.type);return}for(let t of e.children)i(t)}}return i(e),ht({distinctOperators:n.size,distinctOperands:r.size,totalOperators:$(n.values()),totalOperands:$(r.values())})}function ht(e){let{distinctOperators:t,distinctOperands:n,totalOperators:r,totalOperands:i}=e,a=t+n,o=r+i,s=a===0?0:o*Math.log2(a),c=n===0?0:t/2*(i/n),l=c*s;return{distinctOperators:t,distinctOperands:n,totalOperators:r,totalOperands:i,vocabulary:a,length:o,volume:s,difficulty:c,effort:l,time:l/18,bugs:s/3e3}}function gt(e){let t=St(e);if(t)return t;let n=e.childForFieldName(`name`);if(n)return n.text;let r=_t(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`?bt(e,i):e.type===`lambda`&&i.type===`assignment`?vt(i):(e.type===`block`||e.type===`do_block`)&&yt(i)?i.parent?.type===`assignment`?vt(i.parent):void 0:i.childForFieldName(`name`)?.text}}function _t(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 vt(e){let t=e.childForFieldName(`left`);return t?.type===`identifier`||t?.type===`constant`?t.text:void 0}function yt(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 bt(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 xt(e?.[r])}if(n.type===`var_spec`){let e=J(n,`name`)[r];return xt(e)}}}function xt(e){return e?.type===`identifier`&&e.text!==`_`?e.text:void 0}function St(e){let t=e;for(;t;){let e=t.parent,n=e?.parent;if(e?.type!==`arguments`||n?.type!==`call_expression`||!Ct(n))return;let r=n.parent;if(r?.type===`variable_declarator`)return r.childForFieldName(`name`)?.text;t=n}}function Ct(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 wt(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 Tt=new Set([`arrow_function`,`function_expression`,`function`,`lambda`,`lambda_expression`,`closure_expression`,`func_literal`,`anonymous_function`]);function Et(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=wt(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=Dt(t);if(!Tt.has(n.type))return R(n)}function Dt(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 Ot=new Set([`ternary_expression`,`conditional_expression`,`conditional`,`try_expression`,`conditional_type`]);function kt(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&&Ot.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 At(e){if(!L(e))return!1;let t=e.childForFieldName(`function`)??e.namedChild(0);return t?.text===`React.createElement`||t?.text===`createElement`}function jt(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 Mt(e,t){return jt(e)||Nt(e,t)||z(e,t)||B(e)||V(e,t)||Gt(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`?!j(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 Nt(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 Pt(e,t,n){if(t.name===`python`){let t=Ht(e,n);if(t.length>0)return t}if(t.name===`rust`)return Vt(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(`"`)?[`./${Z(t)}`]:[t]:[]}if(V(e,t))return It(e);if(e.type===`preproc_include`){let t=e.childForFieldName(`path`);if(!t)return[];let n=Z(t.text);return[t.type===`string_literal`&&!n.startsWith(`.`)&&!n.startsWith(`/`)?`./${n}`:n]}if(B(e))return zt(e);let r=e.childForFieldName(`source`)??X(e);return r?[Z(r.text)]:[]}const Ft=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&&Ft.has(n.text)}function It(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`?Rt(e.text):e.text).join(``):Z(r.text);return e.childForFieldName(`method`)?.text===`require_relative`?[a.startsWith(`.`)?a:`./${a}`]:[a.replace(/^(?:\.\.?\/)+/u,``)]}const Lt=new Map([[`n`,`
|
|
2
|
-
`],[`t`,` `],[`r`,`\r`],[`s`,` `],[`0`,`\0`]]);function
|
|
1
|
+
import{createLanguageRegistry as e}from"./languages.js";import{measureDuplication as t}from"./duplication.js";import{commentNodeTypes as n,countFunctionNcss as r,countNcss as i,invalidateNcssSetsCache as a}from"./ncss.js";import{measureWithNativeBackend as o}from"./nativeMetrics.js";import s from"tree-sitter";const c=new Set([`&&`,`||`,`and`,`or`]),l=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(`,`)),u=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(`.`)),d=new Set([`interpreted_string_literal`,`regex`,`user_defined_literal`,`integral_type`,`floating_point_type`,`sized_type_specifier`,`placeholder_type_specifier`]);var f=class{registry=e();registerLanguage(e){de(e),a(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,n){let r=this.registry.get(n.language);if(!r)throw Error(`Unsupported language: ${n.language}`);let a=o(e,r,n.includeSyntaxTree??!1);if(a)return h(a,n.includeSyntaxTree??!1);let c=new s;c.setLanguage(r.parserLanguage);let l=c.parse(e,void 0,{bufferSize:e.length+1}).rootNode,u=g(l,w(l,new Set(r.functionNodeTypes)).filter(e=>!ae(e)&&ie(e)),r),d=u.functions,f=pe(l,r,0,!1),{lines:p,codeLineNumbers:m}=Ot(e,l),_=jt(l,e);return{language:r.name,bytes:Buffer.byteLength(e),lines:p,functions:d,classCount:Me(l,r),functionCount:d.length,cyclomaticComplexity:f.cyclomaticComplexity,maxCyclomaticComplexity:_n(d,`cyclomaticComplexity`),cognitiveComplexity:f.cognitiveComplexity,maxCognitiveComplexity:_n(d,`cognitiveComplexity`),nestingDepth:f.nestingDepth,ncssCount:i(l,r),callGraph:u.callGraph,coupling:u.coupling,module:u.module,cohesion:u.cohesion,syntaxFeatures:u.syntaxFeatures,typeComplexity:u.typeComplexity,duplication:t(l,m),halstead:_,maintainabilityIndex:gn(_.volume,f.cyclomaticComplexity,p.code),syntaxTree:n.includeSyntaxTree?l.toString():void 0}}};const p=new f;function m(e,t){return p.measure(e,t)}function h(e,t){let n=Mt(e.halsteadCounts);return{language:e.language,bytes:e.bytes,lines:e.lines,functions:e.functions.map(e=>({name:e.name,nodeType:e.nodeType,startLine:e.startLine,startColumn:e.startColumn,endLine:e.endLine,returnsJsx:e.returnsJsx,cyclomaticComplexity:e.cyclomaticComplexity,cognitiveComplexity:e.cognitiveComplexity,nestingDepth:e.nestingDepth,ncss:e.ncss,callCount:e.callCount,uniqueCalleeCount:e.uniqueCalleeCount,fanIn:e.fanIn,fanOut:e.fanOut,parameterCount:e.parameterCount,recursive:e.recursive})),classCount:e.classCount,functionCount:e.functionCount,cyclomaticComplexity:e.cyclomaticComplexity,maxCyclomaticComplexity:e.maxCyclomaticComplexity,cognitiveComplexity:e.cognitiveComplexity,maxCognitiveComplexity:e.maxCognitiveComplexity,nestingDepth:e.nestingDepth,ncssCount:e.ncssCount,callGraph:e.callGraph,coupling:e.coupling,module:e.module,cohesion:e.cohesion,syntaxFeatures:e.syntaxFeatures,typeComplexity:e.typeComplexity,duplication:e.duplication,halstead:n,maintainabilityIndex:gn(n.volume,e.cyclomaticComplexity,e.lines.code),syntaxTree:t?e.syntaxTree:void 0}}function g(e,t,n){let r=ke(e,n),i=t.map((e,t)=>_(e,n,t,r)),a=b(i);return{functions:i.map(e=>({name:e.name,nodeType:e.nodeType,startLine:e.startLine,startColumn:e.startColumn,endLine:e.endLine,returnsJsx:e.returnsJsx,cyclomaticComplexity:e.cyclomaticComplexity,cognitiveComplexity:e.cognitiveComplexity,nestingDepth:e.nestingDepth,ncss:e.ncss,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:ut(e,n),module:He(e,n),cohesion:Et(i),syntaxFeatures:dt(e,n.name),typeComplexity:Dt(e)}}function _(e,t,n,i){let a=pe(e,t,0,!0),o=we(e,t,i);return{index:n,name:Nt(e),nodeType:e.type,hasImplementation:re(e),startLine:e.startPosition.row+1,startColumn:e.startPosition.column,endLine:e.endPosition.row+1,returnsJsx:Pe(e,t),cyclomaticComplexity:a.cyclomaticComplexity,cognitiveComplexity:a.cognitiveComplexity,nestingDepth:a.nestingDepth,ncss:r(e,t),callCount:o.callCount,parameterCount:ee(e),callees:o.callees,identifiers:je(e)}}function ee(e){if(e.childForFieldName(`parameter`))return 1;let t=y(e);if(!t)return 0;if(t.type===`identifier`)return 1;let n=new Set(Y(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)&&!v(e)).map(e=>e.type===`parameter_declaration`?Math.max(1,Y(e,`name`).length):1))+t.children.filter(e=>!e.isNamed&&e.text===`...`).length}function v(e){return e.type===`parameter_declaration`&&e.childForFieldName(`declarator`)===null&&e.childForFieldName(`type`)?.text===`void`}function y(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=L(n)}return e.namedChildren.find(e=>e.type===`formal_parameters`||e.type===`parameter_list`)}function b(e){let t=te(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=dn(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:vn(r),maxFanOut:vn(i),maxCallDepth:pn(a)}}}function te(e){let t=new Map;for(let n of e)!n.name||!n.hasImplementation||t.set(n.name,t.has(n.name)?void 0:n.index);return new Map([...t.entries()].filter(e=>e[1]!==void 0))}const ne=new Set([`function_definition`,`constructor_declaration`,`compact_constructor_declaration`,`function_signature_item`]);function re(e){return e.type!==`method_declaration`||e.childForFieldName(`body`)!==null}function ie(e){return!ne.has(e.type)||e.childForFieldName(`body`)!==null||e.namedChildren.some(e=>e.type===`try_statement`)}function ae(e){return(e.type===`block`||e.type===`do_block`)&&e.parent?.type===`lambda`}function oe(e,t){return t.has(e.type)&&!ae(e)}const se=new Set([`switch_statement`,`switch_expression`,`expression_switch_statement`,`type_switch_statement`,`select_statement`,`match_expression`,`match_statement`,`case`,`case_match`]),ce=new Set([`case_clause`,`switch_case`,`switch_block_statement_group`,`switch_rule`,`case_statement`,`expression_case`,`type_case`,`communication_case`,`match_arm`,`when`,`in_clause`]),le=new Set([`if_statement`,`if_expression`,`if`,`unless`]),ue=new Set([`throw_statement`]),x=new WeakMap;function de(e){x.delete(e)}function fe(e){let t=x.get(e);return t||(t={functionNodes:new Set(e.functionNodeTypes),decisionNodes:new Set(e.decisionNodeTypes),nestingNodes:new Set(e.nestingNodeTypes)},x.set(e,t)),t}function pe(e,t,n,r){let i=1,a=0,o=n,{functionNodes:s,decisionNodes:c,nestingNodes:l}=fe(t);function u(e,t,n,d,f,p){let m=e.type===`class_body`&&d;m&&(f=!0,n+=1),oe(e,s)&&(d&&(f=!0,p||(n+=1)),d=!0);let h=t+n,g=!(r&&f),_=e.isNamed&&c.has(e.type)&&!xe(e),ee=e.isNamed&&ce.has(e.type),v=e.isNamed&&(l.has(e.type)||e.type===`else`&&(e.parent?.type===`case`||e.parent?.type===`case_match`)),y=_&&be(e);_&&g&&(i+=1),_&&!ee&&!ue.has(e.type)&&(a+=y?1:1+h),e.isNamed&&se.has(e.type)&&(a+=1+h),a+=me(e),he(e)&&(a+=1),Ce(e)&&(g&&(i+=1),_e(e)&&(a+=1)),ye(e)&&(g&&(i+=1),a+=1);let b=v&&!y?t+1:t;g&&(o=Math.max(o,b));for(let t of e.children)u(t,b,n,d,f,m)}for(let t of e.children)u(t,n,0,r,!1,!1);return{cyclomaticComplexity:i,cognitiveComplexity:a,nestingDepth:o}}function me(e){if(!e.isNamed)return 0;if(e.type===`else`)return e.parent?.type===`case`||e.parent?.type===`case_match`?0:1;if(e.type===`else_clause`)return+!e.namedChildren.some(e=>le.has(e.type));if(e.type!==`if_statement`&&e.type!==`if_expression`)return 0;let t=0;for(let n=0;n<e.childCount;n+=1){let r=e.child(n);r&&e.fieldNameForChild(n)===`alternative`&&r.type!==`else_clause`&&r.type!==`elif_clause`&&!le.has(r.type)&&(t+=1)}return t}function he(e){return e.isNamed?e.type===`goto_statement`?!0:e.type===`break_expression`||e.type===`continue_expression`?e.namedChildren.some(e=>e.type===`label`||e.type===`loop_label`):(e.type===`break_statement`||e.type===`continue_statement`)&&e.namedChildren.some(e=>!n.has(e.type)):!1}const ge=new Set([`parenthesized_expression`,`parenthesized_statements`]);function _e(e){let t=e.parent;if(!t)return!0;let n=t.parent;for(;n&&ge.has(n.type);)n=n.parent;return!n||n.type!==t.type||S(ve(n))!==S(e.text)}function S(e){return e===`and`?`&&`:e===`or`?`||`:e}function ve(e){let t=e.childForFieldName(`operator`);return t?t.text:e.children.find(e=>!e.isNamed&&c.has(e.text))?.text}function ye(e){return e.isNamed?e.type===`guard`||e.type===`if_guard`||e.type===`unless_guard`||e.type===`if_clause`||e.type===`match_pattern`&&e.children.some(e=>!e.isNamed&&e.type===`if`):!1}function be(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 xe(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`}const Se=new Set([`binary_expression`,`binary`,`boolean_operator`]);function Ce(e){if(e.isNamed||!c.has(e.text))return!1;let t=e.parent;return t!==null&&Se.has(t.type)}function we(e,t,n=new Set){let r=new Set,i=fe(t).functionNodes,a=0;function o(e,s){if(!(!s&&oe(e,i))){if(!(t.name===`cpp`&&Ee(e)))if(R(e)){a+=1;let i=t.name===`cpp`&&(e.type===`new_expression`||e.type===`call_expression`&&n.has(C(e.childForFieldName(`function`))??``))?void 0:Ut(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(Ae(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 Te=new Set([`static_cast`,`dynamic_cast`,`const_cast`,`reinterpret_cast`]);function Ee(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&&Te.has(n)}function De(e,t){if(t.size===0)return!1;if(e.type===`compound_literal_expression`)return t.has(C(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(C(e.parent?.childForFieldName(`type`))??``)}if((e.type===`identifier`||e.type===`array_declarator`)&&e.parent?.type===`declaration`&&Y(e.parent,`declarator`).some(t=>t.id===e.id)&&!k(e.parent,`extern`)){let n=e;for(;n?.type===`array_declarator`;)n=n.childForFieldName(`declarator`);return n?.type===`identifier`&&t.has(C(e.parent.childForFieldName(`type`))??``)}if(e.type===`field_initializer`){let n=e.namedChild(0),r=n?.type===`field_identifier`?n.text:C(n);return t.has(r??``)}return!1}function C(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 Oe=new Set([`class_specifier`,`struct_specifier`,`union_specifier`]);function ke(e,t){let n=new Set;if(t.name!==`cpp`)return n;for(let t of w(e,Oe)){let e=t.childForFieldName(`name`)?.text;e&&t.childForFieldName(`body`)&&n.add(e)}return n}function Ae(e,t){return t.name===`ruby`?e.type===`yield`||e.type===`super`&&e.parent?.type!==`call`:!1}function je(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 Me(e,t){return w(e,new Set(t.classNodeTypes)).filter(Ne).length}function Ne(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 w(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 Pe(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.id===Fe(e)?.id&&t.type!==`statement_block`&&!n.has(t.type))return T(t,n)||E(t,n);for(let e of t.namedChildren)if(r(e,!1))return!0;return!1}return r(e,!0)}function Fe(e){return e.childForFieldName(`body`)??e.namedChild(e.namedChildCount-1)??void 0}function T(e,t){return Ie(e,t,e=>e.type.startsWith(`jsx_`)||Le(e,t))}function E(e,t){return Ie(e,t,qt)}function Ie(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 Le(e,t){return!R(e)||!Re(e.childForFieldName(`function`)??e.namedChild(0))?!1:e.namedChildren.some(e=>ze(e,t))}function Re(e){if(!e)return!1;let t=z(e);return t===`map`||t===`flatMap`}function ze(e,t){return t.has(e.type)?Be(e,t):e.namedChildren.some(e=>ze(e,t))}function Be(e,t){let n=e.type===`arrow_function`?Fe(e):void 0;return n&&n.type!==`statement_block`&&!t.has(n.type)?T(n,t)||E(n,t):Ve(e,t,e=>T(e,t)||E(e,t))}function Ve(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 He(e,t){let n=new Set;function r(e){if(Yt(e,t))for(let r of Zt(e,t,{expandPythonSubmodules:!0}))n.add(r);for(let t of e.namedChildren)r(t)}return r(e),{declarations:Ue(e,t),importSources:[...n]}}function Ue(e,t){let n=at(e),r=t.name===`java`?We(e):``;return e.namedChildren.flatMap(e=>D(e,!1,r,t.name===`cpp`)).map(e=>n.has(e.name)?{...e,exported:!0}:e)}function We(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 Ge=new Set([`module`,`class`,`singleton_class`]);function D(e,t,n=``,r=!1){if(j(e))return e.namedChildren.flatMap(e=>D(e,!0,n,r));if(e.type===`namespace_definition`){let i=e.childForFieldName(`name`)?.text;return i?(e.childForFieldName(`body`)?.namedChildren??[]).flatMap(e=>D(e,t,`${n}${i}::`,r)):[]}return rt(e)?e.namedChildren.flatMap(e=>D(e,t,n,r)):e.type===`declaration`?O($e(e,t,r),n):e.type===`type_definition`?O(Je(e,t),n):Ge.has(e.type)?Ke(e,t,n):e.type===`assignment`||e.type===`operator_assignment`?O(qe(e,t),n,!0):O(A(e,t),n)}function O(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=O(A(e,t),n,!0),i=r[0]?`${r[0].name}::`:n,a=e.childForFieldName(`body`);for(let e of a?.namedChildren??[])Ge.has(e.type)?r.push(...Ke(e,t,i)):(e.type===`assignment`||e.type===`operator_assignment`)&&r.push(...O(qe(e,t),i,!0));return r}function qe(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?A(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 Y(e,`declarator`)){let e=n.type===`type_identifier`?n.text:I(n);e&&e!==i&&!a.has(e)&&(a.add(e),r.push({exported:t,name:e,startLine:n.startPosition.row+1}))}return r}const Ye=new Set([`init_declarator`,`pointer_declarator`,`array_declarator`,`reference_declarator`,`identifier`,`field_identifier`]);function Xe(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=L(t);return t?.type!==`function_declarator`||t.childForFieldName(`declarator`)?.type===`parenthesized_declarator`}return Ye.has(e.type)?!0:e.type===`function_declarator`&&e.childForFieldName(`declarator`)?.type===`parenthesized_declarator`}function k(e,t){return e.children.some(e=>e.type===`storage_class_specifier`&&e.text===t)}function Ze(e){let t=e.childForFieldName(`type`);return t?.type!==`type_identifier`||t.text!==`import`&&t.text!==`export`&&t.text!==`module`?!1:!Qe(e,t.text)}function Qe(e,t){let n=e;for(;n.parent;)n=n.parent;return w(n,new Set([`type_definition`,`alias_declaration`])).some(e=>(e.childForFieldName(`declarator`)??e.childForFieldName(`name`))?.text===t)}function $e(e,t,n=!1){if(n&&Ze(e)||k(e,`static`))return[];let r=e.childForFieldName(`type`),i=r?A(r,t):[],a=new Set(i.map(e=>e.name)),o=k(e,`extern`);for(let r of e.namedChildren.filter(Xe)){if(o&&r.type!==`init_declarator`||n&&!o&&!k(e,`inline`)&&!et(r)&&!P(e,r))continue;let s=I(r);s&&!a.has(s)&&(a.add(s),i.push({exported:t,name:s,startLine:r.startPosition.row+1}))}return i}function et(e){let t=e.type===`init_declarator`?e.childForFieldName(`declarator`)??e:e;for(;t;){if(t.type===`reference_declarator`)return!0;t=L(t)}return!1}function A(e,t){if(!it(e)||e.type.endsWith(`_specifier`)&&!e.childForFieldName(`body`)||k(e,`static`))return[];if(e.type===`enum_specifier`)return tt(e,t);let n=nt(e);return n?[{exported:t,name:n,startLine:e.startPosition.row+1}]:[]}function tt(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 nt(e){if(e.type===`method_declaration`&&e.childForFieldName(`receiver`))return ct(e);let t=e.childForFieldName(`name`);return t?.type===`template_type`&&(t=t.childForFieldName(`name`)),t?.type===`scope_resolution`?t.text:t?M(t)?t.text:void 0:I(e.childForFieldName(`declarator`),!0)||e.namedChildren.find(M)?.text}function j(e){return e.type===`export_statement`||e.type===`export_declaration`}function rt(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 it(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 M(e){return e.type===`identifier`||e.type===`type_identifier`||e.type===`property_identifier`||e.type===`field_identifier`||e.type===`constant`}function at(e){let t=new Set;function n(e,r){if(!r&&ot(e)){let n=st(e);n&&t.add(n)}let i=r||j(e)&&e.childForFieldName(`source`)!==null;for(let t of e.namedChildren)n(t,i)}return n(e,!1),t}function ot(e){return e.type===`export_specifier`||e.type===`namespace_export`}function st(e){let t=e.childForFieldName(`name`)??e.childForFieldName(`alias`)??e.namedChildren.find(M);return t&&M(t)?t.text:void 0}function ct(e){let t=e.childForFieldName(`name`),n=e.childForFieldName(`receiver`)?.namedChildren[0]?.childForFieldName(`type`);return!t||!M(t)||!n?t&&M(t)?t.text:void 0:`${lt(n.text)}.${t.text}`}function lt(e){return e.replaceAll(/\s+/gu,``).replace(/^\*+/u,``)}function ut(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`))&&(Jt(e)||Xt(e,t)||B(e,t)||V(e)||H(e,t))&&(r+=1),Yt(e,t))for(let r of Zt(e,t,{expandPythonSubmodules:!1}))n.add(r);un(e)&&(i+=1);for(let t of e.namedChildren)a(t)}a(e);let o=[...n].filter(e=>rn(e,t.name)).length;return{importCount:r,importSourceCount:n.size,relativeImportCount:o,externalImportCount:n.size-o,exportCount:i}}function dt(e,t){let n={assignmentCount:0,awaitExpressionCount:0,loopStatementCount:0,mutableBindingCount:0,returnStatementCount:0,throwStatementCount:0,tryStatementCount:0};function r(e){ft(e)&&(n.assignmentCount+=1),pt(e)&&(n.awaitExpressionCount+=1),mt(e)&&(n.loopStatementCount+=1),n.mutableBindingCount+=ht(e,t),xt(e)&&(n.returnStatementCount+=1),St(e)&&(n.throwStatementCount+=1),wt(e)&&(n.tryStatementCount+=1);for(let t of e.namedChildren)r(t)}return r(e),n}function ft(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 pt(e){return e.type===`await_expression`||e.type===`await`||e.type===`co_await_expression`}function mt(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 ht(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 vt(e)?t.length:0}if(n&&(e.type===`declaration`||e.type===`field_declaration`))return N(e,t===`cpp`);if(n&&e.type===`function_definition`){let n=e.childForFieldName(`declarator`);return n?.type===`field_identifier`||n?.type===`identifier`?N(e,t===`cpp`):0}if(e.type===`enhanced_for_statement`)return+!!vt(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&&P(e,t)?gt(t):0}return+!!_t(e)}function N(e,t){return t&&Ze(e)?0:$(e.namedChildren.filter(t=>Xe(t)&&P(e,t)).map(gt))}function gt(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 _t(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`&&bt(e)}function vt(e){return!e.namedChildren.find(e=>e.type===`modifiers`)?.children.some(e=>e.text===`final`)}function P(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=L(n);if(!e)break;if(n.type===`pointer_declarator`&&(r=!0,F(n)&&!yt(e)))return!1;n=e}return r||!F(e)}function yt(e){let t=e;for(;t;){if(t.type===`pointer_declarator`)return!0;t=L(t)}return!1}function F(e){return e.namedChildren.some(e=>e.type===`type_qualifier`&&(e.text===`const`||e.text===`constexpr`))}function bt(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 xt(e){return e.type===`return_statement`||e.type===`return_expression`||e.type===`return`||e.type===`co_return_statement`}function St(e){return e.type===`throw_statement`||e.type===`raise_statement`||Ct(e)}function Ct(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 wt(e){return e.type===`try_statement`||e.type===`try_with_resources_statement`||e.type===`rescue_modifier`||Tt(e)}function Tt(e){return(e.type===`begin`||e.type===`body_statement`)&&e.namedChildren.some(e=>e.type===`rescue`||e.type===`ensure`)}function Et(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=hn(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 Dt(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 Ot(e,t){let n=e.length===0?[]:e.split(/\r\n|\n|\r/),r=new Map;for(let e of kt(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}At(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 kt(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 At(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 jt(e,t){let n=new Map,r=new Map;function i(e){if(!(e.type===`comment`||e.type===`line_comment`||e.type===`block_comment`)){if(d.has(e.type)){Q(r,t.slice(e.startIndex,e.endIndex));return}if(e.childCount===0){let i=t.slice(e.startIndex,e.endIndex);u.has(e.type)?Q(r,i):(l.has(i)||l.has(e.type))&&Kt(e,i)&&Q(n,i||e.type);return}for(let t of e.children)i(t)}}return i(e),Mt({distinctOperators:n.size,distinctOperands:r.size,totalOperators:$(n.values()),totalOperands:$(r.values())})}function Mt(e){let{distinctOperators:t,distinctOperands:n,totalOperators:r,totalOperands:i}=e,a=t+n,o=r+i,s=a===0?0:o*Math.log2(a),c=n===0?0:t/2*(i/n),l=c*s;return{distinctOperators:t,distinctOperands:n,totalOperators:r,totalOperands:i,vocabulary:a,length:o,volume:s,difficulty:c,effort:l,time:l/18,bugs:s/3e3}}function Nt(e){let t=zt(e);if(t)return t;let n=e.childForFieldName(`name`);if(n)return n.text;let r=Pt(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`?I(i.childForFieldName(`declarator`)):e.type===`func_literal`&&i.type===`expression_list`?Lt(e,i):e.type===`lambda`&&i.type===`assignment`?Ft(i):(e.type===`block`||e.type===`do_block`)&&It(i)?i.parent?.type===`assignment`?Ft(i.parent):void 0:i.childForFieldName(`name`)?.text}}function Pt(e){return I(e.childForFieldName(`declarator`))}function I(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=L(n)}}function L(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 Ft(e){let t=e.childForFieldName(`left`);return t?.type===`identifier`||t?.type===`constant`?t.text:void 0}function It(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 Lt(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 Rt(e?.[r])}if(n.type===`var_spec`){let e=Y(n,`name`)[r];return Rt(e)}}}function Rt(e){return e?.type===`identifier`&&e.text!==`_`?e.text:void 0}function zt(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 R(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 Vt(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 Ht=new Set([`arrow_function`,`function_expression`,`function`,`lambda`,`lambda_expression`,`closure_expression`,`func_literal`,`anonymous_function`]);function Ut(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=Vt(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(!Ht.has(n.type))return z(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 Gt=new Set([`ternary_expression`,`conditional_expression`,`conditional`,`try_expression`,`conditional_type`]);function Kt(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&&Gt.has(n)}function z(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 z(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 z(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=z(n);if(r)return r}}function qt(e){if(!R(e))return!1;let t=e.childForFieldName(`function`)??e.namedChild(0);return t?.text===`React.createElement`||t?.text===`createElement`}function Jt(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 Yt(e,t){return Jt(e)||Xt(e,t)||B(e,t)||V(e)||H(e,t)||un(e)&&e.childForFieldName(`source`)!==null}function B(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`?!Qe(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 Xt(e,t){return t.name===`rust`&&e.type===`mod_item`&&!e.childForFieldName(`body`)}function V(e){return R(e)?(e.childForFieldName(`function`)??e.namedChild(0))?.text===`import`:!1}function Zt(e,t,n){if(t.name===`python`){let t=on(e,n);if(t.length>0)return t}if(t.name===`rust`)return an(e);if(t.name===`java`&&e.type===`requires_module_directive`){let t=e.childForFieldName(`module`);return t?[X(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=X(t.text);return[r&&!n?`${i}.*`:i]}if(B(e,t)){let t=/^(?:export\s+)?import\s+([\w.:]+|"[^"]+"|<[^>]+>)/u.exec(e.text)?.[1];return t?t.startsWith(`"`)?[`./${Z(t)}`]:[t]:[]}if(H(e,t))return $t(e);if(e.type===`preproc_include`){let t=e.childForFieldName(`path`);if(!t)return[];let n=Z(t.text);return[t.type===`string_literal`&&!n.startsWith(`.`)&&!n.startsWith(`/`)?`./${n}`:n]}if(V(e))return nn(e);let r=e.childForFieldName(`source`)??cn(e);return r?[Z(r.text)]:[]}const Qt=new Set([`require`,`require_relative`,`load`]);function H(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&&Qt.has(n.text)}function $t(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`?tn(e.text):e.text).join(``):Z(r.text);return e.childForFieldName(`method`)?.text===`require_relative`?[a.startsWith(`.`)?a:`./${a}`]:[a.replace(/^(?:\.\.?\/)+/u,``)]}const en=new Map([[`n`,`
|
|
2
|
+
`],[`t`,` `],[`r`,`\r`],[`s`,` `],[`0`,`\0`]]);function tn(e){let t=e.slice(1);return en.get(t)??t}function nn(e){let t=e.childForFieldName(`arguments`)?.namedChild(0);return t&&ln(t)?[Z(t.text)]:[]}function rn(e,t){return e.startsWith(`.`)||e.startsWith(`/`)?!0:t===`rust`&&U(e)}function U(e){return/^(?:crate|self|super)(?:::|$)/u.test(e)}function an(e){if(e.type===`mod_item`){let t=e.childForFieldName(`name`);return t?[`self::${X(t.text)}`]:[]}if(e.type===`extern_crate_declaration`){let t=e.childForFieldName(`name`);return t?[X(t.text)]:[]}let t=e.childForFieldName(`argument`);return t?W(t,``):[]}function W(e,t){switch(e.type){case`use_list`:return e.namedChildren.flatMap(e=>W(e,t));case`scoped_use_list`:{let n=e.childForFieldName(`list`),r=K(t,G(e.childForFieldName(`path`)));return n?W(n,r):q(r)}case`scoped_identifier`:{let n=K(t,X(e.text));return U(n)?q(n):q(K(t,G(e.childForFieldName(`path`))))}case`use_wildcard`:return q(K(t,G(e.namedChild(0))));case`use_as_clause`:{let n=e.childForFieldName(`path`);return n?W(n,t):[]}case`self`:return q(t);case`identifier`:case`crate`:case`super`:return e.type===`identifier`&&U(t)?q(K(t,X(e.text))):q(t===``?X(e.text):t);default:return[]}}function G(e){return e?X(e.text):``}function K(e,t){return t?e?`${e}::${t}`:t:e}function q(e){return e?[e]:[]}function on(e,t){if(e.type===`import_from_statement`){let n=e.childForFieldName(`module_name`);if(!n)return[];let r=X(n.text),i=Y(e,`name`);if(!t.expandPythonSubmodules||!r.startsWith(`.`))return[r];if(/^\.+$/u.test(r)&&i.length>0)return i.flatMap(J).map(e=>`${r}${e}`);let a=i.flatMap(J).map(e=>`${r}.${e}`);return a.length>0?[r,...a]:[r]}return e.type===`import_statement`?e.namedChildren.map(e=>sn(e)).filter(e=>e!==void 0):[]}function J(e){if(e.type===`aliased_import`){let t=e.childForFieldName(`name`);return t?J(t):[]}return e.type===`identifier`?[e.text]:e.type===`dotted_name`?[X(e.text)]:e.namedChildren.flatMap(J)}function Y(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 sn(e){if(e.type===`dotted_name`||e.type===`relative_import`)return X(e.text);let t=e.childForFieldName(`name`);if(t)return X(t.text);for(let t of e.namedChildren){let e=sn(t);if(e)return e}}function X(e){return e.replaceAll(/\s+/gu,``)}function cn(e){if(ln(e))return e;for(let t of e.namedChildren){let e=cn(t);if(e)return e}}function ln(e){return e.type===`string`||e.type===`string_literal`||e.type===`interpreted_string_literal`}function Z(e){return e.replaceAll(/^['"`<]|['"`>]$/gu,``)}function un(e){return e.type.startsWith(`export`)&&e.type!==`exports_module_directive`||e.type===`public_field_definition`}function dn(e){let t=new Set;for(let n of e.keys())fn(n,n,e,new Set)&&t.add(n);return t}function fn(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),fn(e,t,n,r)))return!0;return!1}function pn(e){let t=new Map,n=0;for(let r of e.keys())n=Math.max(n,mn(r,e,new Set,t).depth);return n}function mn(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=mn(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 hn(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 gn(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 Q(e,t){e.set(t,(e.get(t)??0)+1)}function _n(e,t){return e.length===0?0:Math.max(...e.map(e=>e[t]))}function vn(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{f as TreeMeasurer,p as defaultMeasurer,m as measureCode};
|
|
3
3
|
//# sourceMappingURL=metrics.js.map
|