import{p as L}from"./vendor-lezer-javascript-D7Tj24ot.js";import{L as N,a as X,b as P,c as j,f as F,d as b,e as B,g as V,h as _,s as v,j as M}from"./vendor-codemirror-language-BgPj_McA.js";import{a as R}from"./vendor-codemirror-state-C9awkmn-.js";import{E as W}from"./vendor-codemirror-view-CiLROUVV.js";import{i as Z,c as z,s as p}from"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import{d as H,I as K}from"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";const I=[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=I.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"})]),k=new H,E=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 x(e,t){let r=k.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)||E.has(o.name))return!1}else if(o.to-o.from>8192){for(let l of x(e,o.node))n.push(l);return!1}}),k.set(t,n),n}const h=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,w=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName","JSXText","JSXAttributeValue","JSXOpenTag","JSXCloseTag","JSXSelfClosingTag",".","?."];function U(e){let t=v(e.state).resolveInner(e.pos,-1);if(w.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)E.has(a.name)&&(n=n.concat(x(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=v(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,""):w.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=e,n=[],a=new Set;for(let i=0;;i++){for(let l of(Object.getOwnPropertyNames||Object.keys)(e)){if(!/^[a-zA-Z_$\xaa-\uffdc][\w$\xaa-\uffdc]*$/.test(l)||a.has(l))continue;a.add(l);let c;try{c=r[l]}catch{continue}n.push({label:l,type:typeof c=="function"?/^[A-Z]/.test(l)?"class":t?"function":"method":t?"variable":"property",boost:-i})}let o=Object.getPrototypeOf(e);if(!o)return n;e=o}}function ve(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 u=P.define({name:"javascript",parser:L.configure({props:[j.add({IfStatement:b({except:/^\s*({|else\b)/}),TryStatement:b({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:F,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":b({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}}),V.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":_,BlockComment(e){return{from:e.from+2,to:e.to-2}},JSXElement(e){let t=e.firstChild;if(!t||t.name=="JSXSelfClosingTag")return null;let r=e.lastChild;return{from:t.to,to:r.type.isError?e.to:r.from}},"JSXSelfClosingTag JSXOpenTag"(e){var t;let r=(t=e.firstChild)===null||t===void 0?void 0:t.nextSibling,n=e.lastChild;return!r||r.type.isError?null:{from:r.to,to:n.type.isError?e.to:n.from}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),D={test:e=>/^JSX/.test(e.name),facet:M({commentTokens:{block:{open:"{/*",close:"*/}"}}})},te=u.configure({dialect:"ts"},"typescript"),ne=u.configure({dialect:"jsx",props:[X.add(e=>e.isTop?[D]:void 0)]}),re=u.configure({dialect:"jsx ts",props:[X.add(e=>e.isTop?[D]:void 0)]},"typescript");let O=e=>({label:e,type:"keyword"});const A="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(O),ae=A.concat(["declare","implements","private","protected","public"].map(O));function we(e={}){let t=e.jsx?e.typescript?re:ne:e.typescript?te:u,r=e.typescript?q.concat(ae):I.concat(A);return new N(t,[u.data.of({autocomplete:Z(w,z(r))}),u.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!="/"||!u.isActiveAt(e.state,t,-1))return!1;let i=a(),{state:o}=i,l=o.changeByRange(c=>{var m;let{head:s}=c,f=v(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,S=d.parent;if(S&&d.from==s-2&&((g=T(o.doc,S.firstChild,s))||((m=S.firstChild)===null||m===void 0?void 0:m.name)=="JSXFragmentTag")){let C=`${g}>`;return{range:R.cursor(s+C.length,-1),changes:{from:s,insert:C}}}}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 Ce(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 u.findRegions(n)){let l=n.doc.lineAt(i),c={line:l.number-1,col:i-l.from,pos:i};for(let m of e.verify(n.sliceDoc(i,o),t))a.push(se(m,n.doc,c))}return a}}function J(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=J(e.line,e.column,t,r),a={from:n,to:e.endLine!=null&&e.endColumn!=1?J(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(m,s){m.dispatch({changes:{from:s+l,to:s+c,insert:o},scrollIntoView:!0})}}]}return a}export{le as autoCloseTags,Y as completionPath,Ce as esLint,we as javascript,u as javascriptLanguage,ne as jsxLanguage,U as localCompletionSource,ve as scopeCompletionSource,I as snippets,re as tsxLanguage,te as typescriptLanguage,q as typescriptSnippets};
