Skip to content

Commit

Permalink
#24 Implement v2 bem query
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Kirmas committed Mar 10, 2021
1 parent 086eebc commit fafc380
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 43 deletions.
8 changes: 1 addition & 7 deletions src/bem.types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ describe("BemQuery2", () => {
"{}": {block: {}},
//@ts-expect-error
"el": {block: {el: true}},
//@ts-expect-error
"$": {block: {$: true}},
"$: mod": {block: {$: "mod"}},
"$: +mod": {block: {$: {mod: true}}},
Expand All @@ -108,7 +107,6 @@ describe("BemQuery2", () => {
"{}": {block: {}},
//@ts-expect-error
"el": {block: {el: true}},
//@ts-expect-error
"$": {block: {$: true}},
//@ts-expect-error
"$: mod": {block: {$: "mod"}},
Expand All @@ -132,13 +130,9 @@ describe("BemQuery2", () => {
>> = {
"exact": {
block: {
$: {
mod1: true,
mod2: "val1"
},
$: "mod1",
el: {
mod1: false,
//@ts-expect-error weird bug
mod2: "val1"
}
}
Expand Down
52 changes: 16 additions & 36 deletions src/bem.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,44 +67,24 @@ export type BemQuery2<
: classes extends `${b}${delM}${string}`
? bModKey
: never
)]?: e extends bModKey
)]?: boolean
| (
classes extends `${b}${
e extends bModKey ? "" : `${delE}${e}`
}${delM}${infer MV}`
? (
classes extends `${b}${delM}${infer bMV}`
? (
(
bMV extends `${infer bM}${delM}${infer bV}`
? {[k in bM]?: false | bV}
: (
bMV | {[k in bMV]?: boolean}
)
)
)
: never
)
: (
boolean | (
classes extends `${b}${delE}${e}${delM}${infer eMV}`
? (
(
eMV extends `${infer eM}${delM}${infer eV}`
? {[k in eM]?: false | eV}
: (
eMV | {[k in eMV]?: boolean}
)
)
// (
// eMV extends `${string}${delM}${string}`
// ? never
// : eMV
// ) | {
// [eM in Strip<eMV, delM>]?: false | (
// eMV extends `${eM}${delM}${infer eV}` ? eV : true
// )
// }
)
: never
)
(MV extends `${string}${delM}${string}` ? never : MV)
| {
[
m in Strip<MV, delM>
]?: MV extends `${m}${delM}${infer V}`
//TODO why `[]` is hack to make things work?
? false | V | []
: boolean
}
)
: never
)
}
: never
)
Expand Down

0 comments on commit fafc380

Please sign in to comment.