From 829d91f29ba45713e89e15a143455e4755099e83 Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 2 Apr 2024 00:35:19 +0200 Subject: [PATCH] Typescript: Several fixes - Allow comments to be inside of tags. - Fixes the lexing of ` + data-test-id="outro" disabled> + Some text here. +

, + document.getElementById('root'), ) \ No newline at end of file diff --git a/lexers/testdata/tsx.expected b/lexers/testdata/tsx.expected index c7ddc3213..fa1088092 100644 --- a/lexers/testdata/tsx.expected +++ b/lexers/testdata/tsx.expected @@ -60,5 +60,46 @@ {"type":"LiteralStringSingle","value":"'root'"}, {"type":"Punctuation","value":"),"}, {"type":"Text","value":"\n"}, + {"type":"Punctuation","value":")"}, + {"type":"Text","value":"\n\n"}, + {"type":"NameOther","value":"ReactDOM"}, + {"type":"Punctuation","value":"."}, + {"type":"NameOther","value":"render"}, + {"type":"Punctuation","value":"("}, + {"type":"Text","value":"\n "}, + {"type":"Punctuation","value":"\u003c"}, + {"type":"NameTag","value":"p"}, + {"type":"Text","value":"\n "}, + {"type":"CommentSingle","value":"// This is a inline comment.\n"}, + {"type":"Text","value":" "}, + {"type":"CommentMultiline","value":"/*\n This is a\n Multi line comment\n */"}, + {"type":"Text","value":"\n "}, + {"type":"Comment","value":"\u003c!-- Another multiline\n comment !--\u003e"}, + {"type":"Text","value":"\n "}, + {"type":"NameAttribute","value":"data-test-id"}, + {"type":"Operator","value":"="}, + {"type":"LiteralString","value":"\"outro\""}, + {"type":"Text","value":" "}, + {"type":"NameAttribute","value":"disabled"}, + {"type":"Punctuation","value":"\u003e"}, + {"type":"Text","value":"\n\t"}, + {"type":"NameOther","value":"Some"}, + {"type":"Text","value":" "}, + {"type":"NameOther","value":"text"}, + {"type":"Text","value":" "}, + {"type":"NameOther","value":"here"}, + {"type":"Punctuation","value":"."}, + {"type":"Text","value":"\n "}, + {"type":"Punctuation","value":"\u003c/"}, + {"type":"NameTag","value":"p"}, + {"type":"Punctuation","value":"\u003e,"}, + {"type":"Text","value":"\n "}, + {"type":"NameBuiltin","value":"document"}, + {"type":"Punctuation","value":"."}, + {"type":"NameOther","value":"getElementById"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralStringSingle","value":"'root'"}, + {"type":"Punctuation","value":"),"}, + {"type":"Text","value":"\n"}, {"type":"Punctuation","value":")"} ] diff --git a/lexers/testdata/typescript.actual b/lexers/testdata/typescript.actual new file mode 100644 index 000000000..5c76fcdc7 --- /dev/null +++ b/lexers/testdata/typescript.actual @@ -0,0 +1,5 @@ +const moduleName = modules.map(); + +declare module "fs" {} +declare module "@custom/plugin" {} +declare module "../../compiler/types" {} diff --git a/lexers/testdata/typescript.expected b/lexers/testdata/typescript.expected new file mode 100644 index 000000000..1fbff172f --- /dev/null +++ b/lexers/testdata/typescript.expected @@ -0,0 +1,37 @@ +[ + {"type":"KeywordReserved","value":"const"}, + {"type":"Text","value":" "}, + {"type":"NameOther","value":"moduleName"}, + {"type":"Text","value":" "}, + {"type":"Operator","value":"="}, + {"type":"Text","value":" "}, + {"type":"NameOther","value":"modules"}, + {"type":"Punctuation","value":"."}, + {"type":"NameOther","value":"map"}, + {"type":"Punctuation","value":"();"}, + {"type":"Text","value":"\n\n"}, + {"type":"KeywordReserved","value":"declare"}, + {"type":"Text","value":" "}, + {"type":"KeywordReserved","value":"module"}, + {"type":"Text","value":" "}, + {"type":"NameOther","value":"\"fs\""}, + {"type":"Text","value":" "}, + {"type":"Punctuation","value":"{}"}, + {"type":"Text","value":"\n"}, + {"type":"KeywordReserved","value":"declare"}, + {"type":"Text","value":" "}, + {"type":"KeywordReserved","value":"module"}, + {"type":"Text","value":" "}, + {"type":"NameOther","value":"\"@custom/plugin\""}, + {"type":"Text","value":" "}, + {"type":"Punctuation","value":"{}"}, + {"type":"Text","value":"\n"}, + {"type":"KeywordReserved","value":"declare"}, + {"type":"Text","value":" "}, + {"type":"KeywordReserved","value":"module"}, + {"type":"Text","value":" "}, + {"type":"NameOther","value":"\"../../compiler/types\""}, + {"type":"Text","value":" "}, + {"type":"Punctuation","value":"{}"}, + {"type":"Text","value":"\n"} +]