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.
Files changed (74) hide show
  1. package/README.md +156 -106
  2. package/dist/cli.cjs +3 -3
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +3 -3
  5. package/dist/cli.js.map +1 -1
  6. package/dist/cliConfig.cjs +1 -1
  7. package/dist/cliConfig.cjs.map +1 -1
  8. package/dist/cliConfig.d.ts +27 -84
  9. package/dist/cliConfig.js +1 -1
  10. package/dist/cliConfig.js.map +1 -1
  11. package/dist/crossFileDuplication.cjs +1 -1
  12. package/dist/crossFileDuplication.cjs.map +1 -1
  13. package/dist/crossFileDuplication.d.ts +9 -0
  14. package/dist/crossFileDuplication.js +1 -1
  15. package/dist/crossFileDuplication.js.map +1 -1
  16. package/dist/depDegree.cjs +2 -0
  17. package/dist/depDegree.cjs.map +1 -0
  18. package/dist/depDegree.d.ts +12 -0
  19. package/dist/depDegree.js +2 -0
  20. package/dist/depDegree.js.map +1 -0
  21. package/dist/diffCommand.cjs +5 -0
  22. package/dist/diffCommand.cjs.map +1 -0
  23. package/dist/diffCommand.d.ts +17 -0
  24. package/dist/diffCommand.js +5 -0
  25. package/dist/diffCommand.js.map +1 -0
  26. package/dist/duplication.cjs +1 -1
  27. package/dist/duplication.cjs.map +1 -1
  28. package/dist/duplication.d.ts +23 -2
  29. package/dist/duplication.js +1 -1
  30. package/dist/duplication.js.map +1 -1
  31. package/dist/git.cjs +2 -0
  32. package/dist/git.cjs.map +1 -0
  33. package/dist/git.d.ts +27 -0
  34. package/dist/git.js +2 -0
  35. package/dist/git.js.map +1 -0
  36. package/dist/index.cjs +1 -1
  37. package/dist/index.d.ts +4 -2
  38. package/dist/index.js +1 -1
  39. package/dist/languages.cjs +1 -1
  40. package/dist/languages.cjs.map +1 -1
  41. package/dist/languages.js +1 -1
  42. package/dist/languages.js.map +1 -1
  43. package/dist/metrics.cjs +1 -2
  44. package/dist/metrics.cjs.map +1 -1
  45. package/dist/metrics.d.ts +11 -0
  46. package/dist/metrics.js +1 -2
  47. package/dist/metrics.js.map +1 -1
  48. package/dist/nativeMetrics.cjs +1 -1
  49. package/dist/nativeMetrics.cjs.map +1 -1
  50. package/dist/nativeMetrics.d.ts +7 -3
  51. package/dist/nativeMetrics.js +1 -1
  52. package/dist/nativeMetrics.js.map +1 -1
  53. package/dist/regressionGate.cjs +2 -0
  54. package/dist/regressionGate.cjs.map +1 -0
  55. package/dist/regressionGate.d.ts +106 -0
  56. package/dist/regressionGate.js +2 -0
  57. package/dist/regressionGate.js.map +1 -0
  58. package/dist/scan.cjs +2 -0
  59. package/dist/scan.cjs.map +1 -0
  60. package/dist/scan.d.ts +55 -0
  61. package/dist/scan.js +2 -0
  62. package/dist/scan.js.map +1 -0
  63. package/dist/types.d.ts +24 -76
  64. package/package.json +7 -5
  65. package/dist/architectureMetrics.cjs +0 -2
  66. package/dist/architectureMetrics.cjs.map +0 -1
  67. package/dist/architectureMetrics.d.ts +0 -41
  68. package/dist/architectureMetrics.js +0 -2
  69. package/dist/architectureMetrics.js.map +0 -1
  70. package/dist/typescriptProject.cjs +0 -3
  71. package/dist/typescriptProject.cjs.map +0 -1
  72. package/dist/typescriptProject.d.ts +0 -24
  73. package/dist/typescriptProject.js +0 -3
  74. package/dist/typescriptProject.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@ export { measureCrossFileDuplication } from './crossFileDuplication.js';
2
2
  export type { CrossFileDuplicateBlockGroup, CrossFileDuplicateOccurrence, CrossFileDuplicationMetrics, CrossFileDuplicationSourceFile, } from './crossFileDuplication.js';
3
3
  export type { CrossFileDuplicateCandidate, CrossFileDuplicationFileData } from './duplication.js';
4
4
  export { defaultLanguages, supportedLanguages } from './languages.js';
5
- export { TreeMeasurer, collectCrossFileDuplicationFileData, collectDuplicationCandidates, defaultMeasurer, measureCode, } from './metrics.js';
5
+ export { TreeMeasurer, collectCrossFileDuplicationFileData, collectDuplicationCandidates, collectFunctionTokenSequences, defaultMeasurer, measureCode, } from './metrics.js';
6
6
  export { isNativeBackendAvailable } from './nativeMetrics.js';
