Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript: Several fixes #952

Merged
merged 1 commit into from Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"}
]