typescript.min.js 7.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*! `typescript` grammar compiled for Highlight.js 11.7.0 */
  2. (()=>{var e=(()=>{"use strict"
  3. ;const e="[A-Za-z$_][0-9A-Za-z$_]*",n=["as","in","of","if","for","while","finally","var","new","function","do","return","void","else","break","catch","instanceof","with","throw","case","default","try","switch","continue","typeof","delete","let","yield","const","class","debugger","async","await","static","import","from","export","extends"],a=["true","false","null","undefined","NaN","Infinity"],t=["Object","Function","Boolean","Symbol","Math","Date","Number","BigInt","String","RegExp","Array","Float32Array","Float64Array","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Int32Array","Uint16Array","Uint32Array","BigInt64Array","BigUint64Array","Set","Map","WeakSet","WeakMap","ArrayBuffer","SharedArrayBuffer","Atomics","DataView","JSON","Promise","Generator","GeneratorFunction","AsyncFunction","Reflect","Proxy","Intl","WebAssembly"],s=["Error","EvalError","InternalError","RangeError","ReferenceError","SyntaxError","TypeError","URIError"],c=["setInterval","setTimeout","clearInterval","clearTimeout","require","exports","eval","isFinite","isNaN","parseFloat","parseInt","decodeURI","decodeURIComponent","encodeURI","encodeURIComponent","escape","unescape"],r=["arguments","this","super","console","window","document","localStorage","module","global"],i=[].concat(c,t,s)
  4. ;function o(o){const l=o.regex,d=e,b={begin:/<[A-Za-z0-9\\._:-]+/,
  5. end:/\/[A-Za-z0-9\\._:-]+>|\/>/,isTrulyOpeningTag:(e,n)=>{
  6. const a=e[0].length+e.index,t=e.input[a]
  7. ;if("<"===t||","===t)return void n.ignoreMatch();let s
  8. ;">"===t&&(((e,{after:n})=>{const a="</"+e[0].slice(1)
  9. ;return-1!==e.input.indexOf(a,n)})(e,{after:a})||n.ignoreMatch())
  10. ;const c=e.input.substring(a)
  11. ;((s=c.match(/^\s*=/))||(s=c.match(/^\s+extends\s+/))&&0===s.index)&&n.ignoreMatch()
  12. }},g={$pattern:e,keyword:n,literal:a,built_in:i,"variable.language":r
  13. },u="\\.([0-9](_?[0-9])*)",m="0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*",E={
  14. className:"number",variants:[{
  15. begin:`(\\b(${m})((${u})|\\.)?|(${u}))[eE][+-]?([0-9](_?[0-9])*)\\b`},{
  16. begin:`\\b(${m})\\b((${u})\\b|\\.)?|(${u})\\b`},{
  17. begin:"\\b(0|[1-9](_?[0-9])*)n\\b"},{
  18. begin:"\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b"},{
  19. begin:"\\b0[bB][0-1](_?[0-1])*n?\\b"},{begin:"\\b0[oO][0-7](_?[0-7])*n?\\b"},{
  20. begin:"\\b0[0-7]+n?\\b"}],relevance:0},y={className:"subst",begin:"\\$\\{",
  21. end:"\\}",keywords:g,contains:[]},A={begin:"html`",end:"",starts:{end:"`",
  22. returnEnd:!1,contains:[o.BACKSLASH_ESCAPE,y],subLanguage:"xml"}},p={
  23. begin:"css`",end:"",starts:{end:"`",returnEnd:!1,
  24. contains:[o.BACKSLASH_ESCAPE,y],subLanguage:"css"}},_={className:"string",
  25. begin:"`",end:"`",contains:[o.BACKSLASH_ESCAPE,y]},N={className:"comment",
  26. variants:[o.COMMENT(/\/\*\*(?!\/)/,"\\*/",{relevance:0,contains:[{
  27. begin:"(?=@[A-Za-z]+)",relevance:0,contains:[{className:"doctag",
  28. begin:"@[A-Za-z]+"},{className:"type",begin:"\\{",end:"\\}",excludeEnd:!0,
  29. excludeBegin:!0,relevance:0},{className:"variable",begin:d+"(?=\\s*(-)|$)",
  30. endsParent:!0,relevance:0},{begin:/(?=[^\n])\s/,relevance:0}]}]
  31. }),o.C_BLOCK_COMMENT_MODE,o.C_LINE_COMMENT_MODE]
  32. },f=[o.APOS_STRING_MODE,o.QUOTE_STRING_MODE,A,p,_,{match:/\$\d+/},E]
  33. ;y.contains=f.concat({begin:/\{/,end:/\}/,keywords:g,contains:["self"].concat(f)
  34. });const h=[].concat(N,y.contains),v=h.concat([{begin:/\(/,end:/\)/,keywords:g,
  35. contains:["self"].concat(h)}]),S={className:"params",begin:/\(/,end:/\)/,
  36. excludeBegin:!0,excludeEnd:!0,keywords:g,contains:v},w={variants:[{
  37. match:[/class/,/\s+/,d,/\s+/,/extends/,/\s+/,l.concat(d,"(",l.concat(/\./,d),")*")],
  38. scope:{1:"keyword",3:"title.class",5:"keyword",7:"title.class.inherited"}},{
  39. match:[/class/,/\s+/,d],scope:{1:"keyword",3:"title.class"}}]},R={relevance:0,
  40. match:l.either(/\bJSON/,/\b[A-Z][a-z]+([A-Z][a-z]*|\d)*/,/\b[A-Z]{2,}([A-Z][a-z]+|\d)+([A-Z][a-z]*)*/,/\b[A-Z]{2,}[a-z]+([A-Z][a-z]+|\d)*([A-Z][a-z]*)*/),
  41. className:"title.class",keywords:{_:[...t,...s]}},x={variants:[{
  42. match:[/function/,/\s+/,d,/(?=\s*\()/]},{match:[/function/,/\s*(?=\()/]}],
  43. className:{1:"keyword",3:"title.function"},label:"func.def",contains:[S],
  44. illegal:/%/},k={
  45. match:l.concat(/\b/,(O=[...c,"super","import"],l.concat("(?!",O.join("|"),")")),d,l.lookahead(/\(/)),
  46. className:"title.function",relevance:0};var O;const I={
  47. begin:l.concat(/\./,l.lookahead(l.concat(d,/(?![0-9A-Za-z$_(])/))),end:d,
  48. excludeBegin:!0,keywords:"prototype",className:"property",relevance:0},C={
  49. match:[/get|set/,/\s+/,d,/(?=\()/],className:{1:"keyword",3:"title.function"},
  50. contains:[{begin:/\(\)/},S]
  51. },T="(\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)|"+o.UNDERSCORE_IDENT_RE+")\\s*=>",M={
  52. match:[/const|var|let/,/\s+/,d,/\s*/,/=\s*/,/(async\s*)?/,l.lookahead(T)],
  53. keywords:"async",className:{1:"keyword",3:"title.function"},contains:[S]}
  54. ;return{name:"Javascript",aliases:["js","jsx","mjs","cjs"],keywords:g,exports:{
  55. PARAMS_CONTAINS:v,CLASS_REFERENCE:R},illegal:/#(?![$_A-z])/,
  56. contains:[o.SHEBANG({label:"shebang",binary:"node",relevance:5}),{
  57. label:"use_strict",className:"meta",relevance:10,
  58. begin:/^\s*['"]use (strict|asm)['"]/
  59. },o.APOS_STRING_MODE,o.QUOTE_STRING_MODE,A,p,_,N,{match:/\$\d+/},E,R,{
  60. className:"attr",begin:d+l.lookahead(":"),relevance:0},M,{
  61. begin:"("+o.RE_STARTERS_RE+"|\\b(case|return|throw)\\b)\\s*",
  62. keywords:"return throw case",relevance:0,contains:[N,o.REGEXP_MODE,{
  63. className:"function",begin:T,returnBegin:!0,end:"\\s*=>",contains:[{
  64. className:"params",variants:[{begin:o.UNDERSCORE_IDENT_RE,relevance:0},{
  65. className:null,begin:/\(\s*\)/,skip:!0},{begin:/\(/,end:/\)/,excludeBegin:!0,
  66. excludeEnd:!0,keywords:g,contains:v}]}]},{begin:/,/,relevance:0},{match:/\s+/,
  67. relevance:0},{variants:[{begin:"<>",end:"</>"},{
  68. match:/<[A-Za-z0-9\\._:-]+\s*\/>/},{begin:b.begin,
  69. "on:begin":b.isTrulyOpeningTag,end:b.end}],subLanguage:"xml",contains:[{
  70. begin:b.begin,end:b.end,skip:!0,contains:["self"]}]}]},x,{
  71. beginKeywords:"while if switch catch for"},{
  72. begin:"\\b(?!function)"+o.UNDERSCORE_IDENT_RE+"\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)\\s*\\{",
  73. returnBegin:!0,label:"func.def",contains:[S,o.inherit(o.TITLE_MODE,{begin:d,
  74. className:"title.function"})]},{match:/\.\.\./,relevance:0},I,{match:"\\$"+d,
  75. relevance:0},{match:[/\bconstructor(?=\s*\()/],className:{1:"title.function"},
  76. contains:[S]},k,{relevance:0,match:/\b[A-Z][A-Z_0-9]+\b/,
  77. className:"variable.constant"},w,C,{match:/\$[(.]/}]}}return t=>{
  78. const s=o(t),c=["any","void","number","boolean","string","object","never","symbol","bigint","unknown"],l={
  79. beginKeywords:"namespace",end:/\{/,excludeEnd:!0,
  80. contains:[s.exports.CLASS_REFERENCE]},d={beginKeywords:"interface",end:/\{/,
  81. excludeEnd:!0,keywords:{keyword:"interface extends",built_in:c},
  82. contains:[s.exports.CLASS_REFERENCE]},b={$pattern:e,
  83. keyword:n.concat(["type","namespace","interface","public","private","protected","implements","declare","abstract","readonly","enum","override"]),
  84. literal:a,built_in:i.concat(c),"variable.language":r},g={className:"meta",
  85. begin:"@[A-Za-z$_][0-9A-Za-z$_]*"},u=(e,n,a)=>{
  86. const t=e.contains.findIndex((e=>e.label===n))
  87. ;if(-1===t)throw Error("can not find mode to replace");e.contains.splice(t,1,a)}
  88. ;return Object.assign(s.keywords,b),
  89. s.exports.PARAMS_CONTAINS.push(g),s.contains=s.contains.concat([g,l,d]),
  90. u(s,"shebang",t.SHEBANG()),u(s,"use_strict",{className:"meta",relevance:10,
  91. begin:/^\s*['"]use strict['"]/
  92. }),s.contains.find((e=>"func.def"===e.label)).relevance=0,Object.assign(s,{
  93. name:"TypeScript",aliases:["ts","tsx"]}),s}})()
  94. ;hljs.registerLanguage("typescript",e)})();