import{p as N}from"./vendor-lezer-javascript-BsA5KTFy.js";import{L as O,s as w,c as P,d as F,f as j,e as S,h as B,j as V,k as M,n as J,o as _}from"./cm-language-CDsY7zq0.js";import{E as R}from"./cm-state-X9WpHEQO.js";import{E as W}from"./cm-view-CiSFjroV.js";import{s as p,i as Z,c as z}from"./cm-autocomplete-t9rzw_D0.js";import{a as H,I as K}from"./vendor-lezer-common-tVQBIsvN.js";import"./vendor-lezer-lr-eZ5kYecM.js";import"./vendor-lezer-highlight-DuEf3ZFH.js";import"./vendor-style-mod-Bs6eFhZE.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";const X=[p("function ${name}(${params}) {\n	${}\n}",{label:"function",detail:"definition",type:"keyword"}),p("for (let ${index} = 0; ${index} < ${bound}; ${index}++) {\n	${}\n}",{label:"for",detail:"loop",type:"keyword"}),p("for (let ${name} of ${collection}) {\n	${}\n}",{label:"for",detail:"of loop",type:"keyword"}),p("do {\n	${}\n} while (${})",{label:"do",detail:"loop",type:"keyword"}),p("while (${}) {\n	${}\n}",{label:"while",detail:"loop",type:"keyword"}),p(`try {
	\${}
} catch (\${error}) {
	\${}
}`,{label:"try",detail:"/ catch block",type:"keyword"}),p("if (${}) {\n	${}\n}",{label:"if",detail:"block",type:"keyword"}),p(`if (\${}) {
	\${}
} else {
	\${}
}`,{label:"if",detail:"/ else block",type:"keyword"}),p(`class \${name} {
	constructor(\${params}) {
		\${}
	}
}`,{label:"class",detail:"definition",type:"keyword"}),p('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),p('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],q=X.concat([p("interface ${name} {\n	${}\n}",{label:"interface",detail:"definition",type:"keyword"}),p("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),p("enum ${name} {\n	${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),C=new H,x=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function y(e){return(t,r)=>{let n=t.node.getChild("VariableDefinition");return n&&r(n,e),!0}}const G=["FunctionDeclaration"],Q={FunctionDeclaration:y("function"),ClassDeclaration:y("class"),ClassExpression:()=>!0,EnumDeclaration:y("constant"),TypeAliasDeclaration:y("type"),NamespaceDeclaration:y("namespace"),VariableDefinition(e,t){e.matchContext(G)||t(e,"variable")},TypeDefinition(e,t){t(e,"type")},__proto__:null};function D(e,t){let r=C.get(t);if(r)return r;let n=[],a=!0;function i(o,l){let c=e.sliceString(o.from,o.to);n.push({label:c,type:l})}return t.cursor(K.IncludeAnonymous).iterate(o=>{if(a)a=!1;else if(o.name){let l=Q[o.name];if(l&&l(o,i)||x.has(o.name))return!1}else if(o.to-o.from>8192){for(let l of D(e,o.node))n.push(l);return!1}}),C.set(t,n),n}const h=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,k=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName","JSXText","JSXAttributeValue","JSXOpenTag","JSXCloseTag","JSXSelfClosingTag",".","?."];function U(e){let t=w(e.state).resolveInner(e.pos,-1);if(k.indexOf(t.name)>-1)return null;let r=t.name=="VariableName"||t.to-t.from<20&&h.test(e.state.sliceDoc(t.from,t.to));if(!r&&!e.explicit)return null;let n=[];for(let a=t;a;a=a.parent)x.has(a.name)&&(n=n.concat(D(e.state.doc,a)));return{options:n,from:r?t.from:e.pos,validFor:h}}function $(e,t,r){var n;let a=[];for(;;){let i=t.firstChild,o;if(i?.name=="VariableName")return a.push(e(i)),{path:a.reverse(),name:r};if(i?.name=="MemberExpression"&&((n=o=i.lastChild)===null||n===void 0?void 0:n.name)=="PropertyName")a.push(e(o)),t=i;else return null}}function Y(e){let t=n=>e.state.doc.sliceString(n.from,n.to),r=w(e.state).resolveInner(e.pos,-1);return r.name=="PropertyName"?$(t,r.parent,t(r)):(r.name=="."||r.name=="?.")&&r.parent.name=="MemberExpression"?$(t,r.parent,""):k.indexOf(r.name)>-1?null:r.name=="VariableName"||r.to-r.from<20&&h.test(t(r))?{path:[],name:t(r)}:r.name=="MemberExpression"?$(t,r,""):e.explicit?{path:[],name:""}:null}function ee(e,t){let r=[],n=new Set;for(let a=0;;a++){for(let o of(Object.getOwnPropertyNames||Object.keys)(e)){if(!/^[a-zA-Z_$\xaa-\uffdc][\w$\xaa-\uffdc]*$/.test(o)||n.has(o))continue;n.add(o);let l;try{l=e[o]}catch{continue}r.push({label:o,type:typeof l=="function"?/^[A-Z]/.test(o)?"class":t?"function":"method":t?"variable":"property",boost:-a})}let i=Object.getPrototypeOf(e);if(!i)return r;e=i}}function we(e){let t=new Map;return r=>{let n=Y(r);if(!n)return null;let a=e;for(let o of n.path)if(a=a[o],!a)return null;let i=t.get(a);return i||t.set(a,i=ee(a,!n.path.length)),{from:r.pos-n.name.length,options:i,validFor:h}}}const m=O.define({name:"javascript",parser:N.configure({props:[F.add({IfStatement:S({except:/^\s*({|else\b)/}),TryStatement:S({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:V,SwitchBody:e=>{let t=e.textAfter,r=/^\s*\}/.test(t),n=/^\s*(case|default)\b/.test(t);return e.baseIndent+(r?0:n?1:2)*e.unit},Block:B({closing:"}"}),ArrowFunction:e=>e.baseIndent+e.unit,"TemplateString BlockComment":()=>null,"Statement Property":S({except:/^\s*{/}),JSXElement(e){let t=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},JSXEscape(e){let t=/\s*\}/.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},"JSXOpenTag JSXSelfClosingTag"(e){return e.column(e.node.from)+e.unit}}),j.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":M,BlockComment(e){return{from:e.from+2,to:e.to-2}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),E={test:e=>/^JSX/.test(e.name),facet:_({commentTokens:{block:{open:"{/*",close:"*/}"}}})},te=m.configure({dialect:"ts"},"typescript"),ne=m.configure({dialect:"jsx",props:[J.add(e=>e.isTop?[E]:void 0)]}),re=m.configure({dialect:"jsx ts",props:[J.add(e=>e.isTop?[E]:void 0)]},"typescript");let A=e=>({label:e,type:"keyword"});const L="break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(A),ae=L.concat(["declare","implements","private","protected","public"].map(A));function ke(e={}){let t=e.jsx?e.typescript?re:ne:e.typescript?te:m,r=e.typescript?q.concat(ae):X.concat(L);return new P(t,[m.data.of({autocomplete:Z(k,z(r))}),m.data.of({autocomplete:U}),e.jsx?le:[]])}function oe(e){for(;;){if(e.name=="JSXOpenTag"||e.name=="JSXSelfClosingTag"||e.name=="JSXFragmentTag")return e;if(e.name=="JSXEscape"||!e.parent)return null;e=e.parent}}function T(e,t,r=e.length){for(let n=t?.firstChild;n;n=n.nextSibling)if(n.name=="JSXIdentifier"||n.name=="JSXBuiltin"||n.name=="JSXNamespacedName"||n.name=="JSXMemberExpression")return e.sliceString(n.from,Math.min(n.to,r));return""}const ie=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),le=W.inputHandler.of((e,t,r,n,a)=>{if((ie?e.composing:e.compositionStarted)||e.state.readOnly||t!=r||n!=">"&&n!="/"||!m.isActiveAt(e.state,t,-1))return!1;let i=a(),{state:o}=i,l=o.changeByRange(c=>{var u;let{head:s}=c,f=w(o).resolveInner(s-1,-1),g;if(f.name=="JSXStartTag"&&(f=f.parent),!(o.doc.sliceString(s-1,s)!=n||f.name=="JSXAttributeValue"&&f.to>s)){if(n==">"&&f.name=="JSXFragmentTag")return{range:c,changes:{from:s,insert:"</>"}};if(n=="/"&&f.name=="JSXStartCloseTag"){let d=f.parent,b=d.parent;if(b&&d.from==s-2&&((g=T(o.doc,b.firstChild,s))||((u=b.firstChild)===null||u===void 0?void 0:u.name)=="JSXFragmentTag")){let v=`${g}>`;return{range:R.cursor(s+v.length,-1),changes:{from:s,insert:v}}}}else if(n==">"){let d=oe(f);if(d&&d.name=="JSXOpenTag"&&!/^\/?>|^<\//.test(o.doc.sliceString(s,s+2))&&(g=T(o.doc,d,s)))return{range:c,changes:{from:s,insert:`</${g}>`}}}}return{range:c}});return l.changes.empty?!1:(e.dispatch([i,o.update(l,{userEvent:"input.complete",scrollIntoView:!0})]),!0)});function ve(e,t){return t||(t={parserOptions:{ecmaVersion:2019,sourceType:"module"},env:{browser:!0,node:!0,es6:!0,es2015:!0,es2017:!0,es2020:!0},rules:{}},e.getRules().forEach((r,n)=>{var a;!((a=r.meta.docs)===null||a===void 0)&&a.recommended&&(t.rules[n]=2)})),r=>{let{state:n}=r,a=[];for(let{from:i,to:o}of m.findRegions(n)){let l=n.doc.lineAt(i),c={line:l.number-1,col:i-l.from,pos:i};for(let u of e.verify(n.sliceDoc(i,o),t))a.push(se(u,n.doc,c))}return a}}function I(e,t,r,n){return r.line(e+n.line).from+t+(e==1?n.col-1:-1)}function se(e,t,r){let n=I(e.line,e.column,t,r),a={from:n,to:e.endLine!=null&&e.endColumn!=1?I(e.endLine,e.endColumn,t,r):n,message:e.message,source:e.ruleId?"eslint:"+e.ruleId:"eslint",severity:e.severity==1?"warning":"error"};if(e.fix){let{range:i,text:o}=e.fix,l=i[0]+r.pos-n,c=i[1]+r.pos-n;a.actions=[{name:"fix",apply(u,s){u.dispatch({changes:{from:s+l,to:s+c,insert:o},scrollIntoView:!0})}}]}return a}export{le as autoCloseTags,Y as completionPath,ve as esLint,ke as javascript,m as javascriptLanguage,ne as jsxLanguage,U as localCompletionSource,we as scopeCompletionSource,X as snippets,re as tsxLanguage,te as typescriptLanguage,q as typescriptSnippets};
