[d24f17c] | 1 | const KEYWORDS = [
|
---|
| 2 | "as", // for exports
|
---|
| 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 | // JS handles these with a special rule
|
---|
| 33 | // "get",
|
---|
| 34 | // "set",
|
---|
| 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 | const TYPES = [
|
---|
| 54 | "Intl",
|
---|
| 55 | "DataView",
|
---|
| 56 | "Number",
|
---|
| 57 | "Math",
|
---|
| 58 | "Date",
|
---|
| 59 | "String",
|
---|
| 60 | "RegExp",
|
---|
| 61 | "Object",
|
---|
| 62 | "Function",
|
---|
| 63 | "Boolean",
|
---|
| 64 | "Error",
|
---|
| 65 | "Symbol",
|
---|
| 66 | "Set",
|
---|
| 67 | "Map",
|
---|
| 68 | "WeakSet",
|
---|
| 69 | "WeakMap",
|
---|
| 70 | "Proxy",
|
---|
| 71 | "Reflect",
|
---|
| 72 | "JSON",
|
---|
| 73 | "Promise",
|
---|
| 74 | "Float64Array",
|
---|
| 75 | "Int16Array",
|
---|
| 76 | "Int32Array",
|
---|
| 77 | "Int8Array",
|
---|
| 78 | "Uint16Array",
|
---|
| 79 | "Uint32Array",
|
---|
| 80 | "Float32Array",
|
---|
| 81 | "Array",
|
---|
| 82 | "Uint8Array",
|
---|
| 83 | "Uint8ClampedArray",
|
---|
| 84 | "ArrayBuffer",
|
---|
| 85 | "BigInt64Array",
|
---|
| 86 | "BigUint64Array",
|
---|
| 87 | "BigInt"
|
---|
| 88 | ];
|
---|
| 89 |
|
---|
| 90 | const ERROR_TYPES = [
|
---|
| 91 | "EvalError",
|
---|
| 92 | "InternalError",
|
---|
| 93 | "RangeError",
|
---|
| 94 | "ReferenceError",
|
---|
| 95 | "SyntaxError",
|
---|
| 96 | "TypeError",
|
---|
| 97 | "URIError"
|
---|
| 98 | ];
|
---|
| 99 |
|
---|
| 100 | const BUILT_IN_GLOBALS = [
|
---|
| 101 | "setInterval",
|
---|
| 102 | "setTimeout",
|
---|
| 103 | "clearInterval",
|
---|
| 104 | "clearTimeout",
|
---|
| 105 |
|
---|
| 106 | "require",
|
---|
| 107 | "exports",
|
---|
| 108 |
|
---|
| 109 | "eval",
|
---|
| 110 | "isFinite",
|
---|
| 111 | "isNaN",
|
---|
| 112 | "parseFloat",
|
---|
| 113 | "parseInt",
|
---|
| 114 | "decodeURI",
|
---|
| 115 | "decodeURIComponent",
|
---|
| 116 | "encodeURI",
|
---|
| 117 | "encodeURIComponent",
|
---|
| 118 | "escape",
|
---|
| 119 | "unescape"
|
---|
| 120 | ];
|
---|
| 121 |
|
---|
| 122 | const BUILT_IN_VARIABLES = [
|
---|
| 123 | "arguments",
|
---|
| 124 | "this",
|
---|
| 125 | "super",
|
---|
| 126 | "console",
|
---|
| 127 | "window",
|
---|
| 128 | "document",
|
---|
| 129 | "localStorage",
|
---|
| 130 | "module",
|
---|
| 131 | "global" // Node.js
|
---|
| 132 | ];
|
---|
| 133 |
|
---|
| 134 | const BUILT_INS = [].concat(
|
---|
| 135 | BUILT_IN_GLOBALS,
|
---|
| 136 | BUILT_IN_VARIABLES,
|
---|
| 137 | TYPES,
|
---|
| 138 | ERROR_TYPES
|
---|
| 139 | );
|
---|
| 140 |
|
---|
| 141 | /*
|
---|
| 142 | Language: CoffeeScript
|
---|
| 143 | Author: Dmytrii Nagirniak <dnagir@gmail.com>
|
---|
| 144 | Contributors: Oleg Efimov <efimovov@gmail.com>, Cédric Néhémie <cedric.nehemie@gmail.com>
|
---|
| 145 | Description: CoffeeScript is a programming language that transcompiles to JavaScript. For info about language see http://coffeescript.org/
|
---|
| 146 | Category: common, scripting
|
---|
| 147 | Website: https://coffeescript.org
|
---|
| 148 | */
|
---|
| 149 |
|
---|
| 150 | /** @type LanguageFn */
|
---|
| 151 | function coffeescript(hljs) {
|
---|
| 152 | const COFFEE_BUILT_INS = [
|
---|
| 153 | 'npm',
|
---|
| 154 | 'print'
|
---|
| 155 | ];
|
---|
| 156 | const COFFEE_LITERALS = [
|
---|
| 157 | 'yes',
|
---|
| 158 | 'no',
|
---|
| 159 | 'on',
|
---|
| 160 | 'off'
|
---|
| 161 | ];
|
---|
| 162 | const COFFEE_KEYWORDS = [
|
---|
| 163 | 'then',
|
---|
| 164 | 'unless',
|
---|
| 165 | 'until',
|
---|
| 166 | 'loop',
|
---|
| 167 | 'by',
|
---|
| 168 | 'when',
|
---|
| 169 | 'and',
|
---|
| 170 | 'or',
|
---|
| 171 | 'is',
|
---|
| 172 | 'isnt',
|
---|
| 173 | 'not'
|
---|
| 174 | ];
|
---|
| 175 | const NOT_VALID_KEYWORDS = [
|
---|
| 176 | "var",
|
---|
| 177 | "const",
|
---|
| 178 | "let",
|
---|
| 179 | "function",
|
---|
| 180 | "static"
|
---|
| 181 | ];
|
---|
| 182 | const excluding = (list) =>
|
---|
| 183 | (kw) => !list.includes(kw);
|
---|
| 184 | const KEYWORDS$1 = {
|
---|
| 185 | keyword: KEYWORDS.concat(COFFEE_KEYWORDS).filter(excluding(NOT_VALID_KEYWORDS)),
|
---|
| 186 | literal: LITERALS.concat(COFFEE_LITERALS),
|
---|
| 187 | built_in: BUILT_INS.concat(COFFEE_BUILT_INS)
|
---|
| 188 | };
|
---|
| 189 | const JS_IDENT_RE = '[A-Za-z$_][0-9A-Za-z$_]*';
|
---|
| 190 | const SUBST = {
|
---|
| 191 | className: 'subst',
|
---|
| 192 | begin: /#\{/,
|
---|
| 193 | end: /\}/,
|
---|
| 194 | keywords: KEYWORDS$1
|
---|
| 195 | };
|
---|
| 196 | const EXPRESSIONS = [
|
---|
| 197 | hljs.BINARY_NUMBER_MODE,
|
---|
| 198 | hljs.inherit(hljs.C_NUMBER_MODE, {
|
---|
| 199 | starts: {
|
---|
| 200 | end: '(\\s*/)?',
|
---|
| 201 | relevance: 0
|
---|
| 202 | }
|
---|
| 203 | }), // a number tries to eat the following slash to prevent treating it as a regexp
|
---|
| 204 | {
|
---|
| 205 | className: 'string',
|
---|
| 206 | variants: [
|
---|
| 207 | {
|
---|
| 208 | begin: /'''/,
|
---|
| 209 | end: /'''/,
|
---|
| 210 | contains: [hljs.BACKSLASH_ESCAPE]
|
---|
| 211 | },
|
---|
| 212 | {
|
---|
| 213 | begin: /'/,
|
---|
| 214 | end: /'/,
|
---|
| 215 | contains: [hljs.BACKSLASH_ESCAPE]
|
---|
| 216 | },
|
---|
| 217 | {
|
---|
| 218 | begin: /"""/,
|
---|
| 219 | end: /"""/,
|
---|
| 220 | contains: [
|
---|
| 221 | hljs.BACKSLASH_ESCAPE,
|
---|
| 222 | SUBST
|
---|
| 223 | ]
|
---|
| 224 | },
|
---|
| 225 | {
|
---|
| 226 | begin: /"/,
|
---|
| 227 | end: /"/,
|
---|
| 228 | contains: [
|
---|
| 229 | hljs.BACKSLASH_ESCAPE,
|
---|
| 230 | SUBST
|
---|
| 231 | ]
|
---|
| 232 | }
|
---|
| 233 | ]
|
---|
| 234 | },
|
---|
| 235 | {
|
---|
| 236 | className: 'regexp',
|
---|
| 237 | variants: [
|
---|
| 238 | {
|
---|
| 239 | begin: '///',
|
---|
| 240 | end: '///',
|
---|
| 241 | contains: [
|
---|
| 242 | SUBST,
|
---|
| 243 | hljs.HASH_COMMENT_MODE
|
---|
| 244 | ]
|
---|
| 245 | },
|
---|
| 246 | {
|
---|
| 247 | begin: '//[gim]{0,3}(?=\\W)',
|
---|
| 248 | relevance: 0
|
---|
| 249 | },
|
---|
| 250 | {
|
---|
| 251 | // regex can't start with space to parse x / 2 / 3 as two divisions
|
---|
| 252 | // regex can't start with *, and it supports an "illegal" in the main mode
|
---|
| 253 | begin: /\/(?![ *]).*?(?![\\]).\/[gim]{0,3}(?=\W)/
|
---|
| 254 | }
|
---|
| 255 | ]
|
---|
| 256 | },
|
---|
| 257 | {
|
---|
| 258 | begin: '@' + JS_IDENT_RE // relevance booster
|
---|
| 259 | },
|
---|
| 260 | {
|
---|
| 261 | subLanguage: 'javascript',
|
---|
| 262 | excludeBegin: true,
|
---|
| 263 | excludeEnd: true,
|
---|
| 264 | variants: [
|
---|
| 265 | {
|
---|
| 266 | begin: '```',
|
---|
| 267 | end: '```'
|
---|
| 268 | },
|
---|
| 269 | {
|
---|
| 270 | begin: '`',
|
---|
| 271 | end: '`'
|
---|
| 272 | }
|
---|
| 273 | ]
|
---|
| 274 | }
|
---|
| 275 | ];
|
---|
| 276 | SUBST.contains = EXPRESSIONS;
|
---|
| 277 |
|
---|
| 278 | const TITLE = hljs.inherit(hljs.TITLE_MODE, {
|
---|
| 279 | begin: JS_IDENT_RE
|
---|
| 280 | });
|
---|
| 281 | const POSSIBLE_PARAMS_RE = '(\\(.*\\)\\s*)?\\B[-=]>';
|
---|
| 282 | const PARAMS = {
|
---|
| 283 | className: 'params',
|
---|
| 284 | begin: '\\([^\\(]',
|
---|
| 285 | returnBegin: true,
|
---|
| 286 | /* We need another contained nameless mode to not have every nested
|
---|
| 287 | pair of parens to be called "params" */
|
---|
| 288 | contains: [{
|
---|
| 289 | begin: /\(/,
|
---|
| 290 | end: /\)/,
|
---|
| 291 | keywords: KEYWORDS$1,
|
---|
| 292 | contains: ['self'].concat(EXPRESSIONS)
|
---|
| 293 | }]
|
---|
| 294 | };
|
---|
| 295 |
|
---|
| 296 | return {
|
---|
| 297 | name: 'CoffeeScript',
|
---|
| 298 | aliases: [
|
---|
| 299 | 'coffee',
|
---|
| 300 | 'cson',
|
---|
| 301 | 'iced'
|
---|
| 302 | ],
|
---|
| 303 | keywords: KEYWORDS$1,
|
---|
| 304 | illegal: /\/\*/,
|
---|
| 305 | contains: EXPRESSIONS.concat([
|
---|
| 306 | hljs.COMMENT('###', '###'),
|
---|
| 307 | hljs.HASH_COMMENT_MODE,
|
---|
| 308 | {
|
---|
| 309 | className: 'function',
|
---|
| 310 | begin: '^\\s*' + JS_IDENT_RE + '\\s*=\\s*' + POSSIBLE_PARAMS_RE,
|
---|
| 311 | end: '[-=]>',
|
---|
| 312 | returnBegin: true,
|
---|
| 313 | contains: [
|
---|
| 314 | TITLE,
|
---|
| 315 | PARAMS
|
---|
| 316 | ]
|
---|
| 317 | },
|
---|
| 318 | {
|
---|
| 319 | // anonymous function start
|
---|
| 320 | begin: /[:\(,=]\s*/,
|
---|
| 321 | relevance: 0,
|
---|
| 322 | contains: [{
|
---|
| 323 | className: 'function',
|
---|
| 324 | begin: POSSIBLE_PARAMS_RE,
|
---|
| 325 | end: '[-=]>',
|
---|
| 326 | returnBegin: true,
|
---|
| 327 | contains: [PARAMS]
|
---|
| 328 | }]
|
---|
| 329 | },
|
---|
| 330 | {
|
---|
| 331 | className: 'class',
|
---|
| 332 | beginKeywords: 'class',
|
---|
| 333 | end: '$',
|
---|
| 334 | illegal: /[:="\[\]]/,
|
---|
| 335 | contains: [
|
---|
| 336 | {
|
---|
| 337 | beginKeywords: 'extends',
|
---|
| 338 | endsWithParent: true,
|
---|
| 339 | illegal: /[:="\[\]]/,
|
---|
| 340 | contains: [TITLE]
|
---|
| 341 | },
|
---|
| 342 | TITLE
|
---|
| 343 | ]
|
---|
| 344 | },
|
---|
| 345 | {
|
---|
| 346 | begin: JS_IDENT_RE + ':',
|
---|
| 347 | end: ':',
|
---|
| 348 | returnBegin: true,
|
---|
| 349 | returnEnd: true,
|
---|
| 350 | relevance: 0
|
---|
| 351 | }
|
---|
| 352 | ])
|
---|
| 353 | };
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 | module.exports = coffeescript;
|
---|