TSX: Removed `parameter` token (#3090)
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
diff --git a/components/prism-tsx.js b/components/prism-tsx.js
index badc7a8..2bb2fdc 100644
--- a/components/prism-tsx.js
+++ b/components/prism-tsx.js
@@ -2,6 +2,9 @@
var typescript = Prism.util.clone(Prism.languages.typescript);
Prism.languages.tsx = Prism.languages.extend('jsx', typescript);
+ // doesn't work with TS because TS is too complex
+ delete Prism.languages.tsx['parameter'];
+
// This will prevent collisions between TSX tags and TS generic types.
// Idea by https://github.com/karlhorky
// Discussion: https://github.com/PrismJS/prism/issues/2594#issuecomment-710666928
diff --git a/components/prism-tsx.min.js b/components/prism-tsx.min.js
index a20ba38..79b70fd 100644
--- a/components/prism-tsx.min.js
+++ b/components/prism-tsx.min.js
@@ -1 +1 @@
-!function(a){var e=a.util.clone(a.languages.typescript);a.languages.tsx=a.languages.extend("jsx",e);var t=a.languages.tsx.tag;t.pattern=RegExp("(^|[^\\w$]|(?=</))(?:"+t.pattern.source+")",t.pattern.flags),t.lookbehind=!0}(Prism);
\ No newline at end of file
+!function(e){var a=e.util.clone(e.languages.typescript);e.languages.tsx=e.languages.extend("jsx",a),delete e.languages.tsx.parameter;var t=e.languages.tsx.tag;t.pattern=RegExp("(^|[^\\w$]|(?=</))(?:"+t.pattern.source+")",t.pattern.flags),t.lookbehind=!0}(Prism);
\ No newline at end of file
diff --git a/tests/languages/tsx/issue2594.test b/tests/languages/tsx/issue2594.test
index 3bc8e00..e0540fe 100644
--- a/tests/languages/tsx/issue2594.test
+++ b/tests/languages/tsx/issue2594.test
@@ -31,11 +31,9 @@ export default function Form() {
["keyword", "function"],
["function", "Add1"],
["punctuation", "("],
- ["parameter", [
- "a",
- ["punctuation", ","],
- " b"
- ]],
+ "a",
+ ["punctuation", ","],
+ " b",
["punctuation", ")"],
["punctuation", "{"],
["keyword", "return"],
@@ -57,9 +55,7 @@ export default function Form() {
["punctuation", "}"],
["keyword", "type"],
- ["class-name", [
- "Bar"
- ]],
+ ["class-name", ["Bar"]],
["operator", "="],
" Foo",
["operator", "<"],
@@ -70,11 +66,9 @@ export default function Form() {
["keyword", "function"],
["function", "Add2"],
["punctuation", "("],
- ["parameter", [
- "a",
- ["punctuation", ","],
- " b"
- ]],
+ "a",
+ ["punctuation", ","],
+ " b",
["punctuation", ")"],
["punctuation", "{"],
["keyword", "return"],
@@ -98,37 +92,36 @@ export default function Form() {
["keyword", "function"],
["function", "handleSubmit"],
["punctuation", "("],
- ["parameter", [
- "event",
- ["operator", ":"],
- " FormEvent",
- ["operator", "<"],
- "HTMLFormElement",
- ["operator", ">"]
- ]],
+ "event",
+ ["operator", ":"],
+ " FormEvent",
+ ["operator", "<"],
+ "HTMLFormElement",
+ ["operator", ">"],
["punctuation", ")"],
["punctuation", "{"],
+
"\r\n event",
["punctuation", "."],
["function", "preventDefault"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
+
["punctuation", "}"],
["keyword", "function"],
["function", "handleChange"],
["punctuation", "("],
- ["parameter", [
- "event",
- ["operator", ":"],
- " ChangeEvent",
- ["operator", "<"],
- "HTMLInputElement",
- ["operator", ">"]
- ]],
+ "event",
+ ["operator", ":"],
+ " ChangeEvent",
+ ["operator", "<"],
+ "HTMLInputElement",
+ ["operator", ">"],
["punctuation", ")"],
["punctuation", "{"],
+
["builtin", "console"],
["punctuation", "."],
["function", "log"],
@@ -140,18 +133,18 @@ export default function Form() {
"value",
["punctuation", ")"],
["punctuation", ";"],
+
["punctuation", "}"],
["keyword", "function"],
["function", "handleClick"],
["punctuation", "("],
- ["parameter", [
- "event",
- ["operator", ":"],
- " MouseEvent"
- ]],
+ "event",
+ ["operator", ":"],
+ " MouseEvent",
["punctuation", ")"],
["punctuation", "{"],
+
["builtin", "console"],
["punctuation", "."],
["function", "log"],
@@ -161,6 +154,7 @@ export default function Form() {
"button",
["punctuation", ")"],
["punctuation", ";"],
+
["punctuation", "}"],
["keyword", "export"],
@@ -170,16 +164,16 @@ export default function Form() {
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
+
["keyword", "return"],
["punctuation", "("],
+
["tag", [
["tag", [
["punctuation", "<"],
"form"
]],
- ["attr-name", [
- "onSubmit"
- ]],
+ ["attr-name", ["onSubmit"]],
["script", [
["script-punctuation", "="],
["punctuation", "{"],
@@ -194,18 +188,14 @@ export default function Form() {
["punctuation", "<"],
"input"
]],
- ["attr-name", [
- "onChange"
- ]],
+ ["attr-name", ["onChange"]],
["script", [
["script-punctuation", "="],
["punctuation", "{"],
"handleChange",
["punctuation", "}"]
]],
- ["attr-name", [
- "placeholder"
- ]],
+ ["attr-name", ["placeholder"]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
@@ -220,9 +210,7 @@ export default function Form() {
["punctuation", "<"],
"button"
]],
- ["attr-name", [
- "onClick"
- ]],
+ ["attr-name", ["onClick"]],
["script", [
["script-punctuation", "="],
["punctuation", "{"],
@@ -246,7 +234,9 @@ export default function Form() {
]],
["punctuation", ">"]
]],
+
["punctuation", ")"],
["punctuation", ";"],
+
["punctuation", "}"]
-]
\ No newline at end of file
+]
diff --git a/tests/languages/tsx/issue3089.test b/tests/languages/tsx/issue3089.test
new file mode 100644
index 0000000..02c2e72
--- /dev/null
+++ b/tests/languages/tsx/issue3089.test
@@ -0,0 +1,31 @@
+// react tsx
+function log(msg: string): void {
+ console.log(msg);
+}
+
+----------------------------------------------------
+
+[
+ ["comment", "// react tsx"],
+
+ ["keyword", "function"],
+ ["function", "log"],
+ ["punctuation", "("],
+ "msg",
+ ["operator", ":"],
+ ["builtin", "string"],
+ ["punctuation", ")"],
+ ["operator", ":"],
+ ["keyword", "void"],
+ ["punctuation", "{"],
+
+ ["builtin", "console"],
+ ["punctuation", "."],
+ ["function", "log"],
+ ["punctuation", "("],
+ "msg",
+ ["punctuation", ")"],
+ ["punctuation", ";"],
+
+ ["punctuation", "}"]
+]