Skip to content

Commit fa0bf6c

Browse files
authored
Merge pull request #29 from undeadcat/master
Support .attrs({}) calls
2 parents bcb9cf9 + 964b6e5 commit fa0bf6c

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
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/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin>
22
<id>com.deadlock.scsyntax</id>
33
<name>Styled Components</name>
4-
<version>1.0.4</version>
4+
<version>1.0.5</version>
55
<vendor email="hossam.saraya@gmail.com" url="http://www.saraya.io">Kodehouse</vendor>
66

77
<!-- Enable plugin for all products -->

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" +

webstorm-styled-components.zip

153 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)