@@ -8,6 +8,7 @@ import { Block } from "../BlockTree";
8
8
import { Options , ResolvedConfiguration , resolveConfiguration } from "../configuration" ;
9
9
import { CssBlockError } from "../errors" ;
10
10
import { FileIdentifier , ImportedCompiledCssFile , ImportedFile , Importer } from "../importing" ;
11
+ import { sourceRange } from "../SourceLocation" ;
11
12
import { PromiseQueue } from "../util/PromiseQueue" ;
12
13
13
14
import { BlockParser , ParsedSource } from "./BlockParser" ;
@@ -313,6 +314,7 @@ export class BlockFactory {
313
314
314
315
// NOTE: If we had to upgrade the syntax version of a definition file, here's where'd we do that.
315
316
// But this isn't a thing we need to do until we have multiple syntax versions.
317
+ // TODO: Actually look at the declared version - error if it's greater than 1.
316
318
317
319
// NOTE: No need to run preprocessor - we assume that Compiled CSS has already been preprocessed.
318
320
// Parse the definition file into an AST
@@ -339,10 +341,31 @@ export class BlockFactory {
339
341
}
340
342
341
343
// Construct a Block out of the definition file.
342
- const block = this . parser . parseDefinitionSource ( definitionAst , file . definitionIdentifier , file . blockId ) ;
344
+ const block = await this . parser . parseDefinitionSource ( definitionAst , file . definitionIdentifier , file . blockId ) ;
343
345
344
346
// Merge the rules from the CSS contents into the Block.
345
- // TODO: Actually merge the CSS rules in. (^_^")
347
+ const styleNodesMap = block . compiledClassesMap ( true ) ;
348
+ cssContentsAst . walkRules ( rule => {
349
+ rule . selectors . forEach ( sel => {
350
+ if ( sel . split ( "." ) . length !== 1 || ! sel . startsWith ( "." ) ) {
351
+ // Skip it, we only care about selectors with only one class.
352
+ return ;
353
+ }
354
+ const styleNode = styleNodesMap [ sel ] ;
355
+ if ( ! styleNode ) {
356
+ block . addError (
357
+ new CssBlockError (
358
+ `Selector ${ sel } exists in Compiled CSS file but doesn't match any rules in definition file.` ,
359
+ sourceRange ( this . configuration , cssContentsAst . root ( ) , file . identifier , rule ) ,
360
+ ) ,
361
+ ) ;
362
+ return ;
363
+ }
364
+ styleNode . rulesets . addRuleset ( this . configuration , file . identifier , rule ) ;
365
+ } ) ;
366
+ } ) ;
367
+
368
+ // TODO: Set the block's name from the block-name rule. (We skip this later for definition files.)
346
369
347
370
// And we're done!
348
371
return block ;
0 commit comments