@@ -14,6 +14,7 @@ describe('Parser → Comment', () => {
1414 failures ;
1515
1616 fixtures = [
17+ // standard comments
1718 {
1819 it : 'should parse comments' ,
1920 test : '/*before*/ 1px /*between*/ 1px /*after*/' ,
@@ -53,6 +54,97 @@ describe('Parser → Comment', () => {
5354 { type : 'paren' , value : ')' }
5455 ]
5556 } ,
57+ {
58+ it : 'should parse only one empty comment' ,
59+ test : '/**/' ,
60+ expected : [
61+ { type : 'comment' , value : '' , raws : { before : '' } } ,
62+ ]
63+ } ,
64+
65+ // double slash comment
66+ {
67+ it : 'should parse double slash comments' ,
68+ test : '//before\n 1px //between\n 1px //after\n' ,
69+ loose : true ,
70+ expected : [
71+ { type : 'comment' , value : 'before' , inline : true } ,
72+ { type : 'number' , value : '1' , unit : 'px' , raws : { before : '\n ' } } ,
73+ { type : 'comment' , value : 'between' , inline : true , raws : { before : ' ' } } ,
74+ { type : 'number' , value : '1' , unit : 'px' , raws : { before : '\n ' } } ,
75+ { type : 'comment' , value : 'after' , inline : true , raws : { before : ' ' } }
76+ ]
77+ } ,
78+ {
79+ it : 'should parse double slash comments inside functions' ,
80+ test : 'rgba( 0, 55/55, 0//,.5\n )' ,
81+ loose : true ,
82+ expected : [
83+ { type : 'func' , value : 'rgba' } ,
84+ { type : 'paren' , value : '(' } ,
85+ { type : 'number' , value : '0' , raws : { before : ' ' } } ,
86+ { type : 'comma' , value : ',' } ,
87+ { type : 'number' , value : '55' , raws : { before : ' ' } } ,
88+ { type : 'operator' , value : '/' } ,
89+ { type : 'number' , value : '55' } ,
90+ { type : 'comma' , value : ',' } ,
91+ { type : 'number' , value : '0' , raws : { before : ' ' } } ,
92+ { type : 'comment' , value : ',.5' } ,
93+
94+ ]
95+ } ,
96+ {
97+ it : 'should parse double slash comments when url function have nested function' ,
98+ test : 'url(var(//comment\n))' ,
99+ loose : true ,
100+ expected : [
101+ { type : 'func' , value : 'url' } ,
102+ { type : 'paren' , value : '(' } ,
103+ { type : 'func' , value : 'var' } ,
104+ { type : 'paren' , value : '(' } ,
105+ { type : 'comment' , value : 'comment' } ,
106+ { type : 'paren' , value : ')' } ,
107+ { type : 'paren' , value : ')' }
108+ ]
109+ } ,
110+ {
111+ it : 'should parse only one double slash empty comment' ,
112+ test : '//\n' ,
113+ loose : true ,
114+ expected : [
115+ { type : 'comment' , value : '' , inline : true , raws : { before : '' } } ,
116+ ]
117+ } ,
118+ {
119+ it : 'should parse only one double slash empty comment without newline' ,
120+ test : '//' ,
121+ loose : true ,
122+ expected : [
123+ { type : 'comment' , value : '' , inline : true , raws : { before : '' } } ,
124+ ]
125+ } ,
126+
127+ // mixed standard and double slash comments
128+ {
129+ it : 'should parse mixed comments #1' ,
130+ test : '/*before*/\n//between\n/*after*/' ,
131+ loose : true ,
132+ expected : [
133+ { type : 'comment' , value : 'before' , inline : false , raws : { before : '' } } ,
134+ { type : 'comment' , value : 'between' , inline : true , raws : { before : '\n' } } ,
135+ { type : 'comment' , value : 'after' , inline : false , raws : { before : '\n' } } ,
136+ ]
137+ } ,
138+ {
139+ it : 'should parse mixed comments #2' ,
140+ test : '//before\n/*between*/\n//after' ,
141+ loose : true ,
142+ expected : [
143+ { type : 'comment' , value : 'before' , inline : true , raws : { before : '' } } ,
144+ { type : 'comment' , value : 'between' , inline : false , raws : { before : '\n' } } ,
145+ { type : 'comment' , value : 'after' , inline : true , raws : { before : '\n' } } ,
146+ ]
147+ } ,
56148
57149 // these tests are based on the spec rules surrounding legacy
58150 // quotation-mark–less url notation.
@@ -61,6 +153,8 @@ describe('Parser → Comment', () => {
61153 // doesn't start with either kind of quotation mark.
62154 // postcss-value-parser ignores those rules and allows comments within a url()
63155 // function if the first param starts with a space.
156+
157+ // standard comments
64158 {
65159 it : 'should not parse comments at the end of url functions with quoted first argument, lead by a space' ,
66160 test : 'url( "/demo/bg.png" /*comment*/ )' ,
@@ -90,6 +184,29 @@ describe('Parser → Comment', () => {
90184 { type : 'word' , value : ' /demo/bg.png /*comment*/ ' } ,
91185 { type : 'paren' , value : ')' }
92186 ]
187+ } ,
188+
189+ // double slash comments
190+ {
191+ it : 'should not parse double slash as comment in url function' ,
192+ test : 'url(//bar\n http://domain.com/foo/bar //foo\n)' ,
193+ loose : true ,
194+ expected : [
195+ { type : 'func' , value : 'url' } ,
196+ { type : 'paren' , value : '(' } ,
197+ { type : 'operator' , value : '/' } ,
198+ { type : 'operator' , value : '/' } ,
199+ { type : 'word' , value : 'bar' } ,
200+ { type : 'word' , value : 'http' } ,
201+ { type : 'colon' , value : ':' } ,
202+ { type : 'operator' , value : '/' } ,
203+ { type : 'operator' , value : '/' } ,
204+ { type : 'word' , value : 'domain.com/foo/bar' } ,
205+ { type : 'operator' , value : '/' } ,
206+ { type : 'operator' , value : '/' } ,
207+ { type : 'word' , value : 'foo' } ,
208+ { type : 'paren' , value : ')' } ,
209+ ]
93210 }
94211 ] ;
95212
@@ -100,7 +217,7 @@ describe('Parser → Comment', () => {
100217
101218 fixtures . forEach ( ( fixture ) => {
102219 it ( fixture . it , ( ) => {
103- let ast = new Parser ( fixture . test ) . parse ( ) ,
220+ let ast = new Parser ( fixture . test , { loose : fixture . loose } ) . parse ( ) ,
104221 index = 0 ;
105222
106223 ast . first . walk ( ( node ) => {
0 commit comments