22 lines
11 KiB
JavaScript
22 lines
11 KiB
JavaScript
|
(function(n){"object"==typeof exports&&"object"==typeof module?n(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],n):n(CodeMirror)})(function(n){n.defineMode("javascript",function(ka,p){var D,k,l,r;function m(a,c,e){B=a;E=e;return c}function s(a,c){var e=a.next();if('"'==e||"'"==e)return c.tokenize=la(e),c.tokenize(a,c);if("."==e&&a.match(/^\d+(?:[eE][+\-]?\d+)?/))return m("number","number");if("."==e&&a.match(".."))return m("spread","meta");if(/[\[\]{}\(\),;\:\.]/.test(e))return m(e);
|
|||
|
if("="==e&&a.eat(">"))return m("=>","operator");if("0"==e&&a.eat(/x/i))return a.eatWhile(/[\da-f]/i),m("number","number");if(/\d/.test(e))return a.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/),m("number","number");if("/"==e){if(a.eat("*"))return c.tokenize=F,F(a,c);if(a.eat("/"))return a.skipToEnd(),m("comment","comment");if("operator"==c.lastType||"keyword c"==c.lastType||"sof"==c.lastType||/^[\[{}\(,;:]$/.test(c.lastType)){a:for(var e=!1,d,b=!1;null!=(d=a.next());){if(!e){if("/"==d&&!b)break a;"["==
|
|||
|
d?b=!0:b&&"]"==d&&(b=!1)}e=!e&&"\\"==d}a.eatWhile(/[gimy]/);return m("regexp","string-2")}a.eatWhile(L);return m("operator","operator",a.current())}if("`"==e)return c.tokenize=M,M(a,c);if("#"==e)return a.skipToEnd(),m("error","error");if(L.test(e))return a.eatWhile(L),m("operator","operator",a.current());a.eatWhile(/[\w\$_]/);e=a.current();return(d=X.propertyIsEnumerable(e)&&X[e])&&"."!=c.lastType?m(d.type,d.style,e):m("variable","variable",e)}function la(a){return function(c,e){var d=!1,b;if(G&&
|
|||
|
"@"==c.peek()&&c.match(ma))return e.tokenize=s,m("jsonld-keyword","meta");for(;null!=(b=c.next())&&(b!=a||d);)d=!d&&"\\"==b;d||(e.tokenize=s);return m("string","string")}}function F(a,c){for(var e=!1,d;d=a.next();){if("/"==d&&e){c.tokenize=s;break}e="*"==d}return m("comment","comment")}function M(a,c){for(var e=!1,d;null!=(d=a.next());){if(!e&&("`"==d||"$"==d&&a.eat("{"))){c.tokenize=s;break}e=!e&&"\\"==d}return m("quasi","string-2",a.current())}function N(a,c){c.fatArrowAt&&(c.fatArrowAt=null);var e=
|
|||
|
a.string.indexOf("=>",a.start);if(!(0>e)){for(var d=0,b=!1,e=e-1;0<=e;--e){var f=a.string.charAt(e),g=na.indexOf(f);if(0<=g&&3>g){if(!d){++e;break}if(0==--d)break}else if(3<=g&&6>g)++d;else if(/[$\w]/.test(f))b=!0;else if(b&&!d){++e;break}}b&&!d&&(c.fatArrowAt=e)}}function Y(a,c,e,d,b,f){this.indented=a;this.column=c;this.type=e;this.prev=b;this.info=f;null!=d&&(this.align=d)}function f(){for(var a=arguments.length-1;0<=a;a--)D.push(arguments[a])}function b(){f.apply(null,arguments);return!0}function t(a){function c(c){for(;c;c=
|
|||
|
c.next)if(c.name==a)return!0;return!1}var b=k;b.context?(l="def",c(b.localVars)||(b.localVars={name:a,next:b.localVars})):!c(b.globalVars)&&p.globalVars&&(b.globalVars={name:a,next:b.globalVars})}function u(){k.context={prev:k.context,vars:k.localVars};k.localVars=oa}function v(){k.localVars=k.context.vars;k.context=k.context.prev}function h(a,c){var b=function(){var b=k,e=b.indented;"stat"==b.lexical.type&&(e=b.lexical.indented);b.lexical=new Y(e,r.column(),a,null,b.lexical,c)};b.lex=!0;return b}
|
|||
|
function g(){var a=k;a.lexical.prev&&(")"==a.lexical.type&&(a.indented=a.lexical.indented),a.lexical=a.lexical.prev)}function i(a){function c(e){return e==a?b():";"==a?f():b(c)}return c}function o(a,c){return"var"==a?b(h("vardef",c.length),O,i(";"),g):"keyword a"==a?b(h("form"),j,o,g):"keyword b"==a?b(h("form"),o,g):"{"==a?b(h("}"),P,g):";"==a?b():"if"==a?("else"==k.lexical.info&&k.cc[k.cc.length-1]==g&&k.cc.pop()(),b(h("form"),j,o,g,Z)):"function"==a?b(w):"for"==a?b(h("form"),$,o,g):"variable"==
|
|||
|
a?b(h("stat"),pa):"switch"==a?b(h("form"),j,h("}","switch"),i("{"),P,g,g):"case"==a?b(j,i(":")):"default"==a?b(i(":")):"catch"==a?b(h("form"),u,i("("),Q,i(")"),o,g,v):"module"==a?b(h("form"),u,qa,v,g):"class"==a?b(h("form"),ra,sa,g):"export"==a?b(h("form"),ta,g):"import"==a?b(h("form"),ua,g):f(h("stat"),j,i(";"),g)}function j(a){return aa(a,!1)}function q(a){return aa(a,!0)}function aa(a,c){if(k.fatArrowAt==r.start){var e=c?ba:ca;if("("==a)return b(u,h(")"),C(x,")"),g,i("=>"),e,v);if("variable"==
|
|||
|
a)return f(u,x,i("=>"),e,v)}e=c?R:H;return da.hasOwnProperty(a)?b(e):"function"==a?b(w,e):"keyword c"==a?b(c?va:S):"("==a?b(h(")"),S,I,i(")"),g,e):"operator"==a||"spread"==a?b(c?q:j):"["==a?b(h("]"),wa,g,e):"{"==a?y(ea,"}",null,e):"quasi"==a?f(J,e):b()}function S(a){return a.match(/[;\}\)\],]/)?f():f(j)}function va(a){return a.match(/[;\}\)\],]/)?f():f(q)}function H(a,c){return","==a?b(j):R(a,c,!1)}function R(a,c,e){var d=!1==e?H:R,W=!1==e?j:q;if("=>"==c)return b(u,e?ba:ca,v);if("operator"==a)return/\+\+|--/.test(c)?
|
|||
|
b(d):"?"==c?b(j,i(":"),W):b(W);if("quasi"==a)return f(J,d);if(";"!=a){if("("==a)return y(q,")","call",d);if("."==a)return b(xa,d);if("["==a)return b(h("]"),S,i("]"),g,d)}}function J(a,c){return"quasi"!=a?f():"${"!=c.slice(c.length-2)?b(J):b(j,ya)}function ya(a){if("}"==a)return l="string-2",k.tokenize=M,b(J)}function ca(a){N(r,k);return"{"==a?f(o):f(j)}function ba(a){N(r,k);return"{"==a?f(o):f(q)}function pa(a){return":"==a?b(g,o):f(H,i(";"),g)}function xa(a){if("variable"==a)return l="property",
|
|||
|
b()}function ea(a,c){if("variable"==a){if(l="property","get"==c||"set"==c)return b(za)}else if("number"==a||"string"==a)l=G?"property":a+" property";else if("["==a)return b(j,i("]"),T);if(da.hasOwnProperty(a))return b(T)}function za(a){if("variable"!=a)return f(T);l="property";return b(w)}function T(a){if(":"==a)return b(q);if("("==a)return f(w)}function C(a,c){function e(d){return","==d?(d=k.lexical,"call"==d.info&&(d.pos=(d.pos||0)+1),b(a,e)):d==c?b():b(i(c))}return function(d){return d==c?b():
|
|||
|
f(a,e)}}function y(a,c,e){for(var d=3;d<arguments.length;d++)D.push(arguments[d]);return b(h(c,e),C(a,c),g)}function P(a){return"}"==a?b():f(o,P)}function fa(a){if(ga&&":"==a)return b(Aa)}function Aa(a){if("variable"==a)return l="variable-3",b()}function O(){return f(x,fa,U,Ba)}function x(a,c){if("variable"==a)return t(c),b();if("["==a)return y(x,"]");if("{"==a)return y(Ca,"}")}function Ca(a,c){if("variable"==a&&!r.match(/^\s*:/,!1))return t(c),b(U);"variable"==a&&(l="property");return b(i(":"),x,
|
|||
|
U)}function U(a,c){if("="==c)return b(q)}function Ba(a){if(","==a)return b(O)}function Z(a,c){if("keyword b"==a&&"else"==c)return b(h("form","else"),o,g)}function $(a){if("("==a)return b(h(")"),Da,i(")"),g)}function Da(a){return"var"==a?b(O,i(";"),K):";"==a?b(K):"variable"==a?b(Ea):f(j,i(";"),K)}function Ea(a,c){return"in"==c||"of"==c?(l="keyword",b(j)):b(H,K)}function K(a,c){return";"==a?b(ha):"in"==c||"of"==c?(l="keyword",b(j)):f(j,i(";"),ha)}function ha(a){")"!=a&&b(j)}function w(a,c){if("*"==
|
|||
|
c)return l="keyword",b(w);if("variable"==a)return t(c),b(w);if("("==a)return b(u,h(")"),C(Q,")"),g,o,v)}function Q(a){return"spread"==a?b(Q):f(x,fa)}function ra(a,c){if("variable"==a)return t(c),b(Fa)}function Fa(a,c){if("extends"==c)return b(j)}function sa(a){if("{"==a)return y(ea,"}")}function qa(a,c){if("string"==a)return b(o);if("variable"==a)return t(c),b(V)}function ta(a,c){return"*"==c?(l="keyword",b(V,i(";"))):"default"==c?(l="keyword",b(j,i(";"))):f(o)}function ua(a){return"string"==a?b():
|
|||
|
f(ia,V)}function ia(a,c){if("{"==a)return y(ia,"}");"variable"==a&&t(c);return b()}function V(a,c){if("from"==c)return l="keyword",b(j)}function wa(a){return"]"==a?b():f(q,Ga)}function Ga(a){return"for"==a?f(I,i("]")):","==a?b(C(q,"]")):f(C(q,"]"))}function I(a){if("for"==a)return b($,I);if("if"==a)return b(j,I)}var z=ka.indentUnit,ja=p.statementIndent,G=p.jsonld,A=p.json||G,ga=p.typescript,X=function(){function a(a){return{type:a,style:"keyword"}}var c=a("keyword a"),b=a("keyword b"),d=a("keyword c"),
|
|||
|
f=a("operator"),g={type:"atom",style:"atom"},c={"if":a("if"),"while":c,"with":c,"else":b,"do":b,"try":b,"finally":b,"return":d,"break":d,"continue":d,"new":d,"delete":d,"throw":d,"debugger":d,"var":a("var"),"const":a("var"),let:a("var"),"function":a("function"),"catch":a("catch"),"for":a("for"),"switch":a("switch"),"case":a("case"),"default":a("default"),"in":f,"typeof":f,"instanceof":f,"true":g,"false":g,"null":g,undefined:g,NaN:g,Infinity:g,"this":a("this"),module:a("module"),"class":a("class"),
|
|||
|
"super":a("atom"),yield:d,"export":a("export"),"import":a("import"),"extends":d};if(ga){var b={type:"variable",style:"variable-3"},b={"interface":a("interface"),"extends":a("extends"),constructor:a("constructor"),"public":a("public"),"private":a("private"),"protected":a("protected"),"static":a("static"),string:b,number:b,bool:b,any:b},h;for(h in b)c[h]=b[h]}return c}(),L=/[+\-*&%=<>!?|~^]/,ma=/^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/,B,E,na="([{}])",da=
|
|||
|
{atom:!0,number:!0,variable:!0,string:!0,regexp:!0,"this":!0,"jsonld-keyword":!0};D=l=k=null;r=void 0;var oa={name:"this",next:{name:"arguments"}};g.lex=!0;return{startState:function(a){a={tokenize:s,lastType:"sof",cc:[],lexical:new Y((a||0)-z,0,"block",!1),localVars:p.localVars,context:p.localVars&&{vars:p.localVars},indented:0};p.globalVars&&"object"==typeof p.globalVars&&(a.globalVars=p.globalVars);return a},token:function(a,b){a.sol()&&(b.lexical.hasOwnProperty("align")||(b.lexical.align=!1),
|
|||
|
b.indented=a.indentation(),N(a,b));if(b.tokenize!=F&&a.eatSpace())return null;var e=b.tokenize(a,b);if("comment"==B)return e;b.lastType="operator"==B&&("++"==E||"--"==E)?"incdec":B;var d;a:{var g=B,f=E,h=b.cc;k=b;r=a;l=null;D=h;b.lexical.hasOwnProperty("align")||(b.lexical.align=!0);for(;;)if((h.length?h.pop():A?j:o)(g,f)){for(;h.length&&h[h.length-1].lex;)h.pop()();if(l){d=l;break a}if(d="variable"==g)b:{for(d=b.localVars;d;d=d.next)if(d.name==f){d=!0;break b}for(g=b.context;g;g=g.prev)for(d=g.vars;d;d=
|
|||
|
d.next)if(d.name==f){d=!0;break b}d=void 0}if(d){d="variable-2";break a}d=e;break a}}return d},indent:function(a,b){if(a.tokenize==F)return n.Pass;if(a.tokenize!=s)return 0;var e=b&&b.charAt(0),d=a.lexical;if(!/^\s*else\b/.test(b))for(var f=a.cc.length-1;0<=f;--f){var h=a.cc[f];if(h==g)d=d.prev;else if(h!=Z)break}"stat"==d.type&&"}"==e&&(d=d.prev);ja&&(")"==d.type&&"stat"==d.prev.type)&&(d=d.prev);f=d.type;h=e==f;return"vardef"==f?d.indented+("operator"==a.lastType||","==a.lastType?d.info+1:0):"form"==
|
|||
|
f&&"{"==e?d.indented:"form"==f?d.indented+z:"stat"==f?d.indented+("operator"==a.lastType||","==a.lastType?ja||z:0):"switch"==d.info&&!h&&!1!=p.doubleIndentSwitch?d.indented+(/^(?:case|default)\b/.test(b)?z:2*z):d.align?d.column+(h?0:1):d.indented+(h?0:z)},electricChars:":{}",blockCommentStart:A?null:"/*",blockCommentEnd:A?null:"*/",lineComment:A?null:"//",fold:"brace",helperType:A?"json":"javascript",jsonldMode:G,jsonMode:A}});n.registerHelper("wordChars","javascript",/[\\w$]/);n.defineMIME("text/javascript",
|
|||
|
"javascript");n.defineMIME("text/ecmascript","javascript");n.defineMIME("application/javascript","javascript");n.defineMIME("application/ecmascript","javascript");n.defineMIME("application/json",{name:"javascript",json:!0});n.defineMIME("application/x-json",{name:"javascript",json:!0});n.defineMIME("application/ld+json",{name:"javascript",jsonld:!0});n.defineMIME("text/typescript",{name:"javascript",typescript:!0});n.defineMIME("application/typescript",{name:"javascript",typescript:!0})});
|