@@ -8,18 +8,19 @@ describe("styled-components", () => {
8
8
const file = require . resolve ( "./fixtures/styled" ) ;
9
9
let code = fs . readFileSync ( file ) ;
10
10
11
- const root = syntax . parse ( code , {
11
+ const document = syntax . parse ( code , {
12
12
from : file ,
13
13
} ) ;
14
14
15
15
code = code . toString ( ) ;
16
- expect ( root . toString ( ) , code ) ;
16
+ expect ( document . toString ( ) , code ) ;
17
+ expect ( document . source ) . to . haveOwnProperty ( "lang" , "jsx" ) ;
17
18
18
- expect ( root . nodes ) . to . have . lengthOf ( 1 ) ;
19
- expect ( root . first . nodes ) . to . have . lengthOf ( 8 ) ;
19
+ expect ( document . nodes ) . to . have . lengthOf ( 1 ) ;
20
+ expect ( document . first . nodes ) . to . have . lengthOf ( 8 ) ;
20
21
21
22
const lines = code . match ( / ^ .+ $ / gm) . slice ( 3 ) . map ( line => ( line . replace ( / ^ \s * ( .+ ?) ; ? \s * $ / , "$1" ) ) ) ;
22
- root . first . nodes . forEach ( ( decl , i ) => {
23
+ document . first . nodes . forEach ( ( decl , i ) => {
23
24
if ( i ) {
24
25
expect ( decl ) . to . have . property ( "type" , "decl" ) ;
25
26
} else {
@@ -37,70 +38,76 @@ describe("styled-components", () => {
37
38
"}" ,
38
39
"" ,
39
40
] . join ( "\n" ) ;
40
- const root = syntax . parse ( code , {
41
+ const document = syntax . parse ( code , {
41
42
from : "empty_template_literal.js" ,
42
43
} ) ;
43
- expect ( root . toString ( ) ) . to . equal ( code ) ;
44
- expect ( root . nodes ) . to . have . lengthOf ( 0 ) ;
44
+ expect ( document . toString ( ) ) . to . equal ( code ) ;
45
+ expect ( document . source ) . to . haveOwnProperty ( "lang" , "jsx" ) ;
46
+ expect ( document . nodes ) . to . have . lengthOf ( 0 ) ;
45
47
} ) ;
46
48
47
49
it ( "skip javascript syntax error" , ( ) => {
48
50
const code = "\\`" ;
49
- const root = syntax . parse ( code , {
51
+ const document = syntax . parse ( code , {
50
52
from : "syntax_error.js" ,
51
53
} ) ;
52
- expect ( root . toString ( ) ) . to . equal ( code ) ;
53
- expect ( root . nodes ) . to . have . lengthOf ( 0 ) ;
54
+ expect ( document . toString ( ) ) . to . equal ( code ) ;
55
+ expect ( document . source ) . to . haveOwnProperty ( "lang" , "jsx" ) ;
56
+ expect ( document . nodes ) . to . have . lengthOf ( 0 ) ;
54
57
} ) ;
55
58
56
59
it ( "illegal template literal" , ( ) => {
57
60
const code = "`$\n{display: block}\n${g} {}`" ;
58
- const root = syntax . parse ( code , {
61
+ const document = syntax . parse ( code , {
59
62
from : "illegal_template_literal.js" ,
60
63
} ) ;
61
- expect ( root . toString ( ) ) . to . equal ( code ) ;
62
- expect ( root . nodes ) . to . have . lengthOf ( 1 ) ;
63
- expect ( root . first . nodes ) . to . have . lengthOf ( 2 ) ;
64
- expect ( root . first . first ) . have . property ( "type" , "rule" ) ;
65
- expect ( root . first . first ) . have . property ( "selector" , "$" ) ;
66
- expect ( root . last . last ) . have . property ( "type" , "rule" ) ;
67
- expect ( root . last . last ) . have . property ( "selector" , "${g}" ) ;
64
+ expect ( document . toString ( ) ) . to . equal ( code ) ;
65
+ expect ( document . source ) . to . haveOwnProperty ( "lang" , "jsx" ) ;
66
+ expect ( document . nodes ) . to . have . lengthOf ( 1 ) ;
67
+ expect ( document . first . nodes ) . to . have . lengthOf ( 2 ) ;
68
+ expect ( document . first . first ) . have . property ( "type" , "rule" ) ;
69
+ expect ( document . first . first ) . have . property ( "selector" , "$" ) ;
70
+ expect ( document . last . last ) . have . property ( "type" , "rule" ) ;
71
+ expect ( document . last . last ) . have . property ( "selector" , "${g}" ) ;
68
72
} ) ;
69
73
70
74
it ( "skip CSS syntax error" , ( ) => {
71
75
const code = "`a{`" ;
72
- const root = syntax . parse ( code , {
76
+ const document = syntax . parse ( code , {
73
77
from : "css_syntax_error.js" ,
74
78
} ) ;
75
- expect ( root . toString ( ) ) . to . equal ( code ) ;
76
- expect ( root . nodes ) . to . have . lengthOf ( 0 ) ;
79
+ expect ( document . toString ( ) ) . to . equal ( code ) ;
80
+ expect ( document . source ) . to . haveOwnProperty ( "lang" , "jsx" ) ;
81
+ expect ( document . nodes ) . to . have . lengthOf ( 0 ) ;
77
82
} ) ;
78
83
79
84
it ( "fix CSS syntax error" , ( ) => {
80
85
const code = "`a{`" ;
81
- const root = syntax ( {
86
+ const document = syntax ( {
82
87
css : "safe-parser" ,
83
88
} ) . parse ( code , {
84
89
from : "postcss-safe-parser.js" ,
85
90
} ) ;
86
- expect ( root . toString ( ) ) . to . equal ( "`a{}`" ) ;
87
- expect ( root . nodes ) . to . have . lengthOf ( 1 ) ;
88
- expect ( root . first . nodes ) . to . have . lengthOf ( 1 ) ;
89
- expect ( root . first . first ) . have . property ( "type" , "rule" ) ;
90
- expect ( root . first . first ) . have . property ( "selector" , "a" ) ;
91
+ expect ( document . toString ( ) ) . to . equal ( "`a{}`" ) ;
92
+ expect ( document . source ) . to . haveOwnProperty ( "lang" , "jsx" ) ;
93
+ expect ( document . nodes ) . to . have . lengthOf ( 1 ) ;
94
+ expect ( document . first . nodes ) . to . have . lengthOf ( 1 ) ;
95
+ expect ( document . first . first ) . have . property ( "type" , "rule" ) ;
96
+ expect ( document . first . first ) . have . property ( "selector" , "a" ) ;
91
97
} ) ;
92
98
93
99
it ( "fix styled syntax error" , ( ) => {
94
100
const code = "`${ a } {`" ;
95
- const root = syntax ( {
101
+ const document = syntax ( {
96
102
css : "safe-parser" ,
97
103
} ) . parse ( code , {
98
104
from : "styled-safe-parse.js" ,
99
105
} ) ;
100
- expect ( root . toString ( ) ) . to . equal ( "`${ a } {}`" ) ;
101
- expect ( root . nodes ) . to . have . lengthOf ( 1 ) ;
102
- expect ( root . first . nodes ) . to . have . lengthOf ( 1 ) ;
103
- expect ( root . first . first ) . have . property ( "type" , "rule" ) ;
104
- expect ( root . first . first ) . have . property ( "selector" , "${ a }" ) ;
106
+ expect ( document . toString ( ) ) . to . equal ( "`${ a } {}`" ) ;
107
+ expect ( document . source ) . to . haveOwnProperty ( "lang" , "jsx" ) ;
108
+ expect ( document . nodes ) . to . have . lengthOf ( 1 ) ;
109
+ expect ( document . first . nodes ) . to . have . lengthOf ( 1 ) ;
110
+ expect ( document . first . first ) . have . property ( "type" , "rule" ) ;
111
+ expect ( document . first . first ) . have . property ( "selector" , "${ a }" ) ;
105
112
} ) ;
106
113
} ) ;
0 commit comments