prismjs_components_prism-javascript.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // node_modules/prismjs/components/prism-javascript.js
  2. Prism.languages.javascript = Prism.languages.extend("clike", {
  3. "class-name": [
  4. Prism.languages.clike["class-name"],
  5. {
  6. pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
  7. lookbehind: true
  8. }
  9. ],
  10. "keyword": [
  11. {
  12. pattern: /((?:^|\})\s*)catch\b/,
  13. lookbehind: true
  14. },
  15. {
  16. pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
  17. lookbehind: true
  18. }
  19. ],
  20. // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
  21. "function": /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
  22. "number": {
  23. pattern: RegExp(
  24. /(^|[^\w$])/.source + "(?:" + // constant
  25. (/NaN|Infinity/.source + "|" + // binary integer
  26. /0[bB][01]+(?:_[01]+)*n?/.source + "|" + // octal integer
  27. /0[oO][0-7]+(?:_[0-7]+)*n?/.source + "|" + // hexadecimal integer
  28. /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source + "|" + // decimal bigint
  29. /\d+(?:_\d+)*n/.source + "|" + // decimal number (integer or float) but no bigint
  30. /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source) + ")" + /(?![\w$])/.source
  31. ),
  32. lookbehind: true
  33. },
  34. "operator": /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
  35. });
  36. Prism.languages.javascript["class-name"][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
  37. Prism.languages.insertBefore("javascript", "keyword", {
  38. "regex": {
  39. pattern: RegExp(
  40. // lookbehind
  41. // eslint-disable-next-line regexp/no-dupe-characters-character-class
  42. /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source + // Regex pattern:
  43. // There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
  44. // classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
  45. // with the only syntax, so we have to define 2 different regex patterns.
  46. /\//.source + "(?:" + /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source + "|" + // `v` flag syntax. This supports 3 levels of nested character classes.
  47. /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source + ")" + // lookahead
  48. /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
  49. ),
  50. lookbehind: true,
  51. greedy: true,
  52. inside: {
  53. "regex-source": {
  54. pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
  55. lookbehind: true,
  56. alias: "language-regex",
  57. inside: Prism.languages.regex
  58. },
  59. "regex-delimiter": /^\/|\/$/,
  60. "regex-flags": /^[a-z]+$/
  61. }
  62. },
  63. // This must be declared before keyword because we use "function" inside the look-forward
  64. "function-variable": {
  65. pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
  66. alias: "function"
  67. },
  68. "parameter": [
  69. {
  70. pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
  71. lookbehind: true,
  72. inside: Prism.languages.javascript
  73. },
  74. {
  75. pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
  76. lookbehind: true,
  77. inside: Prism.languages.javascript
  78. },
  79. {
  80. pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
  81. lookbehind: true,
  82. inside: Prism.languages.javascript
  83. },
  84. {
  85. pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,
  86. lookbehind: true,
  87. inside: Prism.languages.javascript
  88. }
  89. ],
  90. "constant": /\b[A-Z](?:[A-Z_]|\dx?)*\b/
  91. });
  92. Prism.languages.insertBefore("javascript", "string", {
  93. "hashbang": {
  94. pattern: /^#!.*/,
  95. greedy: true,
  96. alias: "comment"
  97. },
  98. "template-string": {
  99. pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
  100. greedy: true,
  101. inside: {
  102. "template-punctuation": {
  103. pattern: /^`|`$/,
  104. alias: "string"
  105. },
  106. "interpolation": {
  107. pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
  108. lookbehind: true,
  109. inside: {
  110. "interpolation-punctuation": {
  111. pattern: /^\$\{|\}$/,
  112. alias: "punctuation"
  113. },
  114. rest: Prism.languages.javascript
  115. }
  116. },
  117. "string": /[\s\S]+/
  118. }
  119. },
  120. "string-property": {
  121. pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
  122. lookbehind: true,
  123. greedy: true,
  124. alias: "property"
  125. }
  126. });
  127. Prism.languages.insertBefore("javascript", "operator", {
  128. "literal-property": {
  129. pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
  130. lookbehind: true,
  131. alias: "property"
  132. }
  133. });
  134. if (Prism.languages.markup) {
  135. Prism.languages.markup.tag.addInlined("script", "javascript");
  136. Prism.languages.markup.tag.addAttribute(
  137. /on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,
  138. "javascript"
  139. );
  140. }
  141. Prism.languages.js = Prism.languages.javascript;
  142. //# sourceMappingURL=prismjs_components_prism-javascript.js.map