@@ -33,7 +33,7 @@ describe("styled-components", () => {
33
33
it ( "empty template literal" , ( ) => {
34
34
const code = [
35
35
"function test() {" ,
36
- " console.log( `debug`) " ,
36
+ " alert `debug`" ,
37
37
" return ``;" ,
38
38
"}" ,
39
39
"" ,
@@ -169,4 +169,67 @@ describe("styled-components", () => {
169
169
expect ( document . nodes ) . to . have . lengthOf ( 1 ) ;
170
170
expect ( document . first . first ) . to . haveOwnProperty ( "prop" , "margin-${/* sc-custom 'left' */ rtlSwitch}" ) ;
171
171
} ) ;
172
+
173
+ it ( "lazy assignment" , ( ) => {
174
+ const code = [
175
+ "let myDiv;" ,
176
+ "myDiv = require(\"styled-components\").div;" ,
177
+ "myDiv`a{}`;" ,
178
+ ] . join ( "\n" ) ;
179
+ const document = syntax . parse ( code , {
180
+ from : "lazy_assign.js" ,
181
+ } ) ;
182
+ expect ( document . toString ( ) ) . to . equal ( code ) ;
183
+ expect ( document . source ) . to . haveOwnProperty ( "lang" , "jsx" ) ;
184
+ expect ( document . nodes ) . to . have . lengthOf ( 1 ) ;
185
+ } ) ;
186
+
187
+ it ( "lazy assignment without init" , ( ) => {
188
+ const code = [
189
+ "myDiv = require(\"styled-components\").div;" ,
190
+ "myDiv`a{}`;" ,
191
+ ] . join ( "\n" ) ;
192
+ const document = syntax . parse ( code , {
193
+ from : "lazy_assign_no_init.js" ,
194
+ } ) ;
195
+ expect ( document . toString ( ) ) . to . equal ( code ) ;
196
+ expect ( document . source ) . to . haveOwnProperty ( "lang" , "jsx" ) ;
197
+ expect ( document . nodes ) . to . have . lengthOf ( 1 ) ;
198
+ } ) ;
199
+
200
+ it ( "array destructuring assignment" , ( ) => {
201
+ const code = [
202
+ "const [" ,
203
+ "\tstyledDiv," ,
204
+ "\t...c" ,
205
+ "] = require(\"styled-components\");" ,
206
+ "styledDiv`a{}`;" ,
207
+ ] . join ( "\n" ) ;
208
+ const document = syntax . parse ( code , {
209
+ from : "arr_destructuring.js" ,
210
+ } ) ;
211
+ expect ( document . toString ( ) ) . to . equal ( code ) ;
212
+ expect ( document . source ) . to . haveOwnProperty ( "lang" , "jsx" ) ;
213
+ expect ( document . nodes ) . to . have . lengthOf ( 1 ) ;
214
+ } ) ;
215
+
216
+ it ( "object destructuring assignment" , ( ) => {
217
+ const code = [
218
+ "const {" ,
219
+ "\t// commit" ,
220
+ "\t['div']: styledDiv," ,
221
+ "\ta," ,
222
+ "\t...styled" ,
223
+ "} = require(\"styled-components\");" ,
224
+ "styledDiv`a{}`;" ,
225
+ "styled.div`a{}`;" ,
226
+ "a`a{}`;" ,
227
+ ] . join ( "\n" ) ;
228
+ const document = syntax . parse ( code , {
229
+ from : "obj_destructuring.js" ,
230
+ } ) ;
231
+ expect ( document . toString ( ) ) . to . equal ( code ) ;
232
+ expect ( document . source ) . to . haveOwnProperty ( "lang" , "jsx" ) ;
233
+ expect ( document . nodes ) . to . have . lengthOf ( 3 ) ;
234
+ } ) ;
172
235
} ) ;
0 commit comments