1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-17 20:58:08 +02:00

fix(typescript): highlight string literal type parameters (#1010)

Fixes #1009
This commit is contained in:
Steven Kalt 2024-11-13 16:48:23 -05:00 committed by GitHub
parent e76e1e2233
commit 23ed7b98d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 61 additions and 0 deletions

View File

@ -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>

View File

@ -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 }

View File

@ -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":"{"},