Skip to content

Commit 31cc214

Browse files
TypeScript: Added support for decorators (#2820)
1 parent 01b7b6f commit 31cc214

File tree

4 files changed

+170
-1
lines changed

4 files changed

+170
-1
lines changed

components/prism-typescript.js

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
Prism.languages.typescript['class-name'].inside = typeInside;
2323

2424
Prism.languages.insertBefore('typescript', 'function', {
25+
'decorator': {
26+
pattern: /@[$\w\xA0-\uFFFF]+/,
27+
inside: {
28+
'at': {
29+
pattern: /^@/,
30+
alias: 'operator'
31+
},
32+
'function': /^[\s\S]+/
33+
}
34+
},
2535
'generic-function': {
2636
// e.g. foo<T extends "bar" | "baz">( ...
2737
pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,

components/prism-typescript.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
@f @g x
2+
3+
@f
4+
@g
5+
x
6+
7+
@sealed
8+
class ExampleClass {
9+
10+
@first()
11+
@second()
12+
method() {}
13+
14+
@enumerable(false)
15+
greet() {
16+
return "Hello, " + this.greeting;
17+
}
18+
19+
@configurable(false)
20+
get y() {
21+
return this._y;
22+
}
23+
24+
}
25+
26+
----------------------------------------------------
27+
28+
[
29+
["decorator", [
30+
["at", "@"],
31+
["function", "f"]
32+
]],
33+
["decorator", [
34+
["at", "@"],
35+
["function", "g"]
36+
]],
37+
" x\r\n\r\n",
38+
39+
["decorator", [
40+
["at", "@"],
41+
["function", "f"]
42+
]],
43+
["decorator", [
44+
["at", "@"],
45+
["function", "g"]
46+
]],
47+
"\r\nx\r\n\r\n",
48+
49+
["decorator", [
50+
["at", "@"],
51+
["function", "sealed"]
52+
]],
53+
["keyword", "class"], ["class-name", ["ExampleClass"]], ["punctuation", "{"],
54+
55+
["decorator", [
56+
["at", "@"],
57+
["function", "first"]
58+
]],
59+
["punctuation", "("],
60+
["punctuation", ")"],
61+
62+
["decorator", [
63+
["at", "@"],
64+
["function", "second"]
65+
]],
66+
["punctuation", "("],
67+
["punctuation", ")"],
68+
69+
["function", "method"],
70+
["punctuation", "("],
71+
["punctuation", ")"],
72+
["punctuation", "{"],
73+
["punctuation", "}"],
74+
75+
["decorator", [
76+
["at", "@"],
77+
["function", "enumerable"]
78+
]],
79+
["punctuation", "("],
80+
["boolean", "false"],
81+
["punctuation", ")"],
82+
83+
["function", "greet"],
84+
["punctuation", "("],
85+
["punctuation", ")"],
86+
["punctuation", "{"],
87+
88+
["keyword", "return"],
89+
["string", "\"Hello, \""],
90+
["operator", "+"],
91+
["keyword", "this"],
92+
["punctuation", "."],
93+
"greeting",
94+
["punctuation", ";"],
95+
96+
["punctuation", "}"],
97+
98+
["decorator", [
99+
["at", "@"],
100+
["function", "configurable"]
101+
]],
102+
["punctuation", "("],
103+
["boolean", "false"],
104+
["punctuation", ")"],
105+
106+
["keyword", "get"],
107+
["function", "y"],
108+
["punctuation", "("],
109+
["punctuation", ")"],
110+
["punctuation", "{"],
111+
112+
["keyword", "return"],
113+
["keyword", "this"],
114+
["punctuation", "."],
115+
"_y",
116+
["punctuation", ";"],
117+
118+
["punctuation", "}"],
119+
120+
["punctuation", "}"]
121+
]
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@Component({
2+
selector: 'my-app',
3+
template: `<div>Hello World!</div>`
4+
})
5+
export class AppComponent {}
6+
7+
----------------------------------------------------
8+
9+
[
10+
["decorator", [
11+
["at", "@"],
12+
["function", "Component"]
13+
]],
14+
["punctuation", "("],
15+
["punctuation", "{"],
16+
17+
"\r\n selector",
18+
["operator", ":"],
19+
["string", "'my-app'"],
20+
["punctuation", ","],
21+
22+
"\r\n template",
23+
["operator", ":"],
24+
["template-string", [
25+
["template-punctuation", "`"],
26+
["string", "<div>Hello World!</div>"],
27+
["template-punctuation", "`"]
28+
]],
29+
30+
["punctuation", "}"],
31+
["punctuation", ")"],
32+
33+
["keyword", "export"],
34+
["keyword", "class"],
35+
["class-name", ["AppComponent"]],
36+
["punctuation", "{"],
37+
["punctuation", "}"]
38+
]

0 commit comments

Comments
 (0)