1
- const isLastLineWhitespaceOnly = require ( './general' ) . isLastLineWhitespaceOnly
2
- const isEmptyOrSpaceOnly = require ( './general' ) . isEmptyOrSpaceOnly
1
+ const nextNonWhitespaceChar = require ( './general' ) . nextNonWhitespaceChar
2
+ const isLastDeclarationCompleted = require ( './general' ) . isLastDeclarationCompleted
3
3
4
4
/**
5
5
* Check if a node is a tagged template literal
@@ -14,24 +14,36 @@ const hasInterpolations = node => !node.quasi.quasis[0].tail
14
14
/**
15
15
* Merges the interpolations in a parsed tagged template literals with the strings
16
16
*/
17
- // Used for making sure our dummy mixins are all unique
18
- let count = 0
19
17
const interleave = ( quasis , expressions ) => {
18
+ // Used for making sure our dummy mixins are all unique
19
+ let count = 0
20
20
let css = ''
21
21
for ( let i = 0 , l = expressions . length ; i < l ; i += 1 ) {
22
22
const prevText = quasis [ i ] . value . raw
23
23
const nextText = quasis [ i + 1 ] . value . raw
24
24
25
25
css += prevText
26
- if ( isLastLineWhitespaceOnly ( prevText ) && ! isEmptyOrSpaceOnly ( prevText ) ) {
27
- css += `-styled-mixin${ count } : dummyValue`
26
+ let substitute
27
+ if ( isLastDeclarationCompleted ( css ) ) {
28
+ /** This block assumes that if you put an interpolation in the position
29
+ * of the start of a declaration that the interpolation will
30
+ * contain a full declaration and not later in the template literal
31
+ * be completed by another interpolation / completed by following text
32
+ * in the literal
33
+ */
34
+ substitute = `-styled-mixin${ count } : dummyValue`
28
35
count += 1
29
- if ( nextText . charAt ( 0 ) !== ';' ) {
30
- css += ';'
36
+ if ( nextNonWhitespaceChar ( nextText ) !== ';' ) {
37
+ substitute += ';'
31
38
}
32
39
} else {
33
- css += '$dummyValue'
40
+ /* This block assumes that we are in the middle of a declaration
41
+ * and that the interpolation is providing a value, not a property
42
+ * or part of a property
43
+ */
44
+ substitute = '$dummyValue'
34
45
}
46
+ css += substitute
35
47
}
36
48
css += quasis [ quasis . length - 1 ] . value . raw
37
49
return css
0 commit comments