719
Le
lextide / files
lextide / src / languages / typescript.ts
1.5 KB
1import type { LanguageFn } from "../types"; 2 3import { createEcmaScriptGrammar } from "./ecmascript"; 4 5const TYPESCRIPT_KEYWORDS = new Set([ 6 "abstract", 7 "as", 8 "async", 9 "await", 10 "break", 11 "case", 12 "catch", 13 "class", 14 "const", 15 "continue", 16 "declare", 17 "default", 18 "do", 19 "else", 20 "enum", 21 "export", 22 "extends", 23 "finally", 24 "for", 25 "function", 26 "if", 27 "implements", 28 "import", 29 "in", 30 "infer", 31 "interface", 32 "let", 33 "module", 34 "namespace", 35 "new", 36 "override", 37 "private", 38 "protected", 39 "public", 40 "readonly", 41 "return", 42 "satisfies", 43 "switch", 44 "throw", 45 "try", 46 "type", 47 "using", 48 "var", 49 "while", 50]); 51 52const TYPESCRIPT_BUILT_INS = new Set([ 53 "any", 54 "bigint", 55 "boolean", 56 "never", 57 "number", 58 "object", 59 "string", 60 "symbol", 61 "unknown", 62 "void", 63]); 64 65const TYPESCRIPT_LITERALS = new Set(["false", "null", "true", "undefined"]); 66 67export const typescript: LanguageFn = () => 68 createEcmaScriptGrammar({ 69 aliases: ["ts", "tsx", "mts", "cts"], 70 builtIns: TYPESCRIPT_BUILT_INS, 71 declarations: [ 72 { keyword: "function", relevance: 3, scope: "title.function" }, 73 { keyword: "class", relevance: 2, scope: "title.class" }, 74 { keyword: "interface", relevance: 4, scope: "title.class" }, 75 { keyword: "type", relevance: 4, scope: "title.class" }, 76 { keyword: "enum", relevance: 4, scope: "title.class" }, 77 { keyword: "namespace", relevance: 3, scope: "title.class" }, 78 ], 79 decorators: true, 80 keywords: TYPESCRIPT_KEYWORDS, 81 literals: TYPESCRIPT_LITERALS, 82 name: "typescript", 83 types: true, 84 });