forgeplus-react/ui/js/codemirror/mode/jsx/jsx.min.js

3 lines
2.4 KiB
JavaScript

// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/5/LICENSE
(function(d){"object"==typeof exports&&"object"==typeof module?d(require("../../lib/codemirror"),require("../xml/xml"),require("../javascript/javascript")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../xml/xml","../javascript/javascript"],d):d(CodeMirror)})(function(d){function l(d,l,n,p){this.state=d;this.mode=l;this.depth=n;this.prev=p}function q(e){return new l(d.copyState(e.mode,e.state),e.mode,e.depth,e.prev&&q(e.prev))}d.defineMode("jsx",function(e,m){function n(a){var c=a.tagName;a.tagName=null;var b=g.indent(a,"","");a.tagName=c;return b}function p(a,c){if(c.context.mode==g)return r(a,c,c.context);var b=c.context;if("\x3c"==a.peek()&&!a.match(/^<([^<>]|<[^>]*>)+,\s*>/,!1)&&h.expressionAllowed(a,b.state))c.context=new l(d.startState(g,h.indent(b.state,"","")),g,0,c.context),h.skipExpression(b.state),c=null;else{var e=h.token(a,b.state);e||null==b.depth||(a=a.current(),"{"==a?b.depth++:"}"==a&&0==--b.depth&&(c.context=c.context.prev));c=e}return c}function r(a,c,b){if(2==b.depth)return a.match(/^.*?\*\//)?b.depth=1:a.skipToEnd(),"comment";if("{"==a.peek()){g.skipAttribute(b.state);var k=n(b.state),f=b.state.context;if(f&&a.match(/^[^>]*>\s*$/,!1)){for(;f.prev&&!f.startOfLine;)f=f.prev;f.startOfLine?k-=e.indentUnit:b.prev.state.lexical&&(k=b.prev.state.lexical.indented)}else 1==b.depth&&(k+=e.indentUnit);c.context=new l(d.startState(h,k),h,0,c.context);return null}if(1==b.depth){if("\x3c"==a.peek())return g.skipAttribute(b.state),c.context=new l(d.startState(g,n(b.state)),g,0,c.context),null;if(a.match("//"))return a.skipToEnd(),"comment";if(a.match("/*"))return b.depth=2,p(a,c)}var k=g.token(a,b.state),f=a.current(),m;/\btag\b/.test(k)?/>$/.test(f)?b.state.context?b.depth=0:c.context=c.context.prev:/^</.test(f)&&(b.depth=1):!k&&-1<(m=f.indexOf("{"))&&a.backUp(f.length-m);return k}var g=d.getMode(e,{name:"xml",allowMissing:!0,multilineTagIndentPastTag:!1,allowMissingTagName:!0}),h=d.getMode(e,m&&m.base||"javascript");return{startState:function(){return{context:new l(d.startState(h),h)}},copyState:function(a){return{context:q(a.context)}},token:p,indent:function(a,c,b){return a.context.mode.indent(a.context.state,c,b)},innerMode:function(a){return a.context}}},"xml","javascript");d.defineMIME("text/jsx","jsx");d.defineMIME("text/typescript-jsx",{name:"jsx",base:{name:"javascript",typescript:!0}})});