Skip to content

Commit f8ee8c8

Browse files
committed
fix(css-blocks): Rename BlockTree node types, clea up exports.
1 parent 258970e commit f8ee8c8

File tree

7 files changed

+24
-40
lines changed

7 files changed

+24
-40
lines changed

packages/css-blocks/src/Block/Block.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { FileIdentifier } from "../importing";
2424
import { LocalScopedContext } from "../util/LocalScope";
2525

2626
import { BlockClass } from "./BlockClass";
27-
import { Source } from "./BlockTree";
27+
import { SourceNode } from "./BlockTree";
2828
import { State } from "./State";
2929

3030
export type Style = BlockClass | State;
@@ -39,7 +39,7 @@ export const OBJ_REF_SPLITTER = (s: string): [string, string] | undefined => {
3939
};
4040

4141
export class Block
42-
extends Source<Block, BlockClass>
42+
extends SourceNode<Block, BlockClass>
4343
implements SelectorFactory {
4444
private _rootClass: BlockClass;
4545
private _blockReferences: ObjectDictionary<Block> = {};

packages/css-blocks/src/Block/BlockClass.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { OptionsReader } from "../OptionsReader";
55
import { OutputMode } from "../OutputMode";
66

77
import { Block } from "./Block";
8-
import { NodeStyle } from "./BlockTree";
8+
import { StyleNode } from "./BlockTree";
99
import { State } from "./State";
1010
import { StateGroup } from "./StateGroup";
1111

@@ -20,7 +20,7 @@ export interface StateInfo {
2020
/**
2121
* Represents a Class present in the Block.
2222
*/
23-
export class BlockClass extends NodeStyle<BlockClass, Block, Block, StateGroup> {
23+
export class BlockClass extends StyleNode<BlockClass, Block, Block, StateGroup> {
2424
private _sourceAttribute: Attribute | undefined;
2525

2626
protected newChild(name: string): StateGroup { return new StateGroup(name, this, this.block); }

packages/css-blocks/src/Block/BlockTree/Style.ts

-17
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,6 @@ export abstract class Style<
111111
return undefined;
112112
}
113113

114-
/**
115-
* Compute all block objects that are implied by this block object through
116-
* inheritance. Does not include this object or the styles it implies through
117-
* other relationships to this object.
118-
*
119-
* If nothing is inherited, this returns an empty set.
120-
*/
121-
resolveInheritance(): Self[] {
122-
let inherited: Self[] = [];
123-
let base: Self | undefined = this.base;
124-
while (base) {
125-
inherited.unshift(base);
126-
base = base.base;
127-
}
128-
return inherited;
129-
}
130-
131114
/**
132115
* Debug utility to help log Styles
133116
* @param opts Options for rendering cssClass.

packages/css-blocks/src/Block/BlockTree/index.ts

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,50 @@
11
import { AnyNode, Inheritable } from "./Inheritable";
2-
export { Ruleset } from "./RulesetContainer";
32
import { Style } from "./Style";
43

5-
export { Style, isStyle } from "./Style";
6-
74
// Its days like these that I wish JavaScript had multiple inheritance.
8-
export abstract class Source<
9-
Self extends Source<Self, Child>,
5+
export abstract class SourceNode<
6+
Self extends SourceNode<Self, Child>,
107
Child extends Inheritable<Child, Self, Self, AnyNode>
118
> extends Inheritable<Self, Self, null, Child> {
12-
constructor(name: string) {
13-
super(name, null);
14-
}
9+
constructor(name: string) { super(name, null); }
1510
}
1611

1712
export abstract class Node<
1813
Self extends Node<Self, Root, Parent, Child>,
19-
Root extends Source<Root, AnyNode>,
14+
Root extends SourceNode<Root, AnyNode>,
2015
Parent extends Inheritable<Parent, Root, AnyNode, Self>,
2116
Child extends Inheritable<Child, Root, Self, AnyNode | null>
2217
> extends Inheritable<Self, Root, Parent, Child> {
2318
constructor(name: string, parent: Parent, root: Root) { super(name, parent, root); }
2419
}
2520

26-
export abstract class Sink<
21+
export abstract class SinkNode<
2722
Self extends Inheritable<Self, Root, Parent, null>,
28-
Root extends Source<Root, AnyNode>,
23+
Root extends SourceNode<Root, AnyNode>,
2924
Parent extends Inheritable<Parent, Root, AnyNode, Self>
3025
> extends Inheritable<Self, Root, Parent, null> {
3126
constructor(name: string, parent: Parent, root: Root) { super(name, parent, root); }
3227
}
3328

34-
export abstract class NodeStyle<
29+
export abstract class StyleSource<
30+
Self extends StyleSource<Self, Child>,
31+
Child extends Inheritable<Child, Self, Self, AnyNode>
32+
> extends Inheritable<Self, Self, null, Child> {
33+
constructor(name: string) { super(name, null); }
34+
}
35+
36+
export abstract class StyleNode<
3537
Self extends Style<Self, Root, Parent, Child>,
36-
Root extends Source<Root, AnyNode>,
38+
Root extends SourceNode<Root, AnyNode>,
3739
Parent extends Inheritable<Parent, Root, AnyNode | null, Self>,
3840
Child extends Inheritable<Child, Root, Self, AnyNode | null>
3941
> extends Style<Self, Root, Parent, Child> {
4042
constructor(name: string, parent: Parent, root: Root) { super(name, parent, root); }
4143
}
4244

43-
export abstract class SinkStyle<
45+
export abstract class StyleSink<
4446
Self extends Style<Self, Root, Parent, null>,
45-
Root extends Source<Root, AnyNode>,
47+
Root extends SourceNode<Root, AnyNode>,
4648
Parent extends Inheritable<Parent, Root, AnyNode, Self>
4749
> extends Style<Self, Root, Parent, null> {
4850
constructor(name: string, parent: Parent, root: Root) { super(name, parent, root); }

packages/css-blocks/src/Block/State.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import { OutputMode } from "../OutputMode";
1010

1111
import { Block } from "./Block";
1212
import { BlockClass } from "./BlockClass";
13-
import { SinkStyle } from "./BlockTree";
13+
import { StyleSink } from "./BlockTree";
1414
import { StateGroup } from "./StateGroup";
1515

1616
/**
1717
* States represent a state attribute selector in a particular Block.
1818
* A State can have sub-states that are considered to be mutually exclusive.
1919
* States can be designated as "global";
2020
*/
21-
export class State extends SinkStyle<State, Block, StateGroup> {
21+
export class State extends StyleSink<State, Block, StateGroup> {
2222
isGlobal = false;
2323

2424
private _sourceAttributes: AttributeNS[] | undefined;

packages/css-blocks/src/Block/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ export { Style, Block, isBlock, OBJ_REF_SPLITTER } from "./Block";
22
export { BlockClass, isBlockClass } from "./BlockClass";
33
export { StateGroup } from "./StateGroup";
44
export { State, isState } from "./State";
5-
export { RulesetContainer } from "./BlockTree/RulesetContainer";

packages/css-blocks/src/TemplateAnalysis/validations/property-conflict-validator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as propParser from "css-property-parser";
33
import * as postcss from "postcss";
44

55
import { Style } from "../../Block";
6-
import { Ruleset } from "../../Block/BlockTree";
6+
import { Ruleset } from "../../Block/BlockTree/RulesetContainer";
77
import {
88
isBooleanState,
99
isFalseCondition,

0 commit comments

Comments
 (0)