diff --git a/components/prism-tsx.js b/components/prism-tsx.js index badc7a86bd..2bb2fdc9d6 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 a20ba381c9..79b70fd034 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$]|(?="] - ]], + "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 0000000000..02c2e728bb --- /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", "}"] +]