@@ -66,8 +66,11 @@ export async function constructBlock(configuration: Configuration, root: postcss
66
66
let keySel = iSel . key ;
67
67
let sel : CompoundSelector | undefined = iSel . selector ;
68
68
69
- // Assert this selector is well formed according to CSS Blocks' selector rules.
69
+ // Assert this selector is well formed according to CSS Blocks' selector
70
+ // rules.
70
71
assertValidSelector ( configuration , block , rule , iSel , file ) ;
72
+ // this should list all the errors
73
+ // block.assertValid();
71
74
72
75
// For each `CompoundSelector` in this rule, configure the `Block` object
73
76
// depending on the BlockType.
@@ -137,9 +140,9 @@ function assertValidSelector(configuration: Configuration, block: Block, rule: p
137
140
// Verify our key selector targets a block object, but not one from an another block.
138
141
let keyObject = assertBlockObject ( configuration , block , selector . key , rule , file ) ;
139
142
if ( keyObject . blockName ) {
140
- throw new errors . InvalidBlockSyntax (
143
+ block . addError ( new errors . InvalidBlockSyntax (
141
144
`Cannot style values from other blocks: ${ rule . selector } ` ,
142
- range ( configuration , block . stylesheet , file , rule , keyObject . node ) ) ;
145
+ range ( configuration , block . stylesheet , file , rule , keyObject . node ) ) ) ;
143
146
}
144
147
145
148
// Fetch and validate our first `CompoundSelector`
@@ -167,45 +170,45 @@ function assertValidSelector(configuration: Configuration, block: Block, rule: p
167
170
// Don't allow weird combinators like the column combinator (`||`)
168
171
// or the attribute target selector (e.g. `/for/`)
169
172
if ( ! LEGAL_COMBINATORS . has ( combinator ) ) {
170
- throw new errors . InvalidBlockSyntax (
173
+ block . addError ( new errors . InvalidBlockSyntax (
171
174
`Illegal Combinator '${ combinator } ': ${ rule . selector } ` ,
172
175
range ( configuration , block . stylesheet , file , rule , currentCompoundSel . next . combinator ) ,
173
- ) ;
176
+ ) ) ;
174
177
}
175
178
176
179
// Class level objects cannot be ancestors of root level objects
177
180
if ( isClassLevelObject ( currentObject ) && nextLevelIsRoot && SIBLING_COMBINATORS . has ( combinator ) ) {
178
- throw new errors . InvalidBlockSyntax (
181
+ block . addError ( new errors . InvalidBlockSyntax (
179
182
`A class is never a sibling of a ${ blockTypeName ( nextObject . blockType ) } : ${ rule . selector } ` ,
180
183
range ( configuration , block . stylesheet , file , rule , selector . selector . nodes [ 0 ] ) ,
181
- ) ;
184
+ ) ) ;
182
185
}
183
186
184
187
// Once you go to the class level there's no combinator that gets you back to the root level
185
188
if ( foundClassLevel && nextLevelIsRoot ) {
186
- throw new errors . InvalidBlockSyntax (
189
+ block . addError ( new errors . InvalidBlockSyntax (
187
190
`Illegal scoping of a ${ blockTypeName ( currentObject . blockType ) } : ${ rule . selector } ` ,
188
191
range ( configuration , block . stylesheet , file , rule , currentCompoundSel . next . combinator ) ,
189
- ) ;
192
+ ) ) ;
190
193
}
191
194
192
195
// You can't reference a new root level object once you introduce descend the hierarchy
193
196
if ( foundRootLevel && nextLevelIsRoot && foundCombinators . some ( c => HIERARCHICAL_COMBINATORS . has ( c ) ) ) {
194
197
// unless it's only referencing the same object.
195
198
if ( ! foundObjects . every ( f => f . node . toString ( ) === nextObject . node . toString ( ) ) ) {
196
- throw new errors . InvalidBlockSyntax (
199
+ block . addError ( new errors . InvalidBlockSyntax (
197
200
`Illegal scoping of a ${ blockTypeName ( currentObject . blockType ) } : ${ rule . selector } ` ,
198
201
range ( configuration , block . stylesheet , file , rule , currentCompoundSel . next . combinator ) ,
199
- ) ;
202
+ ) ) ;
200
203
}
201
204
}
202
205
203
206
// class-level and root-level objects cannot be siblings.
204
207
if ( isRootLevelObject ( currentObject ) && nextLevelIsClass && SIBLING_COMBINATORS . has ( combinator ) ) {
205
- throw new errors . InvalidBlockSyntax (
208
+ block . addError ( new errors . InvalidBlockSyntax (
206
209
`A ${ blockTypeName ( nextObject . blockType ) } cannot be a sibling with a ${ blockTypeName ( currentObject . blockType ) } : ${ rule . selector } ` ,
207
210
range ( configuration , block . stylesheet , file , rule , currentCompoundSel . next . combinator ) ,
208
- ) ;
211
+ ) ) ;
209
212
}
210
213
211
214
// Class-level objects cannot be combined with each other. only with themselves.
@@ -214,15 +217,15 @@ function assertValidSelector(configuration: Configuration, block: Block, rule: p
214
217
if ( conflictObj ) {
215
218
// slightly better error verbiage for objects of the same type.
216
219
if ( conflictObj . blockType === nextObject . blockType ) {
217
- throw new errors . InvalidBlockSyntax (
220
+ block . addError ( new errors . InvalidBlockSyntax (
218
221
`Distinct ${ blockTypeName ( conflictObj . blockType , { plural : true } ) } cannot be combined: ${ rule . selector } ` ,
219
222
range ( configuration , block . stylesheet , file , rule , nextObject . node ) ,
220
- ) ;
223
+ ) ) ;
221
224
} else {
222
- throw new errors . InvalidBlockSyntax (
225
+ block . addError ( new errors . InvalidBlockSyntax (
223
226
`Cannot combine a ${ blockTypeName ( conflictObj . blockType ) } with a ${ blockTypeName ( nextObject . blockType ) } }: ${ rule . selector } ` ,
224
227
range ( configuration , block . stylesheet , file , rule , nextObject . node ) ,
225
- ) ;
228
+ ) ) ;
226
229
}
227
230
}
228
231
}
@@ -302,10 +305,10 @@ function assertBlockObject(configuration: Configuration, block: Block, sel: Comp
302
305
else if ( isAttributeNode ( n ) ) {
303
306
// Assert this state node uses a valid operator if specifying a value.
304
307
if ( n . value && n . operator !== "=" ) {
305
- throw new errors . InvalidBlockSyntax (
308
+ block . addError ( new errors . InvalidBlockSyntax (
306
309
`A state with a value must use the = operator (found ${ n . operator } instead).` ,
307
310
range ( configuration , block . stylesheet , file , rule , n ) ,
308
- ) ;
311
+ ) ) ;
309
312
}
310
313
if ( n . attribute === "scope" ) {
311
314
throw new errors . InvalidBlockSyntax (
@@ -344,19 +347,19 @@ function assertBlockObject(configuration: Configuration, block: Block, sel: Comp
344
347
} ;
345
348
} else {
346
349
if ( found . blockType === BlockType . root ) {
347
- throw new errors . InvalidBlockSyntax (
350
+ block . addError ( new errors . InvalidBlockSyntax (
348
351
`${ n } cannot be on the same element as ${ found . node } : ${ rule . selector } ` ,
349
- range ( configuration , block . stylesheet , file , rule , sel . nodes [ 0 ] ) ) ;
352
+ range ( configuration , block . stylesheet , file , rule , sel . nodes [ 0 ] ) ) ) ;
350
353
} else if ( found . blockType === BlockType . class ) {
351
354
if ( n . toString ( ) !== found . node . toString ( ) ) {
352
- throw new errors . InvalidBlockSyntax (
355
+ block . addError ( new errors . InvalidBlockSyntax (
353
356
`Two distinct classes cannot be selected on the same element: ${ rule . selector } ` ,
354
- range ( configuration , block . stylesheet , file , rule , n ) ) ;
357
+ range ( configuration , block . stylesheet , file , rule , n ) ) ) ;
355
358
}
356
359
} else if ( found . blockType === BlockType . classAttribute || found . blockType === BlockType . attribute ) {
357
- throw new errors . InvalidBlockSyntax (
360
+ block . addError ( new errors . InvalidBlockSyntax (
358
361
`The class must precede the state: ${ rule . selector } ` ,
359
- range ( configuration , block . stylesheet , file , rule , sel . nodes [ 0 ] ) ) ;
362
+ range ( configuration , block . stylesheet , file , rule , sel . nodes [ 0 ] ) ) ) ;
360
363
}
361
364
}
362
365
}
0 commit comments