1 | const KEYWORDS = [
|
2 | "as",
|
3 | "in",
|
4 | "of",
|
5 | "if",
|
6 | "for",
|
7 | "while",
|
8 | "finally",
|
9 | "var",
|
10 | "new",
|
11 | "function",
|
12 | "do",
|
13 | "return",
|
14 | "void",
|
15 | "else",
|
16 | "break",
|
17 | "catch",
|
18 | "instanceof",
|
19 | "with",
|
20 | "throw",
|
21 | "case",
|
22 | "default",
|
23 | "try",
|
24 | "switch",
|
25 | "continue",
|
26 | "typeof",
|
27 | "delete",
|
28 | "let",
|
29 | "yield",
|
30 | "const",
|
31 | "class",
|
32 |
|
33 |
|
34 |
|
35 | "debugger",
|
36 | "async",
|
37 | "await",
|
38 | "static",
|
39 | "import",
|
40 | "from",
|
41 | "export",
|
42 | "extends"
|
43 | ];
|
44 | const LITERALS = [
|
45 | "true",
|
46 | "false",
|
47 | "null",
|
48 | "undefined",
|
49 | "NaN",
|
50 | "Infinity"
|
51 | ];
|
52 |
|
53 |
|
54 | const TYPES = [
|
55 |
|
56 | "Object",
|
57 | "Function",
|
58 | "Boolean",
|
59 | "Symbol",
|
60 |
|
61 | "Math",
|
62 | "Date",
|
63 | "Number",
|
64 | "BigInt",
|
65 |
|
66 | "String",
|
67 | "RegExp",
|
68 |
|
69 | "Array",
|
70 | "Float32Array",
|
71 | "Float64Array",
|
72 | "Int8Array",
|
73 | "Uint8Array",
|
74 | "Uint8ClampedArray",
|
75 | "Int16Array",
|
76 | "Int32Array",
|
77 | "Uint16Array",
|
78 | "Uint32Array",
|
79 | "BigInt64Array",
|
80 | "BigUint64Array",
|
81 |
|
82 | "Set",
|
83 | "Map",
|
84 | "WeakSet",
|
85 | "WeakMap",
|
86 |
|
87 | "ArrayBuffer",
|
88 | "SharedArrayBuffer",
|
89 | "Atomics",
|
90 | "DataView",
|
91 | "JSON",
|
92 |
|
93 | "Promise",
|
94 | "Generator",
|
95 | "GeneratorFunction",
|
96 | "AsyncFunction",
|
97 |
|
98 | "Reflect",
|
99 | "Proxy",
|
100 |
|
101 | "Intl",
|
102 |
|
103 | "WebAssembly"
|
104 | ];
|
105 |
|
106 | const ERROR_TYPES = [
|
107 | "Error",
|
108 | "EvalError",
|
109 | "InternalError",
|
110 | "RangeError",
|
111 | "ReferenceError",
|
112 | "SyntaxError",
|
113 | "TypeError",
|
114 | "URIError"
|
115 | ];
|
116 |
|
117 | const BUILT_IN_GLOBALS = [
|
118 | "setInterval",
|
119 | "setTimeout",
|
120 | "clearInterval",
|
121 | "clearTimeout",
|
122 |
|
123 | "require",
|
124 | "exports",
|
125 |
|
126 | "eval",
|
127 | "isFinite",
|
128 | "isNaN",
|
129 | "parseFloat",
|
130 | "parseInt",
|
131 | "decodeURI",
|
132 | "decodeURIComponent",
|
133 | "encodeURI",
|
134 | "encodeURIComponent",
|
135 | "escape",
|
136 | "unescape"
|
137 | ];
|
138 |
|
139 | const BUILT_INS = [].concat(
|
140 | BUILT_IN_GLOBALS,
|
141 | TYPES,
|
142 | ERROR_TYPES
|
143 | );
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | function livescript(hljs) {
|
156 | const LIVESCRIPT_BUILT_INS = [
|
157 | 'npm',
|
158 | 'print'
|
159 | ];
|
160 | const LIVESCRIPT_LITERALS = [
|
161 | 'yes',
|
162 | 'no',
|
163 | 'on',
|
164 | 'off',
|
165 | 'it',
|
166 | 'that',
|
167 | 'void'
|
168 | ];
|
169 | const LIVESCRIPT_KEYWORDS = [
|
170 | 'then',
|
171 | 'unless',
|
172 | 'until',
|
173 | 'loop',
|
174 | 'of',
|
175 | 'by',
|
176 | 'when',
|
177 | 'and',
|
178 | 'or',
|
179 | 'is',
|
180 | 'isnt',
|
181 | 'not',
|
182 | 'it',
|
183 | 'that',
|
184 | 'otherwise',
|
185 | 'from',
|
186 | 'to',
|
187 | 'til',
|
188 | 'fallthrough',
|
189 | 'case',
|
190 | 'enum',
|
191 | 'native',
|
192 | 'list',
|
193 | 'map',
|
194 | '__hasProp',
|
195 | '__extends',
|
196 | '__slice',
|
197 | '__bind',
|
198 | '__indexOf'
|
199 | ];
|
200 | const KEYWORDS$1 = {
|
201 | keyword: KEYWORDS.concat(LIVESCRIPT_KEYWORDS),
|
202 | literal: LITERALS.concat(LIVESCRIPT_LITERALS),
|
203 | built_in: BUILT_INS.concat(LIVESCRIPT_BUILT_INS)
|
204 | };
|
205 | const JS_IDENT_RE = '[A-Za-z$_](?:-[0-9A-Za-z$_]|[0-9A-Za-z$_])*';
|
206 | const TITLE = hljs.inherit(hljs.TITLE_MODE, {
|
207 | begin: JS_IDENT_RE
|
208 | });
|
209 | const SUBST = {
|
210 | className: 'subst',
|
211 | begin: /#\{/,
|
212 | end: /\}/,
|
213 | keywords: KEYWORDS$1
|
214 | };
|
215 | const SUBST_SIMPLE = {
|
216 | className: 'subst',
|
217 | begin: /#[A-Za-z$_]/,
|
218 | end: /(?:-[0-9A-Za-z$_]|[0-9A-Za-z$_])*/,
|
219 | keywords: KEYWORDS$1
|
220 | };
|
221 | const EXPRESSIONS = [
|
222 | hljs.BINARY_NUMBER_MODE,
|
223 | {
|
224 | className: 'number',
|
225 | begin: '(\\b0[xX][a-fA-F0-9_]+)|(\\b\\d(\\d|_\\d)*(\\.(\\d(\\d|_\\d)*)?)?(_*[eE]([-+]\\d(_\\d|\\d)*)?)?[_a-z]*)',
|
226 | relevance: 0,
|
227 | starts: {
|
228 | end: '(\\s*/)?',
|
229 | relevance: 0
|
230 | }
|
231 | },
|
232 | {
|
233 | className: 'string',
|
234 | variants: [
|
235 | {
|
236 | begin: /'''/,
|
237 | end: /'''/,
|
238 | contains: [hljs.BACKSLASH_ESCAPE]
|
239 | },
|
240 | {
|
241 | begin: /'/,
|
242 | end: /'/,
|
243 | contains: [hljs.BACKSLASH_ESCAPE]
|
244 | },
|
245 | {
|
246 | begin: /"""/,
|
247 | end: /"""/,
|
248 | contains: [
|
249 | hljs.BACKSLASH_ESCAPE,
|
250 | SUBST,
|
251 | SUBST_SIMPLE
|
252 | ]
|
253 | },
|
254 | {
|
255 | begin: /"/,
|
256 | end: /"/,
|
257 | contains: [
|
258 | hljs.BACKSLASH_ESCAPE,
|
259 | SUBST,
|
260 | SUBST_SIMPLE
|
261 | ]
|
262 | },
|
263 | {
|
264 | begin: /\\/,
|
265 | end: /(\s|$)/,
|
266 | excludeEnd: true
|
267 | }
|
268 | ]
|
269 | },
|
270 | {
|
271 | className: 'regexp',
|
272 | variants: [
|
273 | {
|
274 | begin: '//',
|
275 | end: '//[gim]*',
|
276 | contains: [
|
277 | SUBST,
|
278 | hljs.HASH_COMMENT_MODE
|
279 | ]
|
280 | },
|
281 | {
|
282 |
|
283 |
|
284 | begin: /\/(?![ *])(\\.|[^\\\n])*?\/[gim]*(?=\W)/
|
285 | }
|
286 | ]
|
287 | },
|
288 | {
|
289 | begin: '@' + JS_IDENT_RE
|
290 | },
|
291 | {
|
292 | begin: '``',
|
293 | end: '``',
|
294 | excludeBegin: true,
|
295 | excludeEnd: true,
|
296 | subLanguage: 'javascript'
|
297 | }
|
298 | ];
|
299 | SUBST.contains = EXPRESSIONS;
|
300 |
|
301 | const PARAMS = {
|
302 | className: 'params',
|
303 | begin: '\\(',
|
304 | returnBegin: true,
|
305 | |
306 |
|
307 | contains: [
|
308 | {
|
309 | begin: /\(/,
|
310 | end: /\)/,
|
311 | keywords: KEYWORDS$1,
|
312 | contains: ['self'].concat(EXPRESSIONS)
|
313 | }
|
314 | ]
|
315 | };
|
316 |
|
317 | const SYMBOLS = {
|
318 | begin: '(#=>|=>|\\|>>|-?->|!->)'
|
319 | };
|
320 |
|
321 | return {
|
322 | name: 'LiveScript',
|
323 | aliases: ['ls'],
|
324 | keywords: KEYWORDS$1,
|
325 | illegal: /\/\*/,
|
326 | contains: EXPRESSIONS.concat([
|
327 | hljs.COMMENT('\\/\\*', '\\*\\/'),
|
328 | hljs.HASH_COMMENT_MODE,
|
329 | SYMBOLS,
|
330 | {
|
331 | className: 'function',
|
332 | contains: [
|
333 | TITLE,
|
334 | PARAMS
|
335 | ],
|
336 | returnBegin: true,
|
337 | variants: [
|
338 | {
|
339 | begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?(\\(.*\\)\\s*)?\\B->\\*?',
|
340 | end: '->\\*?'
|
341 | },
|
342 | {
|
343 | begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?!?(\\(.*\\)\\s*)?\\B[-~]{1,2}>\\*?',
|
344 | end: '[-~]{1,2}>\\*?'
|
345 | },
|
346 | {
|
347 | begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?(\\(.*\\)\\s*)?\\B!?[-~]{1,2}>\\*?',
|
348 | end: '!?[-~]{1,2}>\\*?'
|
349 | }
|
350 | ]
|
351 | },
|
352 | {
|
353 | className: 'class',
|
354 | beginKeywords: 'class',
|
355 | end: '$',
|
356 | illegal: /[:="\[\]]/,
|
357 | contains: [
|
358 | {
|
359 | beginKeywords: 'extends',
|
360 | endsWithParent: true,
|
361 | illegal: /[:="\[\]]/,
|
362 | contains: [TITLE]
|
363 | },
|
364 | TITLE
|
365 | ]
|
366 | },
|
367 | {
|
368 | begin: JS_IDENT_RE + ':',
|
369 | end: ':',
|
370 | returnBegin: true,
|
371 | returnEnd: true,
|
372 | relevance: 0
|
373 | }
|
374 | ])
|
375 | };
|
376 | }
|
377 |
|
378 | export { livescript as default };
|