Skip to content

Commit

Permalink
#24 Recover el-mod shortcut in bem
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Kirmas committed Mar 11, 2021
1 parent 210cc73 commit c3ba8b5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion __recipes__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ it("go", () => {
const bem = classBeming<ClassNamesProperty<CssModule> & ClassNamed>()
expect(bem(true, {
"block": {
//@ts-expect-error //TODO Recover shortcut
"&": "m",
"el": {"m": "X"}
}
Expand Down
2 changes: 0 additions & 2 deletions src/bem.types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe("BemQuery", () => {
//@ts-expect-error
"el=1": {block: {el: 1}},
"el": {block: {el: true}},
//@ts-expect-error //TODO Recover shortcut
"el: mod": {block: {el: "mod"}},
"el: -mod": {block: {el: {mod: false}}},
"el: +mod": {block: {el: {mod: true}}}
Expand Down Expand Up @@ -73,7 +72,6 @@ describe("BemQuery", () => {
//@ts-expect-error
"el": {block: {el: true}},
"$": {block: {$: true}},
//@ts-expect-error //TODO Recover shortcut
"$: mod": {block: {$: "mod"}},
"$: +mod": {block: {$: {mod: true}}},
"$: -mod": {block: {$: {mod: false}}},
Expand Down
13 changes: 7 additions & 6 deletions src/bem.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CssModule } from "./definitions.types"
import type {
Subest,
Strip,
PartDeep,
// PartDeep
} from "./ts-swiss.types"
import type { ClassNamed } from "./main.types"
Expand Down Expand Up @@ -29,14 +30,14 @@ export type BemQuery<
bModKey extends string = "blockModKey" extends keyof ReactClassNaming.BemOptions
? ReactClassNaming.BemOptions["blockModKey"]
: ReactClassNaming.BemOptions["$default"]["blockModKey"],
> = string extends classes ? BemAbsraction : {
[b in Strip<Strip<classes, delM>, delE>]?: boolean | (
// [classes extends `${b}${delE | delM}${string}` ? true : never] extends [never] ? never :
> = string extends classes ? BemAbsraction : PartDeep<{
[b in Strip<Strip<classes, delM>, delE>]: boolean | (
Extends<classes, `${b}${delE | delM}${string}`,
{
[e in Elements<classes, b>]?: boolean
[e in Elements<classes, b>]: boolean
| (MVs<classes, b, e> extends `${string}${delM}${string}` ? never : MVs<classes, b, e>)
| (
{[m in Strip<MVs<classes, b, e>, delM>]?:
{[m in Strip<MVs<classes, b, e>, delM>]:
classes extends `${b}${
e extends bModKey ? "" : `${delE}${e}`
}${delM}${m}${delM}${infer V}`
Expand All @@ -48,7 +49,7 @@ export type BemQuery<
>
// : never
)
}
}>

type Extends<T, V, X> = [T extends V ? true : never] extends [never] ? never : X

Expand Down
5 changes: 4 additions & 1 deletion src/ts-swiss.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ export type Cut<Str extends string, Delimiter extends string> = Str extends `${s
export type Subest<Base, Extendent> = Base extends Extendent ? Extendent : Base
// export type SubestDeep<Base, Extendent> = Base extends Extendent ? Extendent : Base

export type PartDeep<T> = Exclude<T, AnyObject> | {[K in keyof Extract<T, AnyObject>]?: Extract<T, AnyObject>[K]}
export type PartDeep<T> = Exclude<T, AnyObject> | (
// [Extract<T, AnyObject>] extends [never] ? never :
T extends AnyObject ? {[K in keyof Extract<T, AnyObject>]?: PartDeep<Extract<T, AnyObject>[K]>} : never
)

0 comments on commit c3ba8b5

Please sign in to comment.