Skip to content

Commit

Permalink
Merge pull request #29 from undeadcat/master
Browse files Browse the repository at this point in the history
Support .attrs({}) calls
  • Loading branch information
undeadcat authored Sep 13, 2017
2 parents bcb9cf9 + 964b6e5 commit fa0bf6c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/kotlin/com/intellij/StyledComponents/Patterns.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -34,6 +35,7 @@ fun withReferenceName(name: String): ElementPattern<JSReferenceExpression> {
}

fun referenceExpression() = PlatformPatterns.psiElement(JSReferenceExpression::class.java)!!
fun callExpression() = PlatformPatterns.psiElement(JSCallExpression::class.java)!!

fun withNameStartingWith(vararg components: String): ElementPattern<JSReferenceExpression> {
val componentsList = ContainerUtil.list(*components)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {", "}")
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>com.deadlock.scsyntax</id>
<name>Styled Components</name>
<version>1.0.4</version>
<version>1.0.5</version>
<vendor email="hossam.saraya@gmail.com" url="http://www.saraya.io">Kodehouse</vendor>

<!-- Enable plugin for all products -->
Expand Down
9 changes: 9 additions & 0 deletions src/test/InjectionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
Binary file modified webstorm-styled-components.zip
Binary file not shown.

0 comments on commit fa0bf6c

Please sign in to comment.