Skip to content

Commit cc63aa9

Browse files
committed
support .attrs({}) call. Fixes #28
1 parent 25d2a2d commit cc63aa9

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/main/kotlin/com/intellij/StyledComponents/Patterns.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.intellij.StyledComponents
22

3+
import com.intellij.lang.javascript.psi.JSCallExpression
34
import com.intellij.lang.javascript.psi.JSExpression
45
import com.intellij.lang.javascript.psi.JSReferenceExpression
56
import com.intellij.lang.javascript.psi.ecma6.ES6TaggedTemplateExpression
@@ -34,6 +35,7 @@ fun withReferenceName(name: String): ElementPattern<JSReferenceExpression> {
3435
}
3536

3637
fun referenceExpression() = PlatformPatterns.psiElement(JSReferenceExpression::class.java)!!
38+
fun callExpression() = PlatformPatterns.psiElement(JSCallExpression::class.java)!!
3739

3840
fun withNameStartingWith(vararg components: String): ElementPattern<JSReferenceExpression> {
3941
val componentsList = ContainerUtil.list(*components)

src/main/kotlin/com/intellij/StyledComponents/StyledComponentsInjector.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class StyledComponentsInjector : MultiHostInjector {
2222
PlatformPatterns.psiElement(JSExpression::class.java)
2323
.withFirstChild(styledPattern))), "div {", "}"),
2424
PlaceInfo(taggedTemplate(withReferenceName("extend")), "div {", "}"),
25+
PlaceInfo(taggedTemplate(callExpression().withChild(withReferenceName("attrs"))), "div {", "}"),
2526
PlaceInfo(taggedTemplate("css"), "div {", "}"),
2627
PlaceInfo(taggedTemplate("injectGlobal")),
2728
PlaceInfo(taggedTemplate("keyframes"), "@keyframes foo {", "}")

src/test/InjectionTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ class InjectionTest : LightCodeInsightFixtureTestCase() {
105105
"}")
106106
}
107107

108+
fun testComponentAttrs() {
109+
doTest("const div = styled.div;\n" +
110+
"const FilterIcon = div.attrs({ iconName: 'filter' })`\n" +
111+
" line-height: 0;\n" +
112+
"`", "div {\n" +
113+
" line-height: 0;\n" +
114+
"}")
115+
}
116+
108117
fun testInjectGlobal() {
109118
doTest("injectGlobal`\n" +
110119
" div{\n" +

0 commit comments

Comments
 (0)