-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbem-block.ts
More file actions
40 lines (30 loc) · 1.01 KB
/
bem-block.ts
File metadata and controls
40 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import Location from './location';
import BemBlockArray from './bem-block-array';
export default class BemBlock {
block: string;
mods?: Map<string, string | number | boolean | null>;
elem?: string;
elemMods?: Map<string, string | number | boolean | null>;
content?: BemBlockArray;
mix?: BemBlockArray;
location?: Location;
constructor() {
this.block = '';
}
findNestedBlocks(blockNames: string[]): BemBlock[] {
let result: BemBlock[] = [];
const traverse = (content: BemBlockArray | undefined) => {
if (!content || !content.blocks || content.blocks.length === 0) {
return;
}
for (const block of content.blocks) {
if (blockNames.indexOf(block.block) > -1) {
result = [...result, block];
}
traverse(block.content);
}
}
traverse(this.content);
return result;
}
}