-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TSX: Temporary fix for the collisions of JSX tags and TS generics (#2596
- Loading branch information
1 parent
129faf5
commit 25bdb49
Showing
5 changed files
with
267 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
var typescript = Prism.util.clone(Prism.languages.typescript); | ||
Prism.languages.tsx = Prism.languages.extend('jsx', typescript); | ||
(function (Prism) { | ||
var typescript = Prism.util.clone(Prism.languages.typescript); | ||
Prism.languages.tsx = Prism.languages.extend('jsx', typescript); | ||
|
||
// 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 | ||
var tag = Prism.languages.tsx.tag; | ||
tag.pattern = RegExp(/(^|[^\w$]|(?=<\/))/.source + '(?:' + tag.pattern.source + ')', tag.pattern.flags); | ||
tag.lookbehind = true; | ||
}(Prism)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
function Add1(a, b) { return <div>a + b</div> } | ||
|
||
type Bar = Foo<string>; | ||
|
||
function Add2(a, b) { return <div>a + b</div> } | ||
|
||
function handleSubmit(event: FormEvent<HTMLFormElement>) { | ||
event.preventDefault(); | ||
} | ||
|
||
function handleChange(event: ChangeEvent<HTMLInputElement>) { | ||
console.log(event.target.value); | ||
} | ||
|
||
function handleClick(event: MouseEvent) { | ||
console.log(event.button); | ||
} | ||
|
||
export default function Form() { | ||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<input onChange={handleChange} placeholder="Name" /> | ||
<button onClick={handleClick}></button> | ||
</form> | ||
); | ||
} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "function"], | ||
["function", "Add1"], | ||
["punctuation", "("], | ||
["parameter", [ | ||
"a", | ||
["punctuation", ","], | ||
" b" | ||
]], | ||
["punctuation", ")"], | ||
["punctuation", "{"], | ||
["keyword", "return"], | ||
["tag", [ | ||
["tag", [ | ||
["punctuation", "<"], | ||
"div" | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["plain-text", "a + b"], | ||
["tag", [ | ||
["tag", [ | ||
["punctuation", "</"], | ||
"div" | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["punctuation", "}"], | ||
|
||
["keyword", "type"], | ||
["class-name", [ | ||
"Bar" | ||
]], | ||
["operator", "="], | ||
" Foo", | ||
["operator", "<"], | ||
["builtin", "string"], | ||
["operator", ">"], | ||
["punctuation", ";"], | ||
|
||
["keyword", "function"], | ||
["function", "Add2"], | ||
["punctuation", "("], | ||
["parameter", [ | ||
"a", | ||
["punctuation", ","], | ||
" b" | ||
]], | ||
["punctuation", ")"], | ||
["punctuation", "{"], | ||
["keyword", "return"], | ||
["tag", [ | ||
["tag", [ | ||
["punctuation", "<"], | ||
"div" | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["plain-text", "a + b"], | ||
["tag", [ | ||
["tag", [ | ||
["punctuation", "</"], | ||
"div" | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["punctuation", "}"], | ||
|
||
["keyword", "function"], | ||
["function", "handleSubmit"], | ||
["punctuation", "("], | ||
["parameter", [ | ||
"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", ">"] | ||
]], | ||
["punctuation", ")"], | ||
["punctuation", "{"], | ||
["builtin", "console"], | ||
["punctuation", "."], | ||
["function", "log"], | ||
["punctuation", "("], | ||
"event", | ||
["punctuation", "."], | ||
"target", | ||
["punctuation", "."], | ||
"value", | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
["punctuation", "}"], | ||
|
||
["keyword", "function"], | ||
["function", "handleClick"], | ||
["punctuation", "("], | ||
["parameter", [ | ||
"event", | ||
["operator", ":"], | ||
" MouseEvent" | ||
]], | ||
["punctuation", ")"], | ||
["punctuation", "{"], | ||
["builtin", "console"], | ||
["punctuation", "."], | ||
["function", "log"], | ||
["punctuation", "("], | ||
"event", | ||
["punctuation", "."], | ||
"button", | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
["punctuation", "}"], | ||
|
||
["keyword", "export"], | ||
["keyword", "default"], | ||
["keyword", "function"], | ||
["function", "Form"], | ||
["punctuation", "("], | ||
["punctuation", ")"], | ||
["punctuation", "{"], | ||
["keyword", "return"], | ||
["punctuation", "("], | ||
["tag", [ | ||
["tag", [ | ||
["punctuation", "<"], | ||
"form" | ||
]], | ||
["attr-name", [ | ||
"onSubmit" | ||
]], | ||
["script", [ | ||
["script-punctuation", "="], | ||
["punctuation", "{"], | ||
"handleSubmit", | ||
["punctuation", "}"] | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["plain-text", "\r\n "], | ||
["tag", [ | ||
["tag", [ | ||
["punctuation", "<"], | ||
"input" | ||
]], | ||
["attr-name", [ | ||
"onChange" | ||
]], | ||
["script", [ | ||
["script-punctuation", "="], | ||
["punctuation", "{"], | ||
"handleChange", | ||
["punctuation", "}"] | ||
]], | ||
["attr-name", [ | ||
"placeholder" | ||
]], | ||
["attr-value", [ | ||
["punctuation", "="], | ||
["punctuation", "\""], | ||
"Name", | ||
["punctuation", "\""] | ||
]], | ||
["punctuation", "/>"] | ||
]], | ||
["plain-text", "\r\n "], | ||
["tag", [ | ||
["tag", [ | ||
["punctuation", "<"], | ||
"button" | ||
]], | ||
["attr-name", [ | ||
"onClick" | ||
]], | ||
["script", [ | ||
["script-punctuation", "="], | ||
["punctuation", "{"], | ||
"handleClick", | ||
["punctuation", "}"] | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["tag", [ | ||
["tag", [ | ||
["punctuation", "</"], | ||
"button" | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["plain-text", "\r\n "], | ||
["tag", [ | ||
["tag", [ | ||
["punctuation", "</"], | ||
"form" | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
["punctuation", "}"] | ||
] |