code-gauge 2.0.0 → 3.1.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 +156 -106
- package/dist/cli.cjs +3 -3
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/cliConfig.cjs +1 -1
- package/dist/cliConfig.cjs.map +1 -1
- package/dist/cliConfig.d.ts +27 -84
- package/dist/cliConfig.js +1 -1
- package/dist/cliConfig.js.map +1 -1
- package/dist/crossFileDuplication.cjs +1 -1
- package/dist/crossFileDuplication.cjs.map +1 -1
- package/dist/crossFileDuplication.d.ts +9 -0
- package/dist/crossFileDuplication.js +1 -1
- package/dist/crossFileDuplication.js.map +1 -1
- package/dist/depDegree.cjs +2 -0
- package/dist/depDegree.cjs.map +1 -0
- package/dist/depDegree.d.ts +12 -0
- package/dist/depDegree.js +2 -0
- package/dist/depDegree.js.map +1 -0
- package/dist/diffCommand.cjs +5 -0
- package/dist/diffCommand.cjs.map +1 -0
- package/dist/diffCommand.d.ts +17 -0
- package/dist/diffCommand.js +5 -0
- package/dist/diffCommand.js.map +1 -0
- package/dist/duplication.cjs +1 -1
- package/dist/duplication.cjs.map +1 -1
- package/dist/duplication.d.ts +23 -2
- package/dist/duplication.js +1 -1
- package/dist/duplication.js.map +1 -1
- package/dist/git.cjs +2 -0
- package/dist/git.cjs.map +1 -0
- package/dist/git.d.ts +27 -0
- package/dist/git.js +2 -0
- package/dist/git.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.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 +1 -2
- package/dist/metrics.cjs.map +1 -1
- package/dist/metrics.d.ts +11 -0
- package/dist/metrics.js +1 -2
- package/dist/metrics.js.map +1 -1
- package/dist/nativeMetrics.cjs +1 -1
- package/dist/nativeMetrics.cjs.map +1 -1
- package/dist/nativeMetrics.d.ts +7 -3
- package/dist/nativeMetrics.js +1 -1
- package/dist/nativeMetrics.js.map +1 -1
- package/dist/regressionGate.cjs +2 -0
- package/dist/regressionGate.cjs.map +1 -0
- package/dist/regressionGate.d.ts +106 -0
- package/dist/regressionGate.js +2 -0
- package/dist/regressionGate.js.map +1 -0
- package/dist/scan.cjs +2 -0
- package/dist/scan.cjs.map +1 -0
- package/dist/scan.d.ts +55 -0
- package/dist/scan.js +2 -0
- package/dist/scan.js.map +1 -0
- package/dist/types.d.ts +24 -76
- package/package.json +7 -5
- package/dist/architectureMetrics.cjs +0 -2
- package/dist/architectureMetrics.cjs.map +0 -1
- package/dist/architectureMetrics.d.ts +0 -41
- package/dist/architectureMetrics.js +0 -2
- package/dist/architectureMetrics.js.map +0 -1
- package/dist/typescriptProject.cjs +0 -3
- package/dist/typescriptProject.cjs.map +0 -1
- package/dist/typescriptProject.d.ts +0 -24
- package/dist/typescriptProject.js +0 -3
- package/dist/typescriptProject.js.map +0 -1
package/dist/metrics.d.ts
CHANGED
|
@@ -7,16 +7,27 @@ export declare class TreeMeasurer {
|
|
|
7
7
|
measure(code: string, options: MeasureOptions): CodeMetrics;
|
|
8
8
|
/** Collects one file's duplicate candidates for cross-file clone detection. */
|
|
9
9
|
collectDuplicationCandidates(code: string, options: MeasureOptions): CrossFileDuplicateCandidate[];
|
|
10
|
+
/**
|
|
11
|
+
* Normalized token hash sequences of every function, index-parallel to the functions array of
|
|
12
|
+
* measure(): identifiers are anonymized by first occurrence within the function, literals by
|
|
13
|
+
* kind, and keywords/operators kept verbatim, so the regression gate can re-match renamed or
|
|
14
|
+
* moved functions across two revisions by token-LCS similarity. Always measured by the
|
|
15
|
+
* TypeScript backend.
|
|
16
|
+
*/
|
|
17
|
+
collectFunctionTokenSequences(code: string, options: MeasureOptions): Int32Array[];
|
|
10
18
|
/**
|
|
11
19
|
* Collects one file's duplicate candidates, normalized tokens, and statement structure for
|
|
12
20
|
* cross-file clone detection with measureCrossFileDuplication. Always measured by the
|
|
13
21
|
* TypeScript backend.
|
|
14
22
|
*/
|
|
15
23
|
collectCrossFileDuplicationFileData(code: string, options: MeasureOptions): CrossFileDuplicationFileData;
|
|
24
|
+
private parse;
|
|
16
25
|
}
|
|
17
26
|
export declare const defaultMeasurer: TreeMeasurer;
|
|
18
27
|
export declare function measureCode(code: string, options: MeasureOptions): CodeMetrics;
|
|
19
28
|
/** Standalone helper mirroring measureCode for the default measurer. */
|
|
20
29
|
export declare function collectDuplicationCandidates(code: string, options: MeasureOptions): CrossFileDuplicateCandidate[];
|
|
21
30
|
/** Standalone helper mirroring measureCode for the default measurer. */
|
|
31
|
+
export declare function collectFunctionTokenSequences(code: string, options: MeasureOptions): Int32Array[];
|
|
32
|
+
/** Standalone helper mirroring measureCode for the default measurer. */
|
|
22
33
|
export declare function collectCrossFileDuplicationFileData(code: string, options: MeasureOptions): CrossFileDuplicationFileData;
|
package/dist/metrics.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import{collectCrossFileDuplicateCandidates as e,defaultDuplicationOptions as t,measureDuplication as n}from"./duplication.js";import{createLanguageRegistry as r}from"./languages.js";import{commentNodeTypes as i,countNcss as a,getNcssSets as o,invalidateNcssSetsCache as s,ncssContribution as c}from"./ncss.js";import{measureWithNativeBackend as l}from"./nativeMetrics.js";import u from"tree-sitter";const d=new Set([`&&`,`||`,`and`,`or`]),f=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(`,`)),p=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(`.`)),m=new Set([`interpreted_string_literal`,`regex`,`user_defined_literal`,`integral_type`,`floating_point_type`,`sized_type_specifier`,`placeholder_type_specifier`]);var h=class{registry=r();registerLanguage(e){Ie(e),s(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,t){let r=this.registry.get(t.language);if(!r)throw Error(`Unsupported language: ${t.language}`);let i=_(t)?l(e,r,t.includeSyntaxTree??!1):void 0;if(i)return te(i,t.includeSyntaxTree??!1);let o=g(e,r),s=x(o,M(o,new Set(r.functionNodeTypes)).filter(e=>!je(e)&&Ae(e)),r),c=s.functions,u=ze(o,r),{lines:d,codeLineNumbers:f}=Cn(e,o),p=En(o,e);return{language:r.name,bytes:Buffer.byteLength(e),lines:d,functions:c,classCount:bt(o,r),functionCount:c.length,cyclomaticComplexity:u.cyclomaticComplexity,maxCyclomaticComplexity:Tr(c,`cyclomaticComplexity`),cognitiveComplexity:u.cognitiveComplexity,maxCognitiveComplexity:Tr(c,`cognitiveComplexity`),nestingDepth:u.nestingDepth,ncssCount:a(o,r),callGraph:s.callGraph,coupling:s.coupling,module:s.module,cohesion:s.cohesion,syntaxFeatures:s.syntaxFeatures,typeComplexity:s.typeComplexity,duplication:n(o,f,t.duplication),halstead:p,maintainabilityIndex:wr(p.volume,u.cyclomaticComplexity,d.code),syntaxTree:t.includeSyntaxTree?o.toString():void 0}}collectDuplicationCandidates(e,t){return this.collectCrossFileDuplicationFileData(e,t).candidates}collectCrossFileDuplicationFileData(t,n){let r=this.registry.get(n.language);if(!r)throw Error(`Unsupported language: ${n.language}`);return e(g(t,r),n.duplication)}};function g(e,t){let n=new u;return n.setLanguage(t.parserLanguage),n.parse(e,void 0,{bufferSize:e.length+1}).rootNode}function _(e){let n=e.duplication;return(n?.minTokens??t.minTokens)===t.minTokens&&(n?.maxGapTokens??t.maxGapTokens)===t.maxGapTokens&&(n?.minSimilarityPercent??t.minSimilarityPercent)===t.minSimilarityPercent}const v=new h;function y(e,t){return v.measure(e,t)}function b(e,t){return v.collectDuplicationCandidates(e,t)}function ee(e,t){return v.collectCrossFileDuplicationFileData(e,t)}function te(e,t){let n=Dn(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:wr(n.volume,e.cyclomaticComplexity,e.lines.code),syntaxTree:t?e.syntaxTree:void 0}}function x(e,t,n){let r=at(e,n),i=Re(e,n),a=t.map((e,t)=>{let a=i.get(e.id);if(!a)throw Error(`missing body metrics for function node at line ${e.startPosition.row+1}`);return S(e,n,t,r,a)}),o=we(a,n.name,be(e,n));return{functions:a.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:o.fanInByIndex.get(e.index)??0,fanOut:o.fanOutByIndex.get(e.index)??0,parameterCount:e.parameterCount,recursive:o.recursiveIndexes.has(e.index)})),callGraph:o.metrics,coupling:tn(e,n),module:At(e,n),cohesion:xn(a),syntaxFeatures:nn(e,n.name),typeComplexity:Sn(e)}}function S(e,t,n,r,i){let a=Ze(e,t,r,le(e)),o=me(e),s=t.name===`python`?he(e):0;return{index:n,name:On(e),nodeType:e.type,scopeName:ne(e,t),hasImplementation:ke(e),startLine:e.startPosition.row+1,startColumn:e.startPosition.column,endLine:e.endPosition.row+1,returnsJsx:St(e,t),cyclomaticComplexity:i.cyclomaticComplexity,cognitiveComplexity:i.cognitiveComplexity,nestingDepth:i.nestingDepth,ncss:i.ncss,callCount:a.callCount,parameterCount:o.count,callableParameterCount:Math.max(o.count-s,0),callableMinParameterCount:Math.max(o.minCount-s,0),unboundedArity:o.unbounded,callees:a.callees,callSites:a.callSites,identifiers:yt(e)}}const C=new Set([`class_declaration`,`class_definition`,`class_specifier`,`struct_specifier`,`union_specifier`,`interface_declaration`,`enum_declaration`,`record_declaration`,`annotation_type_declaration`,`object_creation_expression`,`class`,`module`,`singleton_class`,`struct_item`,`enum_item`,`union_item`,`trait_item`,`impl_item`]),w=new Set([`namespace_definition`,`mod_item`]);function ne(e,t){let{segments:n,hasClassScope:r}=re(e.parent,t);if(r)return n.join(`::`);if(e.type===`method_declaration`){let t=e.childForFieldName(`receiver`)?.namedChildren[0]?.childForFieldName(`type`);if(t)return en(t.text).replace(/\[.*\]$/su,``)}let i=B(e.childForFieldName(`declarator`),!0),a=i?.lastIndexOf(`::`)??-1;if(i!==void 0&&a>0){let t=ae(i.slice(0,a),ce(e));return[...n,t].join(`::`)}}function re(e,t){let n=O(t).functionNodes,r=[],i=!1;for(let t=e;t;t=t.parent){if(w.has(t.type)){let e=t.childForFieldName(`name`)?.text;e&&r.unshift(e);continue}if(i&&E(t,n)){r.unshift(`<fn:${t.startIndex}>`);continue}C.has(t.type)&&(t.type===`object_creation_expression`&&!t.namedChildren.some(e=>e.type===`class_body`)||(r.unshift(ie(t)),i=!0))}return{segments:r,hasClassScope:i}}function ie(e){if(e.type===`impl_item`){let t=e.childForFieldName(`type`)?.text;return t===void 0?T(e):ae(t,oe(e.childForFieldName(`type_parameters`)))}if(e.type===`singleton_class`){let t=e.childForFieldName(`value`)?.text;return t===void 0?T(e):`<<${t.replaceAll(/\s+/gu,``)}`}return e.childForFieldName(`name`)?.text??T(e)}function T(e){return`<anonymous:${e.startIndex}>`}function ae(e,t){let n=e.replaceAll(/\s+/gu,``);if(t.length===0)return n;for(let[e,r]of t.entries()){let t=r.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`);n=n.replaceAll(new RegExp(String.raw`(?<![\w'])${t}(?![\w])`,`gu`),()=>`$${e}`)}return n.replaceAll(/<\$\d+(?:,\$\d+)*>/gu,e=>[...e.matchAll(/\$(\d+)/gu)].map(e=>Number(e[1])).every((e,t)=>e===t)?``:e)}function oe(e){let t=[];for(let n of e?.namedChildren??[]){if(n.type===`comment`)continue;let e=se(n);e!==void 0&&t.push(e)}return t}function se(e){if(e.type===`type_identifier`||e.type===`identifier`||e.type===`lifetime`)return e.text;for(let t of e.namedChildren){let e=se(t);if(e!==void 0)return e}}function ce(e){let t=[];for(let n=e.parent;n;n=n.parent)n.type===`template_declaration`&&t.unshift(...oe(n.childForFieldName(`parameters`)));return t}function le(e){if(e.type!==`method_declaration`)return;let t=e.childForFieldName(`receiver`)?.namedChildren[0]?.childForFieldName(`name`);return t?.type===`identifier`?t.text:void 0}const ue=new Set([`spread_parameter`,`variadic_parameter_declaration`,`variadic_parameter`,`rest_pattern`,`list_splat_pattern`,`dictionary_splat_pattern`,`splat_parameter`,`hash_splat_parameter`]),de=new Set([`optional_parameter_declaration`,`assignment_pattern`,`optional_parameter`,`default_parameter`,`typed_default_parameter`]);function fe(e){return ue.has(e.type)?!0:e.type===`required_parameter`&&e.childForFieldName(`pattern`)?.type===`rest_pattern`}function pe(e){return de.has(e.type)?!0:(e.type===`required_parameter`||e.type===`keyword_parameter`)&&e.childForFieldName(`value`)!==null}function me(e){if(e.childForFieldName(`parameter`))return{count:1,minCount:1,unbounded:!1};let t=_e(e);if(!t)return{count:0,minCount:0,unbounded:!1};if(t.type===`identifier`)return{count:1,minCount:1,unbounded:!1};let n=new Set(Y(t,`locals`).map(e=>e.id)),r=0,i=0,a=!1;for(let e of t.namedChildren){if(e.type===`comment`||e.type===`self_parameter`||e.type===`receiver_parameter`||e.type===`block_parameter`||e.type===`positional_separator`||e.type===`keyword_separator`||n.has(e.id)||ge(e))continue;let t=e.type===`parameter_declaration`?Math.max(1,Y(e,`name`).length):1;r+=t,fe(e)?a=!0:pe(e)||(i+=t)}let o=t.children.filter(e=>!e.isNamed&&e.text===`...`).length;return o>0&&(a=!0),{count:r+o,minCount:i,unbounded:a}}function he(e){if(e.type!==`function_definition`)return 0;let t=e.parent?.type===`decorated_definition`?e.parent:e;if(t.parent?.type!==`block`||t.parent.parent?.type!==`class_definition`||t.type===`decorated_definition`&&t.namedChildren.some(e=>e.type===`decorator`&&e.text.replace(/^@/u,``)===`staticmethod`))return 0;let n=e.childForFieldName(`parameters`)?.namedChildren.find(e=>e.type!==`comment`),r=n?.type===`identifier`?n.text:n?.type===`typed_parameter`?n.namedChild(0)?.text:void 0;return+(r===`self`||r===`cls`)}function ge(e){return e.type===`parameter_declaration`&&e.childForFieldName(`declarator`)===null&&e.childForFieldName(`type`)?.text===`void`}function _e(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=V(n)}return e.namedChildren.find(e=>e.type===`formal_parameters`||e.type===`parameter_list`)}const ve=new Set([`java`,`javascript`,`jsx`,`typescript`,`tsx`,`cpp`,`python`,`ruby`]),ye=new Set([`class_declaration`,`interface_declaration`,`class_specifier`,`struct_specifier`,`class_definition`,`class`]);function be(e,t){let n=new Map;if(!ve.has(t.name))return n;let r=new Set,i=[];for(let n of M(e,ye)){let{segments:e}=re(n.parent,t),a=[...e,ie(n)].join(`::`);r.add(a);let o=Se(n,t.name);o.length>0&&i.push({scope:a,enclosingSegments:e,baseNames:o})}for(let{scope:e,enclosingSegments:t,baseNames:a}of i){let i=a.map(e=>xe(e,t,r)),o=n.get(e)??[];n.set(e,[...o,...i.filter(e=>!o.includes(e))])}return n}function xe(e,t,n){for(let r=t.length;r>0;--r){let i=[...t.slice(0,r),e].join(`::`);if(n.has(i))return i}return e}function Se(e,t){let n=[],r=e.childForFieldName(`superclass`);if(r){let e=r.type===`superclass`?r.namedChildren[0]:r;e&&n.push(e.text)}let i=e.namedChildren.find(e=>e.type===`class_heritage`);if(i){let e=i.namedChildren.find(e=>e.type===`extends_clause`),t=e?Y(e,`value`):i.namedChildren;n.push(...t.map(e=>e.text))}let a=e.namedChildren.find(e=>e.type===`base_class_clause`);a&&n.push(...a.namedChildren.filter(e=>e.type===`type_identifier`||e.type===`template_type`||e.type===`qualified_identifier`).map(e=>e.text));let o=e.childForFieldName(`superclasses`);return o&&n.push(...o.namedChildren.filter(e=>e.type===`identifier`||e.type===`attribute`||e.type===`subscript`).map(e=>e.text)),n.map(e=>Ce(e,t)).filter(e=>e.length>0)}function Ce(e,t){let n=e.replaceAll(/\s+/gu,``);t!==`cpp`&&t!==`ruby`&&(n=n.replaceAll(`.`,`::`));let r=[`<`,`[`].map(e=>n.indexOf(e)).filter(e=>e>=0);return r.length>0&&(n=n.slice(0,Math.min(...r))),n}function we(e,t,n){let r=Te(e),i=new Map,a=new Map,o=new Map,s=0,c=new Set;for(let l of e){s+=l.callCount;for(let e of l.callees)c.add(e);let e=new Set;for(let i of l.callSites){let a=De(i,l.scopeName,r.get(i.name),t,n);a!==void 0&&e.add(a)}o.set(l.index,e),a.set(l.index,e.size);for(let t of e)i.set(t,(i.get(t)??0)+1)}let l=yr(o);return{fanInByIndex:i,fanOutByIndex:a,recursiveIndexes:l,metrics:{callCount:s,uniqueCalleeCount:c.size,internalEdgeCount:$([...o.values()].map(e=>e.size)),recursiveFunctionCount:l.size,maxFanIn:Er(i),maxFanOut:Er(a),maxCallDepth:xr(o)}}}function Te(e){let t=new Map;for(let n of e){if(!n.name||!n.hasImplementation)continue;let e=t.get(n.name)??[];e.push({index:n.index,callableParameterCount:n.callableParameterCount,callableMinParameterCount:n.callableMinParameterCount,unboundedArity:n.unboundedArity,scopeName:n.scopeName}),t.set(n.name,e)}return t}const Ee=new Set([`java`,`ruby`,`cpp`]);function De(e,t,n,r,i){if(!n||n.length===0)return;if(n.length===1)return n[0]?.index;let a=t=>{let n=e.argumentCount;return n===void 0?t:t.filter(e=>e.unboundedArity?n>=e.callableMinParameterCount:e.callableMinParameterCount<=n&&n<=e.callableParameterCount)},o=e.receiver===`none`&&Ee.has(r)&&t!==void 0;if(e.receiver===`self`||o){let r=!1,o=new Set([t]),s=[t];for(;s.length>0;){let e=s.shift(),t=n.filter(t=>t.scopeName===e);if(t.length>0){r=!0;let e=a(t);if(e.length>0)return e.length===1?e[0]?.index:void 0}if(e!==void 0)for(let t of i.get(e)??[])o.has(t)||(o.add(t),s.push(t))}if(e.receiver===`self`||r)return}let s=a(e.receiver===`other`?n:n.filter(e=>e.scopeName===void 0));return s.length===1?s[0]?.index:void 0}const Oe=new Set([`function_definition`,`constructor_declaration`,`compact_constructor_declaration`,`function_signature_item`]);function ke(e){return e.type!==`method_declaration`||e.childForFieldName(`body`)!==null}function Ae(e){return!Oe.has(e.type)||e.childForFieldName(`body`)!==null||e.namedChildren.some(e=>e.type===`try_statement`)}function je(e){return(e.type===`block`||e.type===`do_block`)&&e.parent?.type===`lambda`}function E(e,t){return t.has(e.type)&&!je(e)}const Me=new Set([`switch_statement`,`switch_expression`,`expression_switch_statement`,`type_switch_statement`,`select_statement`,`match_expression`,`match_statement`,`case`,`case_match`]),Ne=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`]),Pe=new Set([`if_statement`,`if_expression`,`if`,`unless`]),Fe=new Set([`throw_statement`]),D=new WeakMap;function Ie(e){D.delete(e)}function O(e){let t=D.get(e);return t||(t={functionNodes:new Set(e.functionNodeTypes),decisionNodes:new Set(e.decisionNodeTypes),nestingNodes:new Set(e.nestingNodeTypes)},D.set(e,t)),t}function Le(e,t){return{cyclomaticComplexity:1,cognitiveComplexity:0,nestingSensitiveCount:0,nestingDepth:0,ncss:0,hasOwnNcssContribution:!1,entryCognitiveNesting:e,entryStructuralNesting:t}}function Re(e,t){let{functionNodes:n,decisionNodes:r,nestingNodes:i}=O(t),{countable:a,containers:s}=o(t),l=new Map,u=[Le(0,0)];function d(e,t,o,f,p,m){let h=e.type===`class_body`&&f;h&&(p=!0,o+=1);let g=E(e,n);g&&(f&&!m&&(o+=1),f=!0);let _=u.at(-1),v=t+o-_.entryCognitiveNesting,y=!p&&!g,b=e.isNamed&&r.has(e.type)&&!Je(e),ee=e.isNamed&&Ne.has(e.type),te=e.isNamed&&(i.has(e.type)||e.type===`else`&&(e.parent?.type===`case`||e.parent?.type===`case_match`)),x=b&&qe(e);b&&y&&(_.cyclomaticComplexity+=1),b&&!ee&&!Fe.has(e.type)&&(x?_.cognitiveComplexity+=1:(_.cognitiveComplexity+=1+v,_.nestingSensitiveCount+=1)),e.isNamed&&Me.has(e.type)&&(_.cognitiveComplexity+=1+v,_.nestingSensitiveCount+=1),_.cognitiveComplexity+=Be(e),Ve(e)&&(_.cognitiveComplexity+=1),Xe(e)&&(y&&(_.cyclomaticComplexity+=1),Ue(e)&&(_.cognitiveComplexity+=1)),Ke(e)&&(y&&(_.cyclomaticComplexity+=1),_.cognitiveComplexity+=1);let S=te&&!x?t+1:t;y&&(_.nestingDepth=Math.max(_.nestingDepth,S-_.entryStructuralNesting)),g&&u.push(Le(S+o,S));let C=c(e,a,s),w=u.at(-1);w.ncss+=C,g&&C>0&&(w.hasOwnNcssContribution=!0);for(let t of e.children)d(t,S,o,f,!g&&p,h);if(g){let t=u.pop();l.set(e.id,{cyclomaticComplexity:t.cyclomaticComplexity,cognitiveComplexity:t.cognitiveComplexity,nestingDepth:t.nestingDepth,ncss:t.ncss+ +!t.hasOwnNcssContribution});let n=u.at(-1);n.cognitiveComplexity+=t.cognitiveComplexity+t.nestingSensitiveCount*(t.entryCognitiveNesting-n.entryCognitiveNesting),n.nestingSensitiveCount+=t.nestingSensitiveCount,n.ncss+=t.ncss}}return d(e,0,0,!1,!1,!1),l}function ze(e,t){let n=1,r=0,i=0,{functionNodes:a,decisionNodes:o,nestingNodes:s}=O(t);function c(e,t,l,u,d){let f=e.type===`class_body`&&u;f&&(l+=1),E(e,a)&&(u&&!d&&(l+=1),u=!0);let p=t+l,m=e.isNamed&&o.has(e.type)&&!Je(e),h=e.isNamed&&Ne.has(e.type),g=e.isNamed&&(s.has(e.type)||e.type===`else`&&(e.parent?.type===`case`||e.parent?.type===`case_match`)),_=m&&qe(e);m&&(n+=1),m&&!h&&!Fe.has(e.type)&&(r+=_?1:1+p),e.isNamed&&Me.has(e.type)&&(r+=1+p),r+=Be(e),Ve(e)&&(r+=1),Xe(e)&&(n+=1,Ue(e)&&(r+=1)),Ke(e)&&(n+=1,r+=1);let v=g&&!_?t+1:t;i=Math.max(i,v);for(let t of e.children)c(t,v,l,u,f)}for(let t of e.children)c(t,0,0,!1,!1);return{cyclomaticComplexity:n,cognitiveComplexity:r,nestingDepth:i}}function Be(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=>Pe.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`&&!Pe.has(r.type)&&(t+=1)}return t}function Ve(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=>!i.has(e.type)):!1}const He=new Set([`parenthesized_expression`,`parenthesized_statements`]);function Ue(e){let t=e.parent;if(!t)return!0;let n=t.parent;for(;n&&He.has(n.type);)n=n.parent;return!n||n.type!==t.type||We(Ge(n))!==We(e.text)}function We(e){return e===`and`?`&&`:e===`or`?`||`:e}function Ge(e){let t=e.childForFieldName(`operator`);return t?t.text:e.children.find(e=>!e.isNamed&&d.has(e.text))?.text}function Ke(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 qe(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 Je(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 Ye=new Set([`binary_expression`,`binary`,`boolean_operator`]);function Xe(e){if(e.isNamed||!d.has(e.text))return!1;let t=e.parent;return t!==null&&Ye.has(t.type)}function Ze(e,t,n=new Set,r){let i=new Set,a=[],o=O(t).functionNodes,s=new Map,c=0;function l(e,n,r){i.add(e);let o=t.name===`python`&&r===`self`?e.split(`.`).at(-1)??e:e;a.push({name:o,argumentCount:n,receiver:r})}function u(e,i){if(!(!i&&E(e,o))){if(!(t.name===`cpp`&&nt(e)))if(H(e)){c+=1;let i=t.name===`cpp`&&(e.type===`new_expression`||e.type===`call_expression`&&n.has(k(e.childForFieldName(`function`))??``))?void 0:Rn(e);if(i&&l(i,t.name===`ruby`&&e.type===`call`&&i.endsWith(`=`)?1:Qe(e),$e(e,t,r)),t.name===`ruby`&&e.type===`call`&&e.parent?.type===`operator_assignment`&&e.parent.childForFieldName(`left`)?.id===e.id){c+=1;let n=e.childForFieldName(`method`);n&&l(`${n.text}=`,1,$e(e,t,r))}}else ot(e,t)||rt(e,n)?c+=1:t.name===`ruby`&&st(e,s)&&(c+=1,l(e.text,0,`none`));for(let t of e.namedChildren)u(t,!1)}}return u(e,!0),{callCount:c,callees:i,callSites:a}}function Qe(e){let t=e.childForFieldName(`arguments`);return t?t.namedChildren.filter(e=>e.type!==`comment`&&e.type!==`block_argument`).length:e.type===`macro_invocation`?void 0:0}function $e(e,t,n){if(t.name===`ruby`&&e.type===`call`){let t=e.childForFieldName(`receiver`);return t?t.type===`self`?`self`:`other`:`none`}if(e.type===`method_invocation`){let t=e.childForFieldName(`object`);return t?t.type===`this`?`self`:`other`:`none`}let r=e.childForFieldName(`function`);if(r){let e=zn(r);if(e.type===`identifier`)return`none`;if(e.type===`scoped_identifier`&&e.childForFieldName(`path`)?.text===`Self`)return`self`;let i=e.type===`member_expression`?e.childForFieldName(`object`):e.type===`field_expression`?e.childForFieldName(`argument`)??e.childForFieldName(`value`):e.type===`attribute`||e.type===`selector_expression`?e.childForFieldName(`object`)??e.childForFieldName(`operand`):void 0;if(i){let e=t.name===`python`&&i.type===`identifier`&&i.text===`cls`;return et(i,n)||e?`self`:`other`}}return`other`}function et(e,t){return e.type===`this`||e.type===`self`||e.type===`identifier`&&(e.text===`self`||t!==void 0&&e.text===t)}const tt=new Set([`static_cast`,`dynamic_cast`,`const_cast`,`reinterpret_cast`]);function nt(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&&tt.has(n)}function rt(e,t){if(t.size===0)return!1;if(e.type===`compound_literal_expression`)return t.has(k(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(k(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)&&!L(e.parent,`extern`)){let n=e;for(;n?.type===`array_declarator`;)n=n.childForFieldName(`declarator`);return n?.type===`identifier`&&t.has(k(e.parent.childForFieldName(`type`))??``)}if(e.type===`field_initializer`){let n=e.namedChild(0),r=n?.type===`field_identifier`?n.text:k(n);return t.has(r??``)}return!1}function k(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 it=new Set([`class_specifier`,`struct_specifier`,`union_specifier`]);function at(e,t){let n=new Set;if(t.name!==`cpp`)return n;for(let t of M(e,it)){let e=t.childForFieldName(`name`)?.text;e&&t.childForFieldName(`body`)&&n.add(e)}return n}function ot(e,t){return t.name===`ruby`?e.type===`yield`||e.type===`super`&&e.parent?.type!==`call`:!1}function st(e,t){return e.type!==`identifier`||ct.has(e.text)||!lt(e)?!1:!pt(e,t)}const ct=new Set([`__FILE__`,`__LINE__`,`__ENCODING__`]);function lt(e){let t=e.parent;if(!t)return!1;switch(t.type){case`call`:if(t.childForFieldName(`method`)?.id===e.id)return!1;break;case`method`:case`singleton_method`:if(t.childForFieldName(`name`)?.id===e.id||t.childForFieldName(`object`)?.id===e.id)return!1;break;case`setter`:case`alias`:case`undef`:return!1;case`assignment`:case`operator_assignment`:if(t.childForFieldName(`left`)?.id===e.id)return!1;break;case`left_assignment_list`:case`destructured_left_assignment`:case`rest_assignment`:case`exception_variable`:case`method_parameters`:case`block_parameters`:case`lambda_parameters`:case`destructured_parameter`:case`splat_parameter`:case`optional_parameter`:case`keyword_parameter`:case`hash_splat_parameter`:case`block_parameter`:return t.childForFieldName(`value`)?.id===e.id;case`for`:if(t.childForFieldName(`pattern`)?.id===e.id)return!1}for(let t=e;t;t=t.parent){if(ut.has(t.type)||(t.parent?.type===`in_clause`||t.parent?.type===`match_pattern`)&&t.parent.childForFieldName(`pattern`)?.id===t.id)return!1;if(A.has(t.type))break}let n=t;for(;n.type===`parenthesized_statements`&&n.parent;)n=n.parent;return n.type!==`unary`||n.child(0)?.text!==`defined?`}const ut=new Set([`array_pattern`,`hash_pattern`,`find_pattern`,`keyword_pattern`,`as_pattern`,`alternative_pattern`]),dt=new Set([`method`,`singleton_method`,`class`,`module`,`singleton_class`,`program`]),ft=new Set([`block`,`do_block`,`lambda`]),A=new Set([...dt,...ft]);function pt(e,t){let n=e.text;for(let r=mt(e.parent);r;r=dt.has(r.type)?void 0:mt(r.parent)){let i=t.get(r.id);i||(i=ht(r),t.set(r.id,i));let a=i.get(n);if(a!==void 0&&a<e.startIndex)return!0}return!1}function mt(e){for(let t=e;t;t=t.parent)if(A.has(t.type))return t}function ht(e){let t=new Map,n=(e,n)=>{let r=t.get(e);(r===void 0||n<r)&&t.set(e,n)};if(vt(e.childForFieldName(`parameters`),n),ft.has(e.type)&&!e.childForFieldName(`parameters`)){n(`it`,e.startIndex);for(let t=1;t<=9;t+=1)n(`_${t}`,e.startIndex)}function r(e){for(let t of e.namedChildren)A.has(t.type)||(gt(t,n),r(t))}return r(e),t}function gt(e,t){switch(e.type){case`assignment`:j(e.childForFieldName(`left`),t);break;case`operator_assignment`:{let n=e.childForFieldName(`left`);n?.type===`identifier`&&t(n.text,n.startIndex);break}case`for`:j(e.childForFieldName(`pattern`),t);break;case`exception_variable`:{let n=e.namedChild(0);n?.type===`identifier`&&t(n.text,n.startIndex);break}case`in_clause`:case`match_pattern`:{let n=e.childForFieldName(`pattern`);n&&_t(n,t);break}case`binary`:if(e.children.some(e=>!e.isNamed&&e.text===`=~`)){let n=e.childForFieldName(`left`);if(n?.type===`regex`)for(let r of n.text.matchAll(/\(\?(?:<([A-Za-z_][A-Za-z0-9_]*)>|'([A-Za-z_][A-Za-z0-9_]*)')/gu)){let n=r[1]??r[2];n&&t(n,e.endIndex)}}}}function j(e,t){if(e){if(e.type===`identifier`){t(e.text,e.startIndex);return}if(e.type===`left_assignment_list`||e.type===`destructured_left_assignment`||e.type===`rest_assignment`)for(let n of e.namedChildren)j(n,t)}}function _t(e,t){if(e.type===`identifier`){t(e.text,e.startIndex);return}if(e.type===`keyword_pattern`&&e.namedChildCount===1){let n=e.childForFieldName(`key`);n&&t(n.text,n.startIndex)}for(let n of e.namedChildren)_t(n,t)}function vt(e,t){if(e)for(let n of e.namedChildren)if(n.type===`identifier`)t(n.text,n.startIndex);else if(n.type===`destructured_parameter`)vt(n,t);else{let e=n.childForFieldName(`name`);e?.type===`identifier`&&t(e.text,e.startIndex)}}function yt(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 bt(e,t){return M(e,new Set(t.classNodeTypes)).filter(xt).length}function xt(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 M(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 St(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===Ct(e)?.id&&t.type!==`statement_block`&&!n.has(t.type))return N(t,n)||P(t,n);for(let e of t.namedChildren)if(r(e,!1))return!0;return!1}return r(e,!0)}function Ct(e){return e.childForFieldName(`body`)??e.namedChild(e.namedChildCount-1)??void 0}function N(e,t){return wt(e,t,e=>e.type.startsWith(`jsx_`)||Tt(e,t))}function P(e,t){return wt(e,t,Hn)}function wt(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 Tt(e,t){return!H(e)||!Et(e.childForFieldName(`function`)??e.namedChild(0))?!1:e.namedChildren.some(e=>Dt(e,t))}function Et(e){if(!e)return!1;let t=U(e);return t===`map`||t===`flatMap`}function Dt(e,t){return t.has(e.type)?Ot(e,t):e.namedChildren.some(e=>Dt(e,t))}function Ot(e,t){let n=e.type===`arrow_function`?Ct(e):void 0;return n&&n.type!==`statement_block`&&!t.has(n.type)?N(n,t)||P(n,t):kt(e,t,e=>N(e,t)||P(e,t))}function kt(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 At(e,t){let n=new Set;function r(e){if(Wn(e,t))for(let r of Jn(e,t,{expandPythonSubmodules:!0}))n.add(r);for(let t of e.namedChildren)r(t)}return r(e),{declarations:jt(e,t),importSources:[...n]}}function jt(e,t){let n=Xt(e),r=t.name===`java`?Nt(e):``;return e.namedChildren.flatMap(e=>F(e,!1,r,t.name)).map(e=>!e.exported&&(n.has(e.name)||Mt(e,t))?{...e,exported:!0}:e)}function Mt(e,t){return t.name===`go`&&vr(e.name.split(`.`).at(-1)??``)}function Nt(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 Pt=new Set([`module`,`class`,`singleton_class`]);function F(e,t,n=``,r=``){let i=r===`cpp`;if(qt(e))return e.namedChildren.flatMap(e=>F(e,!0,n,r));if(e.type===`namespace_definition`){let i=e.childForFieldName(`name`)?.text;return i?(e.childForFieldName(`body`)?.namedChildren??[]).flatMap(e=>F(e,t,`${n}${i}::`,r)):[]}return Jt(e)?e.namedChildren.flatMap(e=>F(e,t,n,r)):e.type===`declaration`?I(Ut(e,t,i),n):e.type===`type_definition`?I(Rt(e,t),n):Pt.has(e.type)?It(e,t,n):e.type===`assignment`||e.type===`operator_assignment`?I(Lt(e,t),n,!0):I(R(e,t||r===`rust`&&Ft(e)),n)}function Ft(e){return e.namedChildren.some(e=>e.type===`visibility_modifier`&&e.namedChildCount===0)}function I(e,t,n=!1){return t?e.map(e=>n&&e.name.includes(`::`)?e:{...e,name:`${t}${e.name}`}):e}function It(e,t,n=``){let r=I(R(e,t),n,!0),i=r[0]?`${r[0].name}::`:n,a=e.childForFieldName(`body`);for(let e of a?.namedChildren??[])Pt.has(e.type)?r.push(...It(e,t,i)):(e.type===`assignment`||e.type===`operator_assignment`)&&r.push(...I(Lt(e,t),i,!0));return r}function Lt(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 Rt(e,t){let n=e.childForFieldName(`type`),r=n?R(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:B(n);e&&e!==i&&!a.has(e)&&(a.add(e),r.push({exported:t,name:e,startLine:n.startPosition.row+1}))}return r}const zt=new Set([`init_declarator`,`pointer_declarator`,`array_declarator`,`reference_declarator`,`identifier`,`field_identifier`]);function Bt(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=V(t);return t?.type!==`function_declarator`||t.childForFieldName(`declarator`)?.type===`parenthesized_declarator`}return zt.has(e.type)?!0:e.type===`function_declarator`&&e.childForFieldName(`declarator`)?.type===`parenthesized_declarator`}function L(e,t){return e.children.some(e=>e.type===`storage_class_specifier`&&e.text===t)}function Vt(e){let t=e.childForFieldName(`type`);return t?.type!==`type_identifier`||t.text!==`import`&&t.text!==`export`&&t.text!==`module`?!1:!Ht(e,t.text)}function Ht(e,t){let n=e;for(;n.parent;)n=n.parent;return M(n,new Set([`type_definition`,`alias_declaration`])).some(e=>(e.childForFieldName(`declarator`)??e.childForFieldName(`name`))?.text===t)}function Ut(e,t,n=!1){if(n&&Vt(e)||L(e,`static`))return[];let r=e.childForFieldName(`type`),i=r?R(r,t):[],a=new Set(i.map(e=>e.name)),o=L(e,`extern`);for(let r of e.namedChildren.filter(Bt)){if(o&&r.type!==`init_declarator`||n&&!o&&!L(e,`inline`)&&!Wt(r)&&!fn(e,r))continue;let s=B(r);s&&!a.has(s)&&(a.add(s),i.push({exported:t,name:s,startLine:r.startPosition.row+1}))}return i}function Wt(e){let t=e.type===`init_declarator`?e.childForFieldName(`declarator`)??e:e;for(;t;){if(t.type===`reference_declarator`)return!0;t=V(t)}return!1}function R(e,t){if(!Yt(e)||e.type.endsWith(`_specifier`)&&!e.childForFieldName(`body`)||L(e,`static`))return[];if(e.type===`enum_specifier`)return Gt(e,t);let n=Kt(e);return n?[{exported:t,name:n,startLine:e.startPosition.row+1}]:[]}function Gt(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 Kt(e){if(e.type===`method_declaration`&&e.childForFieldName(`receiver`))return $t(e);let t=e.childForFieldName(`name`);return t?.type===`template_type`&&(t=t.childForFieldName(`name`)),t?.type===`scope_resolution`?t.text:t?z(t)?t.text:void 0:B(e.childForFieldName(`declarator`),!0)||e.namedChildren.find(z)?.text}function qt(e){return e.type===`export_statement`||e.type===`export_declaration`}function Jt(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 Yt(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===`type_alias`||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 z(e){return e.type===`identifier`||e.type===`type_identifier`||e.type===`property_identifier`||e.type===`field_identifier`||e.type===`constant`}function Xt(e){let t=new Set;function n(e,r){if(!r&&Zt(e)){let n=Qt(e);n&&t.add(n)}let i=r||qt(e)&&e.childForFieldName(`source`)!==null;for(let t of e.namedChildren)n(t,i)}return n(e,!1),t}function Zt(e){return e.type===`export_specifier`||e.type===`namespace_export`}function Qt(e){let t=e.childForFieldName(`name`)??e.childForFieldName(`alias`)??e.namedChildren.find(z);return t&&z(t)?t.text:void 0}function $t(e){let t=e.childForFieldName(`name`),n=e.childForFieldName(`receiver`)?.namedChildren[0]?.childForFieldName(`type`);return!t||!z(t)||!n?t&&z(t)?t.text:void 0:`${en(n.text)}.${t.text}`}function en(e){return e.replaceAll(/\s+/gu,``).replace(/^\*+/u,``)}function tn(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`)&&(Un(e)||Kn(e,t)||Gn(e,t)||qn(e)||Xn(e,t))&&(r+=1),Wn(e,t))for(let r of Jn(e,t,{expandPythonSubmodules:!1}))n.add(r);cr(e,t)&&(i+=1),t.name===`go`&&(i+=hr(e));for(let t of e.namedChildren)a(t)}a(e);let o=[...n].filter(e=>tr(e,t.name)).length;return{importCount:r,importSourceCount:n.size,relativeImportCount:o,externalImportCount:n.size-o,exportCount:i}}function nn(e,t){let n={assignmentCount:0,awaitExpressionCount:0,loopStatementCount:0,mutableBindingCount:0,returnStatementCount:0,throwStatementCount:0,tryStatementCount:0};function r(e){rn(e)&&(n.assignmentCount+=1),an(e)&&(n.awaitExpressionCount+=1),on(e)&&(n.loopStatementCount+=1),n.mutableBindingCount+=sn(e,t),gn(e)&&(n.returnStatementCount+=1),_n(e)&&(n.throwStatementCount+=1),yn(e)&&(n.tryStatementCount+=1);for(let t of e.namedChildren)r(t)}return r(e),n}function rn(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 an(e){return e.type===`await_expression`||e.type===`await`||e.type===`co_await_expression`}function on(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 sn(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 dn(e)?t.length:0}if(n&&(e.type===`declaration`||e.type===`field_declaration`))return cn(e,t===`cpp`);if(n&&e.type===`function_definition`){let n=e.childForFieldName(`declarator`);return n?.type===`field_identifier`||n?.type===`identifier`?cn(e,t===`cpp`):0}if(e.type===`enhanced_for_statement`)return+!!dn(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&&fn(e,t)?ln(t):0}return+!!un(e)}function cn(e,t){return t&&Vt(e)?0:$(e.namedChildren.filter(t=>Bt(t)&&fn(e,t)).map(ln))}function ln(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 un(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`&&hn(e)}function dn(e){return!e.namedChildren.find(e=>e.type===`modifiers`)?.children.some(e=>e.text===`final`)}function fn(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=V(n);if(!e)break;if(n.type===`pointer_declarator`&&(r=!0,mn(n)&&!pn(e)))return!1;n=e}return r||!mn(e)}function pn(e){let t=e;for(;t;){if(t.type===`pointer_declarator`)return!0;t=V(t)}return!1}function mn(e){return e.namedChildren.some(e=>e.type===`type_qualifier`&&(e.text===`const`||e.text===`constexpr`))}function hn(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 gn(e){return e.type===`return_statement`||e.type===`return_expression`||e.type===`return`||e.type===`co_return_statement`}function _n(e){return e.type===`throw_statement`||e.type===`raise_statement`||vn(e)}function vn(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 yn(e){return e.type===`try_statement`||e.type===`try_with_resources_statement`||e.type===`rescue_modifier`||bn(e)}function bn(e){return(e.type===`begin`||e.type===`body_statement`)&&e.namedChildren.some(e=>e.type===`rescue`||e.type===`ensure`)}function xn(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=Cr(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 Sn(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}for(let t of e.namedChildren)n(t)}return n(e),t}function Cn(e,t){let n=e.length===0?[]:e.split(/\r\n|\n|\r/),r=new Map;for(let e of wn(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}Tn(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 wn(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 Tn(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 En(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(m.has(e.type)){Q(r,t.slice(e.startIndex,e.endIndex));return}if(e.childCount===0){let i=t.slice(e.startIndex,e.endIndex);p.has(e.type)?Q(r,i):(f.has(i)||f.has(e.type))&&Vn(e,i)&&Q(n,i||e.type);return}for(let t of e.children)i(t)}}return i(e),Dn({distinctOperators:n.size,distinctOperands:r.size,totalOperators:$(n.values()),totalOperands:$(r.values())})}function Dn(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 On(e){let t=Pn(e);if(t)return t;let n=e.childForFieldName(`name`);if(n)return n.text;let r=kn(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`?B(i.childForFieldName(`declarator`)):e.type===`func_literal`&&i.type===`expression_list`?Mn(e,i):e.type===`lambda`&&i.type===`assignment`?An(i):(e.type===`block`||e.type===`do_block`)&&jn(i)?i.parent?.type===`assignment`?An(i.parent):void 0:i.childForFieldName(`name`)?.text}}function kn(e){return B(e.childForFieldName(`declarator`))}function B(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=V(n)}}function V(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 An(e){let t=e.childForFieldName(`left`);return t?.type===`identifier`||t?.type===`constant`?t.text:void 0}function jn(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 Mn(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 Nn(e?.[r])}if(n.type===`var_spec`){let e=Y(n,`name`)[r];return Nn(e)}}}function Nn(e){return e?.type===`identifier`&&e.text!==`_`?e.text:void 0}function Pn(e){let t=e;for(;t;){let e=t.parent,n=e?.parent;if(e?.type!==`arguments`||n?.type!==`call_expression`||!Fn(n))return;let r=n.parent;if(r?.type===`variable_declarator`)return r.childForFieldName(`name`)?.text;t=n}}function Fn(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 H(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 In(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 Ln=new Set([`arrow_function`,`function_expression`,`function`,`lambda`,`lambda_expression`,`closure_expression`,`func_literal`,`anonymous_function`]);function Rn(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=In(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=zn(t);if(!Ln.has(n.type))return U(n)}function zn(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 Bn=new Set([`ternary_expression`,`conditional_expression`,`conditional`,`try_expression`,`conditional_type`]);function Vn(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&&Bn.has(n)}function U(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 U(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 U(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=U(n);if(r)return r}}function Hn(e){if(!H(e))return!1;let t=e.childForFieldName(`function`)??e.namedChild(0);return t?.text===`React.createElement`||t?.text===`createElement`}function Un(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 Wn(e,t){return Un(e)||Kn(e,t)||Gn(e,t)||qn(e)||Xn(e,t)||cr(e,t)&&e.childForFieldName(`source`)!==null}function Gn(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`?!Ht(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 Kn(e,t){return t.name===`rust`&&e.type===`mod_item`&&!e.childForFieldName(`body`)}function qn(e){return H(e)?(e.childForFieldName(`function`)??e.namedChild(0))?.text===`import`:!1}function Jn(e,t,n){if(t.name===`python`){let t=ir(e,n);if(t.length>0)return t}if(t.name===`rust`)return rr(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(Gn(e,t)){let t=/^(?:export\s+)?import\s+([\w.:]+|"[^"]+"|<[^>]+>)/u.exec(e.text)?.[1];return t?t.startsWith(`"`)?[`./${Z(t)}`]:[t]:[]}if(Xn(e,t))return Zn(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(qn(e))return er(e);let r=e.childForFieldName(`source`)??or(e);return r?[Z(r.text)]:[]}const Yn=new Set([`require`,`require_relative`,`load`]);function Xn(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&&Yn.has(n.text)}function Zn(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`?$n(e.text):e.text).join(``):Z(r.text);return e.childForFieldName(`method`)?.text===`require_relative`?[a.startsWith(`.`)?a:`./${a}`]:[a.replace(/^(?:\.\.?\/)+/u,``)]}const Qn=new Map([[`n`,`
|
|
2
|
-
`],[`t`,` `],[`r`,`\r`],[`s`,` `],[`0`,`\0`]]);function $n(e){let t=e.slice(1);return Qn.get(t)??t}function er(e){let t=e.childForFieldName(`arguments`)?.namedChild(0);return t&&sr(t)?[Z(t.text)]:[]}function tr(e,t){return e.startsWith(`.`)||e.startsWith(`/`)?!0:t===`rust`&&nr(e)}function nr(e){return/^(?:crate|self|super)(?:::|$)/u.test(e)}function rr(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 nr(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`&&nr(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 ir(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=>ar(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 ar(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=ar(t);if(e)return e}}function X(e){return e.replaceAll(/\s+/gu,``)}function or(e){if(sr(e))return e;for(let t of e.namedChildren){let e=or(t);if(e)return e}}function sr(e){return e.type===`string`||e.type===`string_literal`||e.type===`interpreted_string_literal`}function Z(e){return e.replaceAll(/^['"`<]|['"`>]$/gu,``)}function cr(e,t){return t.name===`rust`?e.type===`visibility_modifier`&&ur(e):t.name===`go`?!1:e.type.startsWith(`export`)&&e.type!==`exports_module_directive`||e.type===`public_field_definition`}const lr=new Set([`struct_item`,`enum_item`,`union_item`,`trait_item`]);function ur(e){if(e.namedChildCount>0)return!1;for(let t=e.parent?.parent;t;t=t.parent)if(t.type===`block`||t.type===`function_item`||(t.type===`mod_item`||lr.has(t.type))&&!Ft(t)||t.type===`impl_item`&&!dr(t))return!1;return!0}function dr(e){let t=mr(e.childForFieldName(`type`));if(t===void 0)return!0;let n=e;for(;n.parent;)n=n.parent;let r=pr(n,t);if(!r)return!0;let i=r.namedChildren.find(e=>e.type===`visibility_modifier`);return i!==void 0&&ur(i)}const fr=new Set([...lr,`type_item`]);function pr(e,t){return M(e,fr).find(e=>e.childForFieldName(`name`)?.text===t)}function mr(e){let t=e??void 0;for(;t;){if(t.type===`type_identifier`)return t.text;t=t.childForFieldName(`name`)??t.childForFieldName(`type`)??t.namedChildren.at(-1)}}function hr(e){if(e.type===`function_declaration`||e.type===`method_declaration`||e.type===`type_spec`||e.type===`type_alias`){let t=e.childForFieldName(`name`)?.text;return t!==void 0&&vr(t)&&_r(e)?1:0}return(e.type===`const_spec`||e.type===`var_spec`)&&_r(e)?Y(e,`name`).filter(e=>vr(e.text)).length:0}const gr=new Set([`type_declaration`,`const_declaration`,`var_declaration`,`var_spec_list`]);function _r(e){let t=e.parent;for(;t&&gr.has(t.type);)t=t.parent;return t?.type===`source_file`}function vr(e){return/^\p{Lu}/u.test(e)}function yr(e){let t=new Set;for(let n of e.keys())br(n,n,e,new Set)&&t.add(n);return t}function br(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),br(e,t,n,r)))return!0;return!1}function xr(e){let t=new Map,n=0;for(let r of e.keys())n=Math.max(n,Sr(r,e,new Set,t).depth);return n}function Sr(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=Sr(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 Cr(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 wr(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 Tr(e,t){return e.length===0?0:Math.max(...e.map(e=>e[t]))}function Er(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{h as TreeMeasurer,ee as collectCrossFileDuplicationFileData,b as collectDuplicationCandidates,v as defaultMeasurer,y as measureCode};
|
|
1
|
+
import{collectCrossFileDuplicateCandidates as e,defaultDuplicationOptions as t,hashText as n,measureDuplication as r}from"./duplication.js";import{createLanguageRegistry as i}from"./languages.js";import{measureDepDegree as a}from"./depDegree.js";import{commentNodeTypes as o,countNcss as s,getNcssSets as c,invalidateNcssSetsCache as l,ncssContribution as u}from"./ncss.js";import{measureWithNativeBackend as d}from"./nativeMetrics.js";import f from"tree-sitter";const p=new Set([`&&`,`||`,`and`,`or`]),m=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(`,`)),h=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(`.`)),g=new Set([`interpreted_string_literal`,`regex`,`user_defined_literal`,`integral_type`,`floating_point_type`,`sized_type_specifier`,`placeholder_type_specifier`]);var _=class{registry=i();registerLanguage(e){ae(e),l(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,t){let n=this.registry.get(t.language);if(!n)throw Error(`Unsupported language: ${t.language}`);let i=y(t)?d(e,n,t.includeSyntaxTree??!1):void 0;if(i)return T(i,t.includeSyntaxTree??!1);let a=v(e,n),o=E(a,U(a,new Set(n.functionNodeTypes)).filter(e=>!D(e)&&ie(e)),n,e),c=se(a,n),{lines:l,codeLineNumbers:u}=W(e,a);return{language:n.name,bytes:Buffer.byteLength(e),lines:l,functions:o,cognitiveComplexity:c.cognitiveComplexity,maxCognitiveComplexity:Ce(o),nestingDepth:c.nestingDepth,ncssCount:s(a,n),duplication:r(a,u,t.duplication),halstead:G(a,e),syntaxTree:t.includeSyntaxTree?a.toString():void 0}}collectDuplicationCandidates(e,t){return this.collectCrossFileDuplicationFileData(e,t).candidates}collectFunctionTokenSequences(e,t){let{language:n,root:r}=this.parse(e,t);return U(r,new Set(n.functionNodeTypes)).filter(e=>!D(e)&&ie(e)).map(e=>me(e))}collectCrossFileDuplicationFileData(t,n){let{root:r}=this.parse(t,n);return{...e(r,n.duplication),codeLineNumbers:W(t,r).codeLineNumbers}}parse(e,t){let n=this.registry.get(t.language);if(!n)throw Error(`Unsupported language: ${t.language}`);return{language:n,root:v(e,n)}}};function v(e,t){let n=new f;return n.setLanguage(t.parserLanguage),n.parse(e,void 0,{bufferSize:e.length+1}).rootNode}function y(e){let n=e.duplication;return(n?.minTokens??t.minTokens)===t.minTokens&&(n?.maxGapTokens??t.maxGapTokens)===t.maxGapTokens&&(n?.minSimilarityPercent??t.minSimilarityPercent)===t.minSimilarityPercent}const b=new _;function x(e,t){return b.measure(e,t)}function S(e,t){return b.collectDuplicationCandidates(e,t)}function C(e,t){return b.collectFunctionTokenSequences(e,t)}function w(e,t){return b.collectCrossFileDuplicationFileData(e,t)}function T(e,t){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,cognitiveComplexity:e.cognitiveComplexity,nestingDepth:e.nestingDepth,ncss:e.ncss,parameterCount:e.parameterCount,halstead:K(e.halsteadCounts),depDegree:e.depDegree})),cognitiveComplexity:e.cognitiveComplexity,maxCognitiveComplexity:e.maxCognitiveComplexity,nestingDepth:e.nestingDepth,ncssCount:e.ncssCount,duplication:e.duplication,halstead:K(e.halsteadCounts),syntaxTree:t?e.syntaxTree:void 0}}function E(e,t,n,r){let i=oe(e,n),{functionNodes:o}=N(n);return t.map(e=>{let t=i.get(e.id);if(!t)throw Error(`missing body metrics for function node at line ${e.startPosition.row+1}`);return{name:he(e),nodeType:e.type,startLine:e.startPosition.row+1,startColumn:e.startPosition.column,endLine:e.endPosition.row+1,cognitiveComplexity:t.cognitiveComplexity,nestingDepth:t.nestingDepth,ncss:t.ncss,parameterCount:ee(e),halstead:G(e,r),depDegree:a(e,e=>O(e,o))}})}function ee(e){if(e.childForFieldName(`parameter`))return 1;let t=ne(e);if(!t)return 0;if(t.type===`identifier`)return 1;let n=new Set(Q(t,`locals`).map(e=>e.id)),r=0;for(let e of t.namedChildren)e.type===`comment`||e.type===`self_parameter`||e.type===`receiver_parameter`||e.type===`block_parameter`||e.type===`positional_separator`||e.type===`keyword_separator`||n.has(e.id)||te(e)||(r+=e.type===`parameter_declaration`?Math.max(1,Q(e,`name`).length):1);let i=t.children.filter(e=>!e.isNamed&&e.text===`...`).length;return r+i}function te(e){return e.type===`parameter_declaration`&&e.childForFieldName(`declarator`)===null&&e.childForFieldName(`type`)?.text===`void`}function ne(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=Y(n)}return e.namedChildren.find(e=>e.type===`formal_parameters`||e.type===`parameter_list`)}const re=new Set([`function_definition`,`constructor_declaration`,`compact_constructor_declaration`,`function_signature_item`]);function ie(e){return!re.has(e.type)||e.childForFieldName(`body`)!==null||e.namedChildren.some(e=>e.type===`try_statement`)}function D(e){return(e.type===`block`||e.type===`do_block`)&&e.parent?.type===`lambda`}function O(e,t){return t.has(e.type)&&!D(e)}const k=new Set([`switch_statement`,`switch_expression`,`expression_switch_statement`,`type_switch_statement`,`select_statement`,`match_expression`,`match_statement`,`case`,`case_match`]),A=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`]),j=new Set([`if_statement`,`if_expression`,`if`,`unless`]),M=new WeakMap;function ae(e){M.delete(e)}function N(e){let t=M.get(e);return t||(t={functionNodes:new Set(e.functionNodeTypes),decisionNodes:new Set(e.decisionNodeTypes),nestingNodes:new Set(e.nestingNodeTypes)},M.set(e,t)),t}function P(e,t){return{cognitiveComplexity:0,nestingSensitiveCount:0,nestingDepth:0,ncss:0,hasOwnNcssContribution:!1,entryCognitiveNesting:e,entryStructuralNesting:t}}function oe(e,t){let{functionNodes:n,decisionNodes:r,nestingNodes:i}=N(t),{countable:a,containers:o}=c(t),s=new Map,l=[P(0,0)];function d(e,t,c,f,p,m){let h=e.type===`class_body`&&f;h&&(p=!0,c+=1);let g=O(e,n);g&&(f&&!m&&(c+=1),f=!0);let _=l.at(-1),v=t+c-_.entryCognitiveNesting,y=!p&&!g,b=e.isNamed&&r.has(e.type)&&!V(e),x=e.isNamed&&A.has(e.type),S=e.isNamed&&(i.has(e.type)||e.type===`else`&&(e.parent?.type===`case`||e.parent?.type===`case_match`)),C=b&&B(e);b&&!x&&(C?_.cognitiveComplexity+=1:(_.cognitiveComplexity+=1+v,_.nestingSensitiveCount+=1)),e.isNamed&&k.has(e.type)&&(_.cognitiveComplexity+=1+v,_.nestingSensitiveCount+=1),_.cognitiveComplexity+=F(e),I(e)&&(_.cognitiveComplexity+=1),H(e)&&L(e)&&(_.cognitiveComplexity+=1),z(e)&&(_.cognitiveComplexity+=1);let w=S&&!C?t+1:t;y&&(_.nestingDepth=Math.max(_.nestingDepth,w-_.entryStructuralNesting)),g&&l.push(P(w+c,w));let T=u(e,a,o),E=l.at(-1);E.ncss+=T,g&&T>0&&(E.hasOwnNcssContribution=!0);for(let t of e.children)d(t,w,c,f,!g&&p,h);if(g){let t=l.pop();s.set(e.id,{cognitiveComplexity:t.cognitiveComplexity,nestingDepth:t.nestingDepth,ncss:t.ncss+ +!t.hasOwnNcssContribution});let n=l.at(-1);n.cognitiveComplexity+=t.cognitiveComplexity+t.nestingSensitiveCount*(t.entryCognitiveNesting-n.entryCognitiveNesting),n.nestingSensitiveCount+=t.nestingSensitiveCount,n.ncss+=t.ncss}}return d(e,0,0,!1,!1,!1),s}function se(e,t){let n=0,r=0,{functionNodes:i,decisionNodes:a,nestingNodes:o}=N(t);function s(e,t,c,l,u){let d=e.type===`class_body`&&l;d&&(c+=1),O(e,i)&&(l&&!u&&(c+=1),l=!0);let f=t+c,p=e.isNamed&&a.has(e.type)&&!V(e),m=e.isNamed&&A.has(e.type),h=e.isNamed&&(o.has(e.type)||e.type===`else`&&(e.parent?.type===`case`||e.parent?.type===`case_match`)),g=p&&B(e);p&&!m&&(n+=g?1:1+f),e.isNamed&&k.has(e.type)&&(n+=1+f),n+=F(e),I(e)&&(n+=1),H(e)&&L(e)&&(n+=1),z(e)&&(n+=1);let _=h&&!g?t+1:t;r=Math.max(r,_);for(let t of e.children)s(t,_,c,l,d)}for(let t of e.children)s(t,0,0,!1,!1);return{cognitiveComplexity:n,nestingDepth:r}}function F(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=>j.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`&&!j.has(r.type)&&(t+=1)}return t}function I(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=>!o.has(e.type)):!1}const ce=new Set([`parenthesized_expression`,`parenthesized_statements`]);function L(e){let t=e.parent;if(!t)return!0;let n=t.parent;for(;n&&ce.has(n.type);)n=n.parent;return!n||n.type!==t.type||R(le(n))!==R(e.text)}function R(e){return e===`and`?`&&`:e===`or`?`||`:e}function le(e){let t=e.childForFieldName(`operator`);return t?t.text:e.children.find(e=>!e.isNamed&&p.has(e.text))?.text}function z(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 B(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 V(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 ue=new Set([`binary_expression`,`binary`,`boolean_operator`]);function H(e){if(e.isNamed||!p.has(e.text))return!1;let t=e.parent;return t!==null&&ue.has(t.type)}function U(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 W(e,t){let n=e.length===0?[]:e.split(/\r\n|\n|\r/),r=new Map;for(let e of de(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}fe(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 de(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 fe(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 G(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(g.has(e.type)){$(r,t.slice(e.startIndex,e.endIndex));return}if(e.childCount===0){let i=t.slice(e.startIndex,e.endIndex);h.has(e.type)?$(r,i):(m.has(i)||m.has(e.type))&&Se(e,i)&&$(n,i||e.type);return}for(let t of e.children)i(t)}}return i(e),K({distinctOperators:n.size,distinctOperands:r.size,totalOperators:we(n.values()),totalOperands:we(r.values())})}function K(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);return{distinctOperators:t,distinctOperands:n,totalOperators:r,totalOperands:i,vocabulary:a,length:o,volume:s,effort:(n===0?0:t/2*(i/n))*s}}const pe=new Set([`identifier`,`property_identifier`,`field_identifier`,`type_identifier`,`constant`,`instance_variable`,`class_variable`,`global_variable`]);function me(e){let t=[];return q(e,t,new Map),Int32Array.from(t)}function q(e,t,r){if(e.type!==`comment`&&e.type!==`line_comment`&&e.type!==`block_comment`){if(g.has(e.type)){t.push(n(e.type));return}if(e.childCount>0){for(let n of e.children)q(n,t,r);return}if(pe.has(e.type)){let i=r.get(e.text);i===void 0&&(i=r.size,r.set(e.text,i)),t.push(n(`id${i}`));return}t.push(n(h.has(e.type)?e.type:e.text))}}function he(e){let t=ye(e);if(t)return t;let n=e.childForFieldName(`name`);if(n)return n.text;let r=ge(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`?J(i.childForFieldName(`declarator`)):e.type===`func_literal`&&i.type===`expression_list`?ve(e,i):e.type===`lambda`&&i.type===`assignment`?X(i):(e.type===`block`||e.type===`do_block`)&&_e(i)?i.parent?.type===`assignment`?X(i.parent):void 0:i.childForFieldName(`name`)?.text}}function ge(e){return J(e.childForFieldName(`declarator`))}function J(e){let t=e;for(;t;)switch(t.type){case`identifier`:case`field_identifier`:case`type_identifier`:case`destructor_name`:case`operator_name`:return t.text;case`operator_cast`:return`operator ${t.childForFieldName(`type`)?.text??``}`.trimEnd();case`template_function`:case`qualified_identifier`:t=t.childForFieldName(`name`);break;default:t=Y(t)}}function Y(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 X(e){let t=e.childForFieldName(`left`);return t?.type===`identifier`||t?.type===`constant`?t.text:void 0}function _e(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 ve(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 Z(e?.[r])}if(n.type===`var_spec`){let e=Q(n,`name`)[r];return Z(e)}}}function Z(e){return e?.type===`identifier`&&e.text!==`_`?e.text:void 0}function ye(e){let t=e;for(;t;){let e=t.parent,n=e?.parent;if(e?.type!==`arguments`||n?.type!==`call_expression`||!be(n))return;let r=n.parent;if(r?.type===`variable_declarator`)return r.childForFieldName(`name`)?.text;t=n}}function be(e){let t=e.childForFieldName(`function`)??e.namedChild(0);return t?.text===`memo`||t?.text===`React.memo`||t?.text===`forwardRef`||t?.text===`React.forwardRef`}const xe=new Set([`ternary_expression`,`conditional_expression`,`conditional`,`try_expression`,`conditional_type`]);function Se(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&&xe.has(n)}function Q(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 $(e,t){e.set(t,(e.get(t)??0)+1)}function Ce(e){return e.length===0?0:Math.max(...e.map(e=>e.cognitiveComplexity))}function we(e){let t=0;for(let n of e)t+=n;return t}export{_ as TreeMeasurer,w as collectCrossFileDuplicationFileData,S as collectDuplicationCandidates,C as collectFunctionTokenSequences,b as defaultMeasurer,x as measureCode};
|
|
3
2
|
//# sourceMappingURL=metrics.js.map
|