File tree 6 files changed +57
-6
lines changed
6 files changed +57
-6
lines changed Original file line number Diff line number Diff line change 1
1
2
+ /*
3
+
4
+ regular multi-line comment
5
+
6
+ */
7
+
8
+ /* regular comment */
9
+
2
10
body
3
11
background : # 888
4
12
color : # eee
5
13
14
+ // stripped comment
15
+
6
16
ul
7
17
margin : 0
8
18
li
16
26
ul
17
27
width: 50px
18
28
li
19
- lis t- style: dis c
29
+ lis t- style: dis c
Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ module.exports = function(node){
47
47
return ret ;
48
48
case 'prop' :
49
49
return prop ( node ) ;
50
+ case 'comment' :
51
+ return comment ( node ) ;
50
52
default :
51
53
throw new Error ( 'invalid node "' + node [ 0 ] + '"' ) ;
52
54
}
@@ -67,6 +69,14 @@ module.exports = function(node){
67
69
return buf . join ( '' ) ;
68
70
}
69
71
72
+ /**
73
+ * Visit comment.
74
+ */
75
+
76
+ function comment ( node ) {
77
+ return indent ( ) + '/*' + node [ 1 ] + '*/\n' ;
78
+ }
79
+
70
80
/**
71
81
* Visit prop.
72
82
*/
Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ module.exports = function(str) {
93
93
function next ( ) {
94
94
return stashed ( )
95
95
|| comment ( )
96
+ || csscomment ( )
96
97
|| indentation ( )
97
98
|| prop ( )
98
99
|| rule ( ) ;
@@ -117,6 +118,22 @@ module.exports = function(str) {
117
118
return next ( ) ;
118
119
}
119
120
121
+ /**
122
+ * Multiline comment.
123
+ */
124
+
125
+ function csscomment ( ) {
126
+ if ( '/' != str [ 0 ] || '*' != str [ 1 ] ) return ;
127
+ str = str . slice ( 2 ) ;
128
+
129
+ var i = 0 ;
130
+ while ( '*' != str [ i ] && '/' != str [ i + 1 ] ) ++ i ;
131
+
132
+ var buf = str . slice ( 0 , i ) ;
133
+ str = str . slice ( buf . length + 2 ) ;
134
+
135
+ return [ 'comment' , buf ] ;
136
+ }
120
137
121
138
/**
122
139
* INDENT
Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ module.exports = function(str) {
78
78
function stmt ( ) {
79
79
if ( is ( 'rule' ) ) return rule ( ) ;
80
80
if ( is ( 'prop' ) ) return prop ( ) ;
81
+ return next ( ) ;
81
82
}
82
83
83
84
/**
Original file line number Diff line number Diff line change 1
1
2
+ /*
3
+
4
+ this is a button
5
+
6
+ */
7
+
2
8
// foo
3
9
button
4
10
// bar
5
11
color : # eee
6
12
// bar
7
-
8
-
9
-
13
+
14
+
15
+
10
16
// baz
11
- background : blue
17
+ /* css style */
18
+ background : blue
Original file line number Diff line number Diff line change
1
+ /*
2
+ this is a button
3
+ */
4
+
5
+
1
6
button {
2
7
color : # eee ;
8
+ /* css style */
3
9
background : blue;
4
- }
10
+ }
You can’t perform that action at this time.
0 commit comments