7
- export type { CallGraphMetrics, CodeMetrics, CohesionMetrics, CouplingMetrics, DeclarationMetrics, DuplicationMetrics, DuplicationOptions, FunctionMetrics, HalsteadMetrics, LanguageDefinition, LanguageName, LineMetrics, MeasureOptions, ModuleMetrics, SupportedLanguage, SyntaxFeatureMetrics, TypeComplexityMetrics, } from './types.js';
7
+ export { defaultGateOptions, evaluateRegressionGate } from './regressionGate.js';
8
+ export type { GateFileInput, GateOptions, GateResult, GateTolerances, GateViolation, NewFunctionThresholds, } from './regressionGate.js';
9
+ export type { CodeMetrics, DuplicationMetrics, DuplicationOptions, FunctionMetrics, HalsteadMetrics, LanguageDefinition, LanguageName, LineMetrics, MeasureOptions, SupportedLanguage, } from './types.js';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{measureCrossFileDuplication as e}from"./crossFileDuplication.js";import{defaultLanguages as t,supportedLanguages as n}from"./languages.js";import{isNativeBackendAvailable as r}from"./nativeMetrics.js";import{TreeMeasurer as i,collectCrossFileDuplicationFileData as a,collectDuplicationCandidates as o,defaultMeasurer as s,measureCode as c}from"./metrics.js";export{i as TreeMeasurer,a as collectCrossFileDuplicationFileData,o as collectDuplicationCandidates,t as defaultLanguages,s as defaultMeasurer,r as isNativeBackendAvailable,c as measureCode,e as measureCrossFileDuplication,n as supportedLanguages};
1
+ import{measureCrossFileDuplication as e}from"./crossFileDuplication.js";import{defaultLanguages as t,supportedLanguages as n}from"./languages.js";import{isNativeBackendAvailable as r}from"./nativeMetrics.js";import{TreeMeasurer as i,collectCrossFileDuplicationFileData as a,collectDuplicationCandidates as o,collectFunctionTokenSequences as s,defaultMeasurer as c,measureCode as l}from"./metrics.js";import{defaultGateOptions as u,evaluateRegressionGate as d}from"./regressionGate.js";export{i as TreeMeasurer,a as collectCrossFileDuplicationFileData,o as collectDuplicationCandidates,s as collectFunctionTokenSequences,u as defaultGateOptions,t as defaultLanguages,c as defaultMeasurer,d as evaluateRegressionGate,r as isNativeBackendAvailable,l as measureCode,e as measureCrossFileDuplication,n as supportedLanguages};
@@ -1,2 +1,2 @@
1
- "use strict";const e=require("./_virtual/_rolldown/runtime.cjs");let t=require("tree-sitter-c");t=e.__toESM(t,1);let n=require("tree-sitter-cpp");n=e.__toESM(n,1);let r=require("tree-sitter-go");r=e.__toESM(r,1);let i=require("tree-sitter-java");i=e.__toESM(i,1);let a=require("tree-sitter-javascript");a=e.__toESM(a,1);let o=require("tree-sitter-python");o=e.__toESM(o,1);let s=require("tree-sitter-ruby");s=e.__toESM(s,1);let c=require("tree-sitter-rust");c=e.__toESM(c,1);let l=require("tree-sitter-typescript");l=e.__toESM(l,1);const u=[`function`,`function_declaration`,`function_definition`,`function_expression`,`function_item`,`function_signature_item`,`function_declarator`,`func_literal`,`method_declaration`,`method_definition`,`method_spec`,`arrow_function`,`generator_function`,`generator_function_declaration`,`lambda`,`lambda_expression`,`closure_expression`],d=[`class`,`class_declaration`,`class_definition`,`interface_declaration`,`trait_item`,`struct_item`,`enum_item`,`union_item`],f=[`if_statement`,`elif_clause`,`else_if_clause`,`for_statement`,`for_in_statement`,`while_statement`,`do_statement`,`catch_clause`,`except_clause`,`case_clause`,`switch_case`,`match_arm`,`conditional_expression`,`ternary_expression`,`if_expression`,`while_expression`,`for_expression`,`loop_expression`],p=[...f,`expression_case`,`type_case`,`communication_case`],m=[...f,`switch_default`],h=[...p,`default_case`],g=[...u,`constructor_declaration`,`compact_constructor_declaration`],_=[...d,`enum_declaration`,`record_declaration`,`annotation_type_declaration`,`object_creation_expression`,`enum_constant`],v=[...f,`enhanced_for_statement`,`switch_block_statement_group`,`switch_rule`],y=[...v,`throw_statement`],b=[`method`,`singleton_method`,`lambda`,`block`,`do_block`],x=[`class`,`module`],S=[`if`,`elsif`,`unless`,`while`,`until`,`for`,`when`,`in_clause`,`rescue`,`conditional`,`if_modifier`,`unless_modifier`,`while_modifier`,`until_modifier`,`rescue_modifier`],C=[`function_definition`,`lambda_expression`],w=[`struct_specifier`,`enum_specifier`,`union_specifier`],T=[...f,`case_statement`],E=[...w,`class_specifier`],D=[...T,`for_range_loop`],O=`import_statement.export_statement.lexical_declaration.variable_declaration.function_declaration.function_signature.generator_function_declaration.class_declaration.abstract_class_declaration.module.method_definition.abstract_method_signature.class_static_block.field_definition.public_field_definition.type_alias_declaration.interface_declaration.enum_declaration.expression_statement.if_statement.else_clause.switch_statement.switch_case.switch_default.for_statement.for_in_statement.while_statement.do_statement.catch_clause.finally_clause.labeled_statement.return_statement.break_statement.continue_statement.throw_statement.debugger_statement.with_statement`.split(`.`),k=`import_statement.import_from_statement.future_import_statement.print_statement.exec_statement.assert_statement.expression_statement.return_statement.delete_statement.raise_statement.pass_statement.break_statement.continue_statement.global_statement.nonlocal_statement.if_statement.elif_clause.else_clause.for_statement.while_statement.except_clause.except_group_clause.finally_clause.with_statement.match_statement.case_clause.function_definition.class_definition.type_alias_statement`.split(`.`),A=`package_clause.import_spec.type_spec.type_alias.const_spec.var_spec.function_declaration.method_declaration.short_var_declaration.expression_statement.send_statement.inc_statement.dec_statement.assignment_statement.if_statement.for_statement.expression_switch_statement.type_switch_statement.select_statement.expression_case.type_case.communication_case.default_case.return_statement.break_statement.continue_statement.goto_statement.fallthrough_statement.defer_statement.go_statement.labeled_statement`.split(`.`),j=[`use_declaration`,`extern_crate_declaration`,`foreign_mod_item`,`mod_item`,`const_item`,`static_item`,`struct_item`,`enum_item`,`union_item`,`trait_item`,`impl_item`,`function_item`,`function_signature_item`,`type_item`,`associated_type`,`macro_definition`,`field_declaration`,`let_declaration`,`expression_statement`,`else_clause`,`match_arm`],M=`package_declaration.import_declaration.module_declaration.requires_module_directive.exports_module_directive.opens_module_directive.uses_module_directive.provides_module_directive.class_declaration.interface_declaration.enum_declaration.annotation_type_declaration.annotation_type_element_declaration.record_declaration.field_declaration.constant_declaration.method_declaration.constructor_declaration.compact_constructor_declaration.static_initializer.explicit_constructor_invocation.local_variable_declaration.expression_statement.if_statement.while_statement.do_statement.for_statement.enhanced_for_statement.switch_statement.switch_expression.switch_label.break_statement.continue_statement.return_statement.throw_statement.assert_statement.synchronized_statement.labeled_statement.yield_statement.resource.catch_clause.finally_clause`.split(`.`),N=[`elsif`,`else`,`when`,`in_clause`,`rescue`,`ensure`],P=[`program`,`body_statement`,`then`,`else`,`do`,`block_body`,`begin`,`ensure`],F=[`preproc_include`,`preproc_def`,`preproc_function_def`,`declaration`,`type_definition`,`field_declaration`,`function_definition`,`struct_specifier`,`enum_specifier`,`union_specifier`,`expression_statement`,`if_statement`,`else_clause`,`switch_statement`,`case_statement`,`for_statement`,`while_statement`,`do_statement`,`return_statement`,`break_statement`,`continue_statement`,`goto_statement`,`labeled_statement`],I=[...F,`class_specifier`,`namespace_definition`,`using_declaration`,`alias_declaration`,`namespace_alias_definition`,`concept_definition`,`static_assert_declaration`,`for_range_loop`,`catch_clause`,`throw_statement`,`co_return_statement`,`co_yield_statement`];function L(e){return z(e,`default`)?e.default:e}function R(e){return l.default[e]}function z(e,t){return typeof e!=`object`||!e||!(t in e)?!1:!!e[t]}const B=[{name:`javascript`,aliases:[`js`,`mjs`,`cjs`],parserLanguage:L(a.default)},{name:`jsx`,parserLanguage:L(a.default)},{name:`typescript`,aliases:[`ts`],parserLanguage:R(`typescript`)},{name:`tsx`,parserLanguage:R(`tsx`)},{name:`python`,aliases:[`py`],parserLanguage:L(o.default),ncssNodeTypes:k},{name:`go`,parserLanguage:L(r.default),decisionNodeTypes:p,nestingNodeTypes:h,ncssNodeTypes:A},{name:`rust`,aliases:[`rs`],parserLanguage:L(c.default),ncssNodeTypes:j,ncssContainerNodeTypes:[`block`,`else_clause`]},{name:`java`,parserLanguage:L(i.default),functionNodeTypes:g,classNodeTypes:_,decisionNodeTypes:y,nestingNodeTypes:v,ncssNodeTypes:M},{name:`ruby`,aliases:[`rb`],parserLanguage:L(s.default),functionNodeTypes:b,classNodeTypes:x,decisionNodeTypes:S,nestingNodeTypes:S,ncssNodeTypes:N,ncssContainerNodeTypes:P},{name:`c`,parserLanguage:L(t.default),functionNodeTypes:C,classNodeTypes:w,decisionNodeTypes:T,nestingNodeTypes:T,ncssNodeTypes:F},{name:`cpp`,aliases:[`c++`,`cxx`],parserLanguage:L(n.default),functionNodeTypes:C,classNodeTypes:E,decisionNodeTypes:D,nestingNodeTypes:D,ncssNodeTypes:I}].map(e=>({functionNodeTypes:u,classNodeTypes:d,decisionNodeTypes:f,nestingNodeTypes:m,ncssNodeTypes:O,...e}));function V(e=B){let t=new Map;for(let n of e){t.set(n.name,n);for(let e of n.aliases??[])t.set(e,n)}return t}const H=B.map(e=>e.name);exports.createLanguageRegistry=V,exports.defaultLanguages=B,exports.supportedLanguages=H;
1
+ "use strict";const e=require("./_virtual/_rolldown/runtime.cjs");let t=require("tree-sitter-c");t=e.__toESM(t,1);let n=require("tree-sitter-cpp");n=e.__toESM(n,1);let r=require("tree-sitter-go");r=e.__toESM(r,1);let i=require("tree-sitter-java");i=e.__toESM(i,1);let a=require("tree-sitter-javascript");a=e.__toESM(a,1);let o=require("tree-sitter-python");o=e.__toESM(o,1);let s=require("tree-sitter-ruby");s=e.__toESM(s,1);let c=require("tree-sitter-rust");c=e.__toESM(c,1);let l=require("tree-sitter-typescript");l=e.__toESM(l,1);const u=[`function`,`function_declaration`,`function_definition`,`function_expression`,`function_item`,`function_signature_item`,`function_declarator`,`func_literal`,`method_declaration`,`method_definition`,`method_spec`,`arrow_function`,`generator_function`,`generator_function_declaration`,`lambda`,`lambda_expression`,`closure_expression`],d=[`if_statement`,`elif_clause`,`else_if_clause`,`for_statement`,`for_in_statement`,`while_statement`,`do_statement`,`catch_clause`,`except_clause`,`case_clause`,`switch_case`,`match_arm`,`conditional_expression`,`ternary_expression`,`if_expression`,`while_expression`,`for_expression`,`loop_expression`],f=[...d,`expression_case`,`type_case`,`communication_case`],p=[...d,`switch_default`],m=[...f,`default_case`],h=[...u,`constructor_declaration`,`compact_constructor_declaration`],g=[...d,`enhanced_for_statement`,`switch_block_statement_group`,`switch_rule`],_=[`method`,`singleton_method`,`lambda`,`block`,`do_block`],v=[`if`,`elsif`,`unless`,`while`,`until`,`for`,`when`,`in_clause`,`rescue`,`conditional`,`if_modifier`,`unless_modifier`,`while_modifier`,`until_modifier`,`rescue_modifier`],y=[`function_definition`,`lambda_expression`],b=[...d,`case_statement`],x=[...b,`for_range_loop`],S=`import_statement.export_statement.lexical_declaration.variable_declaration.function_declaration.function_signature.generator_function_declaration.class_declaration.abstract_class_declaration.module.method_definition.abstract_method_signature.class_static_block.field_definition.public_field_definition.type_alias_declaration.interface_declaration.enum_declaration.expression_statement.if_statement.else_clause.switch_statement.switch_case.switch_default.for_statement.for_in_statement.while_statement.do_statement.catch_clause.finally_clause.labeled_statement.return_statement.break_statement.continue_statement.throw_statement.debugger_statement.with_statement`.split(`.`),C=`import_statement.import_from_statement.future_import_statement.print_statement.exec_statement.assert_statement.expression_statement.return_statement.delete_statement.raise_statement.pass_statement.break_statement.continue_statement.global_statement.nonlocal_statement.if_statement.elif_clause.else_clause.for_statement.while_statement.except_clause.except_group_clause.finally_clause.with_statement.match_statement.case_clause.function_definition.class_definition.type_alias_statement`.split(`.`),w=`package_clause.import_spec.type_spec.type_alias.const_spec.var_spec.function_declaration.method_declaration.short_var_declaration.expression_statement.send_statement.inc_statement.dec_statement.assignment_statement.if_statement.for_statement.expression_switch_statement.type_switch_statement.select_statement.expression_case.type_case.communication_case.default_case.return_statement.break_statement.continue_statement.goto_statement.fallthrough_statement.defer_statement.go_statement.labeled_statement`.split(`.`),T=[`use_declaration`,`extern_crate_declaration`,`foreign_mod_item`,`mod_item`,`const_item`,`static_item`,`struct_item`,`enum_item`,`union_item`,`trait_item`,`impl_item`,`function_item`,`function_signature_item`,`type_item`,`associated_type`,`macro_definition`,`field_declaration`,`let_declaration`,`expression_statement`,`else_clause`,`match_arm`],E=`package_declaration.import_declaration.module_declaration.requires_module_directive.exports_module_directive.opens_module_directive.uses_module_directive.provides_module_directive.class_declaration.interface_declaration.enum_declaration.annotation_type_declaration.annotation_type_element_declaration.record_declaration.field_declaration.constant_declaration.method_declaration.constructor_declaration.compact_constructor_declaration.static_initializer.explicit_constructor_invocation.local_variable_declaration.expression_statement.if_statement.while_statement.do_statement.for_statement.enhanced_for_statement.switch_statement.switch_expression.switch_label.break_statement.continue_statement.return_statement.throw_statement.assert_statement.synchronized_statement.labeled_statement.yield_statement.resource.catch_clause.finally_clause`.split(`.`),D=[`elsif`,`else`,`when`,`in_clause`,`rescue`,`ensure`],O=[`program`,`body_statement`,`then`,`else`,`do`,`block_body`,`begin`,`ensure`],k=[`preproc_include`,`preproc_def`,`preproc_function_def`,`declaration`,`type_definition`,`field_declaration`,`function_definition`,`struct_specifier`,`enum_specifier`,`union_specifier`,`expression_statement`,`if_statement`,`else_clause`,`switch_statement`,`case_statement`,`for_statement`,`while_statement`,`do_statement`,`return_statement`,`break_statement`,`continue_statement`,`goto_statement`,`labeled_statement`],A=[...k,`class_specifier`,`namespace_definition`,`using_declaration`,`alias_declaration`,`namespace_alias_definition`,`concept_definition`,`static_assert_declaration`,`for_range_loop`,`catch_clause`,`throw_statement`,`co_return_statement`,`co_yield_statement`];function j(e){return N(e,`default`)?e.default:e}function M(e){return l.default[e]}function N(e,t){return typeof e!=`object`||!e||!(t in e)?!1:!!e[t]}const P=[{name:`javascript`,aliases:[`js`,`mjs`,`cjs`],parserLanguage:j(a.default)},{name:`jsx`,parserLanguage:j(a.default)},{name:`typescript`,aliases:[`ts`],parserLanguage:M(`typescript`)},{name:`tsx`,parserLanguage:M(`tsx`)},{name:`python`,aliases:[`py`],parserLanguage:j(o.default),ncssNodeTypes:C},{name:`go`,parserLanguage:j(r.default),decisionNodeTypes:f,nestingNodeTypes:m,ncssNodeTypes:w},{name:`rust`,aliases:[`rs`],parserLanguage:j(c.default),ncssNodeTypes:T,ncssContainerNodeTypes:[`block`,`else_clause`]},{name:`java`,parserLanguage:j(i.default),functionNodeTypes:h,decisionNodeTypes:g,nestingNodeTypes:g,ncssNodeTypes:E},{name:`ruby`,aliases:[`rb`],parserLanguage:j(s.default),functionNodeTypes:_,decisionNodeTypes:v,nestingNodeTypes:v,ncssNodeTypes:D,ncssContainerNodeTypes:O},{name:`c`,parserLanguage:j(t.default),functionNodeTypes:y,decisionNodeTypes:b,nestingNodeTypes:b,ncssNodeTypes:k},{name:`cpp`,aliases:[`c++`,`cxx`],parserLanguage:j(n.default),functionNodeTypes:y,decisionNodeTypes:x,nestingNodeTypes:x,ncssNodeTypes:A}].map(e=>({functionNodeTypes:u,decisionNodeTypes:d,nestingNodeTypes:p,ncssNodeTypes:S,...e}));function F(e=P){let t=new Map;for(let n of e){t.set(n.name,n);for(let e of n.aliases??[])t.set(e,n)}return t}const I=P.map(e=>e.name);exports.createLanguageRegistry=F,exports.defaultLanguages=P,exports.supportedLanguages=I;
2
2
  //# sourceMappingURL=languages.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"languages.cjs","names":["grammars","JavaScript","Python","Go","Rust","Java","Ruby","C","Cpp"],"sources":["../src/languages.ts"],"sourcesContent":["import C from 'tree-sitter-c';\nimport Cpp from 'tree-sitter-cpp';\nimport Go from 'tree-sitter-go';\nimport Java from 'tree-sitter-java';\nimport JavaScript from 'tree-sitter-javascript';\nimport Python from 'tree-sitter-python';\nimport Ruby from 'tree-sitter-ruby';\nimport Rust from 'tree-sitter-rust';\nimport TypeScript from 'tree-sitter-typescript';\nimport type { LanguageDefinition, LanguageName, ParserLanguage } from './types.js';\n\ntype GrammarModule = unknown;\n\nconst commonFunctionNodes = [\n 'function',\n 'function_declaration',\n 'function_definition',\n 'function_expression',\n 'function_item',\n 'function_signature_item',\n 'function_declarator',\n 'func_literal',\n 'method_declaration',\n 'method_definition',\n 'method_spec',\n 'arrow_function',\n 'generator_function',\n 'generator_function_declaration',\n 'lambda',\n 'lambda_expression',\n 'closure_expression',\n] as const;\n\nconst commonClassNodes = [\n 'class',\n 'class_declaration',\n 'class_definition',\n 'interface_declaration',\n 'trait_item',\n 'struct_item',\n 'enum_item',\n 'union_item',\n] as const;\n\nconst commonDecisionNodes = [\n 'if_statement',\n 'elif_clause',\n 'else_if_clause',\n 'for_statement',\n 'for_in_statement',\n 'while_statement',\n 'do_statement',\n 'catch_clause',\n 'except_clause',\n 'case_clause',\n 'switch_case',\n 'match_arm',\n 'conditional_expression',\n 'ternary_expression',\n 'if_expression',\n 'while_expression',\n 'for_expression',\n 'loop_expression',\n] as const;\n\n// Go `switch`/`select` branches are `*_case` nodes, not the `case_clause`/`switch_case` of other grammars.\nconst goDecisionNodes = [...commonDecisionNodes, 'expression_case', 'type_case', 'communication_case'] as const;\n\n// Default switch branches add no decision, but their contents are nested inside the switch like\n// any other arm, so they appear in the nesting sets only.\nconst commonNestingNodes = [...commonDecisionNodes, 'switch_default'] as const;\nconst goNestingNodes = [...goDecisionNodes, 'default_case'] as const;\n\nconst javaFunctionNodes = [\n ...commonFunctionNodes,\n 'constructor_declaration',\n 'compact_constructor_declaration',\n] as const;\nconst javaClassNodes = [\n ...commonClassNodes,\n 'enum_declaration',\n 'record_declaration',\n 'annotation_type_declaration',\n // Counted only when they carry a `class_body` (anonymous classes, JLS 15.9.5).\n 'object_creation_expression',\n 'enum_constant',\n] as const;\nconst javaDecisionNodes = [\n ...commonDecisionNodes,\n 'enhanced_for_statement',\n 'switch_block_statement_group',\n 'switch_rule',\n] as const;\n// PMD's standard cyclomatic complexity charges `throw` one path (verified against PMD 7.26.0);\n// it stays out of the nesting set (its argument expressions are not nested) and adds no\n// cognitive point (see cyclomaticOnlyNodeTypes in metrics.ts). Other languages follow their own\n// reference tools (lizard/radon), which do not count throw/raise.\nconst javaCyclomaticDecisionNodes = [...javaDecisionNodes, 'throw_statement'] as const;\n\n// Ruby node types are keyword-like (`if`, `while`, ...), so they must stay Ruby-specific: the same\n// strings appear as anonymous keyword tokens in other grammars and would be double-counted there.\n// `block`/`do_block` are Ruby's closures (`items.map { ... }`), the analog of JS callbacks.\nconst rubyFunctionNodes = ['method', 'singleton_method', 'lambda', 'block', 'do_block'] as const;\n// `singleton_class` (`class << self`) opens an eigenclass scope, not a new type declaration.\nconst rubyClassNodes = ['class', 'module'] as const;\nconst rubyDecisionNodes = [\n 'if',\n 'elsif',\n 'unless',\n 'while',\n 'until',\n 'for',\n 'when',\n 'in_clause',\n 'rescue',\n 'conditional',\n 'if_modifier',\n 'unless_modifier',\n 'while_modifier',\n 'until_modifier',\n 'rescue_modifier',\n] as const;\n\n// `function_declarator` must stay out: it is nested inside every `function_definition` (which\n// would double-count) and also appears in body-less prototypes.\nconst cFunctionNodes = ['function_definition', 'lambda_expression'] as const;\nconst cClassNodes = ['struct_specifier', 'enum_specifier', 'union_specifier'] as const;\nconst cDecisionNodes = [...commonDecisionNodes, 'case_statement'] as const;\nconst cppClassNodes = [...cClassNodes, 'class_specifier'] as const;\nconst cppDecisionNodes = [...cDecisionNodes, 'for_range_loop'] as const;\n\n// NCSS node sets: every listed type counts as one non-commenting source statement. The Java set is\n// calibrated against PMD's NcssCount rule (`try` counts 0; `else`, `case`/`default` labels,\n// `catch`, `finally`, and try-with-resources resources count 1 each); the other languages follow\n// the same conventions with their grammar's node types.\nconst jsNcssNodes = [\n 'import_statement',\n 'export_statement',\n 'lexical_declaration',\n 'variable_declaration',\n 'function_declaration',\n 'function_signature',\n 'generator_function_declaration',\n 'class_declaration',\n 'abstract_class_declaration',\n 'module',\n 'method_definition',\n 'abstract_method_signature',\n 'class_static_block',\n 'field_definition',\n 'public_field_definition',\n 'type_alias_declaration',\n 'interface_declaration',\n 'enum_declaration',\n 'expression_statement',\n 'if_statement',\n 'else_clause',\n 'switch_statement',\n 'switch_case',\n 'switch_default',\n 'for_statement',\n 'for_in_statement',\n 'while_statement',\n 'do_statement',\n 'catch_clause',\n 'finally_clause',\n 'labeled_statement',\n 'return_statement',\n 'break_statement',\n 'continue_statement',\n 'throw_statement',\n 'debugger_statement',\n 'with_statement',\n] as const;\n\nconst pythonNcssNodes = [\n 'import_statement',\n 'import_from_statement',\n 'future_import_statement',\n 'print_statement',\n 'exec_statement',\n 'assert_statement',\n 'expression_statement',\n 'return_statement',\n 'delete_statement',\n 'raise_statement',\n 'pass_statement',\n 'break_statement',\n 'continue_statement',\n 'global_statement',\n 'nonlocal_statement',\n 'if_statement',\n 'elif_clause',\n 'else_clause',\n 'for_statement',\n 'while_statement',\n 'except_clause',\n 'except_group_clause',\n 'finally_clause',\n 'with_statement',\n 'match_statement',\n 'case_clause',\n 'function_definition',\n 'class_definition',\n 'type_alias_statement',\n] as const;\n\nconst goNcssNodes = [\n 'package_clause',\n 'import_spec',\n 'type_spec',\n 'type_alias',\n 'const_spec',\n 'var_spec',\n 'function_declaration',\n 'method_declaration',\n // Struct fields and interface members count contextually (see ncss.ts): only inside a named\n // `type T struct/interface { ... }`, not in inline anonymous types, which are part of one\n // declaration.\n 'short_var_declaration',\n 'expression_statement',\n 'send_statement',\n 'inc_statement',\n 'dec_statement',\n 'assignment_statement',\n 'if_statement',\n 'for_statement',\n 'expression_switch_statement',\n 'type_switch_statement',\n 'select_statement',\n 'expression_case',\n 'type_case',\n 'communication_case',\n 'default_case',\n 'return_statement',\n 'break_statement',\n 'continue_statement',\n 'goto_statement',\n 'fallthrough_statement',\n 'defer_statement',\n 'go_statement',\n 'labeled_statement',\n] as const;\n\nconst rustNcssNodes = [\n 'use_declaration',\n 'extern_crate_declaration',\n 'foreign_mod_item',\n 'mod_item',\n 'const_item',\n 'static_item',\n 'struct_item',\n 'enum_item',\n 'union_item',\n 'trait_item',\n 'impl_item',\n 'function_item',\n 'function_signature_item',\n 'type_item',\n 'associated_type',\n 'macro_definition',\n 'field_declaration',\n 'let_declaration',\n 'expression_statement',\n 'else_clause',\n 'match_arm',\n] as const;\n\nconst javaNcssNodes = [\n 'package_declaration',\n 'import_declaration',\n 'module_declaration',\n 'requires_module_directive',\n 'exports_module_directive',\n 'opens_module_directive',\n 'uses_module_directive',\n 'provides_module_directive',\n 'class_declaration',\n 'interface_declaration',\n 'enum_declaration',\n 'annotation_type_declaration',\n 'annotation_type_element_declaration',\n 'record_declaration',\n 'field_declaration',\n 'constant_declaration',\n 'method_declaration',\n 'constructor_declaration',\n 'compact_constructor_declaration',\n 'static_initializer',\n 'explicit_constructor_invocation',\n 'local_variable_declaration',\n 'expression_statement',\n 'if_statement',\n 'while_statement',\n 'do_statement',\n 'for_statement',\n 'enhanced_for_statement',\n 'switch_statement',\n 'switch_expression',\n 'switch_label',\n 'break_statement',\n 'continue_statement',\n 'return_statement',\n 'throw_statement',\n 'assert_statement',\n 'synchronized_statement',\n 'labeled_statement',\n 'yield_statement',\n 'resource',\n 'catch_clause',\n 'finally_clause',\n] as const;\n\n// Ruby statements have no wrapper node types, so bodies are counted positionally (see\n// ncssContainerNodeTypes); only clause nodes hanging off non-container parents need listing.\nconst rubyNcssNodes = ['elsif', 'else', 'when', 'in_clause', 'rescue', 'ensure'] as const;\nconst rubyNcssContainers = [\n 'program',\n 'body_statement',\n 'then',\n 'else',\n 'do',\n 'block_body',\n 'begin',\n 'ensure',\n] as const;\n\nconst cNcssNodes = [\n 'preproc_include',\n 'preproc_def',\n 'preproc_function_def',\n 'declaration',\n 'type_definition',\n 'field_declaration',\n 'function_definition',\n // Counted only when they carry a body (see bodylessNcssSpecifierTypes in ncss.ts).\n 'struct_specifier',\n 'enum_specifier',\n 'union_specifier',\n 'expression_statement',\n 'if_statement',\n 'else_clause',\n 'switch_statement',\n 'case_statement',\n 'for_statement',\n 'while_statement',\n 'do_statement',\n 'return_statement',\n 'break_statement',\n 'continue_statement',\n 'goto_statement',\n 'labeled_statement',\n] as const;\nconst cppNcssNodes = [\n ...cNcssNodes,\n 'class_specifier',\n 'namespace_definition',\n 'using_declaration',\n 'alias_declaration',\n 'namespace_alias_definition',\n 'concept_definition',\n 'static_assert_declaration',\n 'for_range_loop',\n 'catch_clause',\n 'throw_statement',\n 'co_return_statement',\n 'co_yield_statement',\n] as const;\n\nfunction normalizeGrammar(module: GrammarModule): ParserLanguage {\n if (isGrammarWrapper(module, 'default')) {\n return module.default;\n }\n\n return module;\n}\n\nfunction getTypeScriptGrammar(name: 'typescript' | 'tsx'): ParserLanguage {\n const grammars = TypeScript as unknown as Record<string, GrammarModule>;\n return grammars[name];\n}\n\nfunction isGrammarWrapper(value: GrammarModule, key: 'default'): value is Record<typeof key, ParserLanguage> {\n if (typeof value !== 'object' || value === null || !(key in value)) {\n return false;\n }\n\n return Boolean((value as Record<string, ParserLanguage>)[key]);\n}\n\nexport const defaultLanguages: readonly LanguageDefinition[] = [\n {\n name: 'javascript',\n aliases: ['js', 'mjs', 'cjs'],\n parserLanguage: normalizeGrammar(JavaScript as unknown as GrammarModule),\n },\n {\n name: 'jsx',\n parserLanguage: normalizeGrammar(JavaScript as unknown as GrammarModule),\n },\n {\n name: 'typescript',\n aliases: ['ts'],\n parserLanguage: getTypeScriptGrammar('typescript'),\n },\n {\n name: 'tsx',\n parserLanguage: getTypeScriptGrammar('tsx'),\n },\n {\n name: 'python',\n aliases: ['py'],\n parserLanguage: normalizeGrammar(Python as unknown as GrammarModule),\n ncssNodeTypes: pythonNcssNodes,\n },\n {\n name: 'go',\n parserLanguage: normalizeGrammar(Go as unknown as GrammarModule),\n decisionNodeTypes: goDecisionNodes,\n nestingNodeTypes: goNestingNodes,\n ncssNodeTypes: goNcssNodes,\n },\n {\n name: 'rust',\n aliases: ['rs'],\n parserLanguage: normalizeGrammar(Rust as unknown as GrammarModule),\n ncssNodeTypes: rustNcssNodes,\n // `else_clause` is a container so `else if` chains count the nested if_expression; a plain\n // `else { ... }` is unaffected because its only child is a `block`, itself a container.\n ncssContainerNodeTypes: ['block', 'else_clause'],\n },\n {\n name: 'java',\n parserLanguage: normalizeGrammar(Java as unknown as GrammarModule),\n functionNodeTypes: javaFunctionNodes,\n classNodeTypes: javaClassNodes,\n decisionNodeTypes: javaCyclomaticDecisionNodes,\n nestingNodeTypes: javaDecisionNodes,\n ncssNodeTypes: javaNcssNodes,\n },\n {\n name: 'ruby',\n aliases: ['rb'],\n parserLanguage: normalizeGrammar(Ruby as unknown as GrammarModule),\n functionNodeTypes: rubyFunctionNodes,\n classNodeTypes: rubyClassNodes,\n decisionNodeTypes: rubyDecisionNodes,\n nestingNodeTypes: rubyDecisionNodes,\n ncssNodeTypes: rubyNcssNodes,\n ncssContainerNodeTypes: rubyNcssContainers,\n },\n {\n name: 'c',\n parserLanguage: normalizeGrammar(C as unknown as GrammarModule),\n functionNodeTypes: cFunctionNodes,\n classNodeTypes: cClassNodes,\n decisionNodeTypes: cDecisionNodes,\n nestingNodeTypes: cDecisionNodes,\n ncssNodeTypes: cNcssNodes,\n },\n {\n name: 'cpp',\n aliases: ['c++', 'cxx'],\n parserLanguage: normalizeGrammar(Cpp as unknown as GrammarModule),\n functionNodeTypes: cFunctionNodes,\n classNodeTypes: cppClassNodes,\n decisionNodeTypes: cppDecisionNodes,\n nestingNodeTypes: cppDecisionNodes,\n ncssNodeTypes: cppNcssNodes,\n },\n].map((language) => ({\n functionNodeTypes: commonFunctionNodes,\n classNodeTypes: commonClassNodes,\n decisionNodeTypes: commonDecisionNodes,\n nestingNodeTypes: commonNestingNodes,\n ncssNodeTypes: jsNcssNodes,\n ...language,\n}));\n\nexport function createLanguageRegistry(\n languages: readonly LanguageDefinition[] = defaultLanguages\n): Map<LanguageName, LanguageDefinition> {\n const registry = new Map<LanguageName, LanguageDefinition>();\n\n for (const language of languages) {\n registry.set(language.name, language);\n for (const alias of language.aliases ?? []) {\n registry.set(alias, language);\n }\n }\n\n return registry;\n}\n\nexport const supportedLanguages = defaultLanguages.map((language) => language.name);\n"],"mappings":"ohBAaA,MAAM,EAAsB,CAC1B,WACA,uBACA,sBACA,sBACA,gBACA,0BACA,sBACA,eACA,qBACA,oBACA,cACA,iBACA,qBACA,iCACA,SACA,oBACA,oBACF,EAEM,EAAmB,CACvB,QACA,oBACA,mBACA,wBACA,aACA,cACA,YACA,YACF,EAEM,EAAsB,CAC1B,eACA,cACA,iBACA,gBACA,mBACA,kBACA,eACA,eACA,gBACA,cACA,cACA,YACA,yBACA,qBACA,gBACA,mBACA,iBACA,iBACF,EAGM,EAAkB,CAAC,GAAG,EAAqB,kBAAmB,YAAa,oBAAoB,EAI/F,EAAqB,CAAC,GAAG,EAAqB,gBAAgB,EAC9D,EAAiB,CAAC,GAAG,EAAiB,cAAc,EAEpD,EAAoB,CACxB,GAAG,EACH,0BACA,iCACF,EACM,EAAiB,CACrB,GAAG,EACH,mBACA,qBACA,8BAEA,6BACA,eACF,EACM,EAAoB,CACxB,GAAG,EACH,yBACA,+BACA,aACF,EAKM,EAA8B,CAAC,GAAG,EAAmB,iBAAiB,EAKtE,EAAoB,CAAC,SAAU,mBAAoB,SAAU,QAAS,UAAU,EAEhF,EAAiB,CAAC,QAAS,QAAQ,EACnC,EAAoB,CACxB,KACA,QACA,SACA,QACA,QACA,MACA,OACA,YACA,SACA,cACA,cACA,kBACA,iBACA,iBACA,iBACF,EAIM,EAAiB,CAAC,sBAAuB,mBAAmB,EAC5D,EAAc,CAAC,mBAAoB,iBAAkB,iBAAiB,EACtE,EAAiB,CAAC,GAAG,EAAqB,gBAAgB,EAC1D,EAAgB,CAAC,GAAG,EAAa,iBAAiB,EAClD,EAAmB,CAAC,GAAG,EAAgB,gBAAgB,EAMvD,EAAc,iqBAsCpB,EAEM,EAAkB,gfA8BxB,EAEM,EAAc,kgBAmCpB,EAEM,EAAgB,CACpB,kBACA,2BACA,mBACA,WACA,aACA,cACA,cACA,YACA,aACA,aACA,YACA,gBACA,0BACA,YACA,kBACA,mBACA,oBACA,kBACA,uBACA,cACA,WACF,EAEM,EAAgB,k1BA2CtB,EAIM,EAAgB,CAAC,QAAS,OAAQ,OAAQ,YAAa,SAAU,QAAQ,EACzE,EAAqB,CACzB,UACA,iBACA,OACA,OACA,KACA,aACA,QACA,QACF,EAEM,EAAa,CACjB,kBACA,cACA,uBACA,cACA,kBACA,oBACA,sBAEA,mBACA,iBACA,kBACA,uBACA,eACA,cACA,mBACA,iBACA,gBACA,kBACA,eACA,mBACA,kBACA,qBACA,iBACA,mBACF,EACM,EAAe,CACnB,GAAG,EACH,kBACA,uBACA,oBACA,oBACA,6BACA,qBACA,4BACA,iBACA,eACA,kBACA,sBACA,oBACF,EAEA,SAAS,EAAiB,EAAuC,CAK/D,OAJI,EAAiB,EAAQ,SAAS,EAC7B,EAAO,QAGT,CACT,CAEA,SAAS,EAAqB,EAA4C,CAExE,OAAOA,EAAAA,QAAS,EAClB,CAEA,SAAS,EAAiB,EAAsB,EAA6D,CAK3G,OAJI,OAAO,GAAU,WAAY,GAAkB,EAAE,KAAO,GACnD,GAGF,EAAS,EAAyC,EAC3D,CAEA,MAAa,EAAkD,CAC7D,CACE,KAAM,aACN,QAAS,CAAC,KAAM,MAAO,KAAK,EAC5B,eAAgB,EAAiBC,EAAAA,OAAsC,CACzE,EACA,CACE,KAAM,MACN,eAAgB,EAAiBA,EAAAA,OAAsC,CACzE,EACA,CACE,KAAM,aACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAqB,YAAY,CACnD,EACA,CACE,KAAM,MACN,eAAgB,EAAqB,KAAK,CAC5C,EACA,CACE,KAAM,SACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAiBC,EAAAA,OAAkC,EACnE,cAAe,CACjB,EACA,CACE,KAAM,KACN,eAAgB,EAAiBC,EAAAA,OAA8B,EAC/D,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,EACA,CACE,KAAM,OACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAiBC,EAAAA,OAAgC,EACjE,cAAe,EAGf,uBAAwB,CAAC,QAAS,aAAa,CACjD,EACA,CACE,KAAM,OACN,eAAgB,EAAiBC,EAAAA,OAAgC,EACjE,kBAAmB,EACnB,eAAgB,EAChB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,EACA,CACE,KAAM,OACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAiBC,EAAAA,OAAgC,EACjE,kBAAmB,EACnB,eAAgB,EAChB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,EACf,uBAAwB,CAC1B,EACA,CACE,KAAM,IACN,eAAgB,EAAiBC,EAAAA,OAA6B,EAC9D,kBAAmB,EACnB,eAAgB,EAChB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,EACA,CACE,KAAM,MACN,QAAS,CAAC,MAAO,KAAK,EACtB,eAAgB,EAAiBC,EAAAA,OAA+B,EAChE,kBAAmB,EACnB,eAAgB,EAChB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,CACF,CAAC,CAAC,IAAK,IAAc,CACnB,kBAAmB,EACnB,eAAgB,EAChB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,EACf,GAAG,CACL,EAAE,EAEF,SAAgB,EACd,EAA2C,EACJ,CACvC,IAAM,EAAW,IAAI,IAErB,IAAK,IAAM,KAAY,EAAW,CAChC,EAAS,IAAI,EAAS,KAAM,CAAQ,EACpC,IAAK,IAAM,KAAS,EAAS,SAAW,CAAC,EACvC,EAAS,IAAI,EAAO,CAAQ,CAEhC,CAEA,OAAO,CACT,CAEA,MAAa,EAAqB,EAAiB,IAAK,GAAa,EAAS,IAAI"}
