@@ -14,7 +14,6 @@ module.exports = function(css, options){
14
14
*/
15
15
16
16
function updatePosition ( str ) {
17
- if ( ! options . position ) return ;
18
17
var lines = str . match ( / \n / g) ;
19
18
if ( lines ) lineno += lines . length ;
20
19
var i = str . lastIndexOf ( '\n' ) ;
@@ -49,6 +48,18 @@ module.exports = function(css, options){
49
48
return node ;
50
49
}
51
50
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
+
52
63
/**
53
64
* Parse stylesheet.
54
65
*/
@@ -173,11 +184,11 @@ module.exports = function(css, options){
173
184
prop = prop [ 0 ] ;
174
185
175
186
// :
176
- if ( ! match ( / ^ : \s * / ) ) return ;
187
+ if ( ! match ( / ^ : \s * / ) ) return error ( "property missing ':'" ) ;
177
188
178
189
// val
179
190
var val = match ( / ^ ( (?: ' (?: \\ ' | .) * ?' | " (?: \\ " | .) * ?" | \( [ ^ \) ] * ?\) | [ ^ } ; ] ) + ) / ) ;
180
- if ( ! val ) return ;
191
+ if ( ! val ) return error ( 'property missing value' ) ;
181
192
182
193
var ret = pos ( {
183
194
type : 'declaration' ,
@@ -187,6 +198,7 @@ module.exports = function(css, options){
187
198
188
199
// ;
189
200
match ( / ^ [ ; \s ] * / ) ;
201
+
190
202
return ret ;
191
203
}
192
204
@@ -197,7 +209,7 @@ module.exports = function(css, options){
197
209
function declarations ( ) {
198
210
var decls = [ ] ;
199
211
200
- if ( ! open ( ) ) return ;
212
+ if ( ! open ( ) ) return error ( "missing '{'" ) ;
201
213
comments ( decls ) ;
202
214
203
215
// declarations
@@ -207,7 +219,7 @@ module.exports = function(css, options){
207
219
comments ( decls ) ;
208
220
}
209
221
210
- if ( ! close ( ) ) return ;
222
+ if ( ! close ( ) ) return error ( "missing '}'" ) ;
211
223
return decls ;
212
224
}
213
225
@@ -247,10 +259,10 @@ module.exports = function(css, options){
247
259
248
260
// identifier
249
261
var m = match ( / ^ ( [ - \w ] + ) \s * / ) ;
250
- if ( ! m ) return ;
262
+ if ( ! m ) return error ( "@keyframes missing name" ) ;
251
263
var name = m [ 1 ] ;
252
264
253
- if ( ! open ( ) ) return ;
265
+ if ( ! open ( ) ) return error ( "@keyframes missing '{'" ) ;
254
266
comments ( ) ;
255
267
256
268
var frame ;
@@ -260,7 +272,7 @@ module.exports = function(css, options){
260
272
comments ( ) ;
261
273
}
262
274
263
- if ( ! close ( ) ) return ;
275
+ if ( ! close ( ) ) return error ( "@keyframes missing '}'" ) ;
264
276
265
277
return pos ( {
266
278
type : 'keyframes' ,
@@ -281,12 +293,12 @@ module.exports = function(css, options){
281
293
if ( ! m ) return ;
282
294
var supports = m [ 1 ] . trim ( ) ;
283
295
284
- if ( ! open ( ) ) return ;
296
+ if ( ! open ( ) ) return error ( "@supports missing '{'" ) ;
285
297
comments ( ) ;
286
298
287
299
var style = rules ( ) ;
288
300
289
- if ( ! close ( ) ) return ;
301
+ if ( ! close ( ) ) return error ( "@supports missing '}'" ) ;
290
302
291
303
return pos ( {
292
304
type : 'supports' ,
@@ -306,12 +318,12 @@ module.exports = function(css, options){
306
318
if ( ! m ) return ;
307
319
var media = m [ 1 ] . trim ( ) ;
308
320
309
- if ( ! open ( ) ) return ;
321
+ if ( ! open ( ) ) return error ( "@media missing '{'" ) ;
310
322
comments ( ) ;
311
323
312
324
var style = rules ( ) ;
313
325
314
- if ( ! close ( ) ) return ;
326
+ if ( ! close ( ) ) return error ( "@media missing '}'" ) ;
315
327
316
328
return pos ( {
317
329
type : 'media' ,
@@ -332,7 +344,7 @@ module.exports = function(css, options){
332
344
var sel = selector ( ) || [ ] ;
333
345
var decls = [ ] ;
334
346
335
- if ( ! open ( ) ) return ;
347
+ if ( ! open ( ) ) return error ( "@page missing '{'" ) ;
336
348
comments ( ) ;
337
349
338
350
// declarations
@@ -342,7 +354,7 @@ module.exports = function(css, options){
342
354
comments ( ) ;
343
355
}
344
356
345
- if ( ! close ( ) ) return ;
357
+ if ( ! close ( ) ) return error ( "@page missing '}'" ) ;
346
358
347
359
return pos ( {
348
360
type : 'page' ,
@@ -363,12 +375,12 @@ module.exports = function(css, options){
363
375
var vendor = ( m [ 1 ] || '' ) . trim ( ) ;
364
376
var doc = m [ 2 ] . trim ( ) ;
365
377
366
- if ( ! open ( ) ) return ;
378
+ if ( ! open ( ) ) return error ( "@document missing '{'" ) ;
367
379
comments ( ) ;
368
380
369
381
var style = rules ( ) ;
370
382
371
- if ( ! close ( ) ) return ;
383
+ if ( ! close ( ) ) return error ( "@document missing '}'" ) ;
372
384
373
385
return pos ( {
374
386
type : 'document' ,
0 commit comments