@@ -42,9 +42,13 @@ function shouldBeParsedAsBlockSelector(rule: postcss.Rule): boolean {
42
42
**/
43
43
function getParsedSelectors ( configuration : Configuration , block : Block , rule : postcss . Rule , file : string ) : ParsedSelector [ ] {
44
44
let res ;
45
- try { res = block . getParsedSelectors ( rule ) ; }
46
- catch ( e ) { throw new errors . InvalidBlockSyntax ( e . message , sourceRange ( configuration , block . stylesheet , file , rule ) ) ; }
47
- return res ;
45
+ try {
46
+ res = block . getParsedSelectors ( rule ) ;
47
+ }
48
+ catch ( e ) {
49
+ block . addError ( new errors . InvalidBlockSyntax ( e . message , sourceRange ( configuration , block . stylesheet , file , rule ) ) ) ;
50
+ }
51
+ return res || [ ] ;
48
52
}
49
53
50
54
export async function constructBlock ( configuration : Configuration , root : postcss . Root , block : Block , file : string ) : Promise < Block > {
@@ -114,10 +118,10 @@ function addStyleRules(configuration: Configuration, block: Block, rule: postcss
114
118
decl . value . split ( / \s + / ) . map ( alias => {
115
119
let cleanedAlias = stripQuotes ( alias ) ;
116
120
if ( ! CLASS_NAME_IDENT . test ( cleanedAlias ) ) {
117
- throw new errors . InvalidBlockSyntax (
121
+ block . addError ( new errors . InvalidBlockSyntax (
118
122
`Illegal block-alias. "${ alias } " is not a legal CSS identifier.` ,
119
123
sourceRange ( configuration , block . stylesheet , file , rule ) ,
120
- ) ;
124
+ ) ) ;
121
125
}
122
126
aliases . add ( cleanedAlias ) ;
123
127
} ) ;
@@ -297,10 +301,10 @@ function assertBlockObject(configuration: Configuration, block: Block, sel: Comp
297
301
} ;
298
302
} else {
299
303
if ( found . blockType === BlockType . class || found . blockType === BlockType . classAttribute ) {
300
- throw new errors . InvalidBlockSyntax (
304
+ block . addError ( new errors . InvalidBlockSyntax (
301
305
`${ n } cannot be on the same element as ${ found . node } : ${ rule . selector } ` ,
302
306
range ( configuration , block . stylesheet , file , rule , sel . nodes [ 0 ] ) ,
303
- ) ;
307
+ ) ) ;
304
308
}
305
309
}
306
310
}
@@ -316,10 +320,10 @@ function assertBlockObject(configuration: Configuration, block: Block, sel: Comp
316
320
) ) ;
317
321
}
318
322
if ( n . attribute === "scope" ) {
319
- throw new errors . InvalidBlockSyntax (
323
+ block . addError ( new errors . InvalidBlockSyntax (
320
324
`A state cannot be named 'scope'.` ,
321
325
range ( configuration , block . stylesheet , file , rule , n ) ,
322
- ) ;
326
+ ) ) ;
323
327
}
324
328
if ( ! found ) {
325
329
block . addError ( new errors . InvalidBlockSyntax (
@@ -330,14 +334,15 @@ function assertBlockObject(configuration: Configuration, block: Block, sel: Comp
330
334
found = { node : n , blockType : BlockType . classAttribute } ;
331
335
} else if ( found . blockType === BlockType . root || found . blockType === BlockType . attribute ) {
332
336
if ( n . namespace === true ) {
333
- throw new errors . InvalidBlockSyntax (
337
+ block . addError ( new errors . InvalidBlockSyntax (
334
338
`The "any namespace" selector is not supported: ${ rule . selector } ` ,
335
339
range ( configuration , block . stylesheet , file , rule , n ) ,
336
- ) ;
340
+ ) ) ;
341
+ } else {
342
+ // XXX this is where we drop the ref to the other attribute nodes,
343
+ // XXX potentially causing the interface to not be fully discovered
344
+ found = { node : n , blockType : BlockType . attribute , blockName : n . namespace } ;
337
345
}
338
- // XXX this is where we drop the ref to the other attribute nodes,
339
- // XXX potentially causing the interface to not be fully discovered
340
- found = { node : n , blockType : BlockType . attribute , blockName : n . namespace } ;
341
346
}
342
347
}
343
348
@@ -389,19 +394,20 @@ function assertBlockObject(configuration: Configuration, block: Block, sel: Comp
389
394
}
390
395
let external = block . getReferencedBlock ( blockName ) ;
391
396
if ( ! external ) {
392
- throw new errors . InvalidBlockSyntax ( `A block named "${ blockName } " does not exist in this context.` ,
393
- range ( configuration , block . stylesheet , file , rule , sel . nodes [ 0 ] ) ) ;
394
- }
395
- let globalStates = external . rootClass . allAttributeValues ( ) . filter ( ( a ) => a . isGlobal ) ;
396
- if ( ! globalStates . length ) {
397
- throw new errors . InvalidBlockSyntax (
398
- `External Block '${ blockName } ' has no global states.` ,
399
- range ( configuration , block . stylesheet , file , rule , sel . nodes [ 0 ] ) ) ;
400
- }
401
- if ( result . blockType !== BlockType . attribute ) {
402
- throw new errors . InvalidBlockSyntax (
403
- `Missing global state selector on external Block '${ blockName } '. Did you mean one of: ${ globalStates . map ( ( s ) => s . asSource ( ) ) . join ( " " ) } ` ,
404
- range ( configuration , block . stylesheet , file , rule , sel . nodes [ 0 ] ) ) ;
397
+ block . addError ( new errors . InvalidBlockSyntax ( `A block named "${ blockName } " does not exist in this context.` ,
398
+ range ( configuration , block . stylesheet , file , rule , sel . nodes [ 0 ] ) ) ) ;
399
+ } else {
400
+ let globalStates = external . rootClass . allAttributeValues ( ) . filter ( ( a ) => a . isGlobal ) ;
401
+ if ( ! globalStates . length ) {
402
+ block . addError ( new errors . InvalidBlockSyntax (
403
+ `External Block '${ blockName } ' has no global states.` ,
404
+ range ( configuration , block . stylesheet , file , rule , sel . nodes [ 0 ] ) ) ) ;
405
+ }
406
+ if ( result . blockType !== BlockType . attribute ) {
407
+ block . addError ( new errors . InvalidBlockSyntax (
408
+ `Missing global state selector on external Block '${ blockName } '. Did you mean one of: ${ globalStates . map ( ( s ) => s . asSource ( ) ) . join ( " " ) } ` ,
409
+ range ( configuration , block . stylesheet , file , rule , sel . nodes [ 0 ] ) ) ) ;
410
+ }
405
411
}
406
412
return result ;
407
413
}
0 commit comments