1
+ {"version":3,"file":"languages.cjs","names":["grammars","JavaScript","Python","Go","Rust","Java","Ruby","C","Cpp"],"sources":["../src/languages.ts"],"sourcesContent":["import C from 'tree-sitter-c';\nimport Cpp from 'tree-sitter-cpp';\nimport Go from 'tree-sitter-go';\nimport Java from 'tree-sitter-java';\nimport JavaScript from 'tree-sitter-javascript';\nimport Python from 'tree-sitter-python';\nimport Ruby from 'tree-sitter-ruby';\nimport Rust from 'tree-sitter-rust';\nimport TypeScript from 'tree-sitter-typescript';\nimport type { LanguageDefinition, LanguageName, ParserLanguage } from './types.js';\n\ntype GrammarModule = unknown;\n\nconst commonFunctionNodes = [\n 'function',\n 'function_declaration',\n 'function_definition',\n 'function_expression',\n 'function_item',\n 'function_signature_item',\n 'function_declarator',\n 'func_literal',\n 'method_declaration',\n 'method_definition',\n 'method_spec',\n 'arrow_function',\n 'generator_function',\n 'generator_function_declaration',\n 'lambda',\n 'lambda_expression',\n 'closure_expression',\n] as const;\n\nconst commonDecisionNodes = [\n 'if_statement',\n 'elif_clause',\n 'else_if_clause',\n 'for_statement',\n 'for_in_statement',\n 'while_statement',\n 'do_statement',\n 'catch_clause',\n 'except_clause',\n 'case_clause',\n 'switch_case',\n 'match_arm',\n 'conditional_expression',\n 'ternary_expression',\n 'if_expression',\n 'while_expression',\n 'for_expression',\n 'loop_expression',\n] as const;\n\n// Go `switch`/`select` branches are `*_case` nodes, not the `case_clause`/`switch_case` of other grammars.\nconst goDecisionNodes = [...commonDecisionNodes, 'expression_case', 'type_case', 'communication_case'] as const;\n\n// Default switch branches add no decision, but their contents are nested inside the switch like\n// any other arm, so they appear in the nesting sets only.\nconst commonNestingNodes = [...commonDecisionNodes, 'switch_default'] as const;\nconst goNestingNodes = [...goDecisionNodes, 'default_case'] as const;\n\nconst javaFunctionNodes = [\n ...commonFunctionNodes,\n 'constructor_declaration',\n 'compact_constructor_declaration',\n] as const;\nconst javaDecisionNodes = [\n ...commonDecisionNodes,\n 'enhanced_for_statement',\n 'switch_block_statement_group',\n 'switch_rule',\n] as const;\n\n// Ruby node types are keyword-like (`if`, `while`, ...), so they must stay Ruby-specific: the same\n// strings appear as anonymous keyword tokens in other grammars and would be double-counted there.\n// `block`/`do_block` are Ruby's closures (`items.map { ... }`), the analog of JS callbacks.\nconst rubyFunctionNodes = ['method', 'singleton_method', 'lambda', 'block', 'do_block'] as const;\nconst rubyDecisionNodes = [\n 'if',\n 'elsif',\n 'unless',\n 'while',\n 'until',\n 'for',\n 'when',\n 'in_clause',\n 'rescue',\n 'conditional',\n 'if_modifier',\n 'unless_modifier',\n 'while_modifier',\n 'until_modifier',\n 'rescue_modifier',\n] as const;\n\n// `function_declarator` must stay out: it is nested inside every `function_definition` (which\n// would double-count) and also appears in body-less prototypes.\nconst cFunctionNodes = ['function_definition', 'lambda_expression'] as const;\nconst cDecisionNodes = [...commonDecisionNodes, 'case_statement'] as const;\nconst cppDecisionNodes = [...cDecisionNodes, 'for_range_loop'] as const;\n\n// NCSS node sets: every listed type counts as one non-commenting source statement. The Java set is\n// calibrated against PMD's NcssCount rule (`try` counts 0; `else`, `case`/`default` labels,\n// `catch`, `finally`, and try-with-resources resources count 1 each); the other languages follow\n// the same conventions with their grammar's node types.\nconst jsNcssNodes = [\n 'import_statement',\n 'export_statement',\n 'lexical_declaration',\n 'variable_declaration',\n 'function_declaration',\n 'function_signature',\n 'generator_function_declaration',\n 'class_declaration',\n 'abstract_class_declaration',\n 'module',\n 'method_definition',\n 'abstract_method_signature',\n 'class_static_block',\n 'field_definition',\n 'public_field_definition',\n 'type_alias_declaration',\n 'interface_declaration',\n 'enum_declaration',\n 'expression_statement',\n 'if_statement',\n 'else_clause',\n 'switch_statement',\n 'switch_case',\n 'switch_default',\n 'for_statement',\n 'for_in_statement',\n 'while_statement',\n 'do_statement',\n 'catch_clause',\n 'finally_clause',\n 'labeled_statement',\n 'return_statement',\n 'break_statement',\n 'continue_statement',\n 'throw_statement',\n 'debugger_statement',\n 'with_statement',\n] as const;\n\nconst pythonNcssNodes = [\n 'import_statement',\n 'import_from_statement',\n 'future_import_statement',\n 'print_statement',\n 'exec_statement',\n 'assert_statement',\n 'expression_statement',\n 'return_statement',\n 'delete_statement',\n 'raise_statement',\n 'pass_statement',\n 'break_statement',\n 'continue_statement',\n 'global_statement',\n 'nonlocal_statement',\n 'if_statement',\n 'elif_clause',\n 'else_clause',\n 'for_statement',\n 'while_statement',\n 'except_clause',\n 'except_group_clause',\n 'finally_clause',\n 'with_statement',\n 'match_statement',\n 'case_clause',\n 'function_definition',\n 'class_definition',\n 'type_alias_statement',\n] as const;\n\nconst goNcssNodes = [\n 'package_clause',\n 'import_spec',\n 'type_spec',\n 'type_alias',\n 'const_spec',\n 'var_spec',\n 'function_declaration',\n 'method_declaration',\n // Struct fields and interface members count contextually (see ncss.ts): only inside a named\n // `type T struct/interface { ... }`, not in inline anonymous types, which are part of one\n // declaration.\n 'short_var_declaration',\n 'expression_statement',\n 'send_statement',\n 'inc_statement',\n 'dec_statement',\n 'assignment_statement',\n 'if_statement',\n 'for_statement',\n 'expression_switch_statement',\n 'type_switch_statement',\n 'select_statement',\n 'expression_case',\n 'type_case',\n 'communication_case',\n 'default_case',\n 'return_statement',\n 'break_statement',\n 'continue_statement',\n 'goto_statement',\n 'fallthrough_statement',\n 'defer_statement',\n 'go_statement',\n 'labeled_statement',\n] as const;\n\nconst rustNcssNodes = [\n 'use_declaration',\n 'extern_crate_declaration',\n 'foreign_mod_item',\n 'mod_item',\n 'const_item',\n 'static_item',\n 'struct_item',\n 'enum_item',\n 'union_item',\n 'trait_item',\n 'impl_item',\n 'function_item',\n 'function_signature_item',\n 'type_item',\n 'associated_type',\n 'macro_definition',\n 'field_declaration',\n 'let_declaration',\n 'expression_statement',\n 'else_clause',\n 'match_arm',\n] as const;\n\nconst javaNcssNodes = [\n 'package_declaration',\n 'import_declaration',\n 'module_declaration',\n 'requires_module_directive',\n 'exports_module_directive',\n 'opens_module_directive',\n 'uses_module_directive',\n 'provides_module_directive',\n 'class_declaration',\n 'interface_declaration',\n 'enum_declaration',\n 'annotation_type_declaration',\n 'annotation_type_element_declaration',\n 'record_declaration',\n 'field_declaration',\n 'constant_declaration',\n 'method_declaration',\n 'constructor_declaration',\n 'compact_constructor_declaration',\n 'static_initializer',\n 'explicit_constructor_invocation',\n 'local_variable_declaration',\n 'expression_statement',\n 'if_statement',\n 'while_statement',\n 'do_statement',\n 'for_statement',\n 'enhanced_for_statement',\n 'switch_statement',\n 'switch_expression',\n 'switch_label',\n 'break_statement',\n 'continue_statement',\n 'return_statement',\n 'throw_statement',\n 'assert_statement',\n 'synchronized_statement',\n 'labeled_statement',\n 'yield_statement',\n 'resource',\n 'catch_clause',\n 'finally_clause',\n] as const;\n\n// Ruby statements have no wrapper node types, so bodies are counted positionally (see\n// ncssContainerNodeTypes); only clause nodes hanging off non-container parents need listing.\nconst rubyNcssNodes = ['elsif', 'else', 'when', 'in_clause', 'rescue', 'ensure'] as const;\nconst rubyNcssContainers = [\n 'program',\n 'body_statement',\n 'then',\n 'else',\n 'do',\n 'block_body',\n 'begin',\n 'ensure',\n] as const;\n\nconst cNcssNodes = [\n 'preproc_include',\n 'preproc_def',\n 'preproc_function_def',\n 'declaration',\n 'type_definition',\n 'field_declaration',\n 'function_definition',\n // Counted only when they carry a body (see bodylessNcssSpecifierTypes in ncss.ts).\n 'struct_specifier',\n 'enum_specifier',\n 'union_specifier',\n 'expression_statement',\n 'if_statement',\n 'else_clause',\n 'switch_statement',\n 'case_statement',\n 'for_statement',\n 'while_statement',\n 'do_statement',\n 'return_statement',\n 'break_statement',\n 'continue_statement',\n 'goto_statement',\n 'labeled_statement',\n] as const;\nconst cppNcssNodes = [\n ...cNcssNodes,\n 'class_specifier',\n 'namespace_definition',\n 'using_declaration',\n 'alias_declaration',\n 'namespace_alias_definition',\n 'concept_definition',\n 'static_assert_declaration',\n 'for_range_loop',\n 'catch_clause',\n 'throw_statement',\n 'co_return_statement',\n 'co_yield_statement',\n] as const;\n\nfunction normalizeGrammar(module: GrammarModule): ParserLanguage {\n if (isGrammarWrapper(module, 'default')) {\n return module.default;\n }\n\n return module;\n}\n\nfunction getTypeScriptGrammar(name: 'typescript' | 'tsx'): ParserLanguage {\n const grammars = TypeScript as unknown as Record<string, GrammarModule>;\n return grammars[name];\n}\n\nfunction isGrammarWrapper(value: GrammarModule, key: 'default'): value is Record<typeof key, ParserLanguage> {\n if (typeof value !== 'object' || value === null || !(key in value)) {\n return false;\n }\n\n return Boolean((value as Record<string, ParserLanguage>)[key]);\n}\n\nexport const defaultLanguages: readonly LanguageDefinition[] = [\n {\n name: 'javascript',\n aliases: ['js', 'mjs', 'cjs'],\n parserLanguage: normalizeGrammar(JavaScript as unknown as GrammarModule),\n },\n {\n name: 'jsx',\n parserLanguage: normalizeGrammar(JavaScript as unknown as GrammarModule),\n },\n {\n name: 'typescript',\n aliases: ['ts'],\n parserLanguage: getTypeScriptGrammar('typescript'),\n },\n {\n name: 'tsx',\n parserLanguage: getTypeScriptGrammar('tsx'),\n },\n {\n name: 'python',\n aliases: ['py'],\n parserLanguage: normalizeGrammar(Python as unknown as GrammarModule),\n ncssNodeTypes: pythonNcssNodes,\n },\n {\n name: 'go',\n parserLanguage: normalizeGrammar(Go as unknown as GrammarModule),\n decisionNodeTypes: goDecisionNodes,\n nestingNodeTypes: goNestingNodes,\n ncssNodeTypes: goNcssNodes,\n },\n {\n name: 'rust',\n aliases: ['rs'],\n parserLanguage: normalizeGrammar(Rust as unknown as GrammarModule),\n ncssNodeTypes: rustNcssNodes,\n // `else_clause` is a container so `else if` chains count the nested if_expression; a plain\n // `else { ... }` is unaffected because its only child is a `block`, itself a container.\n ncssContainerNodeTypes: ['block', 'else_clause'],\n },\n {\n name: 'java',\n parserLanguage: normalizeGrammar(Java as unknown as GrammarModule),\n functionNodeTypes: javaFunctionNodes,\n decisionNodeTypes: javaDecisionNodes,\n nestingNodeTypes: javaDecisionNodes,\n ncssNodeTypes: javaNcssNodes,\n },\n {\n name: 'ruby',\n aliases: ['rb'],\n parserLanguage: normalizeGrammar(Ruby as unknown as GrammarModule),\n functionNodeTypes: rubyFunctionNodes,\n decisionNodeTypes: rubyDecisionNodes,\n nestingNodeTypes: rubyDecisionNodes,\n ncssNodeTypes: rubyNcssNodes,\n ncssContainerNodeTypes: rubyNcssContainers,\n },\n {\n name: 'c',\n parserLanguage: normalizeGrammar(C as unknown as GrammarModule),\n functionNodeTypes: cFunctionNodes,\n decisionNodeTypes: cDecisionNodes,\n nestingNodeTypes: cDecisionNodes,\n ncssNodeTypes: cNcssNodes,\n },\n {\n name: 'cpp',\n aliases: ['c++', 'cxx'],\n parserLanguage: normalizeGrammar(Cpp as unknown as GrammarModule),\n functionNodeTypes: cFunctionNodes,\n decisionNodeTypes: cppDecisionNodes,\n nestingNodeTypes: cppDecisionNodes,\n ncssNodeTypes: cppNcssNodes,\n },\n].map((language) => ({\n functionNodeTypes: commonFunctionNodes,\n decisionNodeTypes: commonDecisionNodes,\n nestingNodeTypes: commonNestingNodes,\n ncssNodeTypes: jsNcssNodes,\n ...language,\n}));\n\nexport function createLanguageRegistry(\n languages: readonly LanguageDefinition[] = defaultLanguages\n): Map<LanguageName, LanguageDefinition> {\n const registry = new Map<LanguageName, LanguageDefinition>();\n\n for (const language of languages) {\n registry.set(language.name, language);\n for (const alias of language.aliases ?? []) {\n registry.set(alias, language);\n }\n }\n\n return registry;\n}\n\nexport const supportedLanguages = defaultLanguages.map((language) => language.name);\n"],"mappings":"ohBAaA,MAAM,EAAsB,CAC1B,WACA,uBACA,sBACA,sBACA,gBACA,0BACA,sBACA,eACA,qBACA,oBACA,cACA,iBACA,qBACA,iCACA,SACA,oBACA,oBACF,EAEM,EAAsB,CAC1B,eACA,cACA,iBACA,gBACA,mBACA,kBACA,eACA,eACA,gBACA,cACA,cACA,YACA,yBACA,qBACA,gBACA,mBACA,iBACA,iBACF,EAGM,EAAkB,CAAC,GAAG,EAAqB,kBAAmB,YAAa,oBAAoB,EAI/F,EAAqB,CAAC,GAAG,EAAqB,gBAAgB,EAC9D,EAAiB,CAAC,GAAG,EAAiB,cAAc,EAEpD,EAAoB,CACxB,GAAG,EACH,0BACA,iCACF,EACM,EAAoB,CACxB,GAAG,EACH,yBACA,+BACA,aACF,EAKM,EAAoB,CAAC,SAAU,mBAAoB,SAAU,QAAS,UAAU,EAChF,EAAoB,CACxB,KACA,QACA,SACA,QACA,QACA,MACA,OACA,YACA,SACA,cACA,cACA,kBACA,iBACA,iBACA,iBACF,EAIM,EAAiB,CAAC,sBAAuB,mBAAmB,EAC5D,EAAiB,CAAC,GAAG,EAAqB,gBAAgB,EAC1D,EAAmB,CAAC,GAAG,EAAgB,gBAAgB,EAMvD,EAAc,iqBAsCpB,EAEM,EAAkB,gfA8BxB,EAEM,EAAc,kgBAmCpB,EAEM,EAAgB,CACpB,kBACA,2BACA,mBACA,WACA,aACA,cACA,cACA,YACA,aACA,aACA,YACA,gBACA,0BACA,YACA,kBACA,mBACA,oBACA,kBACA,uBACA,cACA,WACF,EAEM,EAAgB,k1BA2CtB,EAIM,EAAgB,CAAC,QAAS,OAAQ,OAAQ,YAAa,SAAU,QAAQ,EACzE,EAAqB,CACzB,UACA,iBACA,OACA,OACA,KACA,aACA,QACA,QACF,EAEM,EAAa,CACjB,kBACA,cACA,uBACA,cACA,kBACA,oBACA,sBAEA,mBACA,iBACA,kBACA,uBACA,eACA,cACA,mBACA,iBACA,gBACA,kBACA,eACA,mBACA,kBACA,qBACA,iBACA,mBACF,EACM,EAAe,CACnB,GAAG,EACH,kBACA,uBACA,oBACA,oBACA,6BACA,qBACA,4BACA,iBACA,eACA,kBACA,sBACA,oBACF,EAEA,SAAS,EAAiB,EAAuC,CAK/D,OAJI,EAAiB,EAAQ,SAAS,EAC7B,EAAO,QAGT,CACT,CAEA,SAAS,EAAqB,EAA4C,CAExE,OAAOA,EAAAA,QAAS,EAClB,CAEA,SAAS,EAAiB,EAAsB,EAA6D,CAK3G,OAJI,OAAO,GAAU,WAAY,GAAkB,EAAE,KAAO,GACnD,GAGF,EAAS,EAAyC,EAC3D,CAEA,MAAa,EAAkD,CAC7D,CACE,KAAM,aACN,QAAS,CAAC,KAAM,MAAO,KAAK,EAC5B,eAAgB,EAAiBC,EAAAA,OAAsC,CACzE,EACA,CACE,KAAM,MACN,eAAgB,EAAiBA,EAAAA,OAAsC,CACzE,EACA,CACE,KAAM,aACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAqB,YAAY,CACnD,EACA,CACE,KAAM,MACN,eAAgB,EAAqB,KAAK,CAC5C,EACA,CACE,KAAM,SACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAiBC,EAAAA,OAAkC,EACnE,cAAe,CACjB,EACA,CACE,KAAM,KACN,eAAgB,EAAiBC,EAAAA,OAA8B,EAC/D,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,EACA,CACE,KAAM,OACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAiBC,EAAAA,OAAgC,EACjE,cAAe,EAGf,uBAAwB,CAAC,QAAS,aAAa,CACjD,EACA,CACE,KAAM,OACN,eAAgB,EAAiBC,EAAAA,OAAgC,EACjE,kBAAmB,EACnB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,EACA,CACE,KAAM,OACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAiBC,EAAAA,OAAgC,EACjE,kBAAmB,EACnB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,EACf,uBAAwB,CAC1B,EACA,CACE,KAAM,IACN,eAAgB,EAAiBC,EAAAA,OAA6B,EAC9D,kBAAmB,EACnB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,EACA,CACE,KAAM,MACN,QAAS,CAAC,MAAO,KAAK,EACtB,eAAgB,EAAiBC,EAAAA,OAA+B,EAChE,kBAAmB,EACnB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,CACF,CAAC,CAAC,IAAK,IAAc,CACnB,kBAAmB,EACnB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,EACf,GAAG,CACL,EAAE,EAEF,SAAgB,EACd,EAA2C,EACJ,CACvC,IAAM,EAAW,IAAI,IAErB,IAAK,IAAM,KAAY,EAAW,CAChC,EAAS,IAAI,EAAS,KAAM,CAAQ,EACpC,IAAK,IAAM,KAAS,EAAS,SAAW,CAAC,EACvC,EAAS,IAAI,EAAO,CAAQ,CAEhC,CAEA,OAAO,CACT,CAEA,MAAa,EAAqB,EAAiB,IAAK,GAAa,EAAS,IAAI"}
package/dist/languages.js CHANGED
@@ -1,2 +1,2 @@
1
- import e from"tree-sitter-c";import t from"tree-sitter-cpp";import n from"tree-sitter-go";import r from"tree-sitter-java";import i from"tree-sitter-javascript";import a from"tree-sitter-python";import o from"tree-sitter-ruby";import s from"tree-sitter-rust";import c from"tree-sitter-typescript";const l=[`function`,`function_declaration`,`function_definition`,`function_expression`,`function_item`,`function_signature_item`,`function_declarator`,`func_literal`,`method_declaration`,`method_definition`,`method_spec`,`arrow_function`,`generator_function`,`generator_function_declaration`,`lambda`,`lambda_expression`,`closure_expression`],u=[`class`,`class_declaration`,`class_definition`,`interface_declaration`,`trait_item`,`struct_item`,`enum_item`,`union_item`],d=[`if_statement`,`elif_clause`,`else_if_clause`,`for_statement`,`for_in_statement`,`while_statement`,`do_statement`,`catch_clause`,`except_clause`,`case_clause`,`switch_case`,`match_arm`,`conditional_expression`,`ternary_expression`,`if_expression`,`while_expression`,`for_expression`,`loop_expression`],f=[...d,`expression_case`,`type_case`,`communication_case`],p=[...d,`switch_default`],m=[...f,`default_case`],h=[...l,`constructor_declaration`,`compact_constructor_declaration`],g=[...u,`enum_declaration`,`record_declaration`,`annotation_type_declaration`,`object_creation_expression`,`enum_constant`],_=[...d,`enhanced_for_statement`,`switch_block_statement_group`,`switch_rule`],v=[..._,`throw_statement`],y=[`method`,`singleton_method`,`lambda`,`block`,`do_block`],b=[`class`,`module`],x=[`if`,`elsif`,`unless`,`while`,`until`,`for`,`when`,`in_clause`,`rescue`,`conditional`,`if_modifier`,`unless_modifier`,`while_modifier`,`until_modifier`,`rescue_modifier`],S=[`function_definition`,`lambda_expression`],C=[`struct_specifier`,`enum_specifier`,`union_specifier`],w=[...d,`case_statement`],T=[...C,`class_specifier`],E=[...w,`for_range_loop`],D=`import_statement.export_statement.lexical_declaration.variable_declaration.function_declaration.function_signature.generator_function_declaration.class_declaration.abstract_class_declaration.module.method_definition.abstract_method_signature.class_static_block.field_definition.public_field_definition.type_alias_declaration.interface_declaration.enum_declaration.expression_statement.if_statement.else_clause.switch_statement.switch_case.switch_default.for_statement.for_in_statement.while_statement.do_statement.catch_clause.finally_clause.labeled_statement.return_statement.break_statement.continue_statement.throw_statement.debugger_statement.with_statement`.split(`.`),O=`import_statement.import_from_statement.future_import_statement.print_statement.exec_statement.assert_statement.expression_statement.return_statement.delete_statement.raise_statement.pass_statement.break_statement.continue_statement.global_statement.nonlocal_statement.if_statement.elif_clause.else_clause.for_statement.while_statement.except_clause.except_group_clause.finally_clause.with_statement.match_statement.case_clause.function_definition.class_definition.type_alias_statement`.split(`.`),k=`package_clause.import_spec.type_spec.type_alias.const_spec.var_spec.function_declaration.method_declaration.short_var_declaration.expression_statement.send_statement.inc_statement.dec_statement.assignment_statement.if_statement.for_statement.expression_switch_statement.type_switch_statement.select_statement.expression_case.type_case.communication_case.default_case.return_statement.break_statement.continue_statement.goto_statement.fallthrough_statement.defer_statement.go_statement.labeled_statement`.split(`.`),A=[`use_declaration`,`extern_crate_declaration`,`foreign_mod_item`,`mod_item`,`const_item`,`static_item`,`struct_item`,`enum_item`,`union_item`,`trait_item`,`impl_item`,`function_item`,`function_signature_item`,`type_item`,`associated_type`,`macro_definition`,`field_declaration`,`let_declaration`,`expression_statement`,`else_clause`,`match_arm`],j=`package_declaration.import_declaration.module_declaration.requires_module_directive.exports_module_directive.opens_module_directive.uses_module_directive.provides_module_directive.class_declaration.interface_declaration.enum_declaration.annotation_type_declaration.annotation_type_element_declaration.record_declaration.field_declaration.constant_declaration.method_declaration.constructor_declaration.compact_constructor_declaration.static_initializer.explicit_constructor_invocation.local_variable_declaration.expression_statement.if_statement.while_statement.do_statement.for_statement.enhanced_for_statement.switch_statement.switch_expression.switch_label.break_statement.continue_statement.return_statement.throw_statement.assert_statement.synchronized_statement.labeled_statement.yield_statement.resource.catch_clause.finally_clause`.split(`.`),M=[`elsif`,`else`,`when`,`in_clause`,`rescue`,`ensure`],N=[`program`,`body_statement`,`then`,`else`,`do`,`block_body`,`begin`,`ensure`],P=[`preproc_include`,`preproc_def`,`preproc_function_def`,`declaration`,`type_definition`,`field_declaration`,`function_definition`,`struct_specifier`,`enum_specifier`,`union_specifier`,`expression_statement`,`if_statement`,`else_clause`,`switch_statement`,`case_statement`,`for_statement`,`while_statement`,`do_statement`,`return_statement`,`break_statement`,`continue_statement`,`goto_statement`,`labeled_statement`],F=[...P,`class_specifier`,`namespace_definition`,`using_declaration`,`alias_declaration`,`namespace_alias_definition`,`concept_definition`,`static_assert_declaration`,`for_range_loop`,`catch_clause`,`throw_statement`,`co_return_statement`,`co_yield_statement`];function I(e){return R(e,`default`)?e.default:e}function L(e){return c[e]}function R(e,t){return typeof e!=`object`||!e||!(t in e)?!1:!!e[t]}const z=[{name:`javascript`,aliases:[`js`,`mjs`,`cjs`],parserLanguage:I(i)},{name:`jsx`,parserLanguage:I(i)},{name:`typescript`,aliases:[`ts`],parserLanguage:L(`typescript`)},{name:`tsx`,parserLanguage:L(`tsx`)},{name:`python`,aliases:[`py`],parserLanguage:I(a),ncssNodeTypes:O},{name:`go`,parserLanguage:I(n),decisionNodeTypes:f,nestingNodeTypes:m,ncssNodeTypes:k},{name:`rust`,aliases:[`rs`],parserLanguage:I(s),ncssNodeTypes:A,ncssContainerNodeTypes:[`block`,`else_clause`]},{name:`java`,parserLanguage:I(r),functionNodeTypes:h,classNodeTypes:g,decisionNodeTypes:v,nestingNodeTypes:_,ncssNodeTypes:j},{name:`ruby`,aliases:[`rb`],parserLanguage:I(o),functionNodeTypes:y,classNodeTypes:b,decisionNodeTypes:x,nestingNodeTypes:x,ncssNodeTypes:M,ncssContainerNodeTypes:N},{name:`c`,parserLanguage:I(e),functionNodeTypes:S,classNodeTypes:C,decisionNodeTypes:w,nestingNodeTypes:w,ncssNodeTypes:P},{name:`cpp`,aliases:[`c++`,`cxx`],parserLanguage:I(t),functionNodeTypes:S,classNodeTypes:T,decisionNodeTypes:E,nestingNodeTypes:E,ncssNodeTypes:F}].map(e=>({functionNodeTypes:l,classNodeTypes:u,decisionNodeTypes:d,nestingNodeTypes:p,ncssNodeTypes:D,...e}));function B(e=z){let t=new Map;for(let n of e){t.set(n.name,n);for(let e of n.aliases??[])t.set(e,n)}return t}const V=z.map(e=>e.name);export{B as createLanguageRegistry,z as defaultLanguages,V as supportedLanguages};
1
+ import e from"tree-sitter-c";import t from"tree-sitter-cpp";import n from"tree-sitter-go";import r from"tree-sitter-java";import i from"tree-sitter-javascript";import a from"tree-sitter-python";import o from"tree-sitter-ruby";import s from"tree-sitter-rust";import c from"tree-sitter-typescript";const l=[`function`,`function_declaration`,`function_definition`,`function_expression`,`function_item`,`function_signature_item`,`function_declarator`,`func_literal`,`method_declaration`,`method_definition`,`method_spec`,`arrow_function`,`generator_function`,`generator_function_declaration`,`lambda`,`lambda_expression`,`closure_expression`],u=[`if_statement`,`elif_clause`,`else_if_clause`,`for_statement`,`for_in_statement`,`while_statement`,`do_statement`,`catch_clause`,`except_clause`,`case_clause`,`switch_case`,`match_arm`,`conditional_expression`,`ternary_expression`,`if_expression`,`while_expression`,`for_expression`,`loop_expression`],d=[...u,`expression_case`,`type_case`,`communication_case`],f=[...u,`switch_default`],p=[...d,`default_case`],m=[...l,`constructor_declaration`,`compact_constructor_declaration`],h=[...u,`enhanced_for_statement`,`switch_block_statement_group`,`switch_rule`],g=[`method`,`singleton_method`,`lambda`,`block`,`do_block`],_=[`if`,`elsif`,`unless`,`while`,`until`,`for`,`when`,`in_clause`,`rescue`,`conditional`,`if_modifier`,`unless_modifier`,`while_modifier`,`until_modifier`,`rescue_modifier`],v=[`function_definition`,`lambda_expression`],y=[...u,`case_statement`],b=[...y,`for_range_loop`],x=`import_statement.export_statement.lexical_declaration.variable_declaration.function_declaration.function_signature.generator_function_declaration.class_declaration.abstract_class_declaration.module.method_definition.abstract_method_signature.class_static_block.field_definition.public_field_definition.type_alias_declaration.interface_declaration.enum_declaration.expression_statement.if_statement.else_clause.switch_statement.switch_case.switch_default.for_statement.for_in_statement.while_statement.do_statement.catch_clause.finally_clause.labeled_statement.return_statement.break_statement.continue_statement.throw_statement.debugger_statement.with_statement`.split(`.`),S=`import_statement.import_from_statement.future_import_statement.print_statement.exec_statement.assert_statement.expression_statement.return_statement.delete_statement.raise_statement.pass_statement.break_statement.continue_statement.global_statement.nonlocal_statement.if_statement.elif_clause.else_clause.for_statement.while_statement.except_clause.except_group_clause.finally_clause.with_statement.match_statement.case_clause.function_definition.class_definition.type_alias_statement`.split(`.`),C=`package_clause.import_spec.type_spec.type_alias.const_spec.var_spec.function_declaration.method_declaration.short_var_declaration.expression_statement.send_statement.inc_statement.dec_statement.assignment_statement.if_statement.for_statement.expression_switch_statement.type_switch_statement.select_statement.expression_case.type_case.communication_case.default_case.return_statement.break_statement.continue_statement.goto_statement.fallthrough_statement.defer_statement.go_statement.labeled_statement`.split(`.`),w=[`use_declaration`,`extern_crate_declaration`,`foreign_mod_item`,`mod_item`,`const_item`,`static_item`,`struct_item`,`enum_item`,`union_item`,`trait_item`,`impl_item`,`function_item`,`function_signature_item`,`type_item`,`associated_type`,`macro_definition`,`field_declaration`,`let_declaration`,`expression_statement`,`else_clause`,`match_arm`],T=`package_declaration.import_declaration.module_declaration.requires_module_directive.exports_module_directive.opens_module_directive.uses_module_directive.provides_module_directive.class_declaration.interface_declaration.enum_declaration.annotation_type_declaration.annotation_type_element_declaration.record_declaration.field_declaration.constant_declaration.method_declaration.constructor_declaration.compact_constructor_declaration.static_initializer.explicit_constructor_invocation.local_variable_declaration.expression_statement.if_statement.while_statement.do_statement.for_statement.enhanced_for_statement.switch_statement.switch_expression.switch_label.break_statement.continue_statement.return_statement.throw_statement.assert_statement.synchronized_statement.labeled_statement.yield_statement.resource.catch_clause.finally_clause`.split(`.`),E=[`elsif`,`else`,`when`,`in_clause`,`rescue`,`ensure`],D=[`program`,`body_statement`,`then`,`else`,`do`,`block_body`,`begin`,`ensure`],O=[`preproc_include`,`preproc_def`,`preproc_function_def`,`declaration`,`type_definition`,`field_declaration`,`function_definition`,`struct_specifier`,`enum_specifier`,`union_specifier`,`expression_statement`,`if_statement`,`else_clause`,`switch_statement`,`case_statement`,`for_statement`,`while_statement`,`do_statement`,`return_statement`,`break_statement`,`continue_statement`,`goto_statement`,`labeled_statement`],k=[...O,`class_specifier`,`namespace_definition`,`using_declaration`,`alias_declaration`,`namespace_alias_definition`,`concept_definition`,`static_assert_declaration`,`for_range_loop`,`catch_clause`,`throw_statement`,`co_return_statement`,`co_yield_statement`];function A(e){return M(e,`default`)?e.default:e}function j(e){return c[e]}function M(e,t){return typeof e!=`object`||!e||!(t in e)?!1:!!e[t]}const N=[{name:`javascript`,aliases:[`js`,`mjs`,`cjs`],parserLanguage:A(i)},{name:`jsx`,parserLanguage:A(i)},{name:`typescript`,aliases:[`ts`],parserLanguage:j(`typescript`)},{name:`tsx`,parserLanguage:j(`tsx`)},{name:`python`,aliases:[`py`],parserLanguage:A(a),ncssNodeTypes:S},{name:`go`,parserLanguage:A(n),decisionNodeTypes:d,nestingNodeTypes:p,ncssNodeTypes:C},{name:`rust`,aliases:[`rs`],parserLanguage:A(s),ncssNodeTypes:w,ncssContainerNodeTypes:[`block`,`else_clause`]},{name:`java`,parserLanguage:A(r),functionNodeTypes:m,decisionNodeTypes:h,nestingNodeTypes:h,ncssNodeTypes:T},{name:`ruby`,aliases:[`rb`],parserLanguage:A(o),functionNodeTypes:g,decisionNodeTypes:_,nestingNodeTypes:_,ncssNodeTypes:E,ncssContainerNodeTypes:D},{name:`c`,parserLanguage:A(e),functionNodeTypes:v,decisionNodeTypes:y,nestingNodeTypes:y,ncssNodeTypes:O},{name:`cpp`,aliases:[`c++`,`cxx`],parserLanguage:A(t),functionNodeTypes:v,decisionNodeTypes:b,nestingNodeTypes:b,ncssNodeTypes:k}].map(e=>({functionNodeTypes:l,decisionNodeTypes:u,nestingNodeTypes:f,ncssNodeTypes:x,...e}));function P(e=N){let t=new Map;for(let n of e){t.set(n.name,n);for(let e of n.aliases??[])t.set(e,n)}return t}const F=N.map(e=>e.name);export{P as createLanguageRegistry,N as defaultLanguages,F as supportedLanguages};
2
2
  //# sourceMappingURL=languages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"languages.js","names":["grammars"],"sources":["../src/languages.ts"],"sourcesContent":["import C from 'tree-sitter-c';\nimport Cpp from 'tree-sitter-cpp';\nimport Go from 'tree-sitter-go';\nimport Java from 'tree-sitter-java';\nimport JavaScript from 'tree-sitter-javascript';\nimport Python from 'tree-sitter-python';\nimport Ruby from 'tree-sitter-ruby';\nimport Rust from 'tree-sitter-rust';\nimport TypeScript from 'tree-sitter-typescript';\nimport type { LanguageDefinition, LanguageName, ParserLanguage } from './types.js';\n\ntype GrammarModule = unknown;\n\nconst commonFunctionNodes = [\n 'function',\n 'function_declaration',\n 'function_definition',\n 'function_expression',\n 'function_item',\n 'function_signature_item',\n 'function_declarator',\n 'func_literal',\n 'method_declaration',\n 'method_definition',\n 'method_spec',\n 'arrow_function',\n 'generator_function',\n 'generator_function_declaration',\n 'lambda',\n 'lambda_expression',\n 'closure_expression',\n] as const;\n\nconst commonClassNodes = [\n 'class',\n 'class_declaration',\n 'class_definition',\n 'interface_declaration',\n 'trait_item',\n 'struct_item',\n 'enum_item',\n 'union_item',\n] as const;\n\nconst commonDecisionNodes = [\n 'if_statement',\n 'elif_clause',\n 'else_if_clause',\n 'for_statement',\n 'for_in_statement',\n 'while_statement',\n 'do_statement',\n 'catch_clause',\n 'except_clause',\n 'case_clause',\n 'switch_case',\n 'match_arm',\n 'conditional_expression',\n 'ternary_expression',\n 'if_expression',\n 'while_expression',\n 'for_expression',\n 'loop_expression',\n] as const;\n\n// Go `switch`/`select` branches are `*_case` nodes, not the `case_clause`/`switch_case` of other grammars.\nconst goDecisionNodes = [...commonDecisionNodes, 'expression_case', 'type_case', 'communication_case'] as const;\n\n// Default switch branches add no decision, but their contents are nested inside the switch like\n// any other arm, so they appear in the nesting sets only.\nconst commonNestingNodes = [...commonDecisionNodes, 'switch_default'] as const;\nconst goNestingNodes = [...goDecisionNodes, 'default_case'] as const;\n\nconst javaFunctionNodes = [\n ...commonFunctionNodes,\n 'constructor_declaration',\n 'compact_constructor_declaration',\n] as const;\nconst javaClassNodes = [\n ...commonClassNodes,\n 'enum_declaration',\n 'record_declaration',\n 'annotation_type_declaration',\n // Counted only when they carry a `class_body` (anonymous classes, JLS 15.9.5).\n 'object_creation_expression',\n 'enum_constant',\n] as const;\nconst javaDecisionNodes = [\n ...commonDecisionNodes,\n 'enhanced_for_statement',\n 'switch_block_statement_group',\n 'switch_rule',\n] as const;\n// PMD's standard cyclomatic complexity charges `throw` one path (verified against PMD 7.26.0);\n// it stays out of the nesting set (its argument expressions are not nested) and adds no\n// cognitive point (see cyclomaticOnlyNodeTypes in metrics.ts). Other languages follow their own\n// reference tools (lizard/radon), which do not count throw/raise.\nconst javaCyclomaticDecisionNodes = [...javaDecisionNodes, 'throw_statement'] as const;\n\n// Ruby node types are keyword-like (`if`, `while`, ...), so they must stay Ruby-specific: the same\n// strings appear as anonymous keyword tokens in other grammars and would be double-counted there.\n// `block`/`do_block` are Ruby's closures (`items.map { ... }`), the analog of JS callbacks.\nconst rubyFunctionNodes = ['method', 'singleton_method', 'lambda', 'block', 'do_block'] as const;\n// `singleton_class` (`class << self`) opens an eigenclass scope, not a new type declaration.\nconst rubyClassNodes = ['class', 'module'] as const;\nconst rubyDecisionNodes = [\n 'if',\n 'elsif',\n 'unless',\n 'while',\n 'until',\n 'for',\n 'when',\n 'in_clause',\n 'rescue',\n 'conditional',\n 'if_modifier',\n 'unless_modifier',\n 'while_modifier',\n 'until_modifier',\n 'rescue_modifier',\n] as const;\n\n// `function_declarator` must stay out: it is nested inside every `function_definition` (which\n// would double-count) and also appears in body-less prototypes.\nconst cFunctionNodes = ['function_definition', 'lambda_expression'] as const;\nconst cClassNodes = ['struct_specifier', 'enum_specifier', 'union_specifier'] as const;\nconst cDecisionNodes = [...commonDecisionNodes, 'case_statement'] as const;\nconst cppClassNodes = [...cClassNodes, 'class_specifier'] as const;\nconst cppDecisionNodes = [...cDecisionNodes, 'for_range_loop'] as const;\n\n// NCSS node sets: every listed type counts as one non-commenting source statement. The Java set is\n// calibrated against PMD's NcssCount rule (`try` counts 0; `else`, `case`/`default` labels,\n// `catch`, `finally`, and try-with-resources resources count 1 each); the other languages follow\n// the same conventions with their grammar's node types.\nconst jsNcssNodes = [\n 'import_statement',\n 'export_statement',\n 'lexical_declaration',\n 'variable_declaration',\n 'function_declaration',\n 'function_signature',\n 'generator_function_declaration',\n 'class_declaration',\n 'abstract_class_declaration',\n 'module',\n 'method_definition',\n 'abstract_method_signature',\n 'class_static_block',\n 'field_definition',\n 'public_field_definition',\n 'type_alias_declaration',\n 'interface_declaration',\n 'enum_declaration',\n 'expression_statement',\n 'if_statement',\n 'else_clause',\n 'switch_statement',\n 'switch_case',\n 'switch_default',\n 'for_statement',\n 'for_in_statement',\n 'while_statement',\n 'do_statement',\n 'catch_clause',\n 'finally_clause',\n 'labeled_statement',\n 'return_statement',\n 'break_statement',\n 'continue_statement',\n 'throw_statement',\n 'debugger_statement',\n 'with_statement',\n] as const;\n\nconst pythonNcssNodes = [\n 'import_statement',\n 'import_from_statement',\n 'future_import_statement',\n 'print_statement',\n 'exec_statement',\n 'assert_statement',\n 'expression_statement',\n 'return_statement',\n 'delete_statement',\n 'raise_statement',\n 'pass_statement',\n 'break_statement',\n 'continue_statement',\n 'global_statement',\n 'nonlocal_statement',\n 'if_statement',\n 'elif_clause',\n 'else_clause',\n 'for_statement',\n 'while_statement',\n 'except_clause',\n 'except_group_clause',\n 'finally_clause',\n 'with_statement',\n 'match_statement',\n 'case_clause',\n 'function_definition',\n 'class_definition',\n 'type_alias_statement',\n] as const;\n\nconst goNcssNodes = [\n 'package_clause',\n 'import_spec',\n 'type_spec',\n 'type_alias',\n 'const_spec',\n 'var_spec',\n 'function_declaration',\n 'method_declaration',\n // Struct fields and interface members count contextually (see ncss.ts): only inside a named\n // `type T struct/interface { ... }`, not in inline anonymous types, which are part of one\n // declaration.\n 'short_var_declaration',\n 'expression_statement',\n 'send_statement',\n 'inc_statement',\n 'dec_statement',\n 'assignment_statement',\n 'if_statement',\n 'for_statement',\n 'expression_switch_statement',\n 'type_switch_statement',\n 'select_statement',\n 'expression_case',\n 'type_case',\n 'communication_case',\n 'default_case',\n 'return_statement',\n 'break_statement',\n 'continue_statement',\n 'goto_statement',\n 'fallthrough_statement',\n 'defer_statement',\n 'go_statement',\n 'labeled_statement',\n] as const;\n\nconst rustNcssNodes = [\n 'use_declaration',\n 'extern_crate_declaration',\n 'foreign_mod_item',\n 'mod_item',\n 'const_item',\n 'static_item',\n 'struct_item',\n 'enum_item',\n 'union_item',\n 'trait_item',\n 'impl_item',\n 'function_item',\n 'function_signature_item',\n 'type_item',\n 'associated_type',\n 'macro_definition',\n 'field_declaration',\n 'let_declaration',\n 'expression_statement',\n 'else_clause',\n 'match_arm',\n] as const;\n\nconst javaNcssNodes = [\n 'package_declaration',\n 'import_declaration',\n 'module_declaration',\n 'requires_module_directive',\n 'exports_module_directive',\n 'opens_module_directive',\n 'uses_module_directive',\n 'provides_module_directive',\n 'class_declaration',\n 'interface_declaration',\n 'enum_declaration',\n 'annotation_type_declaration',\n 'annotation_type_element_declaration',\n 'record_declaration',\n 'field_declaration',\n 'constant_declaration',\n 'method_declaration',\n 'constructor_declaration',\n 'compact_constructor_declaration',\n 'static_initializer',\n 'explicit_constructor_invocation',\n 'local_variable_declaration',\n 'expression_statement',\n 'if_statement',\n 'while_statement',\n 'do_statement',\n 'for_statement',\n 'enhanced_for_statement',\n 'switch_statement',\n 'switch_expression',\n 'switch_label',\n 'break_statement',\n 'continue_statement',\n 'return_statement',\n 'throw_statement',\n 'assert_statement',\n 'synchronized_statement',\n 'labeled_statement',\n 'yield_statement',\n 'resource',\n 'catch_clause',\n 'finally_clause',\n] as const;\n\n// Ruby statements have no wrapper node types, so bodies are counted positionally (see\n// ncssContainerNodeTypes); only clause nodes hanging off non-container parents need listing.\nconst rubyNcssNodes = ['elsif', 'else', 'when', 'in_clause', 'rescue', 'ensure'] as const;\nconst rubyNcssContainers = [\n 'program',\n 'body_statement',\n 'then',\n 'else',\n 'do',\n 'block_body',\n 'begin',\n 'ensure',\n] as const;\n\nconst cNcssNodes = [\n 'preproc_include',\n 'preproc_def',\n 'preproc_function_def',\n 'declaration',\n 'type_definition',\n 'field_declaration',\n 'function_definition',\n // Counted only when they carry a body (see bodylessNcssSpecifierTypes in ncss.ts).\n 'struct_specifier',\n 'enum_specifier',\n 'union_specifier',\n 'expression_statement',\n 'if_statement',\n 'else_clause',\n 'switch_statement',\n 'case_statement',\n 'for_statement',\n 'while_statement',\n 'do_statement',\n 'return_statement',\n 'break_statement',\n 'continue_statement',\n 'goto_statement',\n 'labeled_statement',\n] as const;\nconst cppNcssNodes = [\n ...cNcssNodes,\n 'class_specifier',\n 'namespace_definition',\n 'using_declaration',\n 'alias_declaration',\n 'namespace_alias_definition',\n 'concept_definition',\n 'static_assert_declaration',\n 'for_range_loop',\n 'catch_clause',\n 'throw_statement',\n 'co_return_statement',\n 'co_yield_statement',\n] as const;\n\nfunction normalizeGrammar(module: GrammarModule): ParserLanguage {\n if (isGrammarWrapper(module, 'default')) {\n return module.default;\n }\n\n return module;\n}\n\nfunction getTypeScriptGrammar(name: 'typescript' | 'tsx'): ParserLanguage {\n const grammars = TypeScript as unknown as Record<string, GrammarModule>;\n return grammars[name];\n}\n\nfunction isGrammarWrapper(value: GrammarModule, key: 'default'): value is Record<typeof key, ParserLanguage> {\n if (typeof value !== 'object' || value === null || !(key in value)) {\n return false;\n }\n\n return Boolean((value as Record<string, ParserLanguage>)[key]);\n}\n\nexport const defaultLanguages: readonly LanguageDefinition[] = [\n {\n name: 'javascript',\n aliases: ['js', 'mjs', 'cjs'],\n parserLanguage: normalizeGrammar(JavaScript as unknown as GrammarModule),\n },\n {\n name: 'jsx',\n parserLanguage: normalizeGrammar(JavaScript as unknown as GrammarModule),\n },\n {\n name: 'typescript',\n aliases: ['ts'],\n parserLanguage: getTypeScriptGrammar('typescript'),\n },\n {\n name: 'tsx',\n parserLanguage: getTypeScriptGrammar('tsx'),\n },\n {\n name: 'python',\n aliases: ['py'],\n parserLanguage: normalizeGrammar(Python as unknown as GrammarModule),\n ncssNodeTypes: pythonNcssNodes,\n },\n {\n name: 'go',\n parserLanguage: normalizeGrammar(Go as unknown as GrammarModule),\n decisionNodeTypes: goDecisionNodes,\n nestingNodeTypes: goNestingNodes,\n ncssNodeTypes: goNcssNodes,\n },\n {\n name: 'rust',\n aliases: ['rs'],\n parserLanguage: normalizeGrammar(Rust as unknown as GrammarModule),\n ncssNodeTypes: rustNcssNodes,\n // `else_clause` is a container so `else if` chains count the nested if_expression; a plain\n // `else { ... }` is unaffected because its only child is a `block`, itself a container.\n ncssContainerNodeTypes: ['block', 'else_clause'],\n },\n {\n name: 'java',\n parserLanguage: normalizeGrammar(Java as unknown as GrammarModule),\n functionNodeTypes: javaFunctionNodes,\n classNodeTypes: javaClassNodes,\n decisionNodeTypes: javaCyclomaticDecisionNodes,\n nestingNodeTypes: javaDecisionNodes,\n ncssNodeTypes: javaNcssNodes,\n },\n {\n name: 'ruby',\n aliases: ['rb'],\n parserLanguage: normalizeGrammar(Ruby as unknown as GrammarModule),\n functionNodeTypes: rubyFunctionNodes,\n classNodeTypes: rubyClassNodes,\n decisionNodeTypes: rubyDecisionNodes,\n nestingNodeTypes: rubyDecisionNodes,\n ncssNodeTypes: rubyNcssNodes,\n ncssContainerNodeTypes: rubyNcssContainers,\n },\n {\n name: 'c',\n parserLanguage: normalizeGrammar(C as unknown as GrammarModule),\n functionNodeTypes: cFunctionNodes,\n classNodeTypes: cClassNodes,\n decisionNodeTypes: cDecisionNodes,\n nestingNodeTypes: cDecisionNodes,\n ncssNodeTypes: cNcssNodes,\n },\n {\n name: 'cpp',\n aliases: ['c++', 'cxx'],\n parserLanguage: normalizeGrammar(Cpp as unknown as GrammarModule),\n functionNodeTypes: cFunctionNodes,\n classNodeTypes: cppClassNodes,\n decisionNodeTypes: cppDecisionNodes,\n nestingNodeTypes: cppDecisionNodes,\n ncssNodeTypes: cppNcssNodes,\n },\n].map((language) => ({\n functionNodeTypes: commonFunctionNodes,\n classNodeTypes: commonClassNodes,\n decisionNodeTypes: commonDecisionNodes,\n nestingNodeTypes: commonNestingNodes,\n ncssNodeTypes: jsNcssNodes,\n ...language,\n}));\n\nexport function createLanguageRegistry(\n languages: readonly LanguageDefinition[] = defaultLanguages\n): Map<LanguageName, LanguageDefinition> {\n const registry = new Map<LanguageName, LanguageDefinition>();\n\n for (const language of languages) {\n registry.set(language.name, language);\n for (const alias of language.aliases ?? []) {\n registry.set(alias, language);\n }\n }\n\n return registry;\n}\n\nexport const supportedLanguages = defaultLanguages.map((language) => language.name);\n"],"mappings":"wSAaA,MAAM,EAAsB,CAC1B,WACA,uBACA,sBACA,sBACA,gBACA,0BACA,sBACA,eACA,qBACA,oBACA,cACA,iBACA,qBACA,iCACA,SACA,oBACA,oBACF,EAEM,EAAmB,CACvB,QACA,oBACA,mBACA,wBACA,aACA,cACA,YACA,YACF,EAEM,EAAsB,CAC1B,eACA,cACA,iBACA,gBACA,mBACA,kBACA,eACA,eACA,gBACA,cACA,cACA,YACA,yBACA,qBACA,gBACA,mBACA,iBACA,iBACF,EAGM,EAAkB,CAAC,GAAG,EAAqB,kBAAmB,YAAa,oBAAoB,EAI/F,EAAqB,CAAC,GAAG,EAAqB,gBAAgB,EAC9D,EAAiB,CAAC,GAAG,EAAiB,cAAc,EAEpD,EAAoB,CACxB,GAAG,EACH,0BACA,iCACF,EACM,EAAiB,CACrB,GAAG,EACH,mBACA,qBACA,8BAEA,6BACA,eACF,EACM,EAAoB,CACxB,GAAG,EACH,yBACA,+BACA,aACF,EAKM,EAA8B,CAAC,GAAG,EAAmB,iBAAiB,EAKtE,EAAoB,CAAC,SAAU,mBAAoB,SAAU,QAAS,UAAU,EAEhF,EAAiB,CAAC,QAAS,QAAQ,EACnC,EAAoB,CACxB,KACA,QACA,SACA,QACA,QACA,MACA,OACA,YACA,SACA,cACA,cACA,kBACA,iBACA,iBACA,iBACF,EAIM,EAAiB,CAAC,sBAAuB,mBAAmB,EAC5D,EAAc,CAAC,mBAAoB,iBAAkB,iBAAiB,EACtE,EAAiB,CAAC,GAAG,EAAqB,gBAAgB,EAC1D,EAAgB,CAAC,GAAG,EAAa,iBAAiB,EAClD,EAAmB,CAAC,GAAG,EAAgB,gBAAgB,EAMvD,EAAc,iqBAsCpB,EAEM,EAAkB,gfA8BxB,EAEM,EAAc,kgBAmCpB,EAEM,EAAgB,CACpB,kBACA,2BACA,mBACA,WACA,aACA,cACA,cACA,YACA,aACA,aACA,YACA,gBACA,0BACA,YACA,kBACA,mBACA,oBACA,kBACA,uBACA,cACA,WACF,EAEM,EAAgB,k1BA2CtB,EAIM,EAAgB,CAAC,QAAS,OAAQ,OAAQ,YAAa,SAAU,QAAQ,EACzE,EAAqB,CACzB,UACA,iBACA,OACA,OACA,KACA,aACA,QACA,QACF,EAEM,EAAa,CACjB,kBACA,cACA,uBACA,cACA,kBACA,oBACA,sBAEA,mBACA,iBACA,kBACA,uBACA,eACA,cACA,mBACA,iBACA,gBACA,kBACA,eACA,mBACA,kBACA,qBACA,iBACA,mBACF,EACM,EAAe,CACnB,GAAG,EACH,kBACA,uBACA,oBACA,oBACA,6BACA,qBACA,4BACA,iBACA,eACA,kBACA,sBACA,oBACF,EAEA,SAAS,EAAiB,EAAuC,CAK/D,OAJI,EAAiB,EAAQ,SAAS,EAC7B,EAAO,QAGT,CACT,CAEA,SAAS,EAAqB,EAA4C,CAExE,OAAOA,EAAS,EAClB,CAEA,SAAS,EAAiB,EAAsB,EAA6D,CAK3G,OAJI,OAAO,GAAU,WAAY,GAAkB,EAAE,KAAO,GACnD,GAGF,EAAS,EAAyC,EAC3D,CAEA,MAAa,EAAkD,CAC7D,CACE,KAAM,aACN,QAAS,CAAC,KAAM,MAAO,KAAK,EAC5B,eAAgB,EAAiB,CAAsC,CACzE,EACA,CACE,KAAM,MACN,eAAgB,EAAiB,CAAsC,CACzE,EACA,CACE,KAAM,aACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAqB,YAAY,CACnD,EACA,CACE,KAAM,MACN,eAAgB,EAAqB,KAAK,CAC5C,EACA,CACE,KAAM,SACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAiB,CAAkC,EACnE,cAAe,CACjB,EACA,CACE,KAAM,KACN,eAAgB,EAAiB,CAA8B,EAC/D,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,EACA,CACE,KAAM,OACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAiB,CAAgC,EACjE,cAAe,EAGf,uBAAwB,CAAC,QAAS,aAAa,CACjD,EACA,CACE,KAAM,OACN,eAAgB,EAAiB,CAAgC,EACjE,kBAAmB,EACnB,eAAgB,EAChB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,EACA,CACE,KAAM,OACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAiB,CAAgC,EACjE,kBAAmB,EACnB,eAAgB,EAChB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,EACf,uBAAwB,CAC1B,EACA,CACE,KAAM,IACN,eAAgB,EAAiB,CAA6B,EAC9D,kBAAmB,EACnB,eAAgB,EAChB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,EACA,CACE,KAAM,MACN,QAAS,CAAC,MAAO,KAAK,EACtB,eAAgB,EAAiB,CAA+B,EAChE,kBAAmB,EACnB,eAAgB,EAChB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,CACF,CAAC,CAAC,IAAK,IAAc,CACnB,kBAAmB,EACnB,eAAgB,EAChB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,EACf,GAAG,CACL,EAAE,EAEF,SAAgB,EACd,EAA2C,EACJ,CACvC,IAAM,EAAW,IAAI,IAErB,IAAK,IAAM,KAAY,EAAW,CAChC,EAAS,IAAI,EAAS,KAAM,CAAQ,EACpC,IAAK,IAAM,KAAS,EAAS,SAAW,CAAC,EACvC,EAAS,IAAI,EAAO,CAAQ,CAEhC,CAEA,OAAO,CACT,CAEA,MAAa,EAAqB,EAAiB,IAAK,GAAa,EAAS,IAAI"}
