123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- const KEYWORDS = [
- "as", // for exports
- "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",
- // JS handles these with a special rule
- // "get",
- // "set",
- "debugger",
- "async",
- "await",
- "static",
- "import",
- "from",
- "export",
- "extends"
- ];
- const LITERALS = [
- "true",
- "false",
- "null",
- "undefined",
- "NaN",
- "Infinity"
- ];
- const TYPES = [
- "Intl",
- "DataView",
- "Number",
- "Math",
- "Date",
- "String",
- "RegExp",
- "Object",
- "Function",
- "Boolean",
- "Error",
- "Symbol",
- "Set",
- "Map",
- "WeakSet",
- "WeakMap",
- "Proxy",
- "Reflect",
- "JSON",
- "Promise",
- "Float64Array",
- "Int16Array",
- "Int32Array",
- "Int8Array",
- "Uint16Array",
- "Uint32Array",
- "Float32Array",
- "Array",
- "Uint8Array",
- "Uint8ClampedArray",
- "ArrayBuffer",
- "BigInt64Array",
- "BigUint64Array",
- "BigInt"
- ];
- const ERROR_TYPES = [
- "EvalError",
- "InternalError",
- "RangeError",
- "ReferenceError",
- "SyntaxError",
- "TypeError",
- "URIError"
- ];
- const BUILT_IN_GLOBALS = [
- "setInterval",
- "setTimeout",
- "clearInterval",
- "clearTimeout",
- "require",
- "exports",
- "eval",
- "isFinite",
- "isNaN",
- "parseFloat",
- "parseInt",
- "decodeURI",
- "decodeURIComponent",
- "encodeURI",
- "encodeURIComponent",
- "escape",
- "unescape"
- ];
- const BUILT_IN_VARIABLES = [
- "arguments",
- "this",
- "super",
- "console",
- "window",
- "document",
- "localStorage",
- "module",
- "global" // Node.js
- ];
- const BUILT_INS = [].concat(
- BUILT_IN_GLOBALS,
- BUILT_IN_VARIABLES,
- TYPES,
- ERROR_TYPES
- );
- /*
- Language: CoffeeScript
- Author: Dmytrii Nagirniak <dnagir@gmail.com>
- Contributors: Oleg Efimov <efimovov@gmail.com>, Cédric Néhémie <cedric.nehemie@gmail.com>
- Description: CoffeeScript is a programming language that transcompiles to JavaScript. For info about language see http://coffeescript.org/
- Category: common, scripting
- Website: https://coffeescript.org
- */
- /** @type LanguageFn */
- function coffeescript(hljs) {
- const COFFEE_BUILT_INS = [
- 'npm',
- 'print'
- ];
- const COFFEE_LITERALS = [
- 'yes',
- 'no',
- 'on',
- 'off'
- ];
- const COFFEE_KEYWORDS = [
- 'then',
- 'unless',
- 'until',
- 'loop',
- 'by',
- 'when',
- 'and',
- 'or',
- 'is',
- 'isnt',
- 'not'
- ];
- const NOT_VALID_KEYWORDS = [
- "var",
- "const",
- "let",
- "function",
- "static"
- ];
- const excluding = (list) =>
- (kw) => !list.includes(kw);
- const KEYWORDS$1 = {
- keyword: KEYWORDS.concat(COFFEE_KEYWORDS).filter(excluding(NOT_VALID_KEYWORDS)),
- literal: LITERALS.concat(COFFEE_LITERALS),
- built_in: BUILT_INS.concat(COFFEE_BUILT_INS)
- };
- const JS_IDENT_RE = '[A-Za-z$_][0-9A-Za-z$_]*';
- const SUBST = {
- className: 'subst',
- begin: /#\{/,
- end: /\}/,
- keywords: KEYWORDS$1
- };
- const EXPRESSIONS = [
- hljs.BINARY_NUMBER_MODE,
- hljs.inherit(hljs.C_NUMBER_MODE, {
- starts: {
- end: '(\\s*/)?',
- relevance: 0
- }
- }), // a number tries to eat the following slash to prevent treating it as a regexp
- {
- className: 'string',
- variants: [
- {
- begin: /'''/,
- end: /'''/,
- contains: [hljs.BACKSLASH_ESCAPE]
- },
- {
- begin: /'/,
- end: /'/,
- contains: [hljs.BACKSLASH_ESCAPE]
- },
- {
- begin: /"""/,
- end: /"""/,
- contains: [
- hljs.BACKSLASH_ESCAPE,
- SUBST
- ]
- },
- {
- begin: /"/,
- end: /"/,
- contains: [
- hljs.BACKSLASH_ESCAPE,
- SUBST
- ]
- }
- ]
- },
- {
- className: 'regexp',
- variants: [
- {
- begin: '///',
- end: '///',
- contains: [
- SUBST,
- hljs.HASH_COMMENT_MODE
- ]
- },
- {
- begin: '//[gim]{0,3}(?=\\W)',
- relevance: 0
- },
- {
- // regex can't start with space to parse x / 2 / 3 as two divisions
- // regex can't start with *, and it supports an "illegal" in the main mode
- begin: /\/(?![ *]).*?(?![\\]).\/[gim]{0,3}(?=\W)/
- }
- ]
- },
- {
- begin: '@' + JS_IDENT_RE // relevance booster
- },
- {
- subLanguage: 'javascript',
- excludeBegin: true,
- excludeEnd: true,
- variants: [
- {
- begin: '```',
- end: '```'
- },
- {
- begin: '`',
- end: '`'
- }
- ]
- }
- ];
- SUBST.contains = EXPRESSIONS;
- const TITLE = hljs.inherit(hljs.TITLE_MODE, {
- begin: JS_IDENT_RE
- });
- const POSSIBLE_PARAMS_RE = '(\\(.*\\)\\s*)?\\B[-=]>';
- const PARAMS = {
- className: 'params',
- begin: '\\([^\\(]',
- returnBegin: true,
- /* We need another contained nameless mode to not have every nested
- pair of parens to be called "params" */
- contains: [{
- begin: /\(/,
- end: /\)/,
- keywords: KEYWORDS$1,
- contains: ['self'].concat(EXPRESSIONS)
- }]
- };
- return {
- name: 'CoffeeScript',
- aliases: [
- 'coffee',
- 'cson',
- 'iced'
- ],
- keywords: KEYWORDS$1,
- illegal: /\/\*/,
- contains: EXPRESSIONS.concat([
- hljs.COMMENT('###', '###'),
- hljs.HASH_COMMENT_MODE,
- {
- className: 'function',
- begin: '^\\s*' + JS_IDENT_RE + '\\s*=\\s*' + POSSIBLE_PARAMS_RE,
- end: '[-=]>',
- returnBegin: true,
- contains: [
- TITLE,
- PARAMS
- ]
- },
- {
- // anonymous function start
- begin: /[:\(,=]\s*/,
- relevance: 0,
- contains: [{
- className: 'function',
- begin: POSSIBLE_PARAMS_RE,
- end: '[-=]>',
- returnBegin: true,
- contains: [PARAMS]
- }]
- },
- {
- className: 'class',
- beginKeywords: 'class',
- end: '$',
- illegal: /[:="\[\]]/,
- contains: [
- {
- beginKeywords: 'extends',
- endsWithParent: true,
- illegal: /[:="\[\]]/,
- contains: [TITLE]
- },
- TITLE
- ]
- },
- {
- begin: JS_IDENT_RE + ':',
- end: ':',
- returnBegin: true,
- returnEnd: true,
- relevance: 0
- }
- ])
- };
- }
- module.exports = coffeescript;
|