@@ -13,6 +13,7 @@ type BlockToBemSelectorMap = Map<string, ElementToBemSelectorMap>;
13
13
type BemToBlockClassMap = WeakMap < BemSelector , BlockClassSelector > ;
14
14
15
15
const EMPTY_ELEMENT_PLACEHOLDER = "EMPTY-ELEMENT-PLACEHOLDER" ;
16
+ const COMMON_PREFIXES_FOR_MODIFIERS = [ "is" ] ;
16
17
17
18
export function convertBemToBlocks ( files : Array < string > ) : Promise < void > [ ] {
18
19
let promises : Promise < void > [ ] = [ ] ;
@@ -22,7 +23,7 @@ export function convertBemToBlocks(files: Array<string>): Promise<void>[] {
22
23
. process ( css , { from : file } ) ;
23
24
// rewrite the file with the processed output
24
25
const parsedFilePath = path . parse ( file ) ;
25
- const blockFilePath = Object . assign ( parsedFilePath , { ext : `.block${ parsedFilePath . ext } ` , base : parsedFilePath . base . replace ( parsedFilePath . ext , `.block ${ parsedFilePath . ext } ` ) } ) ;
26
+ const blockFilePath = Object . assign ( parsedFilePath , { ext : `.block${ parsedFilePath . ext } ` , base : undefined } ) ;
26
27
promises . push ( fs . writeFile ( path . format ( blockFilePath ) , output . toString ( ) ) ) ;
27
28
} ) ;
28
29
} ) ;
@@ -109,8 +110,14 @@ export function constructBlocksMap(bemSelectorCache: BemSelectorMap): BemToBlock
109
110
let blockClass = resultMap . get ( sel ) ;
110
111
let lcs = blockClass && blockClass . state && lcsMap [ blockClass . state ] ;
111
112
if ( blockClass && blockClass . state && lcs ) {
112
- blockClass . subState = blockClass . state . replace ( `${ lcs } -` , "" ) ;
113
- blockClass . state = lcs . replace ( / - $ / , "" ) ;
113
+ if ( COMMON_PREFIXES_FOR_MODIFIERS . indexOf ( lcs ) > - 1 ) {
114
+ // if we find that the state contains a common prefix, we strip
115
+ // it of that prefix
116
+ blockClass . state = blockClass . state . replace ( `${ lcs } -` , "" ) ; ;
117
+ } else {
118
+ blockClass . subState = blockClass . state . replace ( `${ lcs } -` , "" ) ;
119
+ blockClass . state = lcs . replace ( / - $ / , "" ) ;
120
+ }
114
121
}
115
122
} ) ;
116
123
}
@@ -184,6 +191,9 @@ export const bemToBlocksPlugin: postcss.Plugin<PostcssAny> = postcss.plugin("bem
184
191
quoteMark : blockClassName . subState ? '"' : undefined ,
185
192
operator : blockClassName . subState ? "=" : undefined ,
186
193
value : blockClassName . subState ,
194
+ // the API for postcss-selector-parser mentions raws to be
195
+ // deprecated when used with quoteMark but that didn't work as
196
+ // expected. Keeping quoteMark and raws until it is fixed.
187
197
raws : { value : blockClassName . subState ? `"${ blockClassName . subState } "` : undefined } ,
188
198
} ) ;
189
199
0 commit comments