1
+ {"version":3,"file":"languages.js","names":["grammars"],"sources":["../src/languages.ts"],"sourcesContent":["import C from 'tree-sitter-c';\nimport Cpp from 'tree-sitter-cpp';\nimport Go from 'tree-sitter-go';\nimport Java from 'tree-sitter-java';\nimport JavaScript from 'tree-sitter-javascript';\nimport Python from 'tree-sitter-python';\nimport Ruby from 'tree-sitter-ruby';\nimport Rust from 'tree-sitter-rust';\nimport TypeScript from 'tree-sitter-typescript';\nimport type { LanguageDefinition, LanguageName, ParserLanguage } from './types.js';\n\ntype GrammarModule = unknown;\n\nconst commonFunctionNodes = [\n 'function',\n 'function_declaration',\n 'function_definition',\n 'function_expression',\n 'function_item',\n 'function_signature_item',\n 'function_declarator',\n 'func_literal',\n 'method_declaration',\n 'method_definition',\n 'method_spec',\n 'arrow_function',\n 'generator_function',\n 'generator_function_declaration',\n 'lambda',\n 'lambda_expression',\n 'closure_expression',\n] as const;\n\nconst commonDecisionNodes = [\n 'if_statement',\n 'elif_clause',\n 'else_if_clause',\n 'for_statement',\n 'for_in_statement',\n 'while_statement',\n 'do_statement',\n 'catch_clause',\n 'except_clause',\n 'case_clause',\n 'switch_case',\n 'match_arm',\n 'conditional_expression',\n 'ternary_expression',\n 'if_expression',\n 'while_expression',\n 'for_expression',\n 'loop_expression',\n] as const;\n\n// Go `switch`/`select` branches are `*_case` nodes, not the `case_clause`/`switch_case` of other grammars.\nconst goDecisionNodes = [...commonDecisionNodes, 'expression_case', 'type_case', 'communication_case'] as const;\n\n// Default switch branches add no decision, but their contents are nested inside the switch like\n// any other arm, so they appear in the nesting sets only.\nconst commonNestingNodes = [...commonDecisionNodes, 'switch_default'] as const;\nconst goNestingNodes = [...goDecisionNodes, 'default_case'] as const;\n\nconst javaFunctionNodes = [\n ...commonFunctionNodes,\n 'constructor_declaration',\n 'compact_constructor_declaration',\n] as const;\nconst javaDecisionNodes = [\n ...commonDecisionNodes,\n 'enhanced_for_statement',\n 'switch_block_statement_group',\n 'switch_rule',\n] as const;\n\n// Ruby node types are keyword-like (`if`, `while`, ...), so they must stay Ruby-specific: the same\n// strings appear as anonymous keyword tokens in other grammars and would be double-counted there.\n// `block`/`do_block` are Ruby's closures (`items.map { ... }`), the analog of JS callbacks.\nconst rubyFunctionNodes = ['method', 'singleton_method', 'lambda', 'block', 'do_block'] as const;\nconst rubyDecisionNodes = [\n 'if',\n 'elsif',\n 'unless',\n 'while',\n 'until',\n 'for',\n 'when',\n 'in_clause',\n 'rescue',\n 'conditional',\n 'if_modifier',\n 'unless_modifier',\n 'while_modifier',\n 'until_modifier',\n 'rescue_modifier',\n] as const;\n\n// `function_declarator` must stay out: it is nested inside every `function_definition` (which\n// would double-count) and also appears in body-less prototypes.\nconst cFunctionNodes = ['function_definition', 'lambda_expression'] as const;\nconst cDecisionNodes = [...commonDecisionNodes, 'case_statement'] as const;\nconst cppDecisionNodes = [...cDecisionNodes, 'for_range_loop'] as const;\n\n// NCSS node sets: every listed type counts as one non-commenting source statement. The Java set is\n// calibrated against PMD's NcssCount rule (`try` counts 0; `else`, `case`/`default` labels,\n// `catch`, `finally`, and try-with-resources resources count 1 each); the other languages follow\n// the same conventions with their grammar's node types.\nconst jsNcssNodes = [\n 'import_statement',\n 'export_statement',\n 'lexical_declaration',\n 'variable_declaration',\n 'function_declaration',\n 'function_signature',\n 'generator_function_declaration',\n 'class_declaration',\n 'abstract_class_declaration',\n 'module',\n 'method_definition',\n 'abstract_method_signature',\n 'class_static_block',\n 'field_definition',\n 'public_field_definition',\n 'type_alias_declaration',\n 'interface_declaration',\n 'enum_declaration',\n 'expression_statement',\n 'if_statement',\n 'else_clause',\n 'switch_statement',\n 'switch_case',\n 'switch_default',\n 'for_statement',\n 'for_in_statement',\n 'while_statement',\n 'do_statement',\n 'catch_clause',\n 'finally_clause',\n 'labeled_statement',\n 'return_statement',\n 'break_statement',\n 'continue_statement',\n 'throw_statement',\n 'debugger_statement',\n 'with_statement',\n] as const;\n\nconst pythonNcssNodes = [\n 'import_statement',\n 'import_from_statement',\n 'future_import_statement',\n 'print_statement',\n 'exec_statement',\n 'assert_statement',\n 'expression_statement',\n 'return_statement',\n 'delete_statement',\n 'raise_statement',\n 'pass_statement',\n 'break_statement',\n 'continue_statement',\n 'global_statement',\n 'nonlocal_statement',\n 'if_statement',\n 'elif_clause',\n 'else_clause',\n 'for_statement',\n 'while_statement',\n 'except_clause',\n 'except_group_clause',\n 'finally_clause',\n 'with_statement',\n 'match_statement',\n 'case_clause',\n 'function_definition',\n 'class_definition',\n 'type_alias_statement',\n] as const;\n\nconst goNcssNodes = [\n 'package_clause',\n 'import_spec',\n 'type_spec',\n 'type_alias',\n 'const_spec',\n 'var_spec',\n 'function_declaration',\n 'method_declaration',\n // Struct fields and interface members count contextually (see ncss.ts): only inside a named\n // `type T struct/interface { ... }`, not in inline anonymous types, which are part of one\n // declaration.\n 'short_var_declaration',\n 'expression_statement',\n 'send_statement',\n 'inc_statement',\n 'dec_statement',\n 'assignment_statement',\n 'if_statement',\n 'for_statement',\n 'expression_switch_statement',\n 'type_switch_statement',\n 'select_statement',\n 'expression_case',\n 'type_case',\n 'communication_case',\n 'default_case',\n 'return_statement',\n 'break_statement',\n 'continue_statement',\n 'goto_statement',\n 'fallthrough_statement',\n 'defer_statement',\n 'go_statement',\n 'labeled_statement',\n] as const;\n\nconst rustNcssNodes = [\n 'use_declaration',\n 'extern_crate_declaration',\n 'foreign_mod_item',\n 'mod_item',\n 'const_item',\n 'static_item',\n 'struct_item',\n 'enum_item',\n 'union_item',\n 'trait_item',\n 'impl_item',\n 'function_item',\n 'function_signature_item',\n 'type_item',\n 'associated_type',\n 'macro_definition',\n 'field_declaration',\n 'let_declaration',\n 'expression_statement',\n 'else_clause',\n 'match_arm',\n] as const;\n\nconst javaNcssNodes = [\n 'package_declaration',\n 'import_declaration',\n 'module_declaration',\n 'requires_module_directive',\n 'exports_module_directive',\n 'opens_module_directive',\n 'uses_module_directive',\n 'provides_module_directive',\n 'class_declaration',\n 'interface_declaration',\n 'enum_declaration',\n 'annotation_type_declaration',\n 'annotation_type_element_declaration',\n 'record_declaration',\n 'field_declaration',\n 'constant_declaration',\n 'method_declaration',\n 'constructor_declaration',\n 'compact_constructor_declaration',\n 'static_initializer',\n 'explicit_constructor_invocation',\n 'local_variable_declaration',\n 'expression_statement',\n 'if_statement',\n 'while_statement',\n 'do_statement',\n 'for_statement',\n 'enhanced_for_statement',\n 'switch_statement',\n 'switch_expression',\n 'switch_label',\n 'break_statement',\n 'continue_statement',\n 'return_statement',\n 'throw_statement',\n 'assert_statement',\n 'synchronized_statement',\n 'labeled_statement',\n 'yield_statement',\n 'resource',\n 'catch_clause',\n 'finally_clause',\n] as const;\n\n// Ruby statements have no wrapper node types, so bodies are counted positionally (see\n// ncssContainerNodeTypes); only clause nodes hanging off non-container parents need listing.\nconst rubyNcssNodes = ['elsif', 'else', 'when', 'in_clause', 'rescue', 'ensure'] as const;\nconst rubyNcssContainers = [\n 'program',\n 'body_statement',\n 'then',\n 'else',\n 'do',\n 'block_body',\n 'begin',\n 'ensure',\n] as const;\n\nconst cNcssNodes = [\n 'preproc_include',\n 'preproc_def',\n 'preproc_function_def',\n 'declaration',\n 'type_definition',\n 'field_declaration',\n 'function_definition',\n // Counted only when they carry a body (see bodylessNcssSpecifierTypes in ncss.ts).\n 'struct_specifier',\n 'enum_specifier',\n 'union_specifier',\n 'expression_statement',\n 'if_statement',\n 'else_clause',\n 'switch_statement',\n 'case_statement',\n 'for_statement',\n 'while_statement',\n 'do_statement',\n 'return_statement',\n 'break_statement',\n 'continue_statement',\n 'goto_statement',\n 'labeled_statement',\n] as const;\nconst cppNcssNodes = [\n ...cNcssNodes,\n 'class_specifier',\n 'namespace_definition',\n 'using_declaration',\n 'alias_declaration',\n 'namespace_alias_definition',\n 'concept_definition',\n 'static_assert_declaration',\n 'for_range_loop',\n 'catch_clause',\n 'throw_statement',\n 'co_return_statement',\n 'co_yield_statement',\n] as const;\n\nfunction normalizeGrammar(module: GrammarModule): ParserLanguage {\n if (isGrammarWrapper(module, 'default')) {\n return module.default;\n }\n\n return module;\n}\n\nfunction getTypeScriptGrammar(name: 'typescript' | 'tsx'): ParserLanguage {\n const grammars = TypeScript as unknown as Record<string, GrammarModule>;\n return grammars[name];\n}\n\nfunction isGrammarWrapper(value: GrammarModule, key: 'default'): value is Record<typeof key, ParserLanguage> {\n if (typeof value !== 'object' || value === null || !(key in value)) {\n return false;\n }\n\n return Boolean((value as Record<string, ParserLanguage>)[key]);\n}\n\nexport const defaultLanguages: readonly LanguageDefinition[] = [\n {\n name: 'javascript',\n aliases: ['js', 'mjs', 'cjs'],\n parserLanguage: normalizeGrammar(JavaScript as unknown as GrammarModule),\n },\n {\n name: 'jsx',\n parserLanguage: normalizeGrammar(JavaScript as unknown as GrammarModule),\n },\n {\n name: 'typescript',\n aliases: ['ts'],\n parserLanguage: getTypeScriptGrammar('typescript'),\n },\n {\n name: 'tsx',\n parserLanguage: getTypeScriptGrammar('tsx'),\n },\n {\n name: 'python',\n aliases: ['py'],\n parserLanguage: normalizeGrammar(Python as unknown as GrammarModule),\n ncssNodeTypes: pythonNcssNodes,\n },\n {\n name: 'go',\n parserLanguage: normalizeGrammar(Go as unknown as GrammarModule),\n decisionNodeTypes: goDecisionNodes,\n nestingNodeTypes: goNestingNodes,\n ncssNodeTypes: goNcssNodes,\n },\n {\n name: 'rust',\n aliases: ['rs'],\n parserLanguage: normalizeGrammar(Rust as unknown as GrammarModule),\n ncssNodeTypes: rustNcssNodes,\n // `else_clause` is a container so `else if` chains count the nested if_expression; a plain\n // `else { ... }` is unaffected because its only child is a `block`, itself a container.\n ncssContainerNodeTypes: ['block', 'else_clause'],\n },\n {\n name: 'java',\n parserLanguage: normalizeGrammar(Java as unknown as GrammarModule),\n functionNodeTypes: javaFunctionNodes,\n decisionNodeTypes: javaDecisionNodes,\n nestingNodeTypes: javaDecisionNodes,\n ncssNodeTypes: javaNcssNodes,\n },\n {\n name: 'ruby',\n aliases: ['rb'],\n parserLanguage: normalizeGrammar(Ruby as unknown as GrammarModule),\n functionNodeTypes: rubyFunctionNodes,\n decisionNodeTypes: rubyDecisionNodes,\n nestingNodeTypes: rubyDecisionNodes,\n ncssNodeTypes: rubyNcssNodes,\n ncssContainerNodeTypes: rubyNcssContainers,\n },\n {\n name: 'c',\n parserLanguage: normalizeGrammar(C as unknown as GrammarModule),\n functionNodeTypes: cFunctionNodes,\n decisionNodeTypes: cDecisionNodes,\n nestingNodeTypes: cDecisionNodes,\n ncssNodeTypes: cNcssNodes,\n },\n {\n name: 'cpp',\n aliases: ['c++', 'cxx'],\n parserLanguage: normalizeGrammar(Cpp as unknown as GrammarModule),\n functionNodeTypes: cFunctionNodes,\n decisionNodeTypes: cppDecisionNodes,\n nestingNodeTypes: cppDecisionNodes,\n ncssNodeTypes: cppNcssNodes,\n },\n].map((language) => ({\n functionNodeTypes: commonFunctionNodes,\n decisionNodeTypes: commonDecisionNodes,\n nestingNodeTypes: commonNestingNodes,\n ncssNodeTypes: jsNcssNodes,\n ...language,\n}));\n\nexport function createLanguageRegistry(\n languages: readonly LanguageDefinition[] = defaultLanguages\n): Map<LanguageName, LanguageDefinition> {\n const registry = new Map<LanguageName, LanguageDefinition>();\n\n for (const language of languages) {\n registry.set(language.name, language);\n for (const alias of language.aliases ?? []) {\n registry.set(alias, language);\n }\n }\n\n return registry;\n}\n\nexport const supportedLanguages = defaultLanguages.map((language) => language.name);\n"],"mappings":"wSAaA,MAAM,EAAsB,CAC1B,WACA,uBACA,sBACA,sBACA,gBACA,0BACA,sBACA,eACA,qBACA,oBACA,cACA,iBACA,qBACA,iCACA,SACA,oBACA,oBACF,EAEM,EAAsB,CAC1B,eACA,cACA,iBACA,gBACA,mBACA,kBACA,eACA,eACA,gBACA,cACA,cACA,YACA,yBACA,qBACA,gBACA,mBACA,iBACA,iBACF,EAGM,EAAkB,CAAC,GAAG,EAAqB,kBAAmB,YAAa,oBAAoB,EAI/F,EAAqB,CAAC,GAAG,EAAqB,gBAAgB,EAC9D,EAAiB,CAAC,GAAG,EAAiB,cAAc,EAEpD,EAAoB,CACxB,GAAG,EACH,0BACA,iCACF,EACM,EAAoB,CACxB,GAAG,EACH,yBACA,+BACA,aACF,EAKM,EAAoB,CAAC,SAAU,mBAAoB,SAAU,QAAS,UAAU,EAChF,EAAoB,CACxB,KACA,QACA,SACA,QACA,QACA,MACA,OACA,YACA,SACA,cACA,cACA,kBACA,iBACA,iBACA,iBACF,EAIM,EAAiB,CAAC,sBAAuB,mBAAmB,EAC5D,EAAiB,CAAC,GAAG,EAAqB,gBAAgB,EAC1D,EAAmB,CAAC,GAAG,EAAgB,gBAAgB,EAMvD,EAAc,iqBAsCpB,EAEM,EAAkB,gfA8BxB,EAEM,EAAc,kgBAmCpB,EAEM,EAAgB,CACpB,kBACA,2BACA,mBACA,WACA,aACA,cACA,cACA,YACA,aACA,aACA,YACA,gBACA,0BACA,YACA,kBACA,mBACA,oBACA,kBACA,uBACA,cACA,WACF,EAEM,EAAgB,k1BA2CtB,EAIM,EAAgB,CAAC,QAAS,OAAQ,OAAQ,YAAa,SAAU,QAAQ,EACzE,EAAqB,CACzB,UACA,iBACA,OACA,OACA,KACA,aACA,QACA,QACF,EAEM,EAAa,CACjB,kBACA,cACA,uBACA,cACA,kBACA,oBACA,sBAEA,mBACA,iBACA,kBACA,uBACA,eACA,cACA,mBACA,iBACA,gBACA,kBACA,eACA,mBACA,kBACA,qBACA,iBACA,mBACF,EACM,EAAe,CACnB,GAAG,EACH,kBACA,uBACA,oBACA,oBACA,6BACA,qBACA,4BACA,iBACA,eACA,kBACA,sBACA,oBACF,EAEA,SAAS,EAAiB,EAAuC,CAK/D,OAJI,EAAiB,EAAQ,SAAS,EAC7B,EAAO,QAGT,CACT,CAEA,SAAS,EAAqB,EAA4C,CAExE,OAAOA,EAAS,EAClB,CAEA,SAAS,EAAiB,EAAsB,EAA6D,CAK3G,OAJI,OAAO,GAAU,WAAY,GAAkB,EAAE,KAAO,GACnD,GAGF,EAAS,EAAyC,EAC3D,CAEA,MAAa,EAAkD,CAC7D,CACE,KAAM,aACN,QAAS,CAAC,KAAM,MAAO,KAAK,EAC5B,eAAgB,EAAiB,CAAsC,CACzE,EACA,CACE,KAAM,MACN,eAAgB,EAAiB,CAAsC,CACzE,EACA,CACE,KAAM,aACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAqB,YAAY,CACnD,EACA,CACE,KAAM,MACN,eAAgB,EAAqB,KAAK,CAC5C,EACA,CACE,KAAM,SACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAiB,CAAkC,EACnE,cAAe,CACjB,EACA,CACE,KAAM,KACN,eAAgB,EAAiB,CAA8B,EAC/D,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,EACA,CACE,KAAM,OACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAiB,CAAgC,EACjE,cAAe,EAGf,uBAAwB,CAAC,QAAS,aAAa,CACjD,EACA,CACE,KAAM,OACN,eAAgB,EAAiB,CAAgC,EACjE,kBAAmB,EACnB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,EACA,CACE,KAAM,OACN,QAAS,CAAC,IAAI,EACd,eAAgB,EAAiB,CAAgC,EACjE,kBAAmB,EACnB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,EACf,uBAAwB,CAC1B,EACA,CACE,KAAM,IACN,eAAgB,EAAiB,CAA6B,EAC9D,kBAAmB,EACnB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,EACA,CACE,KAAM,MACN,QAAS,CAAC,MAAO,KAAK,EACtB,eAAgB,EAAiB,CAA+B,EAChE,kBAAmB,EACnB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,CACjB,CACF,CAAC,CAAC,IAAK,IAAc,CACnB,kBAAmB,EACnB,kBAAmB,EACnB,iBAAkB,EAClB,cAAe,EACf,GAAG,CACL,EAAE,EAEF,SAAgB,EACd,EAA2C,EACJ,CACvC,IAAM,EAAW,IAAI,IAErB,IAAK,IAAM,KAAY,EAAW,CAChC,EAAS,IAAI,EAAS,KAAM,CAAQ,EACpC,IAAK,IAAM,KAAS,EAAS,SAAW,CAAC,EACvC,EAAS,IAAI,EAAO,CAAQ,CAEhC,CAEA,OAAO,CACT,CAEA,MAAa,EAAqB,EAAiB,IAAK,GAAa,EAAS,IAAI"}
package/dist/metrics.cjs CHANGED
@@ -1,3 +1,2 @@
1
- "use strict";const e=require("./_virtual/_rolldown/runtime.cjs"),t=require("./duplication.cjs"),n=require("./languages.cjs"),r=require("./ncss.cjs"),i=require("./nativeMetrics.cjs");let a=require("tree-sitter");a=e.__toESM(a,1);const o=new Set([`&&`,`||`,`and`,`or`]),s=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(`,`)),c=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(`.`)),l=new Set([`interpreted_string_literal`,`regex`,`user_defined_literal`,`integral_type`,`floating_point_type`,`sized_type_specifier`,`placeholder_type_specifier`]);var u=class{registry=n.createLanguageRegistry();registerLanguage(e){Me(e),r.invalidateNcssSetsCache(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 a=this.registry.get(n.language);if(!a)throw Error(`Unsupported language: ${n.language}`);let o=f(n)?i.measureWithNativeBackend(e,a,n.includeSyntaxTree??!1):void 0;if(o)return _(o,n.includeSyntaxTree??!1);let s=d(e,a),c=v(s,A(s,new Set(a.functionNodeTypes)).filter(e=>!De(e)&&Ee(e)),a),l=c.functions,u=Fe(s,a),{lines:p,codeLineNumbers:m}=yn(e,s),h=Sn(s,e);return{language:a.name,bytes:Buffer.byteLength(e),lines:p,functions:l,classCount:_t(s,a),functionCount:l.length,cyclomaticComplexity:u.cyclomaticComplexity,maxCyclomaticComplexity:br(l,`cyclomaticComplexity`),cognitiveComplexity:u.cognitiveComplexity,maxCognitiveComplexity:br(l,`cognitiveComplexity`),nestingDepth:u.nestingDepth,ncssCount:r.countNcss(s,a),callGraph:c.callGraph,coupling:c.coupling,module:c.module,cohesion:c.cohesion,syntaxFeatures:c.syntaxFeatures,typeComplexity:c.typeComplexity,duplication:t.measureDuplication(s,m,n.duplication),halstead:h,maintainabilityIndex:vr(h.volume,u.cyclomaticComplexity,p.code),syntaxTree:n.includeSyntaxTree?s.toString():void 0}}collectDuplicationCandidates(e,t){return this.collectCrossFileDuplicationFileData(e,t).candidates}collectCrossFileDuplicationFileData(e,n){let r=this.registry.get(n.language);if(!r)throw Error(`Unsupported language: ${n.language}`);return t.collectCrossFileDuplicateCandidates(d(e,r),n.duplication)}};function d(e,t){let n=new a.default;return n.setLanguage(t.parserLanguage),n.parse(e,void 0,{bufferSize:e.length+1}).rootNode}function f(e){let n=e.duplication;return(n?.minTokens??t.defaultDuplicationOptions.minTokens)===t.defaultDuplicationOptions.minTokens&&(n?.maxGapTokens??t.defaultDuplicationOptions.maxGapTokens)===t.defaultDuplicationOptions.maxGapTokens&&(n?.minSimilarityPercent??t.defaultDuplicationOptions.minSimilarityPercent)===t.defaultDuplicationOptions.minSimilarityPercent}const p=new u;function m(e,t){return p.measure(e,t)}function h(e,t){return p.collectDuplicationCandidates(e,t)}function g(e,t){return p.collectCrossFileDuplicationFileData(e,t)}function _(e,t){let n=Cn(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:vr(n.volume,e.cyclomaticComplexity,e.lines.code),syntaxTree:t?e.syntaxTree:void 0}}function v(e,t,n){let r=tt(e,n),i=Pe(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 y(e,n,t,r,a)}),o=be(a,n.name,ge(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:Qt(e,n),module:Dt(e,n),cohesion:_n(a),syntaxFeatures:$t(e,n.name),typeComplexity:vn(e)}}function y(e,t,n,r,i){let a=qe(e,t,r,ae(e)),o=ue(e),s=t.name===`python`?de(e):0;return{index:n,name:wn(e),nodeType:e.type,scopeName:te(e,t),hasImplementation:Te(e),startLine:e.startPosition.row+1,startColumn:e.startPosition.column,endLine:e.endPosition.row+1,returnsJsx:yt(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:gt(e)}}const b=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`]),ee=new Set([`namespace_definition`,`mod_item`]);function te(e,t){let{segments:n,hasClassScope:r}=x(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 Zt(t.text).replace(/\[.*\]$/su,``)}let i=z(e.childForFieldName(`declarator`),!0),a=i?.lastIndexOf(`::`)??-1;if(i!==void 0&&a>0){let t=w(i.slice(0,a),ie(e));return[...n,t].join(`::`)}}function x(e,t){let n=D(t).functionNodes,r=[],i=!1;for(let t=e;t;t=t.parent){if(ee.has(t.type)){let e=t.childForFieldName(`name`)?.text;e&&r.unshift(e);continue}if(i&&T(t,n)){r.unshift(`<fn:${t.startIndex}>`);continue}b.has(t.type)&&(t.type===`object_creation_expression`&&!t.namedChildren.some(e=>e.type===`class_body`)||(r.unshift(S(t)),i=!0))}return{segments:r,hasClassScope:i}}function S(e){if(e.type===`impl_item`){let t=e.childForFieldName(`type`)?.text;return t===void 0?C(e):w(t,ne(e.childForFieldName(`type_parameters`)))}if(e.type===`singleton_class`){let t=e.childForFieldName(`value`)?.text;return t===void 0?C(e):`<<${t.replaceAll(/\s+/gu,``)}`}return e.childForFieldName(`name`)?.text??C(e)}function C(e){return`<anonymous:${e.startIndex}>`}function w(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 ne(e){let t=[];for(let n of e?.namedChildren??[]){if(n.type===`comment`)continue;let e=re(n);e!==void 0&&t.push(e)}return t}function re(e){if(e.type===`type_identifier`||e.type===`identifier`||e.type===`lifetime`)return e.text;for(let t of e.namedChildren){let e=re(t);if(e!==void 0)return e}}function ie(e){let t=[];for(let n=e.parent;n;n=n.parent)n.type===`template_declaration`&&t.unshift(...ne(n.childForFieldName(`parameters`)));return t}function ae(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 oe=new Set([`spread_parameter`,`variadic_parameter_declaration`,`variadic_parameter`,`rest_pattern`,`list_splat_pattern`,`dictionary_splat_pattern`,`splat_parameter`,`hash_splat_parameter`]),se=new Set([`optional_parameter_declaration`,`assignment_pattern`,`optional_parameter`,`default_parameter`,`typed_default_parameter`]);function ce(e){return oe.has(e.type)?!0:e.type===`required_parameter`&&e.childForFieldName(`pattern`)?.type===`rest_pattern`}function le(e){return se.has(e.type)?!0:(e.type===`required_parameter`||e.type===`keyword_parameter`)&&e.childForFieldName(`value`)!==null}function ue(e){if(e.childForFieldName(`parameter`))return{count:1,minCount:1,unbounded:!1};let t=pe(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(X(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)||fe(e))continue;let t=e.type===`parameter_declaration`?Math.max(1,X(e,`name`).length):1;r+=t,ce(e)?a=!0:le(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 de(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 fe(e){return e.type===`parameter_declaration`&&e.childForFieldName(`declarator`)===null&&e.childForFieldName(`type`)?.text===`void`}function pe(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=B(n)}return e.namedChildren.find(e=>e.type===`formal_parameters`||e.type===`parameter_list`)}const me=new Set([`java`,`javascript`,`jsx`,`typescript`,`tsx`,`cpp`,`python`,`ruby`]),he=new Set([`class_declaration`,`interface_declaration`,`class_specifier`,`struct_specifier`,`class_definition`,`class`]);function ge(e,t){let n=new Map;if(!me.has(t.name))return n;let r=new Set,i=[];for(let n of A(e,he)){let{segments:e}=x(n.parent,t),a=[...e,S(n)].join(`::`);r.add(a);let o=ve(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=>_e(e,t,r)),o=n.get(e)??[];n.set(e,[...o,...i.filter(e=>!o.includes(e))])}return n}function _e(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 ve(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?X(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=>ye(e,t)).filter(e=>e.length>0)}function ye(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 be(e,t,n){let r=xe(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=Ce(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=pr(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:xr(i),maxFanOut:xr(a),maxCallDepth:hr(o)}}}function xe(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 Se=new Set([`java`,`ruby`,`cpp`]);function Ce(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`&&Se.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 we=new Set([`function_definition`,`constructor_declaration`,`compact_constructor_declaration`,`function_signature_item`]);function Te(e){return e.type!==`method_declaration`||e.childForFieldName(`body`)!==null}function Ee(e){return!we.has(e.type)||e.childForFieldName(`body`)!==null||e.namedChildren.some(e=>e.type===`try_statement`)}function De(e){return(e.type===`block`||e.type===`do_block`)&&e.parent?.type===`lambda`}function T(e,t){return t.has(e.type)&&!De(e)}const Oe=new Set([`switch_statement`,`switch_expression`,`expression_switch_statement`,`type_switch_statement`,`select_statement`,`match_expression`,`match_statement`,`case`,`case_match`]),ke=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`]),Ae=new Set([`if_statement`,`if_expression`,`if`,`unless`]),je=new Set([`throw_statement`]),E=new WeakMap;function Me(e){E.delete(e)}function D(e){let t=E.get(e);return t||(t={functionNodes:new Set(e.functionNodeTypes),decisionNodes:new Set(e.decisionNodeTypes),nestingNodes:new Set(e.nestingNodeTypes)},E.set(e,t)),t}function Ne(e,t){return{cyclomaticComplexity:1,cognitiveComplexity:0,nestingSensitiveCount:0,nestingDepth:0,ncss:0,hasOwnNcssContribution:!1,entryCognitiveNesting:e,entryStructuralNesting:t}}function Pe(e,t){let{functionNodes:n,decisionNodes:i,nestingNodes:a}=D(t),{countable:o,containers:s}=r.getNcssSets(t),c=new Map,l=[Ne(0,0)];function u(e,t,d,f,p,m){let h=e.type===`class_body`&&f;h&&(p=!0,d+=1);let g=T(e,n);g&&(f&&!m&&(d+=1),f=!0);let _=l.at(-1),v=t+d-_.entryCognitiveNesting,y=!p&&!g,b=e.isNamed&&i.has(e.type)&&!We(e),ee=e.isNamed&&ke.has(e.type),te=e.isNamed&&(a.has(e.type)||e.type===`else`&&(e.parent?.type===`case`||e.parent?.type===`case_match`)),x=b&&Ue(e);b&&y&&(_.cyclomaticComplexity+=1),b&&!ee&&!je.has(e.type)&&(x?_.cognitiveComplexity+=1:(_.cognitiveComplexity+=1+v,_.nestingSensitiveCount+=1)),e.isNamed&&Oe.has(e.type)&&(_.cognitiveComplexity+=1+v,_.nestingSensitiveCount+=1),_.cognitiveComplexity+=Ie(e),Le(e)&&(_.cognitiveComplexity+=1),Ke(e)&&(y&&(_.cyclomaticComplexity+=1),ze(e)&&(_.cognitiveComplexity+=1)),He(e)&&(y&&(_.cyclomaticComplexity+=1),_.cognitiveComplexity+=1);let S=te&&!x?t+1:t;y&&(_.nestingDepth=Math.max(_.nestingDepth,S-_.entryStructuralNesting)),g&&l.push(Ne(S+d,S));let C=r.ncssContribution(e,o,s),w=l.at(-1);w.ncss+=C,g&&C>0&&(w.hasOwnNcssContribution=!0);for(let t of e.children)u(t,S,d,f,!g&&p,h);if(g){let t=l.pop();c.set(e.id,{cyclomaticComplexity:t.cyclomaticComplexity,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 u(e,0,0,!1,!1,!1),c}function Fe(e,t){let n=1,r=0,i=0,{functionNodes:a,decisionNodes:o,nestingNodes:s}=D(t);function c(e,t,l,u,d){let f=e.type===`class_body`&&u;f&&(l+=1),T(e,a)&&(u&&!d&&(l+=1),u=!0);let p=t+l,m=e.isNamed&&o.has(e.type)&&!We(e),h=e.isNamed&&ke.has(e.type),g=e.isNamed&&(s.has(e.type)||e.type===`else`&&(e.parent?.type===`case`||e.parent?.type===`case_match`)),_=m&&Ue(e);m&&(n+=1),m&&!h&&!je.has(e.type)&&(r+=_?1:1+p),e.isNamed&&Oe.has(e.type)&&(r+=1+p),r+=Ie(e),Le(e)&&(r+=1),Ke(e)&&(n+=1,ze(e)&&(r+=1)),He(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 Ie(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=>Ae.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`&&!Ae.has(r.type)&&(t+=1)}return t}function Le(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=>!r.commentNodeTypes.has(e.type)):!1}const Re=new Set([`parenthesized_expression`,`parenthesized_statements`]);function ze(e){let t=e.parent;if(!t)return!0;let n=t.parent;for(;n&&Re.has(n.type);)n=n.parent;return!n||n.type!==t.type||Be(Ve(n))!==Be(e.text)}function Be(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&&o.has(e.text))?.text}function He(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 Ue(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 We(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 Ge=new Set([`binary_expression`,`binary`,`boolean_operator`]);function Ke(e){if(e.isNamed||!o.has(e.text))return!1;let t=e.parent;return t!==null&&Ge.has(t.type)}function qe(e,t,n=new Set,r){let i=new Set,a=[],o=D(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&&T(e,o))){if(!(t.name===`cpp`&&Qe(e)))if(V(e)){c+=1;let i=t.name===`cpp`&&(e.type===`new_expression`||e.type===`call_expression`&&n.has(O(e.childForFieldName(`function`))??``))?void 0:Pn(e);if(i&&l(i,t.name===`ruby`&&e.type===`call`&&i.endsWith(`=`)?1:Je(e),Ye(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,Ye(e,t,r))}}else nt(e,t)||$e(e,n)?c+=1:t.name===`ruby`&&rt(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 Je(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 Ye(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=Fn(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 Xe(i,n)||e?`self`:`other`}}return`other`}function Xe(e,t){return e.type===`this`||e.type===`self`||e.type===`identifier`&&(e.text===`self`||t!==void 0&&e.text===t)}const Ze=new Set([`static_cast`,`dynamic_cast`,`const_cast`,`reinterpret_cast`]);function Qe(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&&Ze.has(n)}function $e(e,t){if(t.size===0)return!1;if(e.type===`compound_literal_expression`)return t.has(O(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(O(e.parent?.childForFieldName(`type`))??``)}if((e.type===`identifier`||e.type===`array_declarator`)&&e.parent?.type===`declaration`&&X(e.parent,`declarator`).some(t=>t.id===e.id)&&!F(e.parent,`extern`)){let n=e;for(;n?.type===`array_declarator`;)n=n.childForFieldName(`declarator`);return n?.type===`identifier`&&t.has(O(e.parent.childForFieldName(`type`))??``)}if(e.type===`field_initializer`){let n=e.namedChild(0),r=n?.type===`field_identifier`?n.text:O(n);return t.has(r??``)}return!1}function O(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 et=new Set([`class_specifier`,`struct_specifier`,`union_specifier`]);function tt(e,t){let n=new Set;if(t.name!==`cpp`)return n;for(let t of A(e,et)){let e=t.childForFieldName(`name`)?.text;e&&t.childForFieldName(`body`)&&n.add(e)}return n}function nt(e,t){return t.name===`ruby`?e.type===`yield`||e.type===`super`&&e.parent?.type!==`call`:!1}function rt(e,t){return e.type!==`identifier`||it.has(e.text)||!at(e)?!1:!ut(e,t)}const it=new Set([`__FILE__`,`__LINE__`,`__ENCODING__`]);function at(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(ot.has(t.type)||(t.parent?.type===`in_clause`||t.parent?.type===`match_pattern`)&&t.parent.childForFieldName(`pattern`)?.id===t.id)return!1;if(lt.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 ot=new Set([`array_pattern`,`hash_pattern`,`find_pattern`,`keyword_pattern`,`as_pattern`,`alternative_pattern`]),st=new Set([`method`,`singleton_method`,`class`,`module`,`singleton_class`,`program`]),ct=new Set([`block`,`do_block`,`lambda`]),lt=new Set([...st,...ct]);function ut(e,t){let n=e.text;for(let r=dt(e.parent);r;r=st.has(r.type)?void 0:dt(r.parent)){let i=t.get(r.id);i||(i=ft(r),t.set(r.id,i));let a=i.get(n);if(a!==void 0&&a<e.startIndex)return!0}return!1}function dt(e){for(let t=e;t;t=t.parent)if(lt.has(t.type))return t}function ft(e){let t=new Map,n=(e,n)=>{let r=t.get(e);(r===void 0||n<r)&&t.set(e,n)};if(ht(e.childForFieldName(`parameters`),n),ct.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)lt.has(t.type)||(pt(t,n),r(t))}return r(e),t}function pt(e,t){switch(e.type){case`assignment`:k(e.childForFieldName(`left`),t);break;case`operator_assignment`:{let n=e.childForFieldName(`left`);n?.type===`identifier`&&t(n.text,n.startIndex);break}case`for`:k(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&&mt(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 k(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)k(n,t)}}function mt(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)mt(n,t)}function ht(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`)ht(n,t);else{let e=n.childForFieldName(`name`);e?.type===`identifier`&&t(e.text,e.startIndex)}}function gt(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 _t(e,t){return A(e,new Set(t.classNodeTypes)).filter(vt).length}function vt(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 A(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 yt(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===bt(e)?.id&&t.type!==`statement_block`&&!n.has(t.type))return j(t,n)||M(t,n);for(let e of t.namedChildren)if(r(e,!1))return!0;return!1}return r(e,!0)}function bt(e){return e.childForFieldName(`body`)??e.namedChild(e.namedChildCount-1)??void 0}function j(e,t){return xt(e,t,e=>e.type.startsWith(`jsx_`)||St(e,t))}function M(e,t){return xt(e,t,Rn)}function xt(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 St(e,t){return!V(e)||!Ct(e.childForFieldName(`function`)??e.namedChild(0))?!1:e.namedChildren.some(e=>wt(e,t))}function Ct(e){if(!e)return!1;let t=H(e);return t===`map`||t===`flatMap`}function wt(e,t){return t.has(e.type)?Tt(e,t):e.namedChildren.some(e=>wt(e,t))}function Tt(e,t){let n=e.type===`arrow_function`?bt(e):void 0;return n&&n.type!==`statement_block`&&!t.has(n.type)?j(n,t)||M(n,t):Et(e,t,e=>j(e,t)||M(e,t))}function Et(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 Dt(e,t){let n=new Set;function r(e){if(Bn(e,t))for(let r of Hn(e,t,{expandPythonSubmodules:!0}))n.add(r);for(let t of e.namedChildren)r(t)}return r(e),{declarations:Ot(e,t),importSources:[...n]}}function Ot(e,t){let n=qt(e),r=t.name===`java`?At(e):``;return e.namedChildren.flatMap(e=>N(e,!1,r,t.name)).map(e=>!e.exported&&(n.has(e.name)||kt(e,t))?{...e,exported:!0}:e)}function kt(e,t){return t.name===`go`&&fr(e.name.split(`.`).at(-1)??``)}function At(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 jt=new Set([`module`,`class`,`singleton_class`]);function N(e,t,n=``,r=``){let i=r===`cpp`;if(Wt(e))return e.namedChildren.flatMap(e=>N(e,!0,n,r));if(e.type===`namespace_definition`){let i=e.childForFieldName(`name`)?.text;return i?(e.childForFieldName(`body`)?.namedChildren??[]).flatMap(e=>N(e,t,`${n}${i}::`,r)):[]}return Gt(e)?e.namedChildren.flatMap(e=>N(e,t,n,r)):e.type===`declaration`?P(Bt(e,t,i),n):e.type===`type_definition`?P(Ft(e,t),n):jt.has(e.type)?Nt(e,t,n):e.type===`assignment`||e.type===`operator_assignment`?P(Pt(e,t),n,!0):P(I(e,t||r===`rust`&&Mt(e)),n)}function Mt(e){return e.namedChildren.some(e=>e.type===`visibility_modifier`&&e.namedChildCount===0)}function P(e,t,n=!1){return t?e.map(e=>n&&e.name.includes(`::`)?e:{...e,name:`${t}${e.name}`}):e}function Nt(e,t,n=``){let r=P(I(e,t),n,!0),i=r[0]?`${r[0].name}::`:n,a=e.childForFieldName(`body`);for(let e of a?.namedChildren??[])jt.has(e.type)?r.push(...Nt(e,t,i)):(e.type===`assignment`||e.type===`operator_assignment`)&&r.push(...P(Pt(e,t),i,!0));return r}function Pt(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 Ft(e,t){let n=e.childForFieldName(`type`),r=n?I(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 X(e,`declarator`)){let e=n.type===`type_identifier`?n.text:z(n);e&&e!==i&&!a.has(e)&&(a.add(e),r.push({exported:t,name:e,startLine:n.startPosition.row+1}))}return r}const It=new Set([`init_declarator`,`pointer_declarator`,`array_declarator`,`reference_declarator`,`identifier`,`field_identifier`]);function Lt(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=B(t);return t?.type!==`function_declarator`||t.childForFieldName(`declarator`)?.type===`parenthesized_declarator`}return It.has(e.type)?!0:e.type===`function_declarator`&&e.childForFieldName(`declarator`)?.type===`parenthesized_declarator`}function F(e,t){return e.children.some(e=>e.type===`storage_class_specifier`&&e.text===t)}function Rt(e){let t=e.childForFieldName(`type`);return t?.type!==`type_identifier`||t.text!==`import`&&t.text!==`export`&&t.text!==`module`?!1:!zt(e,t.text)}function zt(e,t){let n=e;for(;n.parent;)n=n.parent;return A(n,new Set([`type_definition`,`alias_declaration`])).some(e=>(e.childForFieldName(`declarator`)??e.childForFieldName(`name`))?.text===t)}function Bt(e,t,n=!1){if(n&&Rt(e)||F(e,`static`))return[];let r=e.childForFieldName(`type`),i=r?I(r,t):[],a=new Set(i.map(e=>e.name)),o=F(e,`extern`);for(let r of e.namedChildren.filter(Lt)){if(o&&r.type!==`init_declarator`||n&&!o&&!F(e,`inline`)&&!Vt(r)&&!R(e,r))continue;let s=z(r);s&&!a.has(s)&&(a.add(s),i.push({exported:t,name:s,startLine:r.startPosition.row+1}))}return i}function Vt(e){let t=e.type===`init_declarator`?e.childForFieldName(`declarator`)??e:e;for(;t;){if(t.type===`reference_declarator`)return!0;t=B(t)}return!1}function I(e,t){if(!Kt(e)||e.type.endsWith(`_specifier`)&&!e.childForFieldName(`body`)||F(e,`static`))return[];if(e.type===`enum_specifier`)return Ht(e,t);let n=Ut(e);return n?[{exported:t,name:n,startLine:e.startPosition.row+1}]:[]}function Ht(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 Ut(e){if(e.type===`method_declaration`&&e.childForFieldName(`receiver`))return Xt(e);let t=e.childForFieldName(`name`);return t?.type===`template_type`&&(t=t.childForFieldName(`name`)),t?.type===`scope_resolution`?t.text:t?L(t)?t.text:void 0:z(e.childForFieldName(`declarator`),!0)||e.namedChildren.find(L)?.text}function Wt(e){return e.type===`export_statement`||e.type===`export_declaration`}function Gt(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 Kt(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 L(e){return e.type===`identifier`||e.type===`type_identifier`||e.type===`property_identifier`||e.type===`field_identifier`||e.type===`constant`}function qt(e){let t=new Set;function n(e,r){if(!r&&Jt(e)){let n=Yt(e);n&&t.add(n)}let i=r||Wt(e)&&e.childForFieldName(`source`)!==null;for(let t of e.namedChildren)n(t,i)}return n(e,!1),t}function Jt(e){return e.type===`export_specifier`||e.type===`namespace_export`}function Yt(e){let t=e.childForFieldName(`name`)??e.childForFieldName(`alias`)??e.namedChildren.find(L);return t&&L(t)?t.text:void 0}function Xt(e){let t=e.childForFieldName(`name`),n=e.childForFieldName(`receiver`)?.namedChildren[0]?.childForFieldName(`type`);return!t||!L(t)||!n?t&&L(t)?t.text:void 0:`${Zt(n.text)}.${t.text}`}function Zt(e){return e.replaceAll(/\s+/gu,``).replace(/^\*+/u,``)}function Qt(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`)&&(zn(e)||Vn(e,t)||U(e,t)||W(e)||G(e,t))&&(r+=1),Bn(e,t))for(let r of Hn(e,t,{expandPythonSubmodules:!1}))n.add(r);nr(e,t)&&(i+=1),t.name===`go`&&(i+=lr(e));for(let t of e.namedChildren)a(t)}a(e);let o=[...n].filter(e=>Jn(e,t.name)).length;return{importCount:r,importSourceCount:n.size,relativeImportCount:o,externalImportCount:n.size-o,exportCount:i}}function $t(e,t){let n={assignmentCount:0,awaitExpressionCount:0,loopStatementCount:0,mutableBindingCount:0,returnStatementCount:0,throwStatementCount:0,tryStatementCount:0};function r(e){en(e)&&(n.assignmentCount+=1),tn(e)&&(n.awaitExpressionCount+=1),nn(e)&&(n.loopStatementCount+=1),n.mutableBindingCount+=rn(e,t),fn(e)&&(n.returnStatementCount+=1),pn(e)&&(n.throwStatementCount+=1),hn(e)&&(n.tryStatementCount+=1);for(let t of e.namedChildren)r(t)}return r(e),n}function en(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 tn(e){return e.type===`await_expression`||e.type===`await`||e.type===`co_await_expression`}function nn(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 rn(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 cn(e)?t.length:0}if(n&&(e.type===`declaration`||e.type===`field_declaration`))return an(e,t===`cpp`);if(n&&e.type===`function_definition`){let n=e.childForFieldName(`declarator`);return n?.type===`field_identifier`||n?.type===`identifier`?an(e,t===`cpp`):0}if(e.type===`enhanced_for_statement`)return+!!cn(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&&R(e,t)?on(t):0}return+!!sn(e)}function an(e,t){return t&&Rt(e)?0:$(e.namedChildren.filter(t=>Lt(t)&&R(e,t)).map(on))}function on(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 sn(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`&&dn(e)}function cn(e){return!e.namedChildren.find(e=>e.type===`modifiers`)?.children.some(e=>e.text===`final`)}function R(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=B(n);if(!e)break;if(n.type===`pointer_declarator`&&(r=!0,un(n)&&!ln(e)))return!1;n=e}return r||!un(e)}function ln(e){let t=e;for(;t;){if(t.type===`pointer_declarator`)return!0;t=B(t)}return!1}function un(e){return e.namedChildren.some(e=>e.type===`type_qualifier`&&(e.text===`const`||e.text===`constexpr`))}function dn(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 fn(e){return e.type===`return_statement`||e.type===`return_expression`||e.type===`return`||e.type===`co_return_statement`}function pn(e){return e.type===`throw_statement`||e.type===`raise_statement`||mn(e)}function mn(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 hn(e){return e.type===`try_statement`||e.type===`try_with_resources_statement`||e.type===`rescue_modifier`||gn(e)}function gn(e){return(e.type===`begin`||e.type===`body_statement`)&&e.namedChildren.some(e=>e.type===`rescue`||e.type===`ensure`)}function _n(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=_r(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 vn(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 yn(e,t){let n=e.length===0?[]:e.split(/\r\n|\n|\r/),r=new Map;for(let e of bn(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}xn(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 bn(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 xn(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 Sn(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(l.has(e.type)){yr(r,t.slice(e.startIndex,e.endIndex));return}if(e.childCount===0){let i=t.slice(e.startIndex,e.endIndex);c.has(e.type)?yr(r,i):(s.has(i)||s.has(e.type))&&Ln(e,i)&&yr(n,i||e.type);return}for(let t of e.children)i(t)}}return i(e),Cn({distinctOperators:n.size,distinctOperands:r.size,totalOperators:$(n.values()),totalOperands:$(r.values())})}function Cn(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 wn(e){let t=An(e);if(t)return t;let n=e.childForFieldName(`name`);if(n)return n.text;let r=Tn(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`?z(i.childForFieldName(`declarator`)):e.type===`func_literal`&&i.type===`expression_list`?On(e,i):e.type===`lambda`&&i.type===`assignment`?En(i):(e.type===`block`||e.type===`do_block`)&&Dn(i)?i.parent?.type===`assignment`?En(i.parent):void 0:i.childForFieldName(`name`)?.text}}function Tn(e){return z(e.childForFieldName(`declarator`))}function z(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=B(n)}}function B(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 En(e){let t=e.childForFieldName(`left`);return t?.type===`identifier`||t?.type===`constant`?t.text:void 0}function Dn(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 On(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 kn(e?.[r])}if(n.type===`var_spec`){let e=X(n,`name`)[r];return kn(e)}}}function kn(e){return e?.type===`identifier`&&e.text!==`_`?e.text:void 0}function An(e){let t=e;for(;t;){let e=t.parent,n=e?.parent;if(e?.type!==`arguments`||n?.type!==`call_expression`||!jn(n))return;let r=n.parent;if(r?.type===`variable_declarator`)return r.childForFieldName(`name`)?.text;t=n}}function jn(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 V(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 Mn(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 Nn=new Set([`arrow_function`,`function_expression`,`function`,`lambda`,`lambda_expression`,`closure_expression`,`func_literal`,`anonymous_function`]);function Pn(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=Mn(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=Fn(t);if(!Nn.has(n.type))return H(n)}function Fn(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 In=new Set([`ternary_expression`,`conditional_expression`,`conditional`,`try_expression`,`conditional_type`]);function Ln(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&&In.has(n)}function H(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 H(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 H(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=H(n);if(r)return r}}function Rn(e){if(!V(e))return!1;let t=e.childForFieldName(`function`)??e.namedChild(0);return t?.text===`React.createElement`||t?.text===`createElement`}function zn(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 Bn(e,t){return zn(e)||Vn(e,t)||U(e,t)||W(e)||G(e,t)||nr(e,t)&&e.childForFieldName(`source`)!==null}function U(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`?!zt(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 Vn(e,t){return t.name===`rust`&&e.type===`mod_item`&&!e.childForFieldName(`body`)}function W(e){return V(e)?(e.childForFieldName(`function`)??e.namedChild(0))?.text===`import`:!1}function Hn(e,t,n){if(t.name===`python`){let t=Qn(e,n);if(t.length>0)return t}if(t.name===`rust`)return Xn(e);if(t.name===`java`&&e.type===`requires_module_directive`){let t=e.childForFieldName(`module`);return t?[Z(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=Z(t.text);return[r&&!n?`${i}.*`:i]}if(U(e,t)){let t=/^(?:export\s+)?import\s+([\w.:]+|"[^"]+"|<[^>]+>)/u.exec(e.text)?.[1];return t?t.startsWith(`"`)?[`./${Q(t)}`]:[t]:[]}if(G(e,t))return Wn(e);if(e.type===`preproc_include`){let t=e.childForFieldName(`path`);if(!t)return[];let n=Q(t.text);return[t.type===`string_literal`&&!n.startsWith(`.`)&&!n.startsWith(`/`)?`./${n}`:n]}if(W(e))return qn(e);let r=e.childForFieldName(`source`)??er(e);return r?[Q(r.text)]:[]}const Un=new Set([`require`,`require_relative`,`load`]);function G(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&&Un.has(n.text)}function Wn(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`?Kn(e.text):e.text).join(``):Q(r.text);return e.childForFieldName(`method`)?.text===`require_relative`?[a.startsWith(`.`)?a:`./${a}`]:[a.replace(/^(?:\.\.?\/)+/u,``)]}const Gn=new Map([[`n`,`
2
- `],[`t`,` `],[`r`,`\r`],[`s`,` `],[`0`,`\0`]]);function Kn(e){let t=e.slice(1);return Gn.get(t)??t}function qn(e){let t=e.childForFieldName(`arguments`)?.namedChild(0);return t&&tr(t)?[Q(t.text)]:[]}function Jn(e,t){return e.startsWith(`.`)||e.startsWith(`/`)?!0:t===`rust`&&Yn(e)}function Yn(e){return/^(?:crate|self|super)(?:::|$)/u.test(e)}function Xn(e){if(e.type===`mod_item`){let t=e.childForFieldName(`name`);return t?[`self::${Z(t.text)}`]:[]}if(e.type===`extern_crate_declaration`){let t=e.childForFieldName(`name`);return t?[Z(t.text)]:[]}let t=e.childForFieldName(`argument`);return t?K(t,``):[]}function K(e,t){switch(e.type){case`use_list`:return e.namedChildren.flatMap(e=>K(e,t));case`scoped_use_list`:{let n=e.childForFieldName(`list`),r=q(t,Zn(e.childForFieldName(`path`)));return n?K(n,r):J(r)}case`scoped_identifier`:{let n=q(t,Z(e.text));return Yn(n)?J(n):J(q(t,Zn(e.childForFieldName(`path`))))}case`use_wildcard`:return J(q(t,Zn(e.namedChild(0))));case`use_as_clause`:{let n=e.childForFieldName(`path`);return n?K(n,t):[]}case`self`:return J(t);case`identifier`:case`crate`:case`super`:return e.type===`identifier`&&Yn(t)?J(q(t,Z(e.text))):J(t===``?Z(e.text):t);default:return[]}}function Zn(e){return e?Z(e.text):``}function q(e,t){return t?e?`${e}::${t}`:t:e}function J(e){return e?[e]:[]}function Qn(e,t){if(e.type===`import_from_statement`){let n=e.childForFieldName(`module_name`);if(!n)return[];let r=Z(n.text),i=X(e,`name`);if(!t.expandPythonSubmodules||!r.startsWith(`.`))return[r];if(/^\.+$/u.test(r)&&i.length>0)return i.flatMap(Y).map(e=>`${r}${e}`);let a=i.flatMap(Y).map(e=>`${r}.${e}`);return a.length>0?[r,...a]:[r]}return e.type===`import_statement`?e.namedChildren.map(e=>$n(e)).filter(e=>e!==void 0):[]}function Y(e){if(e.type===`aliased_import`){let t=e.childForFieldName(`name`);return t?Y(t):[]}return e.type===`identifier`?[e.text]:e.type===`dotted_name`?[Z(e.text)]:e.namedChildren.flatMap(Y)}function X(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 $n(e){if(e.type===`dotted_name`||e.type===`relative_import`)return Z(e.text);let t=e.childForFieldName(`name`);if(t)return Z(t.text);for(let t of e.namedChildren){let e=$n(t);if(e)return e}}function Z(e){return e.replaceAll(/\s+/gu,``)}function er(e){if(tr(e))return e;for(let t of e.namedChildren){let e=er(t);if(e)return e}}function tr(e){return e.type===`string`||e.type===`string_literal`||e.type===`interpreted_string_literal`}function Q(e){return e.replaceAll(/^['"`<]|['"`>]$/gu,``)}function nr(e,t){return t.name===`rust`?e.type===`visibility_modifier`&&ir(e):t.name===`go`?!1:e.type.startsWith(`export`)&&e.type!==`exports_module_directive`||e.type===`public_field_definition`}const rr=new Set([`struct_item`,`enum_item`,`union_item`,`trait_item`]);function ir(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`||rr.has(t.type))&&!Mt(t)||t.type===`impl_item`&&!ar(t))return!1;return!0}function ar(e){let t=cr(e.childForFieldName(`type`));if(t===void 0)return!0;let n=e;for(;n.parent;)n=n.parent;let r=sr(n,t);if(!r)return!0;let i=r.namedChildren.find(e=>e.type===`visibility_modifier`);return i!==void 0&&ir(i)}const or=new Set([...rr,`type_item`]);function sr(e,t){return A(e,or).find(e=>e.childForFieldName(`name`)?.text===t)}function cr(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 lr(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&&fr(t)&&dr(e)?1:0}return(e.type===`const_spec`||e.type===`var_spec`)&&dr(e)?X(e,`name`).filter(e=>fr(e.text)).length:0}const ur=new Set([`type_declaration`,`const_declaration`,`var_declaration`,`var_spec_list`]);function dr(e){let t=e.parent;for(;t&&ur.has(t.type);)t=t.parent;return t?.type===`source_file`}function fr(e){return/^\p{Lu}/u.test(e)}function pr(e){let t=new Set;for(let n of e.keys())mr(n,n,e,new Set)&&t.add(n);return t}function mr(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),mr(e,t,n,r)))return!0;return!1}function hr(e){let t=new Map,n=0;for(let r of e.keys())n=Math.max(n,gr(r,e,new Set,t).depth);return n}function gr(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=gr(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 _r(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 vr(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 yr(e,t){e.set(t,(e.get(t)??0)+1)}function br(e,t){return e.length===0?0:Math.max(...e.map(e=>e[t]))}function xr(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}exports.TreeMeasurer=u,exports.collectCrossFileDuplicationFileData=g,exports.collectDuplicationCandidates=h,exports.defaultMeasurer=p,exports.measureCode=m;
1
+ "use strict";const e=require("./_virtual/_rolldown/runtime.cjs"),t=require("./duplication.cjs"),n=require("./languages.cjs"),r=require("./depDegree.cjs"),i=require("./ncss.cjs"),a=require("./nativeMetrics.cjs");let o=require("tree-sitter");o=e.__toESM(o,1);const s=new Set([`&&`,`||`,`and`,`or`]),c=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(`,`)),l=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(`.`)),u=new Set([`interpreted_string_literal`,`regex`,`user_defined_literal`,`integral_type`,`floating_point_type`,`sized_type_specifier`,`placeholder_type_specifier`]);var d=class{registry=n.createLanguageRegistry();registerLanguage(e){ee(e),i.invalidateNcssSetsCache(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 o=p(n)?a.measureWithNativeBackend(e,r,n.includeSyntaxTree??!1):void 0;if(o)return y(o,n.includeSyntaxTree??!1);let s=f(e,r),c=b(s,H(s,new Set(r.functionNodeTypes)).filter(e=>!E(e)&&T(e)),r,e),l=ne(s,r),{lines:u,codeLineNumbers:d}=U(e,s);return{language:r.name,bytes:Buffer.byteLength(e),lines:u,functions:c,cognitiveComplexity:l.cognitiveComplexity,maxCognitiveComplexity:ve(c),nestingDepth:l.nestingDepth,ncssCount:i.countNcss(s,r),duplication:t.measureDuplication(s,d,n.duplication),halstead:W(s,e),syntaxTree:n.includeSyntaxTree?s.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 H(r,new Set(n.functionNodeTypes)).filter(e=>!E(e)&&T(e)).map(e=>le(e))}collectCrossFileDuplicationFileData(e,n){let{root:r}=this.parse(e,n);return{...t.collectCrossFileDuplicateCandidates(r,n.duplication),codeLineNumbers:U(e,r).codeLineNumbers}}parse(e,t){let n=this.registry.get(t.language);if(!n)throw Error(`Unsupported language: ${t.language}`);return{language:n,root:f(e,n)}}};function f(e,t){let n=new o.default;return n.setLanguage(t.parserLanguage),n.parse(e,void 0,{bufferSize:e.length+1}).rootNode}function p(e){let n=e.duplication;return(n?.minTokens??t.defaultDuplicationOptions.minTokens)===t.defaultDuplicationOptions.minTokens&&(n?.maxGapTokens??t.defaultDuplicationOptions.maxGapTokens)===t.defaultDuplicationOptions.maxGapTokens&&(n?.minSimilarityPercent??t.defaultDuplicationOptions.minSimilarityPercent)===t.defaultDuplicationOptions.minSimilarityPercent}const m=new d;function h(e,t){return m.measure(e,t)}function g(e,t){return m.collectDuplicationCandidates(e,t)}function _(e,t){return m.collectFunctionTokenSequences(e,t)}function v(e,t){return m.collectCrossFileDuplicationFileData(e,t)}function y(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:G(e.halsteadCounts),depDegree:e.depDegree})),cognitiveComplexity:e.cognitiveComplexity,maxCognitiveComplexity:e.maxCognitiveComplexity,nestingDepth:e.nestingDepth,ncssCount:e.ncssCount,duplication:e.duplication,halstead:G(e.halsteadCounts),syntaxTree:t?e.syntaxTree:void 0}}function b(e,t,n,i){let a=te(e,n),{functionNodes:o}=M(n);return t.map(e=>{let t=a.get(e.id);if(!t)throw Error(`missing body metrics for function node at line ${e.startPosition.row+1}`);return{name:ue(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:x(e),halstead:W(e,i),depDegree:r.measureDepDegree(e,e=>D(e,o))}})}function x(e){if(e.childForFieldName(`parameter`))return 1;let t=C(e);if(!t)return 0;if(t.type===`identifier`)return 1;let n=new Set(Z(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)||S(e)||(r+=e.type===`parameter_declaration`?Math.max(1,Z(e,`name`).length):1);let i=t.children.filter(e=>!e.isNamed&&e.text===`...`).length;return r+i}function S(e){return e.type===`parameter_declaration`&&e.childForFieldName(`declarator`)===null&&e.childForFieldName(`type`)?.text===`void`}function C(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=J(n)}return e.namedChildren.find(e=>e.type===`formal_parameters`||e.type===`parameter_list`)}const w=new Set([`function_definition`,`constructor_declaration`,`compact_constructor_declaration`,`function_signature_item`]);function T(e){return!w.has(e.type)||e.childForFieldName(`body`)!==null||e.namedChildren.some(e=>e.type===`try_statement`)}function E(e){return(e.type===`block`||e.type===`do_block`)&&e.parent?.type===`lambda`}function D(e,t){return t.has(e.type)&&!E(e)}const O=new Set([`switch_statement`,`switch_expression`,`expression_switch_statement`,`type_switch_statement`,`select_statement`,`match_expression`,`match_statement`,`case`,`case_match`]),k=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`]),A=new Set([`if_statement`,`if_expression`,`if`,`unless`]),j=new WeakMap;function ee(e){j.delete(e)}function M(e){let t=j.get(e);return t||(t={functionNodes:new Set(e.functionNodeTypes),decisionNodes:new Set(e.decisionNodeTypes),nestingNodes:new Set(e.nestingNodeTypes)},j.set(e,t)),t}function N(e,t){return{cognitiveComplexity:0,nestingSensitiveCount:0,nestingDepth:0,ncss:0,hasOwnNcssContribution:!1,entryCognitiveNesting:e,entryStructuralNesting:t}}function te(e,t){let{functionNodes:n,decisionNodes:r,nestingNodes:a}=M(t),{countable:o,containers:s}=i.getNcssSets(t),c=new Map,l=[N(0,0)];function u(e,t,d,f,p,m){let h=e.type===`class_body`&&f;h&&(p=!0,d+=1);let g=D(e,n);g&&(f&&!m&&(d+=1),f=!0);let _=l.at(-1),v=t+d-_.entryCognitiveNesting,y=!p&&!g,b=e.isNamed&&r.has(e.type)&&!B(e),x=e.isNamed&&k.has(e.type),S=e.isNamed&&(a.has(e.type)||e.type===`else`&&(e.parent?.type===`case`||e.parent?.type===`case_match`)),C=b&&z(e);b&&!x&&(C?_.cognitiveComplexity+=1:(_.cognitiveComplexity+=1+v,_.nestingSensitiveCount+=1)),e.isNamed&&O.has(e.type)&&(_.cognitiveComplexity+=1+v,_.nestingSensitiveCount+=1),_.cognitiveComplexity+=P(e),F(e)&&(_.cognitiveComplexity+=1),V(e)&&I(e)&&(_.cognitiveComplexity+=1),R(e)&&(_.cognitiveComplexity+=1);let w=S&&!C?t+1:t;y&&(_.nestingDepth=Math.max(_.nestingDepth,w-_.entryStructuralNesting)),g&&l.push(N(w+d,w));let T=i.ncssContribution(e,o,s),E=l.at(-1);E.ncss+=T,g&&T>0&&(E.hasOwnNcssContribution=!0);for(let t of e.children)u(t,w,d,f,!g&&p,h);if(g){let t=l.pop();c.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 u(e,0,0,!1,!1,!1),c}function ne(e,t){let n=0,r=0,{functionNodes:i,decisionNodes:a,nestingNodes:o}=M(t);function s(e,t,c,l,u){let d=e.type===`class_body`&&l;d&&(c+=1),D(e,i)&&(l&&!u&&(c+=1),l=!0);let f=t+c,p=e.isNamed&&a.has(e.type)&&!B(e),m=e.isNamed&&k.has(e.type),h=e.isNamed&&(o.has(e.type)||e.type===`else`&&(e.parent?.type===`case`||e.parent?.type===`case_match`)),g=p&&z(e);p&&!m&&(n+=g?1:1+f),e.isNamed&&O.has(e.type)&&(n+=1+f),n+=P(e),F(e)&&(n+=1),V(e)&&I(e)&&(n+=1),R(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 P(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=>A.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`&&!A.has(r.type)&&(t+=1)}return t}function F(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.commentNodeTypes.has(e.type)):!1}const re=new Set([`parenthesized_expression`,`parenthesized_statements`]);function I(e){let t=e.parent;if(!t)return!0;let n=t.parent;for(;n&&re.has(n.type);)n=n.parent;return!n||n.type!==t.type||L(ie(n))!==L(e.text)}function L(e){return e===`and`?`&&`:e===`or`?`||`:e}function ie(e){let t=e.childForFieldName(`operator`);return t?t.text:e.children.find(e=>!e.isNamed&&s.has(e.text))?.text}function R(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 z(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 B(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 ae=new Set([`binary_expression`,`binary`,`boolean_operator`]);function V(e){if(e.isNamed||!s.has(e.text))return!1;let t=e.parent;return t!==null&&ae.has(t.type)}function H(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 U(e,t){let n=e.length===0?[]:e.split(/\r\n|\n|\r/),r=new Map;for(let e of oe(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}se(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 oe(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 se(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 W(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(u.has(e.type)){Q(r,t.slice(e.startIndex,e.endIndex));return}if(e.childCount===0){let i=t.slice(e.startIndex,e.endIndex);l.has(e.type)?Q(r,i):(c.has(i)||c.has(e.type))&&_e(e,i)&&Q(n,i||e.type);return}for(let t of e.children)i(t)}}return i(e),G({distinctOperators:n.size,distinctOperands:r.size,totalOperators:$(n.values()),totalOperands:$(r.values())})}function G(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 ce=new Set([`identifier`,`property_identifier`,`field_identifier`,`type_identifier`,`constant`,`instance_variable`,`class_variable`,`global_variable`]);function le(e){let t=[];return K(e,t,new Map),Int32Array.from(t)}function K(e,n,r){if(e.type!==`comment`&&e.type!==`line_comment`&&e.type!==`block_comment`){if(u.has(e.type)){n.push(t.hashText(e.type));return}if(e.childCount>0){for(let t of e.children)K(t,n,r);return}if(ce.has(e.type)){let i=r.get(e.text);i===void 0&&(i=r.size,r.set(e.text,i)),n.push(t.hashText(`id${i}`));return}n.push(t.hashText(l.has(e.type)?e.type:e.text))}}function ue(e){let t=me(e);if(t)return t;let n=e.childForFieldName(`name`);if(n)return n.text;let r=de(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`?q(i.childForFieldName(`declarator`)):e.type===`func_literal`&&i.type===`expression_list`?pe(e,i):e.type===`lambda`&&i.type===`assignment`?Y(i):(e.type===`block`||e.type===`do_block`)&&fe(i)?i.parent?.type===`assignment`?Y(i.parent):void 0:i.childForFieldName(`name`)?.text}}function de(e){return q(e.childForFieldName(`declarator`))}function q(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=J(t)}}function J(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 Y(e){let t=e.childForFieldName(`left`);return t?.type===`identifier`||t?.type===`constant`?t.text:void 0}function fe(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 pe(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 X(e?.[r])}if(n.type===`var_spec`){let e=Z(n,`name`)[r];return X(e)}}}function X(e){return e?.type===`identifier`&&e.text!==`_`?e.text:void 0}function me(e){let t=e;for(;t;){let e=t.parent,n=e?.parent;if(e?.type!==`arguments`||n?.type!==`call_expression`||!he(n))return;let r=n.parent;if(r?.type===`variable_declarator`)return r.childForFieldName(`name`)?.text;t=n}}function he(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 ge=new Set([`ternary_expression`,`conditional_expression`,`conditional`,`try_expression`,`conditional_type`]);function _e(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&&ge.has(n)}function Z(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 Q(e,t){e.set(t,(e.get(t)??0)+1)}function ve(e){return e.length===0?0:Math.max(...e.map(e=>e.cognitiveComplexity))}function $(e){let t=0;for(let n of e)t+=n;return t}exports.TreeMeasurer=d,exports.collectCrossFileDuplicationFileData=v,exports.collectDuplicationCandidates=g,exports.collectFunctionTokenSequences=_,exports.defaultMeasurer=m,exports.measureCode=h;
3
2
  //# sourceMappingURL=metrics.cjs.map