1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
# A compact, self-contained TypeScript grammar — syntect's bundled set ships
# JavaScript but not TypeScript, so `.ts`/`.tsx` would otherwise render plain.
# Covers comments, strings (incl. template literals with interpolation), numbers,
# the TS keyword set (including type-level keywords), capitalized type names,
# decorators, and function-call names. Scopes match MARS's theme mapping in
# `syntax.rs::theme_for` (keyword→accent, type→info, function→accent-bright, …).
name: TypeScript
file_extensions:
- ts
- tsx
- mts
- cts
scope: source.ts
contexts:
main:
- include: comments
- include: strings
- include: numbers
- include: decorators
- include: keywords
- include: names
comments:
- match: //
scope: punctuation.definition.comment.ts
push:
- meta_scope: comment.line.double-slash.ts
- match: $\n?
pop: true
- match: /\*
scope: punctuation.definition.comment.ts
push:
- meta_scope: comment.block.ts
- match: \*/
pop: true
strings:
- match: '"'
scope: punctuation.definition.string.begin.ts
push:
- meta_scope: string.quoted.double.ts
- match: \\.
scope: constant.character.escape.ts
- match: '"'
scope: punctuation.definition.string.end.ts
pop: true
- match: "'"
scope: punctuation.definition.string.begin.ts
push:
- meta_scope: string.quoted.single.ts
- match: \\.
scope: constant.character.escape.ts
- match: "'"
scope: punctuation.definition.string.end.ts
pop: true
- match: '`'
scope: punctuation.definition.string.begin.ts
push:
- meta_scope: string.template.ts
- match: '`'
scope: punctuation.definition.string.end.ts
pop: true
- match: \\.
scope: constant.character.escape.ts
- match: \$\{
scope: punctuation.definition.template-expression.begin.ts
push:
- clear_scopes: 1
- match: \}
scope: punctuation.definition.template-expression.end.ts
pop: true
- include: main
numbers:
- match: '\b(0[xX][0-9a-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|(\d[\d_]*)(\.[\d_]+)?([eE][+-]?\d+)?)n?\b'
scope: constant.numeric.ts
decorators:
- match: '@[A-Za-z_$][\w$]*'
scope: entity.name.function.decorator.ts
keywords:
- match: \b(as|asserts|await|break|case|catch|const|continue|debugger|default|delete|do|else|export|extends|finally|for|from|if|implements|import|in|infer|instanceof|is|keyof|new|of|return|satisfies|switch|throw|try|typeof|void|while|with|yield)\b
scope: keyword.control.ts
- match: \b(abstract|async|declare|enum|function|get|interface|namespace|override|package|private|protected|public|readonly|set|static|type|var|let|class)\b
scope: storage.type.ts
- match: \b(any|bigint|boolean|never|null|number|object|string|symbol|undefined|unique|unknown)\b
scope: support.type.primitive.ts
- match: \b(true|false|this|super)\b
scope: constant.language.ts
names:
- match: '\b([A-Z][A-Za-z0-9_$]*)\b'
scope: entity.name.type.ts
- match: '\b([a-z_$][\w$]*)\s*(?=\()'
scope: entity.name.function.ts