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

Add generic tagged template literals support #50

Closed
wants to merge 1 commit into from
Closed

Add generic tagged template literals support #50

wants to merge 1 commit into from

Conversation

mmalicki
Copy link

@mmalicki mmalicki commented Jul 7, 2018

No description provided.

Copy link
Member

@mxstbr mxstbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very aware of all this code so forgive me if this is a wrong comment, but we definitely do not want to highlight all tagged template literals. People use them for things other than CSS.

@undeadcat
Copy link
Contributor

Thanks for the pull request! It's great to see someone take an interest in the code.

Unfortunately, I don't think it's needed at all.

Template string generic type arguments were added in Typescript 2.9 in April and aren't parsed in any way correctly in IDE versions released prior to that (generic type arguments are represented in WebStorm/IDEA syntax structure by TypeScriptTypeArgumentList, JSBinaryExpression is used only for actual binary expressions).

While the current approach is a good first start and handles simple cases, unfortunately, TypeScript has much more complicated types which would be difficult to handle without correct parsing (see examples below)...

WebStorm 2018.2 EAP builds parse type arguments correctly after support was added in this issue and the plugin correctly highlights styled-components code for me in 2018.2:

image

import styled from 'styled-components';
let one = styled.div<Foo>`color:red`;
let another = styled.div<Foo<number>>`color:yellow`;
let withCallback = styled.div<Foo<Bar<{ onClick: () => void }>>>`color:yellow`;

image

2018.2 EAP builds are available on the WebStorm EAP page (or a similar page for other IDEs). A release is planned for the second half of July.

@mmalicki
Copy link
Author

mmalicki commented Jul 7, 2018

Thanks for a such detailed response!

Indeed, this handling of generic template literals felt somewhat hacky, as it didn't appear to be recognized properly by Intellij - I should have done more research. Glad that it works now out of the box in 2018.2 build.

I will close that PR, as it's not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants