text: // TODO actually recognize syntax of TypeScript constructs
  CodeMirror.defineMode("javascript",function(e,t){function a(e){var t=!1,n,r=!1;while((n=e.next())!=null){if(!t){if(n=="/"&&!r)return;n=="["?r=!0:r&&n=="]"&&(r=!1)}t=!t&&n=="\\"}}function c(e,t,n){return f=e,l=n,t}function h(e,t){var n=e.next();if(n=='"'||n=="'")return t.tokenize=p(n),t.tokenize(e,t);if(n=="."&&e.match(/^\d+(?:[eE][+\-]?\d+)?/))return c("number","number");if(n=="."&&e.match(".."))return c("spread","meta");if(/[\[\]{}\(\),;\:\.]/.test(n))return c(n);if(n=="="&&e.eat(">"))return c("=>","operator");if(n=="0"&&e.eat(/x/i))return e.eatWhile(/[\da-f]/i),c("number","number");if(/\d/.test(n))return e.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/),c("number","number");if(n=="/")return e.eat("*")?(t.tokenize=d,d(e,t)):e.eat("/")?(e.skipToEnd(),c("comment","comment")):t.lastType=="operator"||t.lastType=="keyword c"||t.lastType=="sof"||/^[\[{}\(,;:]$/.test(t.lastType)?(a(e),e.eatWhile(/[gimy]/),c("regexp","string-2")):(e.eatWhile(u),c("operator","operator",e.current()));if(n=="`")return t.tokenize=v,v(e,t);if(n=="#")return e.skipToEnd(),c("error","error");if(u.test(n))return e.eatWhile(u),c("operator","operator",e.current());e.eatWhile(/[\w\$_]/);var r=e.current(),i=o.propertyIsEnumerable(r)&&o[r];return i&&t.lastType!="."?c(i.type,i.style,r):c("variable","variable",r)}function p(e){return function(t,n){var r=!1,i;while((i=t.next())!=null){if(i==e&&!r)break;r=!r&&i=="\\"}return r||(n.tokenize=h),c("string","string")}}function d(e,t){var n=!1,r;while(r=e.next()){if(r=="/"&&n){t.tokenize=h;break}n=r=="*"}return c("comment","comment")}function v(e,t){var n=!1,r;while((r=e.next())!=null){if(!n&&(r=="`"||r=="$"&&e.eat("{"))){t.tokenize=h;break}n=!n&&r=="\\"}return c("quasi","string-2",e.current())}function g(e,t){t.fatArrowAt&&(t.fatArrowAt=null);var n=e.string.indexOf("=>",e.start);if(n<0)return;var r=0,i=!1;for(var s=n-1;s>=0;--s){var o=e.string.charAt(s),u=m.indexOf(o);if(u>=0&&u<3){if(!r){++s;break}if(--r==0)break}else if(u>=3&&u<6)++r;else if(/[$\w]/.test(o))i=!0;else if(i&&!r){++s;break}}i&&!r&&(t.fatArrowAt=s)}function b(e,t,n,r,i,s){this.indented=e,this.column=t,this.type=n,this.prev=i,this.info=s,r!=null&&(this.align=r)}function w(e,t){for(var n=e.localVars;n;n=n.next)if(n.name==t)return!0;for(var r=e.context;r;r=r.prev)for(var n=r.vars;n;n=n.next)if(n.name==t)return!0}function E(e,t,n,r,s){var o=e.cc;S.state=e,S.stream=s,S.marked=null,S.cc=o,e.lexical.hasOwnProperty("align")||(e.lexical.align=!0);for(;;){var u=o.length?o.pop():i?D:_;if(u(n,r)){while(o.length&&o[o.length-1].lex)o.pop()();return S.marked?S.marked:n=="variable"&&w(e,r)?"variable-2":t}}}function x(){for(var e=arguments.length-1;e>=0;e--)S.cc.push(arguments[e])}function T(){return x.apply(null,arguments),!0}function N(e){function n(t){for(var n=t;n;n=n.next)if(n.name==e)return!0;return!1}var r=S.state;if(r.context){S.marked="def";if(n(r.localVars))return;r.localVars={name:e,next:r.localVars}}else{if(n(r.globalVars))return;t.globalVars&&(r.globalVars={name:e,next:r.globalVars})}}function k(){S.state.context={prev:S.state.context,vars:S.state.localVars},S.state.localVars=C}function L(){S.state.localVars=S.state.context.vars,S.state.context=S.state.context.prev}function A(e,t){var n=function(){var n=S.state,r=n.indented;n.lexical.type=="stat"&&(r=n.lexical.indented),n.lexical=new b(r,S.stream.column(),e,null,n.lexical,t)};return n.lex=!0,n}function O(){var e=S.state;e.lexical.prev&&(e.lexical.type==")"&&(e.indented=e.lexical.indented),e.lexical=e.lexical.prev)}function M(e){return function(t){return t==e?T():e==";"?x():T(arguments.callee)}}function _(e,t){return e=="var"?T(A("vardef",t.length),et,M(";"),O):e=="keyword a"?T(A("form"),D,_,O):e=="keyword b"?T(A("form"),_,O):e=="{"?T(A("}"),G,O):e==";"?T():e=="if"?T(A("form"),D,_,O,st):e=="function"?T(ct):e=="for"?T(A("form"),ot,_,O):e=="variable"?T(A("stat"),W):e=="switch"?T(A("form"),D,A("}","switch"),M("{"),G,O,O):e=="case"?T(D,M(":")):e=="default"?T(M(":")):e=="catch"?T(A("form"),k,M("("),ht,M(")"),_,O,L):e=="module"?T(A("form"),k,mt,L,O):e=="class"?T(A("form"),pt,vt,O):e=="export"?T(A("form"),gt,O):e=="import"?T(A("form"),yt,O):x(A("stat"),D,M(";"),O)}function D(e){return H(e,!1)}function P(e){return H(e,!0)}function H(e,t){if(S.state.fatArrowAt==S.stream.start){var n=t?z:U;if(e=="(")return T(k,A(")"),K(tt,")"),O,M("=>"),n,L);if(e=="variable")return x(k,tt,M("=>"),n,L)}var r=t?I:F;return y.hasOwnProperty(e)?T(r):e=="function"?T(ct):e=="keyword c"?T(t?j:B):e=="("?T(A(")"),B,xt,M(")"),O,r):e=="operator"||e=="spread"?T(t?P:D):e=="["?T(A("]"),Et,O,r):e=="{"?Q(V,"}",null,r):T()}function B(e){return e.match(/[;\}\)\],]/)?x():x(D)}function j(e){return e.match(/[;\}\)\],]/)?x():x(P)}function F(e,t){return e==","?T(D):I(e,t,!1)}function I(e,t,n){var r=n==0?F:I,i=n==0?D:P;if(t=="=>")return T(k,n?z:U,L);if(e=="operator")return/\+\+|--/.test(t)?T(r):t=="?"?T(D,M(":"),i):T(i);if(e=="quasi")return S.cc.push(r),q(t);if(e==";")return;if(e=="(")return Q(P,")","call",r);if(e==".")return T(X,r);if(e=="[")return T(A("]"),B,M("]"),O,r)}function q(e){return e.slice(e.length-2)!="${"?T():T(D,R)}function R(e){if(e=="}")return S.marked="string-2",S.state.tokenize=v,T()}function U(e){return g(S.stream,S.state),e=="{"?x(_):x(D)}function z(e){return g(S.stream,S.state),e=="{"?x(_):x(P)}function W(e){return e==":"?T(O,_):x(F,M(";"),O)}function X(e){if(e=="variable")return S.marked="property",T()}function V(e,t){if(e=="variable"){S.marked="property";if(t=="get"||t=="set")return T($)}else if(e=="number"||e=="string")S.marked=e+" property";else if(e=="[")return T(D,M("]"),J);if(y.hasOwnProperty(e))return T(J)}function $(e){return e!="variable"?x(J):(S.marked="property",T(ct))}function J(e){if(e==":")return T(P);if(e=="(")return x(ct)}function K(e,t){function n(r){if(r==","){var i=S.state.lexical;return i.info=="call"&&(i.pos=(i.pos||0)+1),T(e,n)}return r==t?T():T(M(t))}return function(r){return r==t?T():x(e,n)}}function Q(e,t,n){for(var r=3;r<arguments.length;r++)S.cc.push(arguments[r]);return T(A(t,n),K(e,t),O)}function G(e){return e=="}"?T():x(_,G)}function Y(e){if(s&&e==":")return T(Z)}function Z(e){if(e=="variable")return S.marked="variable-3",T()}function et(){return x(tt,Y,rt,it)}function tt(e,t){if(e=="variable")return N(t),T();if(e=="[")return Q(tt,"]");if(e=="{")return Q(nt,"}")}function nt(e,t){return e=="variable"&&!S.stream.match(/^\s*:/,!1)?(N(t),T(rt)):(e=="variable"&&(S.marked="property"),T(M(":"),tt,rt))}function rt(e,t){if(t=="=")return T(P)}function it(e){if(e==",")return T(et)}function st(e,t){if(e=="keyword b"&&t=="else")return T(A("form"),_,O)}function ot(e){if(e=="(")return T(A(")"),ut,M(")"),O)}function ut(e){return e=="var"?T(et,M(";"),ft):e==";"?T(ft):e=="variable"?T(at):x(D,M(";"),ft)}function at(e,t){return t=="in"||t=="of"?(S.marked="keyword",T(D)):T(F,ft)}function ft(e,t){return e==";"?T(lt):t=="in"||t=="of"?(S.marked="keyword",T(D)):x(D,M(";"),lt)}function lt(e){e!=")"&&T(D)}function ct(e,t){if(t=="*")return S.marked="keyword",T(ct);if(e=="variable")return N(t),T(ct);if(e=="(")return T(k,A(")"),K(ht,")"),O,_,L)}function ht(e){return e=="spread"?T(ht):x(tt,Y)}function pt(e,t){if(e=="variable")return N(t),T(dt)}function dt(e,t){if(t=="extends")return T(D)}function vt(e){if(e=="{")return Q(V,"}")}function mt(e,t){if(e=="string")return T(_);if(e=="variable")return N(t),T(wt)}function gt(e,t){return t=="*"?(S.marked="keyword",T(wt,M(";"))):t=="default"?(S.marked="keyword",T(D,M(";"))):x(_)}function yt(e){return e=="string"?T():x(bt,wt)}function bt(e,t){return e=="{"?Q(bt,"}"):(e=="variable"&&N(t),T())}function wt(e,t){if(t=="from")return S.marked="keyword",T(D)}function Et(e){return e=="]"?T():x(P,St)}function St(e){return e=="for"?x(xt,M("]")):e==","?T(K(P,"]")):x(K(P,"]"))}function xt(e){if(e=="for")return T(ot,xt);if(e=="if")return T(D,xt)}var n=e.indentUnit,r=t.statementIndent,i=t.json,s=t.typescript,o=function(){function e(e){return{type:e,style:"keyword"}}var t=e("keyword a"),n=e("keyword b"),r=e("keyword c"),i=e("operator"),o={type:"atom",style:"atom"},u={"if":e("if"),"while":t,"with":t,"else":n,"do":n,"try":n,"finally":n,"return":r,"break":r,"continue":r,"new":r,"delete":r,"throw":r,"debugger":r,"var":e("var"),"const":e("var"),let:e("var"),"function":e("function"),"catch":e("catch"),"for":e("for"),"switch":e("switch"),"case":e("case"),"default":e("default"),"in":i,"typeof":i,"instanceof":i,"true":o,"false":o,"null":o,"undefined":o,NaN:o,Infinity:o,"this":e("this"),module:e("module"),"class":e("class"),"super":e("atom"),yield:r,"export":e("export"),"import":e("import"),"extends":r};if(s){var a={type:"variable",style:"variable-3"},f={"interface":e("interface"),"extends":e("extends"),constructor:e("constructor"),"public":e("public"),"private":e("private"),"protected":e("protected"),"static":e("static"),string:a,number:a,bool:a,any:a};for(var l in f)u[l]=f[l]}return u}(),u=/[+\-*&%=<>!?|~^]/,f,l,m="([{}])",y={atom:!0,number:!0,variable:!0,string:!0,regexp:!0,"this":!0},S={state:null,column:null,marked:null,cc:null},C={name:"this",next:{name:"arguments"}};return O.lex=!0,{startState:function(e){var r={tokenize:h,lastType:"sof",cc:[],lexical:new b((e||0)-n,0,"block",!1),localVars:t.localVars,context:t.localVars&&{vars:t.localVars},indented:0};return t.globalVars&&(r.globalVars=t.globalVars),r},token:function(e,t){e.sol()&&(t.lexical.hasOwnProperty("align")||(t.lexical.align=!1),t.indented=e.indentation(),g(e,t));if(t.tokenize!=d&&e.eatSpace())return null;var n=t.tokenize(e,t);return f=="comment"?n:(t.lastType=f!="operator"||l!="++"&&l!="--"?f:"incdec",E(t,n,f,l,e))},indent:function(e,i){if(e.tokenize==d)return CodeMirror.Pass;if(e.tokenize!=h)return 0;var s=i&&i.charAt(0),o=e.lexical;for(var u=e.cc.length-1;u>=0;--u){var a=e.cc[u];if(a==O)o=o.prev;else if(a!=st)break}o.type=="stat"&&s=="}"&&(o=o.prev),r&&o.type==")"&&o.prev.type=="stat"&&(o=o.prev);var f=o.type,l=s==f;return f=="vardef"?o.indented+(e.lastType=="operator"||e.lastType==","?o.info+1:0):f=="form"&&s=="{"?o.indented:f=="form"?o.indented+n:f=="stat"?o.indented+(e.lastType=="operator"||e.lastType==","?r||n:0):o.info=="switch"&&!l&&t.doubleIndentSwitch!=0?o.indented+(/^(?:case|default)\b/.test(i)?n:2*n):o.align?o.column+(l?0:1):o.indented+(l?0:n)},electricChars:":{}",blockCommentStart:i?null:"/*",blockCommentEnd:i?null:"*/",lineComment:i?null:"//",fold:"brace",helperType:i?"json":"javascript",jsonMode:i}}),CodeMirror.defineMIME("text/javascript","javascript"),CodeMirror.defineMIME("text/ecmascript","javascript"),CodeMirror.defineMIME("application/javascript","javascript"),CodeMirror.defineMIME("application/ecmascript","javascript"),CodeMirror.defineMIME("application/json",{name:"javascript",json:!0}),CodeMirror.defineMIME("application/x-json",{name:"javascript",json:!0}),CodeMirror.defineMIME("text/typescript",{name:"javascript",typescript:!0}),CodeMirror.defineMIME("application/typescript",{name:"javascript",typescript:!0});