Skip to content

Commit

Permalink
fix(typescript): highlight string literal type parameters (#1010)
Browse files Browse the repository at this point in the history
Fixes #1009
  • Loading branch information
SKalt authored Nov 13, 2024
1 parent e76e1e2 commit 23ed7b9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lexers/embedded/typescript.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
<rule pattern=",">
<token type="Punctuation"/>
</rule>
<rule pattern="&#34;(\\\\|\\&#34;|[^&#34;])*&#34;">
<token type="LiteralStringDouble"/>
</rule>
<rule pattern="&#39;(\\\\|\\&#39;|[^&#39;])*&#39;">
<token type="LiteralStringSingle"/>
</rule>
<rule pattern="`">
<token type="LiteralStringBacktick"/>
<push state="interp"/>
</rule>
<rule>
<include state="commentsandwhitespace"/>
</rule>
Expand Down
5 changes: 5 additions & 0 deletions lexers/testdata/typescript.actual
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ const TestComponent = ({ a, b }) => (
</Component>
)

type FirstChar<K extends string> = K extends `${infer X}${infer _}`
? X
: never
type SChar = FirstChar<"stuff">

export { TestComponent }
46 changes: 46 additions & 0 deletions lexers/testdata/typescript.expected
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,52 @@
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n"},
{"type":"KeywordReserved","value":"type"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"FirstChar"},
{"type":"Punctuation","value":"\u003c"},
{"type":"NameTag","value":"K"},
{"type":"Text","value":" "},
{"type":"NameAttribute","value":"extends"},
{"type":"Text","value":" "},
{"type":"NameAttribute","value":"string"},
{"type":"Punctuation","value":"\u003e"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"NameOther","value":"K"},
{"type":"Text","value":" "},
{"type":"KeywordReserved","value":"extends"},
{"type":"Text","value":" "},
{"type":"LiteralStringBacktick","value":"`"},
{"type":"LiteralStringInterpol","value":"${"},
{"type":"Keyword","value":"infer"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"X"},
{"type":"LiteralStringInterpol","value":"}${"},
{"type":"Keyword","value":"infer"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"_"},
{"type":"LiteralStringInterpol","value":"}"},
{"type":"LiteralStringBacktick","value":"`"},
{"type":"Text","value":"\n "},
{"type":"Operator","value":"?"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"X"},
{"type":"Text","value":"\n : "},
{"type":"KeywordType","value":"never"},
{"type":"Text","value":"\n"},
{"type":"KeywordReserved","value":"type"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"SChar"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"NameOther","value":"FirstChar"},
{"type":"Operator","value":"\u003c"},
{"type":"LiteralStringDouble","value":"\"stuff\""},
{"type":"Operator","value":"\u003e"},
{"type":"Text","value":"\n\n"},
{"type":"KeywordReserved","value":"export"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
Expand Down

0 comments on commit 23ed7b9

Please sign in to comment.