@omfalos/mokosh 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +104 -56
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +104 -56
- package/dist/cli.mjs.map +1 -1
- package/dist/duplication-worker.d.mts +1 -1
- package/dist/duplication-worker.d.ts +1 -1
- package/dist/duplication-worker.js +6 -4
- package/dist/duplication-worker.js.map +1 -1
- package/dist/duplication-worker.mjs +6 -4
- package/dist/duplication-worker.mjs.map +1 -1
- package/dist/index.d.mts +1164 -48
- package/dist/index.d.ts +1164 -48
- package/dist/index.js +48 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -37
- package/dist/index.mjs.map +1 -1
- package/dist/mcp.js +52 -39
- package/dist/mcp.js.map +1 -1
- package/dist/mcp.mjs +52 -39
- package/dist/mcp.mjs.map +1 -1
- package/dist/parse-worker.d.mts +1 -1
- package/dist/parse-worker.d.ts +1 -1
- package/dist/parse-worker.js +6 -6
- package/dist/parse-worker.js.map +1 -1
- package/dist/parse-worker.mjs +6 -6
- package/dist/parse-worker.mjs.map +1 -1
- package/dist/{tokenizer-DIbb0GLe.d.mts → tokenizer-D9P-y7lH.d.mts} +1 -1
- package/dist/{tokenizer-DIbb0GLe.d.ts → tokenizer-D9P-y7lH.d.ts} +1 -1
- package/dist/{types-y90pqeDR.d.ts → types-B4jVIqMD.d.ts} +7 -0
- package/dist/{types-C153Tz5u.d.mts → types-qfwcXiZS.d.mts} +7 -0
- package/package.json +1 -1
- package/templates/skill/SKILL.md +1 -1
- package/templates/skill/mokosh.md +1 -1
package/dist/parse-worker.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var se=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import
|
|
2
|
-
`&&r++;return r}function
|
|
3
|
-
`)){let i
|
|
4
|
-
`),
|
|
5
|
-
`),n=[],o=new Set;for(let l of i){let p=l.match(Ve);if(p?.[1]){n.push(z(t,p[1]));continue}let f=l.match(Je);if(f?.[2]){o.add(f[2]);continue}let u=l.match(qe);if(u?.[1]){o.add(u[1]);continue}let d=l.match(Ze);d?.[1]&&o.add(d[1])}let a=P(e,!1);a&&n.push(T(t,a));let c=Array.from(o,l=>({name:l}));return{imports:n,exports:c,tags:Array.from(r).map(l=>({name:l,kind:"comment-marker"})),category:w(t,n.map(l=>l.rawSpecifier),{typeNames:[...o],annotations:W(e).annotations})}}import Ge from"livescript";function L(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function He(t){if(!t)return[];if(t.constructor?.name==="Class"){let r=L(t.title);return r?[{name:r}]:[]}if(t.constructor?.name==="Obj"&&Array.isArray(t.items))return t.items.map(r=>L(r.key)??L(r.val)).filter(r=>!!r).map(r=>({name:r}));let e=L(t);return e?[{name:e}]:[]}function Ue(t){let e=t.constructor?.name||t.type;if(e==="Assign"&&t.left?.constructor?.name==="Chain"){let r=t.left,s=L(r.head),n=r.tails?.[0]?.key?.name;if(s==="module"&&n==="exports")return He(t.right);if(s==="exports"&&typeof n=="string")return[{name:n}];if(r.head?.verb==="out"&&typeof n=="string")return[{name:n}]}if(e==="Import"&&t.left?.verb==="out"){let r=t.right;if(r?.constructor?.name==="Obj"&&Array.isArray(r.items))return r.items.map(s=>L(s.val)??L(s.key)).filter(s=>!!s).map(s=>({name:s}))}return[]}var Qe=new Set(["first_line","first_column","last_line","last_column","line","column"]);function Xe(t,e){let r=t.constructor?.name||t.type;if(r==="Import"){let s=t.right?.value;if(typeof s=="string"){let i=k(s);return{fromPath:e,toPath:"",rawSpecifier:i,isStyle:N(i),type:"static"}}}if(r==="Chain"&&t.head?.value==="require"){let s=t.tails?.[0];if(s?.constructor?.name==="Call"||s?.type==="Call"){let i=s.args?.[0]?.value;if(typeof i=="string"){let n=k(i);return{fromPath:e,toPath:"",rawSpecifier:n,isStyle:N(n),type:"require"}}}}return null}function nt(t,e,r){if(!t||typeof t!="object")return[];let s=[],i=Xe(t,e);i&&s.push(i),r.push(...Ue(t));for(let n in t){if(Qe.has(n))continue;let o=t[n];if(!(!o||typeof o!="object"))if(Array.isArray(o))for(let a of o)s.push(...nt(a,e,r));else s.push(...nt(o,e,r))}return s}function Dt(t,e){let r=O(e),s=B(t,r),i=[],n=[];try{i=nt(Ge.ast(e),t,n)}catch{}let o=new Set,a=n.filter(c=>o.has(c.name)?!1:(o.add(c.name),!0));return{imports:i,exports:a,tags:Array.from(r).map(c=>({name:c,kind:"comment-marker"})),category:s}}import Ye from"luaparse";function tr(t,e){let r=[];function s(i){if(!(!i||typeof i!="object")){if((i.type==="CallExpression"||i.type==="StringCallExpression")&&i.base?.type==="Identifier"&&i.base?.name==="require"){let n;if(i.type==="CallExpression"){let o=i.arguments?.[0];o?.type==="StringLiteral"&&(n=k(o.raw))}else if(i.type==="StringCallExpression"){let o=i.argument;o?.type==="StringLiteral"&&(n=k(o.raw))}n&&r.push({fromPath:e,toPath:"",rawSpecifier:n,isStyle:N(n),type:"require"})}for(let n in i){if(n==="loc")continue;let o=i[n];if(o&&typeof o=="object")if(Array.isArray(o))for(let a of o)s(a);else s(o)}}}return s(t),r}function er(t){let e=new Set;for(let r of t)r.type==="LocalStatement"&&r.variables.forEach((s,i)=>{r.init[i]?.type==="TableConstructorExpression"&&e.add(s.name)});return e}function rr(t){let e=t[t.length-1];if(e?.type!=="ReturnStatement")return[];let r=e.arguments[0];if(r?.type!=="TableConstructorExpression")return[];let s=[];for(let i of r.fields)i.type==="TableKeyString"&&s.push({name:i.key.name});return s}function ir(t){let e=t.body,r=er(e),s=rr(e);for(let n of e)if(n.type==="FunctionDeclaration")n.identifier?.type==="MemberExpression"?n.identifier.base.type==="Identifier"&&r.has(n.identifier.base.name)&&s.push({name:n.identifier.identifier.name}):n.identifier?.type==="Identifier"&&!n.isLocal&&s.push({name:n.identifier.name});else if(n.type==="AssignmentStatement")for(let o of n.variables)o.type==="MemberExpression"&&o.base.type==="Identifier"&&r.has(o.base.name)&&s.push({name:o.identifier.name});let i=new Set;return s.filter(n=>i.has(n.name)?!1:(i.add(n.name),!0))}function At(t,e){let r=O(e),s=B(t,r),i=[],n=[];try{let o=Ye.parse(e);i=tr(o,t),n=ir(o)}catch{}return{imports:i,exports:n,tags:Array.from(r).map(o=>({name:o,kind:"comment-marker"})),category:s}}var sr=["http://","https://","mailto:","//"],nr="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",or=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${nr})\\b`,"g"),Lt;async function ar(){return Lt??=(async()=>{let{unified:t}=await import("unified"),e=(await import("remark-parse")).default;return t().use(e)})(),Lt}function cr(t){let e=t.trim();return e.length===0||e.startsWith("#")||sr.some(r=>e.startsWith(r))}function lr(t,e){let r=t.match(or);return r?r.map(s=>({fromPath:e,toPath:"",rawSpecifier:s,isStyle:!1,type:"static"})):[]}function Rt(t,e,r){if(t.type==="link"&&typeof t.url=="string"&&!cr(t.url)&&r.push({fromPath:e,toPath:"",rawSpecifier:t.url,isStyle:!1,type:"static"}),(t.type==="code"||t.type==="inlineCode")&&typeof t.value=="string"&&r.push(...lr(t.value,e)),Array.isArray(t.children))for(let s of t.children)Rt(s,e,r)}async function Mt(t,e){let s=(await ar()).parse(e),i=[];Rt(s,t,i);let n=new Set;return{imports:i.filter(a=>n.has(a.rawSpecifier)?!1:(n.add(a.rawSpecifier),!0)),exports:[],tags:[],category:"other"}}import dr from"path";import{parser as yr}from"@lezer/python";function mr(t){let e=1;function r(s){switch(s.type.name){case"IfStatement":{e+=D(s).filter(n=>n.type.name==="if"||n.type.name==="elif").length;break}case"TryStatement":{e+=D(s).filter(n=>n.type.name==="except").length;break}case"ForStatement":case"WhileStatement":case"ConditionalExpression":e++;break;case"and":case"or":e++;break}let i=s.firstChild;for(;i;)r(i),i=i.nextSibling}return r(t),e}function pr(t,e){let r=0,s=D(t),i=0,n=0;for(;n<s.length;){let o=s[n];if(o?.type.name==="if"||o?.type.name==="elif"){let a=i>0;r+=a?1:1+e;let c=a?e:e+1,l=s[n+1],p=s[n+2];l&&(r+=v(l,c)),p&&(r+=v(p,c)),i++,n+=3}else if(o?.type.name==="else"){r+=1;let a=s[n+1];a&&(r+=v(a,e+1)),n+=2}else n++}return r}function fr(t,e){let r=0,s=D(t),i=0;for(;i<s.length;){let n=s[i];if(n?.type.name==="except"){for(r+=1+e,i++;i<s.length&&s[i]?.type.name!=="Body";)r+=v(s[i],e),i++;i<s.length&&(r+=v(s[i],e),i++)}else n?.type.name==="Body"&&(r+=v(n,e)),i++}return r}function _t(t,e){let r=1+e,s=t.firstChild;for(;s;)r+=v(s,e+1),s=s.nextSibling;return r}function ur(t,e){let r=0,s=t.firstChild;for(;s;)r+=v(s,e),s=s.nextSibling;return r}function v(t,e){let r=t.type.name;switch(r){case"IfStatement":return pr(t,e);case"TryStatement":return fr(t,e);case"ForStatement":case"WhileStatement":return _t(t,e);default:{let s=r==="ConditionalExpression"||r==="and"||r==="or"?1:0;return e>0&&(r==="FunctionDefinition"||r==="LambdaExpression")?s+_t(t,e):s+ur(t,e)}}}function gr(t){return v(t,0)}function ot(t){return{complexity:mr(t),cognitiveComplexity:gr(t)}}function Ot(t,e){let r=[];function s(o,a){let{complexity:c,cognitiveComplexity:l}=ot(o);r.push({name:a,line:A(e,o.from),complexity:c,cognitiveComplexity:l})}function i(o){let a=o.firstChild;for(;a;)n(a),a=a.nextSibling}function n(o){if(o.type.name==="ClassDefinition"){let a=o.getChild("VariableName"),c=a?e.slice(a.from,a.to):void 0,l=o.getChild("Body");if(l){let p=l.firstChild;for(;p;){if(p.type.name==="FunctionDefinition"){let f=p.getChild("VariableName"),u=f?e.slice(f.from,f.to):void 0;u&&s(p,c?`${c}.${u}`:u),i(p)}else n(p);p=p.nextSibling}}return}if(o.type.name==="FunctionDefinition"){let a=o.getChild("VariableName");a&&s(o,e.slice(a.from,a.to)),i(o);return}i(o)}return n(t.topNode),r}var xr=new Set(["pytest","unittest","nose","hypothesis"]);function Bt(t,e){let r=[],s=[],i=new Set,n=dr.basename(t).toLowerCase(),o=yr.parse(e),a=o.cursor();do switch(a.name){case"Comment":{let d=e.slice(a.from,a.to).match(/#\s*@tag\s+([a-zA-Z0-9_-]+)/);d?.[1]&&i.add(d[1]);break}case"ImportStatement":{for(let d of hr(a.node,e,t))r.push(d);break}case"FunctionDefinition":case"ClassDefinition":{let d=a.node.parent;if(d?.name==="Script"||d?.name==="DecoratedStatement"&&d.parent?.name==="Script"){let C=a.node.getChild("VariableName");C&&s.push({name:e.slice(C.from,C.to)})}break}case"AssignStatement":{if(a.node.parent?.name==="Script"){let d=a.node.firstChild;d?.name==="VariableName"&&s.push({name:e.slice(d.from,d.to)})}break}}while(a.next());let c=wr(n,r,i);c==="test"&&i.add("test");let{complexity:l,cognitiveComplexity:p}=ot(o.topNode),f=Ot(o,e),u=c==="test"?[]:Er(o,e);return{imports:r,exports:s,tags:Array.from(i).map(d=>({name:d,kind:"comment-marker"})),category:c,rawCallEdges:u,complexity:l,cognitiveComplexity:p,...f.length>0?{functions:f}:{}}}function hr(t,e,r){let s=t.firstChild;return s?s.name==="from"?Sr(t,e,r):Cr(t,e,r):[]}function Sr(t,e,r){let s=t.firstChild;if(!s)return[];let i=s.nextSibling;for(;i&&i.name!=="import";)i=i.nextSibling;if(!i)return[];let n=e.slice(s.to,i.from).trim(),o=br(i.nextSibling,e);if(!o.length)return[];let a=0;for(;a<n.length&&n[a]===".";)a++;let c=n.slice(a);if(a===0)return[q(r,n,o,!0)];let l=a===1?"./":"../".repeat(a-1);return c?[q(r,l+c.replace(/\./g,"/"),o,!1)]:o[0]==="*"?[q(r,l.slice(0,-1),["*"],!1)]:o.map(p=>q(r,l+p,[p],!1))}function Cr(t,e,r){let s=[],i=t.firstChild?.nextSibling??null;for(;i;){if(i.name==="VariableName"){let n=e.slice(i.from,i.to);for(;i.nextSibling?.name==="."&&i.nextSibling.nextSibling?.name==="VariableName";)i=i.nextSibling.nextSibling,n+=`.${e.slice(i.from,i.to)}`;i.nextSibling?.name==="as"&&(i=i.nextSibling.nextSibling??i.nextSibling),s.push(q(r,n,["*"],!0))}i=i.nextSibling}return s}function br(t,e){let r=[],s=t;for(;s;)s.name==="*"?r.push("*"):s.name==="VariableName"&&(r.push(e.slice(s.from,s.to)),s.nextSibling?.name==="as"&&(s=s.nextSibling.nextSibling??s.nextSibling)),s=s.nextSibling;return r}function Nr(t,e){let r=new Map,s=t.cursor();do{if(s.name!=="ImportStatement")continue;let n=s.node.firstChild;if(n?.type.name!=="from")continue;let o=n.nextSibling;for(;o&&o.type.name!=="import";)o=o.nextSibling;if(!o)continue;let a=e.slice(n.to,o.from).trim(),c=0;for(;c<a.length&&a[c]===".";)c++;let l=a.slice(c),p=c<=1?"./":"../".repeat(c-1),f=o.nextSibling;for(;f;){if(f.type.name==="VariableName"){let u=e.slice(f.from,f.to),d=u;if(f.nextSibling?.type.name==="as"){let C=f.nextSibling.nextSibling;C?.type.name==="VariableName"&&(d=e.slice(C.from,C.to),f=C)}let h=c===0?a:l?p+l.replace(/\./g,"/"):p+u;r.set(d,h)}f=f.nextSibling}}while(s.next());return r}function Er(t,e){let r=Nr(t,e),s=[];function i(a,c){if(a.type.name==="CallExpression"&&a.firstChild?.type.name==="VariableName"){let p=a.firstChild,f=e.slice(p.from,p.to),u=r.get(f);u&&s.push({from:c,to:f,toSpecifier:u})}let l=a.firstChild;for(;l;)i(l,c),l=l.nextSibling}function n(a){let c=a.firstChild;for(;c;)o(c),c=c.nextSibling}function o(a){if(a.type.name==="ClassDefinition"){let c=a.getChild("VariableName"),l=c?e.slice(c.from,c.to):void 0,p=a.getChild("Body");if(p){let f=p.firstChild;for(;f;){if(f.type.name==="FunctionDefinition"){let u=f.getChild("VariableName"),d=u?e.slice(u.from,u.to):void 0;d&&i(f,l?`${l}.${d}`:d)}else o(f);f=f.nextSibling}}return}if(a.type.name==="FunctionDefinition"){let c=a.getChild("VariableName");c&&i(a,e.slice(c.from,c.to));return}n(a)}return o(t.topNode),s}function q(t,e,r,s){return{fromPath:t,toPath:"",rawSpecifier:e,isStyle:!1,isExternal:s,type:"static",symbols:r.length>0?r:void 0}}function wr(t,e,r){return t.startsWith("test_")||t.endsWith("_test.py")?"test":t==="conftest.py"||t==="setup.py"?"config":r.has("test")||e.some(s=>xr.has(s.rawSpecifier))?"test":"logic"}var vr=/^\s*import\s+(.+?)\s*$/,kr=/^(?:@\w+\s+)*(?:private\s+|protected\s+|final\s+|sealed\s+|abstract\s+|implicit\s+|case\s+)*(class|trait|object|type|enum)\s+([A-Za-z_$][A-Za-z0-9_$]*)/;function Ir(t,e){let r=e.split("=>")[0]?.trim();return r?r==="_"||r==="*"||r==="given"?`${t}.*`:`${t}.${r}`:null}function Tr(t){let e=t.indexOf("{");if(e!==-1){let s=t.indexOf("}",e),i=t.slice(0,e).trim().replace(/\.$/,""),n=t.slice(e+1,s===-1?void 0:s);return i?n.split(",").map(o=>Ir(i,o.trim())).filter(o=>o!=null):[]}let r=[];for(let s of t.split(",")){let i=s.trim().replace(/\s+as\s+\w+$/,"");if(i)if(i.endsWith("._")||i.endsWith(".*")||i.endsWith(".given")){let n=i.replace(/\.(_|\*|given)$/,"");n&&r.push(`${n}.*`)}else r.push(i)}return r}function $t(t,e){let r=j(e),i=I(e).split(`
|
|
6
|
-
`),n=[],o=new Set;for(let l of i){let p=l.match(vr);if(p?.[1]){for(let u of Tr(p[1]))n.push(z(t,u));continue}let f=l.match(kr);f?.[2]&&o.add(f[2])}let a=P(e,!0);a&&n.push(T(t,a));let c=Array.from(o,l=>({name:l}));return{imports:n,exports:c,tags:Array.from(r).map(l=>({name:l,kind:"comment-marker"})),category:w(t,n.map(l=>l.rawSpecifier),{typeNames:[...o],annotations:W(e).annotations})}}import Vt from"path";import m from"typescript";var Pr=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],Fr=[];function jt(t){return[...Pr,...Fr].some(e=>typeof e=="string"?t.includes(e):e instanceof RegExp?e.test(t):e(t))}var Dr=[".test.",".spec.","-test.","-spec."],Ar=[];function at(){return[...Dr,...Ar]}var Lr=["jest","vitest","playwright","cypress","@testing-library/"],Rr=[];function ct(){return[...Lr,...Rr]}var Mr=.8,_r=Mr;function lt(){return _r}import g from"typescript";function Or(t){let e=1;function r(s){switch(s.kind){case g.SyntaxKind.IfStatement:case g.SyntaxKind.ConditionalExpression:case g.SyntaxKind.ForStatement:case g.SyntaxKind.ForInStatement:case g.SyntaxKind.ForOfStatement:case g.SyntaxKind.WhileStatement:case g.SyntaxKind.DoStatement:case g.SyntaxKind.CatchClause:case g.SyntaxKind.CaseClause:e++;break;case g.SyntaxKind.BinaryExpression:{let i=s.operatorToken.kind;(i===g.SyntaxKind.AmpersandAmpersandToken||i===g.SyntaxKind.BarBarToken||i===g.SyntaxKind.QuestionQuestionToken)&&e++;break}}g.forEachChild(s,r)}return r(t),e}function zt(t,e,r){let s=r?1:1+e,i=r?e:e+1;return s+=R(t.expression,i,!1),s+=R(t.thenStatement,i,!1),t.elseStatement&&(g.isIfStatement(t.elseStatement)?s+=zt(t.elseStatement,e,!0):s+=1+R(t.elseStatement,e+1,!1)),s}function Wt(t,e){let r=1+e;return g.forEachChild(t,s=>{r+=R(s,e+1,!1)}),r}function Br(t,e){let r=1+e;return g.forEachChild(t,s=>{r+=R(s,e,!1)}),r}function $r(t,e){let r=0;return g.forEachChild(t,s=>{r+=R(s,e,!1)}),r}function jr(t){let e=t.operatorToken.kind;return e===g.SyntaxKind.AmpersandAmpersandToken||e===g.SyntaxKind.BarBarToken||e===g.SyntaxKind.QuestionQuestionToken}function R(t,e,r){if(g.isIfStatement(t))return zt(t,e,r);if(g.isForStatement(t)||g.isForInStatement(t)||g.isForOfStatement(t)||g.isWhileStatement(t)||g.isDoStatement(t)||g.isSwitchStatement(t))return Wt(t,e);if(g.isCatchClause(t))return Br(t,e);let s=0;return g.isConditionalExpression(t)&&(s+=1),g.isBinaryExpression(t)&&jr(t)&&(s+=1),e>0&&(g.isFunctionDeclaration(t)||g.isFunctionExpression(t)||g.isArrowFunction(t))?s+Wt(t,e):s+$r(t,e)}function Wr(t){return R(t,0,!1)}function mt(t){return{complexity:Or(t),cognitiveComplexity:Wr(t)}}import S from"typescript";var pt=new Set(["test","describe","it"]);function Kt(t,e){zr(t,e),Vr(t,e),Jr(t,e),qr(t,e)}function zr(t,e){if((S.isFunctionDeclaration(t)||S.isVariableDeclaration(t))&&t.name&&S.isIdentifier(t.name)&&Kr(t)){let r;if(S.isFunctionDeclaration(t))r="function";else{let s=t.initializer;r=s&&(S.isArrowFunction(s)||S.isFunctionExpression(s))?"function":"variable"}e.tags.add({name:t.name.text,kind:r})}}function Kr(t){if(S.isFunctionDeclaration(t))return S.isSourceFile(t.parent);let e=t.parent?.parent;return!!e&&S.isSourceFile(e.parent)}function Vr(t,e){if(!S.isStringLiteral(t))return;let r=t.text.match(/@[\w-]+/g);if(r)for(let s of r)e.tags.add({name:s.substring(1),kind:"comment-marker"})}function Jr(t,e){if(!S.isSourceFile(t))return;let r=/@tag\s+([a-zA-Z0-9_-]+)/g,s=t.getFullText(),i=r.exec(s);for(;i!==null;)i[1]&&e.tags.add({name:i[1],kind:"comment-marker"}),i=r.exec(s)}function qr(t,e){if(S.isCallExpression(t)&&Zr(t.expression))for(let r of t.arguments)S.isObjectLiteralExpression(r)&&Gr(r,e)}function Zr(t){return S.isIdentifier(t)?pt.has(t.text):!!(S.isPropertyAccessExpression(t)&&(pt.has(t.name.text)||S.isIdentifier(t.expression)&&pt.has(t.expression.text)))}function Gr(t,e){for(let r of t.properties){if(!S.isPropertyAssignment(r)||!S.isIdentifier(r.name)||r.name.text!=="tags"&&r.name.text!=="tag")continue;let{initializer:s}=r,i=S.isArrayLiteralExpression(s)?s.elements.filter(S.isStringLiteral):r.name.text==="tag"&&S.isStringLiteral(s)?[s]:[];for(let n of i)e.tags.add({name:n.text.replace(/^@/,""),kind:"comment-marker"})}}function ft(t,e,r){let s=[],i=new Map,n=new Set,o=m.createSourceFile(t,e,m.ScriptTarget.Latest,!0,r==="typescript"?m.ScriptKind.TSX:m.ScriptKind.JSX),a={filePath:t,imports:s,exports:i,tags:n,rawCallEdges:[],sourceFile:o,hasUI:!1,hasTypesOnly:!0,totalStatements:0,exportStatements:0},c=C=>{Xr(C,a),m.forEachChild(C,c)};c(o);let l=li(t,a);(l==="test"||l==="barrel")&&n.add({name:l,kind:"comment-marker"}),l!=="test"&&mi(a,o);let p=o.statements[0],f=p?qt(p):void 0,{complexity:u,cognitiveComplexity:d}=mt(o),h=Hr(o);return{imports:s,exports:Array.from(i.values()),tags:Array.from(n),category:l,rawCallEdges:a.rawCallEdges??[],complexity:u,cognitiveComplexity:d,...h.length>0?{functions:h}:{},...f!==void 0?{description:f}:{}}}function Hr(t){let e=[],r=(i,n)=>{let{complexity:o,cognitiveComplexity:a}=mt(n),c=t.getLineAndCharacterOfPosition(n.getStart(t)).line+1;e.push({name:i,line:c,complexity:o,cognitiveComplexity:a})},s=(i,n)=>{if(m.isFunctionDeclaration(i)&&i.name&&i.body?r(i.name.text,i):m.isVariableDeclaration(i)&&m.isIdentifier(i.name)&&i.initializer&&(m.isArrowFunction(i.initializer)||m.isFunctionExpression(i.initializer))?r(i.name.text,i.initializer):n&&m.isMethodDeclaration(i)&&m.isIdentifier(i.name)&&i.body?r(`${n}.${i.name.text}`,i):n&&m.isConstructorDeclaration(i)&&i.body?r(`${n}.constructor`,i):n&&m.isGetAccessorDeclaration(i)&&m.isIdentifier(i.name)&&i.body?r(`${n}.get ${i.name.text}`,i):n&&m.isSetAccessorDeclaration(i)&&m.isIdentifier(i.name)&&i.body&&r(`${n}.set ${i.name.text}`,i),m.isClassDeclaration(i)&&i.name){let o=i.name.text;m.forEachChild(i,a=>s(a,o));return}m.forEachChild(i,o=>s(o,n))};return s(t,void 0),e}function Jt(t,e,r,s){let i={name:t},n=qt(r);n!==void 0&&(i.doc=n);let o=Ur(e);o!==void 0&&(i.flags=o);let a=Qr(e,s);return a!==void 0&&(i.signature=a),i}function qt(t){let e=m.getJSDocCommentsAndTags(t);for(let r of e)if(m.isJSDoc(r)&&r.comment)return m.getTextOfJSDocComment(r.comment)||void 0}function Ur(t){let e=new Set(["deprecated","internal","public","alpha","beta"]),r=m.getJSDocTags(t).map(s=>s.tagName.text).filter(s=>e.has(s));return r.length>0?r:void 0}function Qr(t,e){let r=m.createPrinter({removeComments:!0}),s=i=>r.printNode(m.EmitHint.Unspecified,i,e);if(m.isFunctionDeclaration(t)||m.isMethodDeclaration(t)){let i=t.parameters.map(s).join(", "),n=t.type?s(t.type):"void";return`${t.typeParameters?`<${t.typeParameters.map(a=>a.name.text).join(", ")}>`:""}(${i}) => ${n}`}if(m.isVariableDeclaration(t)){if(t.type)return s(t.type);if(t.initializer&&(m.isArrowFunction(t.initializer)||m.isFunctionExpression(t.initializer))){let i=t.initializer,n=i.parameters.map(s).join(", "),o=i.type?s(i.type):"unknown";return`(${n}) => ${o}`}return}if(m.isClassDeclaration(t)&&t.name)return`class ${t.name.text}`;if(m.isInterfaceDeclaration(t))return`interface ${t.name.text}`;if(m.isTypeAliasDeclaration(t))return s(t.type);if(m.isEnumDeclaration(t))return`enum ${t.name.text}`}function Xr(t,e){Yr(t,e),ti(t,e),ri(t,e),ii(t,e),ci(t,e),Kt(t,e)}function Yr(t,e){if(!m.isSourceFile(t))return;let r=t.statements.filter(s=>!m.isEmptyStatement(s));e.totalStatements=r.length,e.exportStatements=r.filter(s=>m.isExportDeclaration(s)||m.isExportAssignment(s)||ut(s)).length}function ti(t,e){if(m.isJsxElement(t)||m.isJsxSelfClosingElement(t)||m.isJsxFragment(t)){e.hasUI=!0,e.hasTypesOnly=!1;return}if(m.isFunctionDeclaration(t)||m.isMethodDeclaration(t)||m.isArrowFunction(t)||m.isClassDeclaration(t)||m.isVariableStatement(t)||m.isEnumDeclaration(t)){e.hasTypesOnly=!1;return}m.isExportDeclaration(t)&&!ei(t)&&(e.hasTypesOnly=!1)}function ei(t){return t.isTypeOnly?!0:!t.exportClause||!m.isNamedExports(t.exportClause)?!1:t.exportClause.elements.every(e=>e.isTypeOnly)}function ri(t,e){if(!m.isImportDeclaration(t)||!t.moduleSpecifier||!m.isStringLiteral(t.moduleSpecifier))return;let r=[];if(t.importClause&&(t.importClause.name&&r.push("default"),t.importClause.namedBindings))if(m.isNamedImports(t.importClause.namedBindings))for(let i of t.importClause.namedBindings.elements)r.push(i.name.text);else m.isNamespaceImport(t.importClause.namedBindings)&&r.push("*");let s=r.length>0?"static":"side-effect";e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:t.moduleSpecifier.text,isStyle:N(t.moduleSpecifier.text),type:s,symbols:r.length>0?r:void 0})}function ii(t,e){m.isExportDeclaration(t)?si(t,e):m.isExportAssignment(t)?e.exports.set("default",{name:"default"}):ut(t)&&ai(t,e)}function si(t,e){if(t.moduleSpecifier&&m.isStringLiteral(t.moduleSpecifier))ni(t,t.moduleSpecifier.text,e);else if(t.exportClause&&m.isNamedExports(t.exportClause))for(let r of t.exportClause.elements){let s=r.name.text;e.exports.set(s,{name:s})}}function ni(t,e,r){let s=oi(t),i={fromPath:r.filePath,toPath:"",rawSpecifier:e,isStyle:N(e),type:"re-export"};s.length>0&&(i.symbols=s),r.imports.push(i)}function oi(t){return t.exportClause?m.isNamedExports(t.exportClause)?t.exportClause.elements.map(e=>e.name.text):[]:["*"]}function ai(t,e){if((m.isFunctionDeclaration(t)||m.isClassDeclaration(t)||m.isInterfaceDeclaration(t)||m.isTypeAliasDeclaration(t)||m.isEnumDeclaration(t))&&t.name){let s=t.name.text;e.exports.set(s,Jt(s,t,t,e.sourceFile));return}if(m.isVariableStatement(t)){for(let s of t.declarationList.declarations)if(m.isIdentifier(s.name)){let i=s.name.text;e.exports.set(i,Jt(i,s,t,e.sourceFile))}}}function ci(t,e){if(!m.isCallExpression(t))return;let r=t.arguments[0];!r||!m.isStringLiteral(r)||(t.expression.kind===m.SyntaxKind.ImportKeyword?e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:N(r.text),type:"dynamic"}):m.isIdentifier(t.expression)&&t.expression.text==="require"&&e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:N(r.text),type:"require"}))}function li(t,e){let r=Vt.basename(t).toLowerCase(),s=Vt.extname(t).toLowerCase();return at().some(n=>r.includes(n))?"test":jt(r)?"config":e.imports.some(n=>ct().some(o=>n.rawSpecifier.includes(o)))?"test":s===".tsx"||s===".jsx"||e.hasUI?"ui":e.hasTypesOnly&&e.totalStatements>0?"type-only":e.totalStatements>0&&e.exportStatements/e.totalStatements>lt()?"barrel":"logic"}function ut(t){return m.canHaveModifiers(t)&&m.getModifiers(t)?.some(e=>e.kind===m.SyntaxKind.ExportKeyword)===!0}function mi(t,e){let r=t.rawCallEdges??[];t.rawCallEdges=r;let s=new Map;for(let i of e.statements){if(!m.isImportDeclaration(i)||!m.isStringLiteral(i.moduleSpecifier))continue;let n=i.moduleSpecifier.text,o=i.importClause;if(o&&(o.name&&s.set(o.name.text,n),o.namedBindings&&m.isNamedImports(o.namedBindings)))for(let a of o.namedBindings.elements)s.set(a.name.text,n)}if(s.size!==0)for(let i of e.statements){let n=fi(i);if(n){let o=ui(i);o&&U(o,n,s,r);continue}m.isClassDeclaration(i)&&i.name&&pi(i,i.name.text,s,r)}}function pi(t,e,r,s){for(let i of t.members)m.isMethodDeclaration(i)&&i.body&&m.isIdentifier(i.name)?U(i.body,`${e}.${i.name.text}`,r,s):m.isConstructorDeclaration(i)&&i.body&&U(i.body,`${e}.constructor`,r,s)}function fi(t){if(ut(t)){if(m.isFunctionDeclaration(t)&&t.name)return t.name.text;if(m.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(m.isIdentifier(e.name)&&e.initializer&&(m.isArrowFunction(e.initializer)||m.isFunctionExpression(e.initializer)))return e.name.text}}}function ui(t){if(m.isFunctionDeclaration(t))return t.body;if(m.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(e.initializer&&(m.isArrowFunction(e.initializer)||m.isFunctionExpression(e.initializer)))return e.initializer}}function U(t,e,r,s){if(m.isCallExpression(t)&&m.isIdentifier(t.expression)){let i=t.expression.text,n=r.get(i);n&&!s.some(o=>o.from===e&&o.to===i&&o.toSpecifier===n)&&s.push({from:e,to:i,toSpecifier:n})}m.forEachChild(t,i=>U(i,e,r,s))}function Q(t,e){if(e.length===0)return"ui";let r=!1;return t.walk(s=>{if(s.type==="rule")return r=!0,!1}),r?"ui":"barrel"}import Gt from"postcss";import*as gi from"postcss-less";var di=gi,Ht=new Set(["reference","inline"]);function Zt(t){return t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||t.startsWith("data:")}function yi(t){let e=t.trim();return e.length>0&&!e.startsWith("http://")&&!e.startsWith("https://")&&!e.startsWith("//")&&!e.startsWith("data:")&&!e.startsWith("#")}function xi(t,e){let r=t.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(r){let n=r[1]?.trim()??"",o=r[2]??"";if(!o)return null;let a=Ht.has(n)?"side-effect":"static";return{fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:a,...Zt(o)?{isExternal:!0}:{}}}let s=t.match(/^url\(['"]?([^'")]+)['"]?\)/),i=s?s[1]?.trim()??"":t.match(/^['"]([^'"]+)['"]/)?.[1]??"";return i?{fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"static",...Zt(i)?{isExternal:!0}:{}}:null}function hi(t,e){let r=[],s=/url\(['"]?([^'")]+)['"]?\)/g,i=s.exec(t);for(;i!==null;){let n=i[1]?.trim()??"";yi(n)&&r.push({fromPath:e,toPath:"",rawSpecifier:n,isStyle:!0,type:"static"}),i=s.exec(t)}return r}function Ut(t,e){let r=[];return t.walk(s=>{if(s.type==="atrule"&&s.name==="import"){let i=xi(s.params,e);i&&r.push(i)}s.type==="decl"&&r.push(...hi(s.value,e))}),r}function Si(t){return t.replace(/(?<!:)\/\/.*/g,"")}function Ci(t,e){let r=[],s=/@import\s+(?:\(([^)]+)\)\s+)?['"]([^'"]+)['"]/g,i=s.exec(t);for(;i!==null;){let n=i[1]?.trim()??"",o=i[2]??"";if(o){let a=Ht.has(n)?"side-effect":"static";r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:a})}i=s.exec(t)}return r}function Qt(t,e){let r=Gt.parse(Si(t));return{imports:Ut(r,e),root:r}}function bi(t){let e=[],r=[];for(let s of t.nodes??[]){if(s.type!=="atrule")continue;let{value:i}=s;if(i===void 0)continue;let n=s.name;n&&(e.push({name:n}),r.push({name:n,kind:"variable"}))}return{exports:e,tags:r}}function Xt(t,e){try{let r=di.parse(t),{exports:s,tags:i}=bi(r);return{imports:Ut(r,e),root:r,exports:s,tags:i}}catch{return{imports:Ci(t,e),root:Gt.parse(""),exports:[],tags:[]}}}import{parse as Ni}from"postcss-scss";function Yt(t){return t.startsWith("_")||t.startsWith("-")}function Ei(t){return!!(t.startsWith("sass:")||t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||!t.startsWith(".")&&!t.startsWith("/")&&!t.startsWith("_"))}function wi(t){let e=t.match(/^['"]([^'"]+)['"]/);if(!e?.[1])return{specifier:""};let r=e[1],i=t.match(/\bas\s+(\S+)/)?.[1];return i!==void 0?{specifier:r,alias:i}:{specifier:r}}function vi(t){let e=[],r=[];for(let s of t.nodes??[]){if(s.type==="decl"&&s.prop.startsWith("$")){let i=s.prop.slice(1);if(!i||Yt(i))continue;e.push({name:i}),r.push({name:i,kind:"variable"});continue}if(s.type==="atrule"&&(s.name==="mixin"||s.name==="function")){let n=s.params.match(/^([\w-]+)/)?.[1];if(!n||Yt(n))continue;let o=s.params.trim();e.push(o.includes("(")?{name:n,signature:o}:{name:n}),r.push({name:n,kind:"function"})}}return{exports:e,tags:r}}function te(t,e){let r=Ni(t),s=[];r.walk(o=>{if(o.type!=="atrule")return;let{name:a,params:c}=o;if(a!=="import"&&a!=="use"&&a!=="forward")return;let{specifier:l,alias:p}=wi(c);if(!l)return;let f={fromPath:e,toPath:"",rawSpecifier:l,isStyle:!0,type:a==="forward"?"re-export":"static",...Ei(l)?{isExternal:!0}:{}};p&&(f.symbols=[p]),s.push(f)});let{exports:i,tags:n}=vi(r);return{imports:s,root:r,exports:i,tags:n}}function ee(t,e){let r=[],s=/@require\s+['"]([^'"]+)['"]/g,i=s.exec(t);for(;i!==null;){let o=i[1];o&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"require"}),i=s.exec(t)}let n=/(?<!@)(?:import|require)\s*\(?\s*['"]([^'"]+)['"]/g;for(i=n.exec(t);i!==null;){let o=i[1];o&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"static"}),i=n.exec(t)}return r}function re(t,e){if(e.length===0)return"ui";try{let r=se("stylus");return new r.Parser(t).parse().nodes.some(n=>n.constructor.name!=="Import")?"ui":"barrel"}catch{return t.replace(/^\s*@?(?:require|import)\b.*/gm,"").trim().length>0?"ui":"barrel"}}function Z(t,e){let r=V(t);if(r==="stylus"){let n=ee(e,t);return{imports:n,exports:[],tags:[],category:re(e,n)}}if(r==="scss"){let{imports:n,root:o,exports:a,tags:c}=te(e,t);return{imports:n,exports:a,tags:c,category:Q(o,n)}}if(r==="less"){let{imports:n,root:o,exports:a,tags:c}=Xt(e,t);return{imports:n,exports:a,tags:c,category:Q(o,n)}}let{imports:s,root:i}=Qt(e,t);return{imports:s,exports:[],tags:[],category:Q(i,s)}}for(let[t,e]of[["javascript",(r,s)=>ft(r,s,"javascript")],["typescript",(r,s)=>ft(r,s,"typescript")],["css",Z],["scss",Z],["less",Z],["stylus",Z],["coffeescript",xt],["livescript",Dt],["lua",At],["python",Bt],["go",wt],["java",Pt],["kotlin",Ft],["scala",$t],["groovy",vt],["gherkin",Y],["markdown",Mt]])J(t,e);async function ie(t,e){let r=V(t),s=St(r);return s?s(t,e):{imports:[],exports:[],tags:[],category:"other"}}function ki(t){return ie(t.filePath,t.content)}export{ki as default};
|
|
1
|
+
var se=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import dt from"path";function J(t){switch(dt.extname(t).toLowerCase()){case".js":case".jsx":case".mjs":case".cjs":return"javascript";case".ts":case".tsx":return"typescript";case".css":return"css";case".scss":case".sass":return"scss";case".less":return"less";case".styl":return"stylus";case".coffee":return"coffeescript";case".ls":return"livescript";case".lua":return"lua";case".py":return"python";case".go":return"go";case".java":return"java";case".kt":case".kts":return"kotlin";case".scala":case".sc":return"scala";case".groovy":case".gradle":return"groovy";case".cpp":case".cc":case".cxx":case".c":return"unknown";case".feature":return"gherkin";case".md":case".mdx":return"markdown";default:return"unknown"}}function N(t){let e=dt.extname(t).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(e)}import oe from"coffeescript";function k(t){return t.startsWith("'")||t.startsWith('"')?t.slice(1,-1):t}function O(t){let e=new Set,r=/@tag\s+([a-zA-Z0-9_-]+)/g,i=r.exec(t);for(;i!==null;)i[1]&&e.add(i[1]),i=r.exec(t);return e}function $(t,e){let r=t.toLowerCase();return r.includes(".test.")||r.includes(".spec.")||e.has("test")?"test":"logic"}function xt(t){if(t){if(typeof t.originalValue=="string")return t.originalValue;if(typeof t.value=="string")return k(t.value)}}function F(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function ae(t,e){let r=xt(e.source);return r?{fromPath:t,toPath:"",rawSpecifier:r,isStyle:N(r),type:"static"}:null}function ce(t,e){let r=e.variable?.base?.value==="require",i=xt(e.args?.[0]?.base);return!r||!i?null:{fromPath:t,toPath:"",rawSpecifier:i,isStyle:N(i),type:"require"}}function yt(t,e){if(e)return[{name:e}];let r=t.value;if(r?.constructor?.name==="Class"){let n=F(r.variable);return n?[{name:n}]:[]}if(r?.base?.constructor?.name==="Obj"&&Array.isArray(r.base.properties))return r.base.properties.map(n=>F(n.variable)??F(n)).filter(n=>!!n).map(n=>({name:n}));let i=F(r);return i?[{name:i}]:[]}function le(t){if(Array.isArray(t.specifiers))return t.specifiers.map(r=>r.identifier??r.original?.value).filter(r=>!!r).map(r=>({name:r}));let e=F(t.variable)??F(t.variable?.base);return e?[{name:e}]:[]}function me(t,e,r,i){let n=e.constructor?.name;if(n==="ImportDeclaration"){let s=ae(t,e);s&&r.push(s)}else if(n==="Call"){let s=ce(t,e);s&&r.push(s)}else if(n==="Assign"){let s=F(e.variable?.base),o=e.variable?.properties?.[0]?.name?.value;s==="module"&&o==="exports"?i.push(...yt(e,void 0)):s==="exports"&&typeof o=="string"&&i.push(...yt(e,o))}else n==="ExportNamedDeclaration"&&e.clause?i.push(...le(e.clause)):n==="ExportDefaultDeclaration"&&i.push({name:"default"})}function Y(t,e,r,i){if(!(!e||typeof e!="object")){me(t,e,r,i);for(let n in e){if(n==="locationData")continue;let s=e[n];if(!(!s||typeof s!="object"))if(Array.isArray(s))for(let o of s)Y(t,o,r,i);else Y(t,s,r,i)}}}function St(t,e){let r=O(e),i=$(t,r),n=[],s=[];try{Y(t,oe.nodes(e),n,s)}catch{}let o=new Set,a=s.filter(c=>o.has(c.name)?!1:(o.add(c.name),!0));return{imports:n,exports:a,tags:Array.from(r).map(c=>({name:c,kind:"comment-marker"})),category:i}}import{AstBuilder as pe,GherkinClassicTokenMatcher as fe,Parser as ue}from"@cucumber/gherkin";import{IdGenerator as ge}from"@cucumber/messages";var ht=new Map;function V(t,e){ht.set(t,e)}function Ct(t){return ht.get(t)}var de=ge.uuid();function tt(t,e){let r=new Set,i=n=>{for(let s of n)r.add(s.name.startsWith("@")?s.name.slice(1):s.name)};try{let n=new pe(de),s=new fe,a=new ue(n,s).parse(e);if(a.feature){i(a.feature.tags);for(let c of a.feature.children){if(c.scenario){i(c.scenario.tags);for(let l of c.scenario.examples)i(l.tags)}if(c.rule)for(let l of c.rule.children)l.scenario&&i(l.scenario.tags)}}}catch(n){console.warn(`[GherkinParser] Failed to parse ${t}:`,n)}return{imports:[],exports:[],tags:Array.from(r).map(n=>({name:n,kind:"comment-marker"})),category:"test"}}V("gherkin",tt);import Ce from"path";import{parser as be}from"@lezer/go";function D(t){let e=[],r=t.firstChild;for(;r;)e.push(r),r=r.nextSibling;return e}function A(t,e){let r=1;for(let i=0;i<e&&i<t.length;i++)t[i]===`
|
|
2
|
+
`&&r++;return r}function ye(t,e){let r=1;function i(n){switch(n.type.name){case"IfStatement":case"ForStatement":r++;break;case"Case":{n.firstChild?.type.name==="case"&&r++;break}case"LogicOp":{let o=e.slice(n.from,n.to);(o==="&&"||o==="||")&&r++;break}}let s=n.firstChild;for(;s;)i(s),s=s.nextSibling}return i(t),r}function Nt(t,e,r,i){let n=r?1:1+e,s=D(t),o=r?e:e+1,a=s[1];a&&a.type.name!=="Block"&&(n+=B(a,o,!1,i));let c=s.find(p=>p.type.name==="Block");c&&(n+=B(c,o,!1,i));let l=s.findIndex(p=>p.type.name==="else");if(l>=0){let p=s[l+1];p?.type.name==="IfStatement"?n+=Nt(p,e,!0,i):p&&(n+=1+B(p,e+1,!1,i))}return n}function bt(t,e,r){let i=1+e,n=t.firstChild;for(;n;)i+=B(n,e+1,!1,r),n=n.nextSibling;return i}function xe(t,e,r){let i=0,n=t.firstChild;for(;n;)i+=B(n,e,!1,r),n=n.nextSibling;return i}function Se(t,e){let r=e.slice(t.from,t.to);return r==="&&"||r==="||"}function B(t,e,r,i){let n=t.type.name;if(n==="IfStatement")return Nt(t,e,r,i);if(n==="ForStatement"||n==="SwitchStatement"||n==="SelectStatement")return bt(t,e,i);let s=n==="LogicOp"&&Se(t,i)?1:0;return e>0&&n==="FunctionLiteral"?s+bt(t,e,i):s+xe(t,e,i)}function he(t,e){return B(t,0,!1,e)}function U(t,e){return{complexity:ye(t,e),cognitiveComplexity:he(t,e)}}function et(t,e){let i=t.getChild("Parameters")?.getChild("Parameter"),n=i?.getChild("TypeName")??i?.getChild("PointerType")?.getChild("TypeName");return n?e.slice(n.from,n.to):void 0}function Et(t,e){let r=[],i=t.cursor();do if(i.name==="FunctionDecl"){let n=i.node.getChild("DefName");if(n){let s=e.slice(n.from,n.to),{complexity:o,cognitiveComplexity:a}=U(i.node,e);r.push({name:s,line:A(e,i.from),complexity:o,cognitiveComplexity:a})}}else if(i.name==="MethodDecl"){let n=i.node.getChild("FieldName");if(n){let s=e.slice(n.from,n.to),o=et(i.node,e),a=o?`${o}.${s}`:s,{complexity:c,cognitiveComplexity:l}=U(i.node,e);r.push({name:a,line:A(e,i.from),complexity:c,cognitiveComplexity:l})}}while(i.next());return r}var Ne=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,Ee=/^\/\/go:build\s+(.+)$/,we=/^\/\/\s*\+build\s+(.+)$/;function vt(t,e){let r=[],i=new Map,n=new Set,s=new Set,o=new Map,a=be.parse(e),c=a.cursor();do switch(c.name){case"LineComment":{let b=e.slice(c.from,c.to),E=b.match(Ne);E?.[1]&&n.add(E[1]);let _=b.match(Ee);_&&wt(_[1],s);let M=b.match(we);M&&wt(M[1],s);break}case"ImportSpec":{let b=c.node.getChild("String");if(b){let _=e.slice(b.from,b.to).slice(1,-1);r.push({fromPath:t,toPath:"",rawSpecifier:_,isExternal:!0,isStyle:!1,type:"static"});let M=c.node.getChild("DefName"),G=M?e.slice(M.from,M.to):_.split("/").pop();G&&G!=="_"&&G!=="."&&o.set(G,_)}break}case"FunctionDecl":case"MethodDecl":case"TypeDecl":case"VarDecl":case"ConstDecl":{let b=c.node.getChild("DefName")??c.node.getChild("FieldName")??c.node.getChild("TypeSpec")?.getChild("DefName")??c.node.getChild("VarSpec")?.getChild("DefName")??c.node.getChild("ConstSpec")?.getChild("DefName");if(b){let E=e.slice(b.from,b.to);E!=="_"&&/^[A-Z]/.test(E)&&!i.has(E)&&i.set(E,{name:E})}break}}while(c.next());let l=r.some(b=>b.rawSpecifier==="testing"),p=Ce.basename(t).endsWith("_test.go")||n.has("test")||l?"test":"logic",f=new Set([...n,...s]),{complexity:u,cognitiveComplexity:d}=U(a.topNode,e),y=Et(a,e),C=p==="test"?[]:ve(a,e,o);return{imports:r,exports:Array.from(i.values()),tags:Array.from(f).map(b=>({name:b,kind:"comment-marker"})),category:p,rawCallEdges:C,complexity:u,cognitiveComplexity:d,...y.length>0?{functions:y}:{}}}function ve(t,e,r){let i=[];function n(o,a){if(o.type.name==="CallExpr"){let l=o.firstChild;if(l?.type.name==="SelectorExpr"){let p=l.firstChild,f=l.getChild("FieldName");if(p?.type.name==="VariableName"&&f){let u=e.slice(p.from,p.to),d=r.get(u);if(d){let y=e.slice(f.from,f.to);i.push({from:a,to:y,toSpecifier:d})}}}}let c=o.firstChild;for(;c;)n(c,a),c=c.nextSibling}let s=t.cursor();do if(s.name==="FunctionDecl"){let o=s.node.getChild("DefName"),a=s.node.getChild("Block");if(o&&a){let c=e.slice(o.from,o.to);/^[A-Z]/.test(c)&&n(a,c)}}else if(s.name==="MethodDecl"){let o=s.node.getChild("FieldName"),a=s.node.getChild("Block");if(o&&a){let c=e.slice(o.from,o.to),l=et(s.node,e);n(a,l?`${l}.${c}`:c)}}while(s.next());return i}function wt(t,e){for(let r of t.split(/[\s,&|!()]+/)){let i=r.trim();i&&i!=="ignore"&&e.add(i)}}var ke=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/g,Te=["org.junit","androidx.test","org.robolectric","org.mockito","org.scalatest","munit","spock.lang","io.kotest","org.spekframework","org.testng","org.assertj","com.google.truth","org.hamcrest","io.mockk","com.nhaarman.mockitokotlin2"],Ie=["test","androidTest","integrationTest","it"],Pe=new RegExp(`/src/(${Ie.join("|")})/`),Fe=/(?:Test|Tests|Spec|IT|ITCase)$/;function De(t){let e=t.replace(/\.\w+$/,"");return Fe.test(e)}function j(t){let e=new Set;for(let r of t.matchAll(ke))r[1]&&e.add(r[1]);return e}function T(t){let e=t.replace(/\/\*[\s\S]*?\*\//g,r=>r.replace(/[^\n]/g," "));return e=e.replace(/\/\/[^\n]*/g,r=>" ".repeat(r.length)),e}function W(t){let e=T(t),r=new Set;for(let n of e.matchAll(/@([A-Z]\w*)/g))n[1]&&r.add(n[1]);let i=new Set;for(let n of e.matchAll(/\b(?:class|object|interface|trait|enum)\s+([A-Za-z_]\w*)/g))n[1]&&i.add(n[1]);return{annotations:[...r],typeNames:[...i]}}function H(t){let e=t.split(".").pop();return e&&e!=="*"?e:void 0}function z(t,e,r=e){let i=H(r);return{fromPath:t,toPath:"",rawSpecifier:e,isExternal:!0,isStyle:!1,type:"static",symbols:i?[i]:void 0}}function I(t,e){return{fromPath:t,toPath:"",rawSpecifier:`${e}.*`,isExternal:!0,isStyle:!1,type:"side-effect",isSamePackage:!0}}function P(t,e){let r=[];for(let i of T(t).split(`
|
|
3
|
+
`)){let n=i.trim();if(!n||n.startsWith("@")||n.startsWith("*"))continue;let s=n.match(/^package\s+(?:object\s+)?([\w.]+)/);if(s?.[1]){if(r.push(s[1]),!e)break;continue}if(!(e&&/^import\s/.test(n)))break}return r.length>0?r.join("."):null}var Ae=new Set(["Configuration","SpringBootApplication","EnableAutoConfiguration"]),Re=new Set(["Composable","Preview"]),Le=new Set(["RestController","Controller","Service","Repository","Component","Entity","MappedSuperclass","Embeddable"]),_e=["Activity","Fragment","ViewModel","Screen","Composable"];function w(t,e,r={}){let i=t.replace(/\\/g,"/"),n=i.split("/").pop()??"";if(n.endsWith(".gradle")||n==="build.gradle.kts"||n==="settings.gradle.kts")return"config";if(Pe.test(i)||e.some(o=>Te.some(a=>o===a||o.startsWith(`${a}.`))))return"test";let s=r.annotations??[];return s.some(o=>Ae.has(o))?"config":s.some(o=>Re.has(o))||(r.typeNames??[]).some(o=>_e.some(a=>o.endsWith(a)))?"ui":s.some(o=>Le.has(o))?"logic":De(n)?"test":"logic"}var Me=/^\s*import\s+(static\s+)?([\w.]+(?:\.\*)?)(?:\s+as\s+\w+)?\s*$/,Oe=/^(?:@\w+\s+)*(?:public\s+|private\s+|protected\s+|final\s+|abstract\s+|static\s+)*(class|interface|trait|enum|def)\s+([A-Za-z_][A-Za-z0-9_]*)/;function $e(t,e){return t?e.endsWith(".*")?e.slice(0,-2)||null:e.split(".").slice(0,-1).join(".")||null:e||null}function kt(t,e){let r=j(e),n=T(e).split(`
|
|
4
|
+
`),s=[],o=new Set;for(let l of n){let p=l.match(Me);if(p?.[2]){let u=$e(!!p[1],p[2]);u&&s.push(z(t,u,p[2]));continue}let f=l.match(Oe);f?.[2]&&o.add(f[2])}let a=P(e,!1);a&&s.push(I(t,a));let c=Array.from(o,l=>({name:l}));return{imports:s,exports:c,tags:Array.from(r).map(l=>({name:l,kind:"comment-marker"})),category:w(t,s.map(l=>l.rawSpecifier),{typeNames:[...o],annotations:W(e).annotations})}}import{parser as Je}from"@lezer/java";var Tt=new Set(["ForStatement","EnhancedForStatement","WhileStatement","DoStatement"]),Be=new Set(["ClassDeclaration","InterfaceDeclaration","EnumDeclaration","RecordDeclaration","AnnotationTypeDeclaration"]);function je(t,e){let r=1;function i(n){let s=n.type.name;if(s==="IfStatement"||s==="CatchClause"||s==="TernaryExpression")r++;else if(Tt.has(s))r++;else if(s==="SwitchLabel")n.firstChild?.type.name==="case"&&r++;else if(s==="LogicOp"){let a=e.slice(n.from,n.to);(a==="&&"||a==="||")&&r++}let o=n.firstChild;for(;o;)i(o),o=o.nextSibling}return i(t),r}function It(t,e,r,i){let n=r?1:1+e,s=[];for(let p=t.firstChild;p;p=p.nextSibling)s.push(p);let o=r?e:e+1,a=s[1];a&&a.type.name!=="Block"&&(n+=K(a,o,!1,i));let c=s.find(p=>p.type.name==="Block");c&&(n+=K(c,o,!1,i));let l=s.findIndex(p=>p.type.name==="else");if(l>=0){let p=s[l+1];p?.type.name==="IfStatement"?n+=It(p,e,!0,i):p&&(n+=1+K(p,e+1,!1,i))}return n}function rt(t,e,r){let i=1+e,n=t.firstChild;for(;n;)i+=K(n,e+1,!1,r),n=n.nextSibling;return i}function We(t,e,r){let i=0,n=t.firstChild;for(;n;)i+=K(n,e,!1,r),n=n.nextSibling;return i}function ze(t,e){let r=e.slice(t.from,t.to);return r==="&&"||r==="||"}function K(t,e,r,i){let n=t.type.name;if(n==="IfStatement")return It(t,e,r,i);if(Tt.has(n)||n==="SwitchStatement"||n==="CatchClause"||n==="TernaryExpression")return rt(t,e,i);let s=n==="LogicOp"&&ze(t,i)?1:0;return e>0&&n==="LambdaExpression"?s+rt(t,e,i):s+We(t,e,i)}function Ke(t,e){return K(t,0,!1,e)}function it(t,e){return{complexity:je(t,e),cognitiveComplexity:Ke(t,e)}}function nt(t,e){for(let r=t.parent;r;r=r.parent)if(Be.has(r.type.name)){let i=r.getChild("Definition");if(i)return e.slice(i.from,i.to)}}function Pt(t,e){let r=[],i=t.cursor();do if(i.name==="MethodDeclaration"||i.name==="ConstructorDeclaration"){let n=i.node.getChild("Definition");if(n){let s=e.slice(n.from,n.to),o=nt(i.node,e),a=o&&i.name==="MethodDeclaration"?`${o}.${s}`:s,{complexity:c,cognitiveComplexity:l}=it(i.node,e);r.push({name:a,line:A(e,i.from),complexity:c,cognitiveComplexity:l})}}while(i.next());return r}var Ve=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/;function qe(t,e){let r=t.getChild("ScopedIdentifier");if(!r)return null;let i=t.getChild("static")!=null,n=t.getChild("Asterisk")!=null,s=e.slice(r.from,r.to);if(i){if(n)return s?{specifier:s,wildcard:!1}:null;let o=s.split(".").slice(0,-1).join(".");return o?{specifier:o,wildcard:!1,symbol:H(s)}:null}return n?{specifier:`${s}.*`,wildcard:!0}:{specifier:s,wildcard:!1,symbol:H(s)}}function Ze(t){let e=new Map;for(let r of t){if(r.type==="side-effect")continue;let i=r.rawSpecifier;if(i.endsWith(".*"))continue;let n=i.split(".").pop();n&&e.set(n,i)}return e}function Ge(t,e){let r=t;if(r.name==="GenericType"&&(r=r.firstChild),!r)return null;if(r.name==="TypeName")return e.slice(r.from,r.to);if(r.name==="ScopedTypeName"){let i=null;for(let n=r.firstChild;n;n=n.nextSibling)n.name==="TypeName"&&(i=n);return i?e.slice(i.from,i.to):null}return null}function Ue(t,e,r){let i=[];function n(o,a){let c=o.type.name;if(c==="MethodInvocation"){let p=o.firstChild;if(p?.type.name==="Identifier"){let f=r.get(e.slice(p.from,p.to)),u=o.getChild("MethodName");f&&u&&i.push({from:a,to:e.slice(u.from,u.to),toSpecifier:f})}}else if(c==="ObjectCreationExpression"){let p=o.getChild("TypeName")??o.getChild("GenericType")??o.getChild("ScopedTypeName"),f=p&&Ge(p,e);if(f){let u=r.get(f);u&&i.push({from:a,to:"new",toSpecifier:u})}}let l=o.firstChild;for(;l;)n(l,a),l=l.nextSibling}let s=t.cursor();do if(s.name==="MethodDeclaration"||s.name==="ConstructorDeclaration"){let o=s.node.getChild("Definition"),a=s.node.getChild("Block")??s.node.getChild("ConstructorBody");if(o&&a){let c=e.slice(o.from,o.to),l=nt(s.node,e),p=l&&s.name==="MethodDeclaration"?`${l}.${c}`:c;n(a,p)}}while(s.next());return i}function Ft(t,e){let r=[],i=new Map,n=new Set,s=new Set,o;try{o=Je.parse(e)}catch{return{imports:[],exports:[],tags:[],category:w(t,[])}}let a=o.cursor();do switch(a.name){case"LineComment":{let y=e.slice(a.from,a.to).match(Ve);y?.[1]&&n.add(y[1]);break}case"MarkerAnnotation":case"Annotation":{let y=a.node.getChild("Identifier");y&&s.add(e.slice(y.from,y.to));break}case"ImportDeclaration":{let y=qe(a.node,e);y&&r.push({fromPath:t,toPath:"",rawSpecifier:y.specifier,isExternal:!0,isStyle:!1,type:"static",symbols:y.symbol?[y.symbol]:void 0});break}case"ClassDeclaration":case"InterfaceDeclaration":case"EnumDeclaration":case"AnnotationTypeDeclaration":{if(a.node.parent?.name==="Program"){let y=a.node.getChild("Definition");if(y){let C=e.slice(y.from,y.to);i.has(C)||i.set(C,{name:C})}}break}}while(a.next());let c=P(e,!1);c&&r.push(I(t,c));let l=w(t,r.map(y=>y.rawSpecifier),{typeNames:[...i.keys()],annotations:[...s]}),{complexity:p,cognitiveComplexity:f}=it(o.topNode,e),u=Pt(o,e),d=l==="test"?[]:Ue(o,e,Ze(r));return{imports:r,exports:Array.from(i.values()),tags:Array.from(n).map(y=>({name:y,kind:"comment-marker"})),category:l,rawCallEdges:d,complexity:p,cognitiveComplexity:f,...u.length>0?{functions:u}:{}}}var He=/^\s*import\s+([\w.]+(?:\.\*)?)(?:\s+as\s+\w+)?\s*$/,st="(?:public\\s+|internal\\s+|private\\s+|protected\\s+|open\\s+|abstract\\s+|final\\s+|sealed\\s+|data\\s+|value\\s+|inline\\s+|noinline\\s+|crossinline\\s+|external\\s+|expect\\s+|actual\\s+|suspend\\s+|operator\\s+|infix\\s+|tailrec\\s+|const\\s+|lateinit\\s+)*",Qe=new RegExp(`^(?:@[\\w.]+(?:\\([^)]*\\))?\\s+)*${st}(?:(?:enum|annotation)\\s+)?(class|interface|object|typealias)\\s+([A-Za-z_][A-Za-z0-9_]*)`),Xe=new RegExp(`^(?:@[\\w.]+(?:\\([^)]*\\))?\\s+)*${st}fun\\s+(?:<[^>]*>\\s*)?(?:[A-Za-z_][\\w.]*(?:<[^>]*>)?\\.)?([A-Za-z_][A-Za-z0-9_]*)\\s*[(<]`),Ye=new RegExp(`^(?:@[\\w.]+(?:\\([^)]*\\))?\\s+)*${st}(?:val|var)\\s+(?:<[^>]*>\\s*)?([A-Za-z_][A-Za-z0-9_]*)`);function Dt(t,e){let r=j(e),n=T(e).split(`
|
|
5
|
+
`),s=[],o=new Set;for(let l of n){let p=l.match(He);if(p?.[1]){s.push(z(t,p[1]));continue}let f=l.match(Qe);if(f?.[2]){o.add(f[2]);continue}let u=l.match(Xe);if(u?.[1]){o.add(u[1]);continue}let d=l.match(Ye);d?.[1]&&o.add(d[1])}let a=P(e,!1);a&&s.push(I(t,a));let c=Array.from(o,l=>({name:l}));return{imports:s,exports:c,tags:Array.from(r).map(l=>({name:l,kind:"comment-marker"})),category:w(t,s.map(l=>l.rawSpecifier),{typeNames:[...o],annotations:W(e).annotations})}}import tr from"livescript";function R(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function er(t){if(!t)return[];if(t.constructor?.name==="Class"){let r=R(t.title);return r?[{name:r}]:[]}if(t.constructor?.name==="Obj"&&Array.isArray(t.items))return t.items.map(r=>R(r.key)??R(r.val)).filter(r=>!!r).map(r=>({name:r}));let e=R(t);return e?[{name:e}]:[]}function rr(t){let e=t.constructor?.name||t.type;if(e==="Assign"&&t.left?.constructor?.name==="Chain"){let r=t.left,i=R(r.head),s=r.tails?.[0]?.key?.name;if(i==="module"&&s==="exports")return er(t.right);if(i==="exports"&&typeof s=="string")return[{name:s}];if(r.head?.verb==="out"&&typeof s=="string")return[{name:s}]}if(e==="Import"&&t.left?.verb==="out"){let r=t.right;if(r?.constructor?.name==="Obj"&&Array.isArray(r.items))return r.items.map(i=>R(i.val)??R(i.key)).filter(i=>!!i).map(i=>({name:i}))}return[]}var ir=new Set(["first_line","first_column","last_line","last_column","line","column"]);function nr(t,e){let r=t.constructor?.name||t.type;if(r==="Import"){let i=t.right?.value;if(typeof i=="string"){let n=k(i);return{fromPath:e,toPath:"",rawSpecifier:n,isStyle:N(n),type:"static"}}}if(r==="Chain"&&t.head?.value==="require"){let i=t.tails?.[0];if(i?.constructor?.name==="Call"||i?.type==="Call"){let n=i.args?.[0]?.value;if(typeof n=="string"){let s=k(n);return{fromPath:e,toPath:"",rawSpecifier:s,isStyle:N(s),type:"require"}}}}return null}function ot(t,e,r){if(!t||typeof t!="object")return[];let i=[],n=nr(t,e);n&&i.push(n),r.push(...rr(t));for(let s in t){if(ir.has(s))continue;let o=t[s];if(!(!o||typeof o!="object"))if(Array.isArray(o))for(let a of o)i.push(...ot(a,e,r));else i.push(...ot(o,e,r))}return i}function At(t,e){let r=O(e),i=$(t,r),n=[],s=[];try{n=ot(tr.ast(e),t,s)}catch{}let o=new Set,a=s.filter(c=>o.has(c.name)?!1:(o.add(c.name),!0));return{imports:n,exports:a,tags:Array.from(r).map(c=>({name:c,kind:"comment-marker"})),category:i}}import sr from"luaparse";function or(t,e){let r=[];function i(n){if(!(!n||typeof n!="object")){if((n.type==="CallExpression"||n.type==="StringCallExpression")&&n.base?.type==="Identifier"&&n.base?.name==="require"){let s;if(n.type==="CallExpression"){let o=n.arguments?.[0];o?.type==="StringLiteral"&&(s=k(o.raw))}else if(n.type==="StringCallExpression"){let o=n.argument;o?.type==="StringLiteral"&&(s=k(o.raw))}s&&r.push({fromPath:e,toPath:"",rawSpecifier:s,isStyle:N(s),type:"require"})}for(let s in n){if(s==="loc")continue;let o=n[s];if(o&&typeof o=="object")if(Array.isArray(o))for(let a of o)i(a);else i(o)}}}return i(t),r}function ar(t){let e=new Set;for(let r of t)r.type==="LocalStatement"&&r.variables.forEach((i,n)=>{r.init[n]?.type==="TableConstructorExpression"&&e.add(i.name)});return e}function cr(t){let e=t[t.length-1];if(e?.type!=="ReturnStatement")return[];let r=e.arguments[0];if(r?.type!=="TableConstructorExpression")return[];let i=[];for(let n of r.fields)n.type==="TableKeyString"&&i.push({name:n.key.name});return i}function lr(t){let e=t.body,r=ar(e),i=cr(e);for(let s of e)if(s.type==="FunctionDeclaration")s.identifier?.type==="MemberExpression"?s.identifier.base.type==="Identifier"&&r.has(s.identifier.base.name)&&i.push({name:s.identifier.identifier.name}):s.identifier?.type==="Identifier"&&!s.isLocal&&i.push({name:s.identifier.name});else if(s.type==="AssignmentStatement")for(let o of s.variables)o.type==="MemberExpression"&&o.base.type==="Identifier"&&r.has(o.base.name)&&i.push({name:o.identifier.name});let n=new Set;return i.filter(s=>n.has(s.name)?!1:(n.add(s.name),!0))}function Rt(t,e){let r=O(e),i=$(t,r),n=[],s=[];try{let o=sr.parse(e);n=or(o,t),s=lr(o)}catch{}return{imports:n,exports:s,tags:Array.from(r).map(o=>({name:o,kind:"comment-marker"})),category:i}}var mr=["http://","https://","mailto:","//"],pr="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",fr=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${pr})\\b`,"g"),Lt;async function ur(){return Lt??=(async()=>{let{unified:t}=await import("unified"),e=(await import("remark-parse")).default;return t().use(e)})(),Lt}function gr(t){let e=t.trim();return e.length===0||e.startsWith("#")||mr.some(r=>e.startsWith(r))}function dr(t,e){let r=t.match(fr);return r?r.map(i=>({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!1,type:"static",isDocReference:!0})):[]}function _t(t,e,r){if(t.type==="link"&&typeof t.url=="string"&&!gr(t.url)&&r.push({fromPath:e,toPath:"",rawSpecifier:t.url,isStyle:!1,type:"static",isDocReference:!0}),(t.type==="code"||t.type==="inlineCode")&&typeof t.value=="string"&&r.push(...dr(t.value,e)),Array.isArray(t.children))for(let i of t.children)_t(i,e,r)}async function Mt(t,e){let i=(await ur()).parse(e),n=[];_t(i,t,n);let s=new Set;return{imports:n.filter(a=>s.has(a.rawSpecifier)?!1:(s.add(a.rawSpecifier),!0)),exports:[],tags:[],category:"other"}}import br from"path";import{parser as Nr}from"@lezer/python";function yr(t){let e=1;function r(i){switch(i.type.name){case"IfStatement":{e+=D(i).filter(s=>s.type.name==="if"||s.type.name==="elif").length;break}case"TryStatement":{e+=D(i).filter(s=>s.type.name==="except").length;break}case"ForStatement":case"WhileStatement":case"ConditionalExpression":e++;break;case"and":case"or":e++;break}let n=i.firstChild;for(;n;)r(n),n=n.nextSibling}return r(t),e}function xr(t,e){let r=0,i=D(t),n=0,s=0;for(;s<i.length;){let o=i[s];if(o?.type.name==="if"||o?.type.name==="elif"){let a=n>0;r+=a?1:1+e;let c=a?e:e+1,l=i[s+1],p=i[s+2];l&&(r+=v(l,c)),p&&(r+=v(p,c)),n++,s+=3}else if(o?.type.name==="else"){r+=1;let a=i[s+1];a&&(r+=v(a,e+1)),s+=2}else s++}return r}function Sr(t,e){let r=0,i=D(t),n=0;for(;n<i.length;){let s=i[n];if(s?.type.name==="except"){for(r+=1+e,n++;n<i.length&&i[n]?.type.name!=="Body";)r+=v(i[n],e),n++;n<i.length&&(r+=v(i[n],e),n++)}else s?.type.name==="Body"&&(r+=v(s,e)),n++}return r}function Ot(t,e){let r=1+e,i=t.firstChild;for(;i;)r+=v(i,e+1),i=i.nextSibling;return r}function hr(t,e){let r=0,i=t.firstChild;for(;i;)r+=v(i,e),i=i.nextSibling;return r}function v(t,e){let r=t.type.name;switch(r){case"IfStatement":return xr(t,e);case"TryStatement":return Sr(t,e);case"ForStatement":case"WhileStatement":return Ot(t,e);default:{let i=r==="ConditionalExpression"||r==="and"||r==="or"?1:0;return e>0&&(r==="FunctionDefinition"||r==="LambdaExpression")?i+Ot(t,e):i+hr(t,e)}}}function Cr(t){return v(t,0)}function at(t){return{complexity:yr(t),cognitiveComplexity:Cr(t)}}function $t(t,e){let r=[];function i(o,a){let{complexity:c,cognitiveComplexity:l}=at(o);r.push({name:a,line:A(e,o.from),complexity:c,cognitiveComplexity:l})}function n(o){let a=o.firstChild;for(;a;)s(a),a=a.nextSibling}function s(o){if(o.type.name==="ClassDefinition"){let a=o.getChild("VariableName"),c=a?e.slice(a.from,a.to):void 0,l=o.getChild("Body");if(l){let p=l.firstChild;for(;p;){if(p.type.name==="FunctionDefinition"){let f=p.getChild("VariableName"),u=f?e.slice(f.from,f.to):void 0;u&&i(p,c?`${c}.${u}`:u),n(p)}else s(p);p=p.nextSibling}}return}if(o.type.name==="FunctionDefinition"){let a=o.getChild("VariableName");a&&i(o,e.slice(a.from,a.to)),n(o);return}n(o)}return s(t.topNode),r}var Er=new Set(["pytest","unittest","nose","hypothesis"]);function Bt(t,e){let r=[],i=[],n=new Set,s=br.basename(t).toLowerCase(),o=Nr.parse(e),a=o.cursor();do switch(a.name){case"Comment":{let d=e.slice(a.from,a.to).match(/#\s*@tag\s+([a-zA-Z0-9_-]+)/);d?.[1]&&n.add(d[1]);break}case"ImportStatement":{for(let d of wr(a.node,e,t))r.push(d);break}case"FunctionDefinition":case"ClassDefinition":{let d=a.node.parent;if(d?.name==="Script"||d?.name==="DecoratedStatement"&&d.parent?.name==="Script"){let C=a.node.getChild("VariableName");C&&i.push({name:e.slice(C.from,C.to)})}break}case"AssignStatement":{if(a.node.parent?.name==="Script"){let d=a.node.firstChild;d?.name==="VariableName"&&i.push({name:e.slice(d.from,d.to)})}break}}while(a.next());let c=Fr(s,r,n);c==="test"&&n.add("test");let{complexity:l,cognitiveComplexity:p}=at(o.topNode),f=$t(o,e),u=c==="test"?[]:Pr(o,e);return{imports:r,exports:i,tags:Array.from(n).map(d=>({name:d,kind:"comment-marker"})),category:c,rawCallEdges:u,complexity:l,cognitiveComplexity:p,...f.length>0?{functions:f}:{}}}function wr(t,e,r){let i=t.firstChild;return i?i.name==="from"?vr(t,e,r):kr(t,e,r):[]}function vr(t,e,r){let i=t.firstChild;if(!i)return[];let n=i.nextSibling;for(;n&&n.name!=="import";)n=n.nextSibling;if(!n)return[];let s=e.slice(i.to,n.from).trim(),o=Tr(n.nextSibling,e);if(!o.length)return[];let a=0;for(;a<s.length&&s[a]===".";)a++;let c=s.slice(a);if(a===0)return[q(r,s,o,!0)];let l=a===1?"./":"../".repeat(a-1);return c?[q(r,l+c.replace(/\./g,"/"),o,!1)]:o[0]==="*"?[q(r,l.slice(0,-1),["*"],!1)]:o.map(p=>q(r,l+p,[p],!1))}function kr(t,e,r){let i=[],n=t.firstChild?.nextSibling??null;for(;n;){if(n.name==="VariableName"){let s=e.slice(n.from,n.to);for(;n.nextSibling?.name==="."&&n.nextSibling.nextSibling?.name==="VariableName";)n=n.nextSibling.nextSibling,s+=`.${e.slice(n.from,n.to)}`;n.nextSibling?.name==="as"&&(n=n.nextSibling.nextSibling??n.nextSibling),i.push(q(r,s,["*"],!0))}n=n.nextSibling}return i}function Tr(t,e){let r=[],i=t;for(;i;)i.name==="*"?r.push("*"):i.name==="VariableName"&&(r.push(e.slice(i.from,i.to)),i.nextSibling?.name==="as"&&(i=i.nextSibling.nextSibling??i.nextSibling)),i=i.nextSibling;return r}function Ir(t,e){let r=new Map,i=t.cursor();do{if(i.name!=="ImportStatement")continue;let s=i.node.firstChild;if(s?.type.name!=="from")continue;let o=s.nextSibling;for(;o&&o.type.name!=="import";)o=o.nextSibling;if(!o)continue;let a=e.slice(s.to,o.from).trim(),c=0;for(;c<a.length&&a[c]===".";)c++;let l=a.slice(c),p=c<=1?"./":"../".repeat(c-1),f=o.nextSibling;for(;f;){if(f.type.name==="VariableName"){let u=e.slice(f.from,f.to),d=u;if(f.nextSibling?.type.name==="as"){let C=f.nextSibling.nextSibling;C?.type.name==="VariableName"&&(d=e.slice(C.from,C.to),f=C)}let y=c===0?a:l?p+l.replace(/\./g,"/"):p+u;r.set(d,y)}f=f.nextSibling}}while(i.next());return r}function Pr(t,e){let r=Ir(t,e),i=[];function n(a,c){if(a.type.name==="CallExpression"&&a.firstChild?.type.name==="VariableName"){let p=a.firstChild,f=e.slice(p.from,p.to),u=r.get(f);u&&i.push({from:c,to:f,toSpecifier:u})}let l=a.firstChild;for(;l;)n(l,c),l=l.nextSibling}function s(a){let c=a.firstChild;for(;c;)o(c),c=c.nextSibling}function o(a){if(a.type.name==="ClassDefinition"){let c=a.getChild("VariableName"),l=c?e.slice(c.from,c.to):void 0,p=a.getChild("Body");if(p){let f=p.firstChild;for(;f;){if(f.type.name==="FunctionDefinition"){let u=f.getChild("VariableName"),d=u?e.slice(u.from,u.to):void 0;d&&n(f,l?`${l}.${d}`:d)}else o(f);f=f.nextSibling}}return}if(a.type.name==="FunctionDefinition"){let c=a.getChild("VariableName");c&&n(a,e.slice(c.from,c.to));return}s(a)}return o(t.topNode),i}function q(t,e,r,i){return{fromPath:t,toPath:"",rawSpecifier:e,isStyle:!1,isExternal:i,type:"static",symbols:r.length>0?r:void 0}}function Fr(t,e,r){return t.startsWith("test_")||t.endsWith("_test.py")?"test":t==="conftest.py"||t==="setup.py"?"config":r.has("test")||e.some(i=>Er.has(i.rawSpecifier))?"test":"logic"}var Dr=/^\s*import\s+(.+?)\s*$/,Ar=/^(?:@\w+\s+)*(?:private\s+|protected\s+|final\s+|sealed\s+|abstract\s+|implicit\s+|case\s+)*(class|trait|object|type|enum)\s+([A-Za-z_$][A-Za-z0-9_$]*)/;function Rr(t,e){let r=e.split("=>")[0]?.trim();return r?r==="_"||r==="*"||r==="given"?`${t}.*`:`${t}.${r}`:null}function Lr(t){let e=t.indexOf("{");if(e!==-1){let i=t.indexOf("}",e),n=t.slice(0,e).trim().replace(/\.$/,""),s=t.slice(e+1,i===-1?void 0:i);return n?s.split(",").map(o=>Rr(n,o.trim())).filter(o=>o!=null):[]}let r=[];for(let i of t.split(",")){let n=i.trim().replace(/\s+as\s+\w+$/,"");if(n)if(n.endsWith("._")||n.endsWith(".*")||n.endsWith(".given")){let s=n.replace(/\.(_|\*|given)$/,"");s&&r.push(`${s}.*`)}else r.push(n)}return r}function jt(t,e){let r=j(e),n=T(e).split(`
|
|
6
|
+
`),s=[],o=new Set;for(let l of n){let p=l.match(Dr);if(p?.[1]){for(let u of Lr(p[1]))s.push(z(t,u));continue}let f=l.match(Ar);f?.[2]&&o.add(f[2])}let a=P(e,!0);a&&s.push(I(t,a));let c=Array.from(o,l=>({name:l}));return{imports:s,exports:c,tags:Array.from(r).map(l=>({name:l,kind:"comment-marker"})),category:w(t,s.map(l=>l.rawSpecifier),{typeNames:[...o],annotations:W(e).annotations})}}import Vt from"path";import m from"typescript";var _r=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],Mr=[];function Wt(t){return[..._r,...Mr].some(e=>typeof e=="string"?t.includes(e):e instanceof RegExp?e.test(t):e(t))}var Or=[".test.",".spec.","-test.","-spec."],$r=[];function ct(){return[...Or,...$r]}var Br=["jest","vitest","playwright","cypress","@testing-library/"],jr=[];function lt(){return[...Br,...jr]}var Wr=.8,zr=Wr;function mt(){return zr}import g from"typescript";function Kr(t){let e=1;function r(i){switch(i.kind){case g.SyntaxKind.IfStatement:case g.SyntaxKind.ConditionalExpression:case g.SyntaxKind.ForStatement:case g.SyntaxKind.ForInStatement:case g.SyntaxKind.ForOfStatement:case g.SyntaxKind.WhileStatement:case g.SyntaxKind.DoStatement:case g.SyntaxKind.CatchClause:case g.SyntaxKind.CaseClause:e++;break;case g.SyntaxKind.BinaryExpression:{let n=i.operatorToken.kind;(n===g.SyntaxKind.AmpersandAmpersandToken||n===g.SyntaxKind.BarBarToken||n===g.SyntaxKind.QuestionQuestionToken)&&e++;break}}g.forEachChild(i,r)}return r(t),e}function Kt(t,e,r){let i=r?1:1+e,n=r?e:e+1;return i+=L(t.expression,n,!1),i+=L(t.thenStatement,n,!1),t.elseStatement&&(g.isIfStatement(t.elseStatement)?i+=Kt(t.elseStatement,e,!0):i+=1+L(t.elseStatement,e+1,!1)),i}function zt(t,e){let r=1+e;return g.forEachChild(t,i=>{r+=L(i,e+1,!1)}),r}function Jr(t,e){let r=1+e;return g.forEachChild(t,i=>{r+=L(i,e,!1)}),r}function Vr(t,e){let r=0;return g.forEachChild(t,i=>{r+=L(i,e,!1)}),r}function qr(t){let e=t.operatorToken.kind;return e===g.SyntaxKind.AmpersandAmpersandToken||e===g.SyntaxKind.BarBarToken||e===g.SyntaxKind.QuestionQuestionToken}function L(t,e,r){if(g.isIfStatement(t))return Kt(t,e,r);if(g.isForStatement(t)||g.isForInStatement(t)||g.isForOfStatement(t)||g.isWhileStatement(t)||g.isDoStatement(t)||g.isSwitchStatement(t))return zt(t,e);if(g.isCatchClause(t))return Jr(t,e);let i=0;return g.isConditionalExpression(t)&&(i+=1),g.isBinaryExpression(t)&&qr(t)&&(i+=1),e>0&&(g.isFunctionDeclaration(t)||g.isFunctionExpression(t)||g.isArrowFunction(t))?i+zt(t,e):i+Vr(t,e)}function Zr(t){return L(t,0,!1)}function pt(t){return{complexity:Kr(t),cognitiveComplexity:Zr(t)}}import h from"typescript";var ft=new Set(["test","describe","it"]);function Jt(t,e){Gr(t,e),Hr(t,e),Qr(t,e)}function Gr(t,e){if((h.isFunctionDeclaration(t)||h.isVariableDeclaration(t))&&t.name&&h.isIdentifier(t.name)&&Ur(t)){let r;if(h.isFunctionDeclaration(t))r="function";else{let i=t.initializer;r=i&&(h.isArrowFunction(i)||h.isFunctionExpression(i))?"function":"variable"}e.tags.add({name:t.name.text,kind:r})}}function Ur(t){if(h.isFunctionDeclaration(t))return h.isSourceFile(t.parent);let e=t.parent?.parent;return!!e&&h.isSourceFile(e.parent)}function Hr(t,e){if(!h.isSourceFile(t))return;let r=/@tag\s+([a-zA-Z0-9_-]+)/g,i=t.getFullText(),n=r.exec(i);for(;n!==null;)n[1]&&e.tags.add({name:n[1],kind:"comment-marker"}),n=r.exec(i)}function Qr(t,e){if(!h.isCallExpression(t)||!Xr(t.expression))return;let[r]=t.arguments;if(r&&h.isStringLiteral(r))for(let i of r.text.match(/@[\w-]+/g)??[])e.tags.add({name:i.substring(1),kind:"comment-marker"});for(let i of t.arguments)h.isObjectLiteralExpression(i)&&Yr(i,e)}function Xr(t){return h.isIdentifier(t)?ft.has(t.text):!!(h.isPropertyAccessExpression(t)&&(ft.has(t.name.text)||h.isIdentifier(t.expression)&&ft.has(t.expression.text)))}function Yr(t,e){for(let r of t.properties){if(!h.isPropertyAssignment(r)||!h.isIdentifier(r.name)||r.name.text!=="tags"&&r.name.text!=="tag")continue;let{initializer:i}=r,n=h.isArrayLiteralExpression(i)?i.elements.filter(h.isStringLiteral):r.name.text==="tag"&&h.isStringLiteral(i)?[i]:[];for(let s of n)e.tags.add({name:s.text.replace(/^@/,""),kind:"comment-marker"})}}function ut(t,e,r){let i=[],n=new Map,s=new Set,o=m.createSourceFile(t,e,m.ScriptTarget.Latest,!0,r==="typescript"?m.ScriptKind.TSX:m.ScriptKind.JSX),a={filePath:t,imports:i,exports:n,tags:s,rawCallEdges:[],sourceFile:o,hasUI:!1,hasTypesOnly:!0,totalStatements:0,exportStatements:0},c=C=>{ii(C,a),m.forEachChild(C,c)};c(o);let l=gi(t,a);(l==="test"||l==="barrel")&&s.add({name:l,kind:"comment-marker"}),l!=="test"&&di(a,o);let p=o.statements[0],f=p?Zt(p):void 0,{complexity:u,cognitiveComplexity:d}=pt(o),y=ti(o);return{imports:i,exports:Array.from(n.values()),tags:Array.from(s),category:l,rawCallEdges:a.rawCallEdges??[],complexity:u,cognitiveComplexity:d,...y.length>0?{functions:y}:{},...f!==void 0?{description:f}:{}}}function ti(t){let e=[],r=(n,s)=>{let{complexity:o,cognitiveComplexity:a}=pt(s),c=t.getLineAndCharacterOfPosition(s.getStart(t)).line+1;e.push({name:n,line:c,complexity:o,cognitiveComplexity:a})},i=(n,s)=>{if(m.isFunctionDeclaration(n)&&n.name&&n.body?r(n.name.text,n):m.isVariableDeclaration(n)&&m.isIdentifier(n.name)&&n.initializer&&(m.isArrowFunction(n.initializer)||m.isFunctionExpression(n.initializer))?r(n.name.text,n.initializer):s&&m.isMethodDeclaration(n)&&m.isIdentifier(n.name)&&n.body?r(`${s}.${n.name.text}`,n):s&&m.isConstructorDeclaration(n)&&n.body?r(`${s}.constructor`,n):s&&m.isGetAccessorDeclaration(n)&&m.isIdentifier(n.name)&&n.body?r(`${s}.get ${n.name.text}`,n):s&&m.isSetAccessorDeclaration(n)&&m.isIdentifier(n.name)&&n.body&&r(`${s}.set ${n.name.text}`,n),m.isClassDeclaration(n)&&n.name){let o=n.name.text;m.forEachChild(n,a=>i(a,o));return}m.forEachChild(n,o=>i(o,s))};return i(t,void 0),e}function qt(t,e,r,i){let n={name:t},s=Zt(r);s!==void 0&&(n.doc=s);let o=ei(e);o!==void 0&&(n.flags=o);let a=ri(e,i);return a!==void 0&&(n.signature=a),n}function Zt(t){let e=m.getJSDocCommentsAndTags(t);for(let r of e)if(m.isJSDoc(r)&&r.comment)return m.getTextOfJSDocComment(r.comment)||void 0}function ei(t){let e=new Set(["deprecated","internal","public","alpha","beta"]),r=m.getJSDocTags(t).map(i=>i.tagName.text).filter(i=>e.has(i));return r.length>0?r:void 0}function ri(t,e){let r=m.createPrinter({removeComments:!0}),i=n=>r.printNode(m.EmitHint.Unspecified,n,e);if(m.isFunctionDeclaration(t)||m.isMethodDeclaration(t)){let n=t.parameters.map(i).join(", "),s=t.type?i(t.type):"void";return`${t.typeParameters?`<${t.typeParameters.map(a=>a.name.text).join(", ")}>`:""}(${n}) => ${s}`}if(m.isVariableDeclaration(t)){if(t.type)return i(t.type);if(t.initializer&&(m.isArrowFunction(t.initializer)||m.isFunctionExpression(t.initializer))){let n=t.initializer,s=n.parameters.map(i).join(", "),o=n.type?i(n.type):"unknown";return`(${s}) => ${o}`}return}if(m.isClassDeclaration(t)&&t.name)return`class ${t.name.text}`;if(m.isInterfaceDeclaration(t))return`interface ${t.name.text}`;if(m.isTypeAliasDeclaration(t))return i(t.type);if(m.isEnumDeclaration(t))return`enum ${t.name.text}`}function ii(t,e){ni(t,e),si(t,e),ai(t,e),ci(t,e),ui(t,e),Jt(t,e)}function ni(t,e){if(!m.isSourceFile(t))return;let r=t.statements.filter(i=>!m.isEmptyStatement(i));e.totalStatements=r.length,e.exportStatements=r.filter(i=>m.isExportDeclaration(i)||m.isExportAssignment(i)||gt(i)).length}function si(t,e){if(m.isJsxElement(t)||m.isJsxSelfClosingElement(t)||m.isJsxFragment(t)){e.hasUI=!0,e.hasTypesOnly=!1;return}if(m.isFunctionDeclaration(t)||m.isMethodDeclaration(t)||m.isArrowFunction(t)||m.isClassDeclaration(t)||m.isVariableStatement(t)||m.isEnumDeclaration(t)){e.hasTypesOnly=!1;return}m.isExportDeclaration(t)&&!oi(t)&&(e.hasTypesOnly=!1)}function oi(t){return t.isTypeOnly?!0:!t.exportClause||!m.isNamedExports(t.exportClause)?!1:t.exportClause.elements.every(e=>e.isTypeOnly)}function ai(t,e){if(!m.isImportDeclaration(t)||!t.moduleSpecifier||!m.isStringLiteral(t.moduleSpecifier))return;let r=[];if(t.importClause&&(t.importClause.name&&r.push("default"),t.importClause.namedBindings))if(m.isNamedImports(t.importClause.namedBindings))for(let n of t.importClause.namedBindings.elements)r.push(n.name.text);else m.isNamespaceImport(t.importClause.namedBindings)&&r.push("*");let i=r.length>0?"static":"side-effect";e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:t.moduleSpecifier.text,isStyle:N(t.moduleSpecifier.text),type:i,symbols:r.length>0?r:void 0})}function ci(t,e){m.isExportDeclaration(t)?li(t,e):m.isExportAssignment(t)?e.exports.set("default",{name:"default"}):gt(t)&&fi(t,e)}function li(t,e){if(t.moduleSpecifier&&m.isStringLiteral(t.moduleSpecifier))mi(t,t.moduleSpecifier.text,e);else if(t.exportClause&&m.isNamedExports(t.exportClause))for(let r of t.exportClause.elements){let i=r.name.text;e.exports.set(i,{name:i})}}function mi(t,e,r){let i=pi(t),n={fromPath:r.filePath,toPath:"",rawSpecifier:e,isStyle:N(e),type:"re-export"};i.length>0&&(n.symbols=i),r.imports.push(n)}function pi(t){return t.exportClause?m.isNamedExports(t.exportClause)?t.exportClause.elements.map(e=>e.name.text):[]:["*"]}function fi(t,e){if((m.isFunctionDeclaration(t)||m.isClassDeclaration(t)||m.isInterfaceDeclaration(t)||m.isTypeAliasDeclaration(t)||m.isEnumDeclaration(t))&&t.name){let i=t.name.text;e.exports.set(i,qt(i,t,t,e.sourceFile));return}if(m.isVariableStatement(t)){for(let i of t.declarationList.declarations)if(m.isIdentifier(i.name)){let n=i.name.text;e.exports.set(n,qt(n,i,t,e.sourceFile))}}}function ui(t,e){if(!m.isCallExpression(t))return;let r=t.arguments[0];!r||!m.isStringLiteral(r)||(t.expression.kind===m.SyntaxKind.ImportKeyword?e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:N(r.text),type:"dynamic"}):m.isIdentifier(t.expression)&&t.expression.text==="require"&&e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:N(r.text),type:"require"}))}function gi(t,e){let r=Vt.basename(t).toLowerCase(),i=Vt.extname(t).toLowerCase();return ct().some(s=>r.includes(s))?"test":Wt(r)?"config":e.imports.some(s=>lt().some(o=>s.rawSpecifier.includes(o)))?"test":i===".tsx"||i===".jsx"||e.hasUI?"ui":e.hasTypesOnly&&e.totalStatements>0?"type-only":e.totalStatements>0&&e.exportStatements/e.totalStatements>mt()?"barrel":"logic"}function gt(t){return m.canHaveModifiers(t)&&m.getModifiers(t)?.some(e=>e.kind===m.SyntaxKind.ExportKeyword)===!0}function di(t,e){let r=t.rawCallEdges??[];t.rawCallEdges=r;let i=new Map;for(let n of e.statements){if(!m.isImportDeclaration(n)||!m.isStringLiteral(n.moduleSpecifier))continue;let s=n.moduleSpecifier.text,o=n.importClause;if(o&&(o.name&&i.set(o.name.text,s),o.namedBindings&&m.isNamedImports(o.namedBindings)))for(let a of o.namedBindings.elements)i.set(a.name.text,s)}if(i.size!==0)for(let n of e.statements){let s=xi(n);if(s){let o=Si(n);o&&Q(o,s,i,r);continue}m.isClassDeclaration(n)&&n.name&&yi(n,n.name.text,i,r)}}function yi(t,e,r,i){for(let n of t.members)m.isMethodDeclaration(n)&&n.body&&m.isIdentifier(n.name)?Q(n.body,`${e}.${n.name.text}`,r,i):m.isConstructorDeclaration(n)&&n.body&&Q(n.body,`${e}.constructor`,r,i)}function xi(t){if(gt(t)){if(m.isFunctionDeclaration(t)&&t.name)return t.name.text;if(m.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(m.isIdentifier(e.name)&&e.initializer&&(m.isArrowFunction(e.initializer)||m.isFunctionExpression(e.initializer)))return e.name.text}}}function Si(t){if(m.isFunctionDeclaration(t))return t.body;if(m.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(e.initializer&&(m.isArrowFunction(e.initializer)||m.isFunctionExpression(e.initializer)))return e.initializer}}function Q(t,e,r,i){if(m.isCallExpression(t)&&m.isIdentifier(t.expression)){let n=t.expression.text,s=r.get(n);s&&!i.some(o=>o.from===e&&o.to===n&&o.toSpecifier===s)&&i.push({from:e,to:n,toSpecifier:s})}m.forEachChild(t,n=>Q(n,e,r,i))}function X(t,e){if(e.length===0)return"ui";let r=!1;return t.walk(i=>{if(i.type==="rule")return r=!0,!1}),r?"ui":"barrel"}import Ut from"postcss";import*as hi from"postcss-less";var Ci=hi,Ht=new Set(["reference","inline"]);function Gt(t){return t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||t.startsWith("data:")}function bi(t){let e=t.trim();return e.length>0&&!e.startsWith("http://")&&!e.startsWith("https://")&&!e.startsWith("//")&&!e.startsWith("data:")&&!e.startsWith("#")}function Ni(t,e){let r=t.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(r){let s=r[1]?.trim()??"",o=r[2]??"";if(!o)return null;let a=Ht.has(s)?"side-effect":"static";return{fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:a,...Gt(o)?{isExternal:!0}:{}}}let i=t.match(/^url\(['"]?([^'")]+)['"]?\)/),n=i?i[1]?.trim()??"":t.match(/^['"]([^'"]+)['"]/)?.[1]??"";return n?{fromPath:e,toPath:"",rawSpecifier:n,isStyle:!0,type:"static",...Gt(n)?{isExternal:!0}:{}}:null}function Ei(t,e){let r=[],i=/url\(['"]?([^'")]+)['"]?\)/g,n=i.exec(t);for(;n!==null;){let s=n[1]?.trim()??"";bi(s)&&r.push({fromPath:e,toPath:"",rawSpecifier:s,isStyle:!0,type:"static"}),n=i.exec(t)}return r}function Qt(t,e){let r=[];return t.walk(i=>{if(i.type==="atrule"&&i.name==="import"){let n=Ni(i.params,e);n&&r.push(n)}i.type==="decl"&&r.push(...Ei(i.value,e))}),r}function wi(t){return t.replace(/(?<!:)\/\/.*/g,"")}function vi(t,e){let r=[],i=/@import\s+(?:\(([^)]+)\)\s+)?['"]([^'"]+)['"]/g,n=i.exec(t);for(;n!==null;){let s=n[1]?.trim()??"",o=n[2]??"";if(o){let a=Ht.has(s)?"side-effect":"static";r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:a})}n=i.exec(t)}return r}function Xt(t,e){let r=Ut.parse(wi(t));return{imports:Qt(r,e),root:r}}function ki(t){let e=[],r=[];for(let i of t.nodes??[]){if(i.type!=="atrule")continue;let{value:n}=i;if(n===void 0)continue;let s=i.name;s&&(e.push({name:s}),r.push({name:s,kind:"variable"}))}return{exports:e,tags:r}}function Yt(t,e){try{let r=Ci.parse(t),{exports:i,tags:n}=ki(r);return{imports:Qt(r,e),root:r,exports:i,tags:n}}catch{return{imports:vi(t,e),root:Ut.parse(""),exports:[],tags:[]}}}import{parse as Ti}from"postcss-scss";function te(t){return t.startsWith("_")||t.startsWith("-")}function Ii(t){return!!(t.startsWith("sass:")||t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||!t.startsWith(".")&&!t.startsWith("/")&&!t.startsWith("_"))}function Pi(t){let e=t.match(/^['"]([^'"]+)['"]/);if(!e?.[1])return{specifier:""};let r=e[1],n=t.match(/\bas\s+(\S+)/)?.[1];return n!==void 0?{specifier:r,alias:n}:{specifier:r}}function Fi(t){let e=[],r=[];for(let i of t.nodes??[]){if(i.type==="decl"&&i.prop.startsWith("$")){let n=i.prop.slice(1);if(!n||te(n))continue;e.push({name:n}),r.push({name:n,kind:"variable"});continue}if(i.type==="atrule"&&(i.name==="mixin"||i.name==="function")){let s=i.params.match(/^([\w-]+)/)?.[1];if(!s||te(s))continue;let o=i.params.trim();e.push(o.includes("(")?{name:s,signature:o}:{name:s}),r.push({name:s,kind:"function"})}}return{exports:e,tags:r}}function ee(t,e){let r=Ti(t),i=[];r.walk(o=>{if(o.type!=="atrule")return;let{name:a,params:c}=o;if(a!=="import"&&a!=="use"&&a!=="forward")return;let{specifier:l,alias:p}=Pi(c);if(!l)return;let f={fromPath:e,toPath:"",rawSpecifier:l,isStyle:!0,type:a==="forward"?"re-export":"static",...Ii(l)?{isExternal:!0}:{}};p&&(f.symbols=[p]),i.push(f)});let{exports:n,tags:s}=Fi(r);return{imports:i,root:r,exports:n,tags:s}}function re(t,e){let r=[],i=/@require\s+['"]([^'"]+)['"]/g,n=i.exec(t);for(;n!==null;){let o=n[1];o&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"require"}),n=i.exec(t)}let s=/(?<!@)(?:import|require)\s*\(?\s*['"]([^'"]+)['"]/g;for(n=s.exec(t);n!==null;){let o=n[1];o&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"static"}),n=s.exec(t)}return r}function ie(t,e){if(e.length===0)return"ui";try{let r=se("stylus");return new r.Parser(t).parse().nodes.some(s=>s.constructor.name!=="Import")?"ui":"barrel"}catch{return t.replace(/^\s*@?(?:require|import)\b.*/gm,"").trim().length>0?"ui":"barrel"}}function Z(t,e){let r=J(t);if(r==="stylus"){let s=re(e,t);return{imports:s,exports:[],tags:[],category:ie(e,s)}}if(r==="scss"){let{imports:s,root:o,exports:a,tags:c}=ee(e,t);return{imports:s,exports:a,tags:c,category:X(o,s)}}if(r==="less"){let{imports:s,root:o,exports:a,tags:c}=Yt(e,t);return{imports:s,exports:a,tags:c,category:X(o,s)}}let{imports:i,root:n}=Xt(e,t);return{imports:i,exports:[],tags:[],category:X(n,i)}}for(let[t,e]of[["javascript",(r,i)=>ut(r,i,"javascript")],["typescript",(r,i)=>ut(r,i,"typescript")],["css",Z],["scss",Z],["less",Z],["stylus",Z],["coffeescript",St],["livescript",At],["lua",Rt],["python",Bt],["go",vt],["java",Ft],["kotlin",Dt],["scala",jt],["groovy",kt],["gherkin",tt],["markdown",Mt]])V(t,e);async function ne(t,e){let r=J(t),i=Ct(r);return i?i(t,e):{imports:[],exports:[],tags:[],category:"other"}}function Di(t){return ne(t.filePath,t.content)}export{Di as default};
|
|
7
7
|
//# sourceMappingURL=parse-worker.mjs.map
|