Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ class InterpolationArgumentsErrorFilter : HighlightErrorFilter(), HighlightInfoF
if (highlightInfo.severity === HighlightSeverity.WARNING
|| highlightInfo.severity === HighlightSeverity.WEAK_WARNING
|| highlightInfo.severity === HighlightSeverity.ERROR) {
return acceptedRanges.any { range ->
highlightInfo.startOffset > range.startOffset
&& highlightInfo.endOffset < range.endOffset
}
return acceptedRanges.any { highlightInfo.startOffset > it.startOffset
&& highlightInfo.endOffset < it.endOffset }
}
return true
}
Expand Down
12 changes: 11 additions & 1 deletion src/main/kotlin/com/intellij/StyledComponents/Patterns.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.intellij.StyledComponents

import com.intellij.lang.javascript.JSTokenTypes
import com.intellij.lang.javascript.psi.JSBinaryExpression
import com.intellij.lang.javascript.psi.JSCallExpression
import com.intellij.lang.javascript.psi.JSExpression
import com.intellij.lang.javascript.psi.JSReferenceExpression
Expand All @@ -24,7 +26,15 @@ fun taggedTemplate(tagPattern: ElementPattern<out JSExpression>): ElementPattern
.withParent(PlatformPatterns.psiElement(ES6TaggedTemplateExpression::class.java)
.withChild(tagPattern))
}

fun genericTaggedTemplate(tagPattern: ElementPattern<out JSExpression>): ElementPattern<JSStringTemplateExpression> {
return PlatformPatterns.psiElement(JSStringTemplateExpression::class.java)
.withParent(PlatformPatterns.psiElement(JSBinaryExpression::class.java)
.withChild(PlatformPatterns.psiElement(JSBinaryExpression::class.java)
.withChild(PlatformPatterns.psiElement(JSReferenceExpression::class.java)
.withChild(tagPattern))
.withChild(PlatformPatterns.psiElement(JSTokenTypes.LT)))
.withChild(PlatformPatterns.psiElement(JSTokenTypes.GT)))
}
fun withReferenceName(name: String): ElementPattern<JSReferenceExpression> {
return referenceExpression()
.with(object : PatternCondition<JSReferenceExpression>("referenceName") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class StyledComponentsInjector : MultiHostInjector {
companion object {
private val styledPattern = withNameStartingWith("styled")
val places: List<PlaceInfo> = listOf(
PlaceInfo(genericTaggedTemplate(styledPattern), "div {", "}"),
PlaceInfo(taggedTemplate(PlatformPatterns.or(styledPattern,
PlatformPatterns.psiElement(JSExpression::class.java)
.withFirstChild(styledPattern))), "div {", "}"),
Expand Down
14 changes: 14 additions & 0 deletions src/test/InjectionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ class InjectionTest : LightCodeInsightFixtureTestCase() {
" height:100px;}")
}

fun testGenericTaggedTemplate() {
val fileContent = """
const Div = styled.div<Props>`
color: red;
`;
""".trimIndent()
val expected = """
div {
color: red;
}
""".trimIndent()
doTest(fileContent, expected)
}

fun testSimpleComponent() {
doTest("const Title = styled.h1`\n" +
" font-size: 1.5em;\n" +
Expand Down