diff --git a/src/main/kotlin/com/intellij/StyledComponents/Patterns.kt b/src/main/kotlin/com/intellij/StyledComponents/Patterns.kt index 7e8c582..4425c62 100644 --- a/src/main/kotlin/com/intellij/StyledComponents/Patterns.kt +++ b/src/main/kotlin/com/intellij/StyledComponents/Patterns.kt @@ -1,5 +1,6 @@ package com.intellij.StyledComponents +import com.intellij.lang.javascript.psi.JSCallExpression import com.intellij.lang.javascript.psi.JSExpression import com.intellij.lang.javascript.psi.JSReferenceExpression import com.intellij.lang.javascript.psi.ecma6.ES6TaggedTemplateExpression @@ -34,6 +35,7 @@ fun withReferenceName(name: String): ElementPattern { } fun referenceExpression() = PlatformPatterns.psiElement(JSReferenceExpression::class.java)!! +fun callExpression() = PlatformPatterns.psiElement(JSCallExpression::class.java)!! fun withNameStartingWith(vararg components: String): ElementPattern { val componentsList = ContainerUtil.list(*components) diff --git a/src/main/kotlin/com/intellij/StyledComponents/StyledComponentsInjector.kt b/src/main/kotlin/com/intellij/StyledComponents/StyledComponentsInjector.kt index 1719229..e3d5ec6 100644 --- a/src/main/kotlin/com/intellij/StyledComponents/StyledComponentsInjector.kt +++ b/src/main/kotlin/com/intellij/StyledComponents/StyledComponentsInjector.kt @@ -22,6 +22,7 @@ class StyledComponentsInjector : MultiHostInjector { PlatformPatterns.psiElement(JSExpression::class.java) .withFirstChild(styledPattern))), "div {", "}"), PlaceInfo(taggedTemplate(withReferenceName("extend")), "div {", "}"), + PlaceInfo(taggedTemplate(callExpression().withChild(withReferenceName("attrs"))), "div {", "}"), PlaceInfo(taggedTemplate("css"), "div {", "}"), PlaceInfo(taggedTemplate("injectGlobal")), PlaceInfo(taggedTemplate("keyframes"), "@keyframes foo {", "}") diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 60bf227..565a576 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,7 +1,7 @@ com.deadlock.scsyntax Styled Components - 1.0.4 + 1.0.5 Kodehouse diff --git a/src/test/InjectionTest.kt b/src/test/InjectionTest.kt index e5a2a42..26ddaca 100644 --- a/src/test/InjectionTest.kt +++ b/src/test/InjectionTest.kt @@ -105,6 +105,15 @@ class InjectionTest : LightCodeInsightFixtureTestCase() { "}") } + fun testComponentAttrs() { + doTest("const div = styled.div;\n" + + "const FilterIcon = div.attrs({ iconName: 'filter' })`\n" + + " line-height: 0;\n" + + "`", "div {\n" + + " line-height: 0;\n" + + "}") + } + fun testInjectGlobal() { doTest("injectGlobal`\n" + " div{\n" + diff --git a/webstorm-styled-components.zip b/webstorm-styled-components.zip index b25eb3c..020d5be 100644 Binary files a/webstorm-styled-components.zip and b/webstorm-styled-components.zip differ