Skip to content

Commit 8603761

Browse files
committed
fix red code when string template arg is exactly at start/end
need to combine prefix/suffix for whole injection with this particular arg
1 parent 48430d4 commit 8603761

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class StyledComponentsInjector : MultiHostInjector {
4040
val stringPlaces = getInjectionPlaces(injectionHost)
4141
registrar.startInjecting(LESSLanguage.INSTANCE)
4242
stringPlaces.forEachIndexed { index, (prefix, range, suffix) ->
43-
val thePrefix = if (index == 0) acceptedPattern.prefix else prefix
44-
val theSuffix = if (index == stringPlaces.size - 1) acceptedPattern.suffix else suffix
43+
val thePrefix = if (index == 0) acceptedPattern.prefix + prefix.orEmpty() else prefix
44+
val theSuffix = if (index == stringPlaces.size - 1) suffix.orEmpty() + acceptedPattern.suffix else suffix
4545
registrar.addPlace(thePrefix, theSuffix, injectionHost, range)
4646
}
4747
registrar.doneInjecting()
@@ -61,6 +61,6 @@ class StyledComponentsInjector : MultiHostInjector {
6161
else result[result.size - 1]
6262
}
6363
data class PlaceInfo(val elementPattern: ElementPattern<JSStringTemplateExpression>,
64-
val prefix: String? = null,
65-
val suffix: String? = null)
64+
val prefix: String = "",
65+
val suffix: String = "")
6666
}

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.1</version>
4+
<version>1.0.2</version>
55
<vendor email="[email protected]" url="http://www.saraya.io">Kodehouse</vendor>
66

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

src/test/InjectionTest.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,18 @@ class InjectionTest : LightCodeInsightFixtureTestCase() {
100100
" }\n")
101101
}
102102

103-
private fun doTest(fileContent: String, expected: String) {
103+
fun testTemplateArgsAtStartEndOfString() {
104+
doTest("let atStart = styled.div`\${getPropName()}:red`\n" +
105+
"let atEnd = styled.div`color:\${getColor()}`\n",
106+
"div {EXTERNAL_FRAGMENT:red}",
107+
"div {color:EXTERNAL_FRAGMENT}")
108+
}
109+
110+
private fun doTest(fileContent: String, vararg expected: String) {
104111
myFixture.setCaresAboutInjection(true)
105112
val file = myFixture.configureByText("dummy.es6", fileContent)
106113
val injections = collectInjectedPsiContents(file)
107-
Assert.assertEquals(1, injections.size)
108-
Assert.assertEquals(expected, injections[0])
114+
Assert.assertEquals(expected.toList(), injections)
109115
}
110116

111117
private fun collectInjectedPsiContents(file: PsiFile): List<String> {

webstorm-styled-components.zip

145 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)