Commit 0a313f4f9d38247812d41e99dffa120efcfdf623

Michael Schmidt 2021-09-26T12:35:00

TSX: Removed `parameter` token (#3090)

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", "}"]
+]