@@ -14,7 +14,6 @@ module.exports = function(css, options){
1414 */
1515
1616 function updatePosition ( str ) {
17- if ( ! options . position ) return ;
1817 var lines = str . match ( / \n / g) ;
1918 if ( lines ) lineno += lines . length ;
2019 var i = str . lastIndexOf ( '\n' ) ;
@@ -49,6 +48,18 @@ module.exports = function(css, options){
4948 return node ;
5049 }
5150
51+ /**
52+ * Error `msg`.
53+ */
54+
55+ function error ( msg ) {
56+ var err = new Error ( msg + ' near line ' + lineno + ':' + column ) ;
57+ err . line = lineno ;
58+ err . column = column ;
59+ err . source = css ;
60+ throw err ;
61+ }
62+
5263 /**
5364 * Parse stylesheet.
5465 */
@@ -173,11 +184,11 @@ module.exports = function(css, options){
173184 prop = prop [ 0 ] ;
174185
175186 // :
176- if ( ! match ( / ^ : \s * / ) ) return ;
187+ if ( ! match ( / ^ : \s * / ) ) return error ( "property missing ':'" ) ;
177188
178189 // val
179190 var val = match ( / ^ ( (?: ' (?: \\ ' | .) * ?' | " (?: \\ " | .) * ?" | \( [ ^ \) ] * ?\) | [ ^ } ; ] ) + ) / ) ;
180- if ( ! val ) return ;
191+ if ( ! val ) return error ( 'property missing value' ) ;
181192
182193 var ret = pos ( {
183194 type : 'declaration' ,
@@ -187,6 +198,7 @@ module.exports = function(css, options){
187198
188199 // ;
189200 match ( / ^ [ ; \s ] * / ) ;
201+
190202 return ret ;
191203 }
192204
@@ -197,7 +209,7 @@ module.exports = function(css, options){
197209 function declarations ( ) {
198210 var decls = [ ] ;
199211
200- if ( ! open ( ) ) return ;
212+ if ( ! open ( ) ) return error ( "missing '{'" ) ;
201213 comments ( decls ) ;
202214
203215 // declarations
@@ -207,7 +219,7 @@ module.exports = function(css, options){
207219 comments ( decls ) ;
208220 }
209221
210- if ( ! close ( ) ) return ;
222+ if ( ! close ( ) ) return error ( "missing '}'" ) ;
211223 return decls ;
212224 }
213225
@@ -247,10 +259,10 @@ module.exports = function(css, options){
247259
248260 // identifier
249261 var m = match ( / ^ ( [ - \w ] + ) \s * / ) ;
250- if ( ! m ) return ;
262+ if ( ! m ) return error ( "@keyframes missing name" ) ;
251263 var name = m [ 1 ] ;
252264
253- if ( ! open ( ) ) return ;
265+ if ( ! open ( ) ) return error ( "@keyframes missing '{'" ) ;
254266 comments ( ) ;
255267
256268 var frame ;
@@ -260,7 +272,7 @@ module.exports = function(css, options){
260272 comments ( ) ;
261273 }
262274
263- if ( ! close ( ) ) return ;
275+ if ( ! close ( ) ) return error ( "@keyframes missing '}'" ) ;
264276
265277 return pos ( {
266278 type : 'keyframes' ,
@@ -281,12 +293,12 @@ module.exports = function(css, options){
281293 if ( ! m ) return ;
282294 var supports = m [ 1 ] . trim ( ) ;
283295
284- if ( ! open ( ) ) return ;
296+ if ( ! open ( ) ) return error ( "@supports missing '{'" ) ;
285297 comments ( ) ;
286298
287299 var style = rules ( ) ;
288300
289- if ( ! close ( ) ) return ;
301+ if ( ! close ( ) ) return error ( "@supports missing '}'" ) ;
290302
291303 return pos ( {
292304 type : 'supports' ,
@@ -306,12 +318,12 @@ module.exports = function(css, options){
306318 if ( ! m ) return ;
307319 var media = m [ 1 ] . trim ( ) ;
308320
309- if ( ! open ( ) ) return ;
321+ if ( ! open ( ) ) return error ( "@media missing '{'" ) ;
310322 comments ( ) ;
311323
312324 var style = rules ( ) ;
313325
314- if ( ! close ( ) ) return ;
326+ if ( ! close ( ) ) return error ( "@media missing '}'" ) ;
315327
316328 return pos ( {
317329 type : 'media' ,
@@ -332,7 +344,7 @@ module.exports = function(css, options){
332344 var sel = selector ( ) || [ ] ;
333345 var decls = [ ] ;
334346
335- if ( ! open ( ) ) return ;
347+ if ( ! open ( ) ) return error ( "@page missing '{'" ) ;
336348 comments ( ) ;
337349
338350 // declarations
@@ -342,7 +354,7 @@ module.exports = function(css, options){
342354 comments ( ) ;
343355 }
344356
345- if ( ! close ( ) ) return ;
357+ if ( ! close ( ) ) return error ( "@page missing '}'" ) ;
346358
347359 return pos ( {
348360 type : 'page' ,
@@ -363,12 +375,12 @@ module.exports = function(css, options){
363375 var vendor = ( m [ 1 ] || '' ) . trim ( ) ;
364376 var doc = m [ 2 ] . trim ( ) ;
365377
366- if ( ! open ( ) ) return ;
378+ if ( ! open ( ) ) return error ( "@document missing '{'" ) ;
367379 comments ( ) ;
368380
369381 var style = rules ( ) ;
370382
371- if ( ! close ( ) ) return ;
383+ if ( ! close ( ) ) return error ( "@document missing '}'" ) ;
372384
373385 return pos ( {
374386 type : 'document' ,
0 commit comments