Navigation Menu

Skip to content

Commit

Permalink
TSX: Removed parameter token (#3090)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Sep 26, 2021
1 parent 2f9672a commit 0a313f4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 48 deletions.
3 changes: 3 additions & 0 deletions components/prism-tsx.js
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/prism-tsx.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 37 additions & 47 deletions tests/languages/tsx/issue2594.test
Expand Up @@ -31,11 +31,9 @@ export default function Form() {
["keyword", "function"],
["function", "Add1"],
["punctuation", "("],
["parameter", [
"a",
["punctuation", ","],
" b"
]],
"a",
["punctuation", ","],
" b",
["punctuation", ")"],
["punctuation", "{"],
["keyword", "return"],
Expand All @@ -57,9 +55,7 @@ export default function Form() {
["punctuation", "}"],

["keyword", "type"],
["class-name", [
"Bar"
]],
["class-name", ["Bar"]],
["operator", "="],
" Foo",
["operator", "<"],
Expand All @@ -70,11 +66,9 @@ export default function Form() {
["keyword", "function"],
["function", "Add2"],
["punctuation", "("],
["parameter", [
"a",
["punctuation", ","],
" b"
]],
"a",
["punctuation", ","],
" b",
["punctuation", ")"],
["punctuation", "{"],
["keyword", "return"],
Expand All @@ -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"],
Expand All @@ -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"],
Expand All @@ -161,6 +154,7 @@ export default function Form() {
"button",
["punctuation", ")"],
["punctuation", ";"],

["punctuation", "}"],

["keyword", "export"],
Expand All @@ -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", "{"],
Expand All @@ -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", "\""],
Expand All @@ -220,9 +210,7 @@ export default function Form() {
["punctuation", "<"],
"button"
]],
["attr-name", [
"onClick"
]],
["attr-name", ["onClick"]],
["script", [
["script-punctuation", "="],
["punctuation", "{"],
Expand All @@ -246,7 +234,9 @@ export default function Form() {
]],
["punctuation", ">"]
]],

["punctuation", ")"],
["punctuation", ";"],

["punctuation", "}"]
]
]
31 changes: 31 additions & 0 deletions 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", "}"]
]

0 comments on commit 0a313f4

Please sign in to comment.