1 | Prism.languages.javascript = Prism.languages.extend('clike', {
|
2 | 'class-name': [
|
3 | Prism.languages.clike['class-name'],
|
4 | {
|
5 | pattern: /(^|[^$\w\xA0-\uFFFF])[_$A-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\.(?:prototype|constructor))/,
|
6 | lookbehind: true
|
7 | }
|
8 | ],
|
9 | 'keyword': [
|
10 | {
|
11 | pattern: /((?:^|})\s*)(?:catch|finally)\b/,
|
12 | lookbehind: true
|
13 | },
|
14 | {
|
15 | pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|for|from|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/,
|
16 | lookbehind: true
|
17 | },
|
18 | ],
|
19 | 'number': /\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,
|
20 |
|
21 | 'function': /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
|
22 | 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
|
23 | });
|
24 |
|
25 | Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/;
|
26 |
|
27 | Prism.languages.insertBefore('javascript', 'keyword', {
|
28 | 'regex': {
|
29 | pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
|
30 | lookbehind: true,
|
31 | greedy: true,
|
32 | inside: {
|
33 | 'regex-source': {
|
34 | pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
|
35 | lookbehind: true,
|
36 | alias: 'language-regex',
|
37 | inside: Prism.languages.regex
|
38 | },
|
39 | 'regex-flags': /[a-z]+$/,
|
40 | 'regex-delimiter': /^\/|\/$/
|
41 | }
|
42 | },
|
43 |
|
44 | 'function-variable': {
|
45 | pattern: /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/,
|
46 | alias: 'function'
|
47 | },
|
48 | 'parameter': [
|
49 | {
|
50 | pattern: /(function(?:\s+[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\))/,
|
51 | lookbehind: true,
|
52 | inside: Prism.languages.javascript
|
53 | },
|
54 | {
|
55 | pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=>)/i,
|
56 | inside: Prism.languages.javascript
|
57 | },
|
58 | {
|
59 | pattern: /(\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*=>)/,
|
60 | lookbehind: true,
|
61 | inside: Prism.languages.javascript
|
62 | },
|
63 | {
|
64 | 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]))(?:[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*\{)/,
|
65 | lookbehind: true,
|
66 | inside: Prism.languages.javascript
|
67 | }
|
68 | ],
|
69 | 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
|
70 | });
|
71 |
|
72 | Prism.languages.insertBefore('javascript', 'string', {
|
73 | 'template-string': {
|
74 | pattern: /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}|(?!\${)[^\\`])*`/,
|
75 | greedy: true,
|
76 | inside: {
|
77 | 'template-punctuation': {
|
78 | pattern: /^`|`$/,
|
79 | alias: 'string'
|
80 | },
|
81 | 'interpolation': {
|
82 | pattern: /((?:^|[^\\])(?:\\{2})*)\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}/,
|
83 | lookbehind: true,
|
84 | inside: {
|
85 | 'interpolation-punctuation': {
|
86 | pattern: /^\${|}$/,
|
87 | alias: 'punctuation'
|
88 | },
|
89 | rest: Prism.languages.javascript
|
90 | }
|
91 | },
|
92 | 'string': /[\s\S]+/
|
93 | }
|
94 | }
|
95 | });
|
96 |
|
97 | if (Prism.languages.markup) {
|
98 | Prism.languages.markup.tag.addInlined('script', 'javascript');
|
99 | }
|
100 |
|
101 | Prism.languages.js = Prism.languages.javascript;
|