Skip to content

Commit

Permalink
Typescript: Several fixes (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusted committed Apr 2, 2024
1 parent e5c25d0 commit 736c0ea
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lexers/embedded/typescript.xml
Expand Up @@ -51,10 +51,13 @@
</rule>
</state>
<state name="tag">
<rule>
<include state="commentsandwhitespace"/>
</rule>
<rule pattern="\s+">
<token type="Text"/>
</rule>
<rule pattern="([\w]+\s*)(=)(\s*)">
<rule pattern="([\w-]+\s*)(=)(\s*)">
<bygroups>
<token type="NameAttribute"/>
<token type="Operator"/>
Expand All @@ -77,12 +80,25 @@
<pop depth="1"/>
</rule>
</state>
<state name="comment">
<rule pattern="[^-]+">
<token type="Comment"/>
</rule>
<rule pattern="--&gt;">
<token type="Comment"/>
<pop depth="1"/>
</rule>
<rule pattern="-">
<token type="Comment"/>
</rule>
</state>
<state name="commentsandwhitespace">
<rule pattern="\s+">
<token type="Text"/>
</rule>
<rule pattern="&lt;!--">
<token type="Comment"/>
<push state="comment"/>
</rule>
<rule pattern="//.*?\n">
<token type="CommentSingle"/>
Expand Down Expand Up @@ -200,7 +216,7 @@
<rule pattern="(Array|Boolean|Date|Error|Function|Math|Number|Object|Packages|RegExp|String|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|isNaN|parseFloat|parseInt|document|this|window)\b">
<token type="NameBuiltin"/>
</rule>
<rule pattern="\b(module)(\s*)(\s*[\w?.$][\w?.$]*)(\s*)">
<rule pattern="\b(module)(\s+)(&quot;[\w\./@]+&quot;)(\s+)">
<bygroups>
<token type="KeywordReserved"/>
<token type="Text"/>
Expand Down
15 changes: 15 additions & 0 deletions lexers/testdata/tsx.actual
Expand Up @@ -10,4 +10,19 @@ ReactDOM.render(
</React.StrictMode>
</>,
document.getElementById('root'),
)

ReactDOM.render(
<p
// This is a inline comment.
/*
This is a
Multi line comment
*/
<!-- Another multiline
comment !-->
data-test-id="outro" disabled>
Some text here.
</p>,
document.getElementById('root'),
)
41 changes: 41 additions & 0 deletions lexers/testdata/tsx.expected
Expand Up @@ -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":")"}
]
5 changes: 5 additions & 0 deletions lexers/testdata/typescript.actual
@@ -0,0 +1,5 @@
const moduleName = modules.map();

declare module "fs" {}
declare module "@custom/plugin" {}
declare module "../../compiler/types" {}
37 changes: 37 additions & 0 deletions 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"}
]

0 comments on commit 736c0ea

Please sign in to comment.