Skip to content

Commit 0a313f4

Browse files
authoredSep 26, 2021
TSX: Removed parameter token (#3090)
1 parent 2f9672a commit 0a313f4

File tree

4 files changed

+72
-48
lines changed

4 files changed

+72
-48
lines changed
 

‎components/prism-tsx.js

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
var typescript = Prism.util.clone(Prism.languages.typescript);
33
Prism.languages.tsx = Prism.languages.extend('jsx', typescript);
44

5+
// doesn't work with TS because TS is too complex
6+
delete Prism.languages.tsx['parameter'];
7+
58
// This will prevent collisions between TSX tags and TS generic types.
69
// Idea by https://github.com/karlhorky
710
// Discussion: https://github.com/PrismJS/prism/issues/2594#issuecomment-710666928

‎components/prism-tsx.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/languages/tsx/issue2594.test

+37-47
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ export default function Form() {
3131
["keyword", "function"],
3232
["function", "Add1"],
3333
["punctuation", "("],
34-
["parameter", [
35-
"a",
36-
["punctuation", ","],
37-
" b"
38-
]],
34+
"a",
35+
["punctuation", ","],
36+
" b",
3937
["punctuation", ")"],
4038
["punctuation", "{"],
4139
["keyword", "return"],
@@ -57,9 +55,7 @@ export default function Form() {
5755
["punctuation", "}"],
5856

5957
["keyword", "type"],
60-
["class-name", [
61-
"Bar"
62-
]],
58+
["class-name", ["Bar"]],
6359
["operator", "="],
6460
" Foo",
6561
["operator", "<"],
@@ -70,11 +66,9 @@ export default function Form() {
7066
["keyword", "function"],
7167
["function", "Add2"],
7268
["punctuation", "("],
73-
["parameter", [
74-
"a",
75-
["punctuation", ","],
76-
" b"
77-
]],
69+
"a",
70+
["punctuation", ","],
71+
" b",
7872
["punctuation", ")"],
7973
["punctuation", "{"],
8074
["keyword", "return"],
@@ -98,37 +92,36 @@ export default function Form() {
9892
["keyword", "function"],
9993
["function", "handleSubmit"],
10094
["punctuation", "("],
101-
["parameter", [
102-
"event",
103-
["operator", ":"],
104-
" FormEvent",
105-
["operator", "<"],
106-
"HTMLFormElement",
107-
["operator", ">"]
108-
]],
95+
"event",
96+
["operator", ":"],
97+
" FormEvent",
98+
["operator", "<"],
99+
"HTMLFormElement",
100+
["operator", ">"],
109101
["punctuation", ")"],
110102
["punctuation", "{"],
103+
111104
"\r\n event",
112105
["punctuation", "."],
113106
["function", "preventDefault"],
114107
["punctuation", "("],
115108
["punctuation", ")"],
116109
["punctuation", ";"],
110+
117111
["punctuation", "}"],
118112

119113
["keyword", "function"],
120114
["function", "handleChange"],
121115
["punctuation", "("],
122-
["parameter", [
123-
"event",
124-
["operator", ":"],
125-
" ChangeEvent",
126-
["operator", "<"],
127-
"HTMLInputElement",
128-
["operator", ">"]
129-
]],
116+
"event",
117+
["operator", ":"],
118+
" ChangeEvent",
119+
["operator", "<"],
120+
"HTMLInputElement",
121+
["operator", ">"],
130122
["punctuation", ")"],
131123
["punctuation", "{"],
124+
132125
["builtin", "console"],
133126
["punctuation", "."],
134127
["function", "log"],
@@ -140,18 +133,18 @@ export default function Form() {
140133
"value",
141134
["punctuation", ")"],
142135
["punctuation", ";"],
136+
143137
["punctuation", "}"],
144138

145139
["keyword", "function"],
146140
["function", "handleClick"],
147141
["punctuation", "("],
148-
["parameter", [
149-
"event",
150-
["operator", ":"],
151-
" MouseEvent"
152-
]],
142+
"event",
143+
["operator", ":"],
144+
" MouseEvent",
153145
["punctuation", ")"],
154146
["punctuation", "{"],
147+
155148
["builtin", "console"],
156149
["punctuation", "."],
157150
["function", "log"],
@@ -161,6 +154,7 @@ export default function Form() {
161154
"button",
162155
["punctuation", ")"],
163156
["punctuation", ";"],
157+
164158
["punctuation", "}"],
165159

166160
["keyword", "export"],
@@ -170,16 +164,16 @@ export default function Form() {
170164
["punctuation", "("],
171165
["punctuation", ")"],
172166
["punctuation", "{"],
167+
173168
["keyword", "return"],
174169
["punctuation", "("],
170+
175171
["tag", [
176172
["tag", [
177173
["punctuation", "<"],
178174
"form"
179175
]],
180-
["attr-name", [
181-
"onSubmit"
182-
]],
176+
["attr-name", ["onSubmit"]],
183177
["script", [
184178
["script-punctuation", "="],
185179
["punctuation", "{"],
@@ -194,18 +188,14 @@ export default function Form() {
194188
["punctuation", "<"],
195189
"input"
196190
]],
197-
["attr-name", [
198-
"onChange"
199-
]],
191+
["attr-name", ["onChange"]],
200192
["script", [
201193
["script-punctuation", "="],
202194
["punctuation", "{"],
203195
"handleChange",
204196
["punctuation", "}"]
205197
]],
206-
["attr-name", [
207-
"placeholder"
208-
]],
198+
["attr-name", ["placeholder"]],
209199
["attr-value", [
210200
["punctuation", "="],
211201
["punctuation", "\""],
@@ -220,9 +210,7 @@ export default function Form() {
220210
["punctuation", "<"],
221211
"button"
222212
]],
223-
["attr-name", [
224-
"onClick"
225-
]],
213+
["attr-name", ["onClick"]],
226214
["script", [
227215
["script-punctuation", "="],
228216
["punctuation", "{"],
@@ -246,7 +234,9 @@ export default function Form() {
246234
]],
247235
["punctuation", ">"]
248236
]],
237+
249238
["punctuation", ")"],
250239
["punctuation", ";"],
240+
251241
["punctuation", "}"]
252-
]
242+
]

‎tests/languages/tsx/issue3089.test

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// react tsx
2+
function log(msg: string): void {
3+
console.log(msg);
4+
}
5+
6+
----------------------------------------------------
7+
8+
[
9+
["comment", "// react tsx"],
10+
11+
["keyword", "function"],
12+
["function", "log"],
13+
["punctuation", "("],
14+
"msg",
15+
["operator", ":"],
16+
["builtin", "string"],
17+
["punctuation", ")"],
18+
["operator", ":"],
19+
["keyword", "void"],
20+
["punctuation", "{"],
21+
22+
["builtin", "console"],
23+
["punctuation", "."],
24+
["function", "log"],
25+
["punctuation", "("],
26+
"msg",
27+
["punctuation", ")"],
28+
["punctuation", ";"],
29+
30+
["punctuation", "}"]
31+
]

0 commit comments

Comments
 (0)
Please sign in to comment.