1
1
import { CompoundSelector , ParsedSelector , postcss , postcssSelectorParser as selectorParser } from "opticss" ;
2
2
3
- import { BLOCK_ALIAS } from "../../BlockSyntax" ;
3
+ import { BLOCK_ALIAS , CLASS_NAME_IDENT } from "../../BlockSyntax" ;
4
4
import { AttrValue , Block , BlockClass , Style } from "../../BlockTree" ;
5
5
import { Configuration } from "../../configuration" ;
6
6
import * as errors from "../../errors" ;
@@ -87,9 +87,9 @@ export async function constructBlock(configuration: Configuration, root: postcss
87
87
// If this is the key selector, save this ruleset on the created style.
88
88
if ( isKey ) {
89
89
if ( foundStyles . blockAttrs . length ) {
90
- foundStyles . blockAttrs . map ( s => addStyleRules ( s , rule , styleRuleTuples ) ) ;
90
+ foundStyles . blockAttrs . map ( s => addStyleRules ( configuration , block , rule , file , s , styleRuleTuples ) ) ;
91
91
} else {
92
- foundStyles . blockClasses . map ( s => addStyleRules ( s , rule , styleRuleTuples ) ) ;
92
+ foundStyles . blockClasses . map ( s => addStyleRules ( configuration , block , rule , file , s , styleRuleTuples ) ) ;
93
93
}
94
94
}
95
95
@@ -107,10 +107,20 @@ export async function constructBlock(configuration: Configuration, root: postcss
107
107
return block ;
108
108
}
109
109
110
- function addStyleRules ( style : AttrValue | BlockClass , rule : postcss . Rule , tuple : Set < [ Style , postcss . Rule ] > ) : void {
110
+ function addStyleRules ( configuration : Configuration , block : Block , rule : postcss . Rule , file : string , style : AttrValue | BlockClass , tuple : Set < [ Style , postcss . Rule ] > ) : void {
111
111
rule . walkDecls ( BLOCK_ALIAS , decl => {
112
- style . setStyleAliases ( new Set ( decl . value . split ( / \s + / ) . map ( stripQuotes ) ) ) ;
113
- decl . remove ( ) ;
112
+ let aliases : Set < string > = new Set ( ) ;
113
+ decl . value . split ( / \s + / ) . map ( alias => {
114
+ let cleanedAlias = stripQuotes ( alias ) ;
115
+ if ( ! CLASS_NAME_IDENT . test ( cleanedAlias ) ) {
116
+ throw new errors . InvalidBlockSyntax (
117
+ `Illegal block-alias in export. "${ alias } " is not a legal CSS identifier.` ,
118
+ sourceRange ( configuration , block . stylesheet , file , rule ) ,
119
+ ) ;
120
+ }
121
+ aliases . add ( cleanedAlias ) ;
122
+ } ) ;
123
+ style . setStyleAliases ( aliases ) ;
114
124
} ) ;
115
125
tuple . add ( [ style , rule ] ) ;
116
126
}
0 commit comments