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

Update TypeScript lexer to allow nested generics #1002

Merged
merged 2 commits into from
Sep 21, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lexers/embedded/typescript.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
</rule>
</state>
<state name="tag">
<rule>
<include state="jsx"/>
</rule>
<rule pattern=",">
<token type="Punctuation"/>
</rule>
<rule>
<include state="commentsandwhitespace"/>
</rule>
Expand Down Expand Up @@ -171,7 +177,7 @@
</rule>
<rule pattern="(?=/)">
<token type="Text"/>
<push state="#pop" state="badregex"/>
<push state="badregex"/>
</rule>
<rule>
<pop depth="1"/>
Expand Down Expand Up @@ -276,4 +282,4 @@
</rule>
</state>
</rules>
</lexer>
</lexer>
13 changes: 13 additions & 0 deletions lexers/testdata/typescript.actual
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@ const moduleName = modules.map();
declare module "fs" {}
declare module "@custom/plugin" {}
declare module "../../compiler/types" {}

type TestType<T> = {
[Key keyof T]: Required<Pick<T, Key>>
}

const TestComponent = ({ a, b }) => (
<Component width={100} prop={{ a, ...b }} attr="text">
<span>This is a component</span>
<SomethingElse />
</Component>
)

export { TestComponent }
111 changes: 110 additions & 1 deletion lexers/testdata/typescript.expected
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,114 @@
{"type":"NameOther","value":"\"../../compiler/types\""},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{}"},
{"type":"Text","value":"\n"}
{"type":"Text","value":"\n\n"},
{"type":"KeywordReserved","value":"type"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"TestType"},
{"type":"Punctuation","value":"\u003c"},
{"type":"NameTag","value":"T"},
{"type":"Punctuation","value":"\u003e"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n "},
{"type":"Punctuation","value":"["},
{"type":"NameOther","value":"Key"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"keyof"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"T"},
{"type":"Punctuation","value":"]"},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"Required"},
{"type":"Punctuation","value":"\u003c"},
{"type":"NameTag","value":"Pick"},
{"type":"Punctuation","value":"\u003c"},
{"type":"NameTag","value":"T"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"NameAttribute","value":"Key"},
{"type":"Punctuation","value":"\u003e\u003e"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n\n"},
{"type":"KeywordReserved","value":"const"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"TestComponent"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"({"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"a"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"NameOther","value":"b"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"})"},
{"type":"Text","value":" "},
{"type":"Operator","value":"=\u003e"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"("},
{"type":"Text","value":"\n "},
{"type":"Punctuation","value":"\u003c"},
{"type":"NameTag","value":"Component"},
{"type":"Text","value":" "},
{"type":"NameAttribute","value":"width"},
{"type":"Operator","value":"="},
{"type":"Punctuation","value":"{"},
{"type":"LiteralNumberInteger","value":"100"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":" "},
{"type":"NameAttribute","value":"prop"},
{"type":"Operator","value":"="},
{"type":"Punctuation","value":"{{"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"a"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"..."},
{"type":"NameOther","value":"b"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"}}"},
{"type":"Text","value":" "},
{"type":"NameAttribute","value":"attr"},
{"type":"Operator","value":"="},
{"type":"LiteralString","value":"\"text\""},
{"type":"Punctuation","value":"\u003e"},
{"type":"Text","value":"\n "},
{"type":"Punctuation","value":"\u003c"},
{"type":"NameTag","value":"span"},
{"type":"Punctuation","value":"\u003e"},
{"type":"NameOther","value":"This"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"is"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"a"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"component"},
{"type":"Punctuation","value":"\u003c/"},
{"type":"NameTag","value":"span"},
{"type":"Punctuation","value":"\u003e"},
{"type":"Text","value":"\n "},
{"type":"Punctuation","value":"\u003c"},
{"type":"NameTag","value":"SomethingElse"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"/\u003e"},
{"type":"Text","value":"\n "},
{"type":"Punctuation","value":"\u003c/"},
{"type":"NameTag","value":"Component"},
{"type":"Punctuation","value":"\u003e"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":"\n\n"},
{"type":"KeywordReserved","value":"export"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"TestComponent"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"}"}
]