This repository was archived by the owner on May 14, 2021. It is now read-only.
File tree 4 files changed +46
-1
lines changed
4 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,22 @@ const isLastLineWhitespaceOnly = text => {
48
48
return true
49
49
}
50
50
51
+ /**
52
+ * Checks if text is empty or space only
53
+ */
54
+ const isEmptyOrSpaceOnly = text => {
55
+ if ( text === '' ) {
56
+ return true
57
+ }
58
+ for ( let i = text . length - 1 ; i >= 0 ; i -= 1 ) {
59
+ const char = text . charAt ( i )
60
+ if ( char !== '\t' && char !== ' ' ) {
61
+ return false
62
+ }
63
+ }
64
+ return true
65
+ }
66
+
51
67
// eslint-disable-next-line no-return-assign
52
68
const wrapSelector = content => `.selector${ ( count += 1 ) } {${ content } }\n`
53
69
const wrapKeyframes = content => `@keyframes {${ content } }\n`
@@ -56,3 +72,4 @@ exports.wrapKeyframes = wrapKeyframes
56
72
exports . wrapSelector = wrapSelector
57
73
exports . fixIndentation = fixIndentation
58
74
exports . isLastLineWhitespaceOnly = isLastLineWhitespaceOnly
75
+ exports . isEmptyOrSpaceOnly = isEmptyOrSpaceOnly
Original file line number Diff line number Diff line change 1
1
const isLastLineWhitespaceOnly = require ( './general' ) . isLastLineWhitespaceOnly
2
+ const isEmptyOrSpaceOnly = require ( './general' ) . isEmptyOrSpaceOnly
2
3
3
4
/**
4
5
* Check if a node is a tagged template literal
@@ -21,7 +22,7 @@ const interleave = (quasis, expressions) => {
21
22
const expression = expressions [ i ]
22
23
23
24
css += prevText
24
- if ( isLastLineWhitespaceOnly ( prevText ) ) {
25
+ if ( isLastLineWhitespaceOnly ( prevText ) && ! isEmptyOrSpaceOnly ( prevText ) ) {
25
26
css += `-styled-mixin: ${ expression . name } `
26
27
if ( nextText . charAt ( 0 ) !== ';' ) {
27
28
css += ';'
Original file line number Diff line number Diff line change @@ -71,3 +71,11 @@ const Button6 = styled.button`
71
71
` }
72
72
background: blue;
73
73
`
74
+
75
+ // multi interpolations within a property
76
+ const borderWidth = '1px'
77
+ const borderStyle = 'solid'
78
+ const Button7 = styled . button `
79
+ width: 20px;
80
+ border: ${ borderWidth } ${ borderStyle } ${ color } ;
81
+ `
Original file line number Diff line number Diff line change 1
1
const interleave = require ( '../src/utils/tagged-template-literal' ) . interleave
2
2
const isLastLineWhitespaceOnly = require ( '../src/utils/general' ) . isLastLineWhitespaceOnly
3
+ const isEmptyOrSpaceOnly = require ( '../src/utils/general' ) . isEmptyOrSpaceOnly
3
4
4
5
describe ( 'utils' , ( ) => {
5
6
describe ( 'interleave' , ( ) => {
@@ -60,4 +61,22 @@ describe('utils', () => {
60
61
expect ( isLastLineWhitespaceOnly ( 'not space\n ' ) ) . toEqual ( true )
61
62
} )
62
63
} )
64
+
65
+ describe ( 'isEmptyOrSpaceOnly' , ( ) => {
66
+ it ( 'should return true for empty string' , ( ) => {
67
+ expect ( isEmptyOrSpaceOnly ( '' ) ) . toEqual ( true )
68
+ } )
69
+
70
+ it ( 'should return true for consecutive empty string' , ( ) => {
71
+ expect ( isEmptyOrSpaceOnly ( ' ' ) ) . toEqual ( true )
72
+ } )
73
+
74
+ it ( 'should return true for string of spaces and tabs' , ( ) => {
75
+ expect ( isEmptyOrSpaceOnly ( ' \t ' ) ) . toEqual ( true )
76
+ } )
77
+
78
+ it ( 'should return false for string of newline' , ( ) => {
79
+ expect ( isEmptyOrSpaceOnly ( '\n' ) ) . toEqual ( false )
80
+ } )
81
+ } )
63
82
} )
You can’t perform that action at this time.
0 commit comments