@@ -23,10 +23,8 @@ import { FileIdentifier } from "../importing";
23
23
import { LocalScopedContext } from "../util/LocalScope" ;
24
24
25
25
import { BlockClass } from "./BlockClass" ;
26
- import { SourceContainer } from "./BlockTree" ;
27
- import { State } from "./State" ;
28
-
29
- export type Style = BlockClass | State ;
26
+ import { Inheritable } from "./Inheritable" ;
27
+ import { Styles } from "./Styles" ;
30
28
31
29
export const OBJ_REF_SPLITTER = ( s : string ) : [ string , string ] | undefined => {
32
30
let index = s . indexOf ( "." ) ;
@@ -37,13 +35,13 @@ export const OBJ_REF_SPLITTER = (s: string): [string, string] | undefined => {
37
35
return ;
38
36
} ;
39
37
40
- export class Block extends SourceContainer < Block , BlockClass > {
38
+ export class Block extends Inheritable < Block , Block , never , BlockClass > {
41
39
private _rootClass : BlockClass ;
42
40
private _blockReferences : ObjectDictionary < Block > = { } ;
43
41
private _blockReferencesReverseLookup : Map < Block , string > = new Map ( ) ;
44
42
private _identifier : FileIdentifier ;
45
43
private _implements : Block [ ] = [ ] ;
46
- private _localScope : LocalScopedContext < Block , Style > ;
44
+ private _localScope : LocalScopedContext < Block , Styles > ;
47
45
private hasHadNameReset = false ;
48
46
/**
49
47
* array of paths that this block depends on and, if changed, would
@@ -59,12 +57,14 @@ export class Block extends SourceContainer<Block, BlockClass> {
59
57
super ( name ) ;
60
58
this . _identifier = identifier ;
61
59
this . parsedRuleSelectors = new WeakMap ( ) ;
62
- this . _localScope = new LocalScopedContext < Block , Style > ( OBJ_REF_SPLITTER , this ) ;
60
+ this . _localScope = new LocalScopedContext < Block , Styles > ( OBJ_REF_SPLITTER , this ) ;
63
61
this . _dependencies = new Set < string > ( ) ;
64
62
this . _rootClass = new BlockClass ( ROOT_CLASS , this ) ;
65
63
this . addClass ( this . _rootClass ) ;
66
64
}
67
65
66
+ get block ( ) : Block { return this . root ; }
67
+
68
68
get name ( ) { return this . _name ; }
69
69
set name ( name : string ) {
70
70
if ( this . hasHadNameReset ) {
@@ -79,7 +79,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
79
79
}
80
80
81
81
/// Start of methods to implement LocalScope<Block, Style>
82
- subScope ( name : string ) : LocalScopedContext < Block , Style > | undefined {
82
+ subScope ( name : string ) : LocalScopedContext < Block , Styles > | undefined {
83
83
let block = this . _blockReferences [ name ] ;
84
84
if ( block ) {
85
85
return block . _localScope ;
@@ -88,7 +88,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
88
88
}
89
89
}
90
90
91
- lookupLocal ( name : string ) : Style | undefined {
91
+ lookupLocal ( name : string ) : Styles | undefined {
92
92
let blockRef = this . _blockReferences [ name ] ;
93
93
if ( blockRef ) {
94
94
return blockRef . rootClass ;
@@ -118,7 +118,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
118
118
* A single dot by itself returns the current block.
119
119
* @returns The Style referenced at the supplied path.
120
120
*/
121
- public lookup ( path : string | BlockPath , errLoc ?: SourceLocation ) : Style | undefined {
121
+ public lookup ( path : string | BlockPath , errLoc ?: SourceLocation ) : Styles | undefined {
122
122
path = new BlockPath ( path ) ;
123
123
let block = this . getReferencedBlock ( path . block ) ;
124
124
if ( ! block ) {
@@ -183,8 +183,8 @@ export class Block extends SourceContainer<Block, BlockClass> {
183
183
* @param b The block to check implementation against.
184
184
* @returns The Styles from b that are missing in the block.
185
185
*/
186
- checkImplementation ( b : Block ) : Style [ ] {
187
- let missing : Style [ ] = [ ] ;
186
+ checkImplementation ( b : Block ) : Styles [ ] {
187
+ let missing : Styles [ ] = [ ] ;
188
188
for ( let o of b . all ( ) ) {
189
189
if ( ! this . find ( o . asSource ( ) ) ) {
190
190
missing . push ( o ) ;
@@ -198,7 +198,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
198
198
*/
199
199
checkImplementations ( ) : void {
200
200
for ( let b of this . getImplementedBlocks ( ) ) {
201
- let missing : Style [ ] = this . checkImplementation ( b ) ;
201
+ let missing : Styles [ ] = this . checkImplementation ( b ) ;
202
202
let paths = missing . map ( o => o . asSource ( ) ) . join ( ", " ) ;
203
203
if ( missing . length > 0 ) {
204
204
let s = missing . length > 1 ? "s" : "" ;
@@ -208,7 +208,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
208
208
}
209
209
210
210
// This is a really dumb impl
211
- find ( sourceName : string ) : Style | undefined {
211
+ find ( sourceName : string ) : Styles | undefined {
212
212
let blockRefName : string | undefined ;
213
213
let md = sourceName . match ( CLASS_NAME_IDENT ) ;
214
214
if ( md && md . index === 0 ) {
@@ -284,8 +284,8 @@ export class Block extends SourceContainer<Block, BlockClass> {
284
284
* @param shallow Pass true to not include inherited objects.
285
285
* @returns Array of Styles.
286
286
*/
287
- all ( shallow ?: boolean ) : Style [ ] {
288
- let result = new Array < Style > ( ) ;
287
+ all ( shallow ?: boolean ) : Styles [ ] {
288
+ let result = new Array < Styles > ( ) ;
289
289
for ( let blockClass of this . classes ) {
290
290
result . push ( ...blockClass . all ( ) ) ;
291
291
}
@@ -295,8 +295,8 @@ export class Block extends SourceContainer<Block, BlockClass> {
295
295
return result ;
296
296
}
297
297
298
- merged ( ) : MultiMap < string , Style > {
299
- let map = new MultiMap < string , Style > ( false ) ;
298
+ merged ( ) : MultiMap < string , Styles > {
299
+ let map = new MultiMap < string , Styles > ( false ) ;
300
300
for ( let obj of this . all ( ) ) {
301
301
map . set ( obj . asSource ( ) , obj ) ;
302
302
}
@@ -307,7 +307,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
307
307
* Fetch a the cached `Style` from `Block` given `NodeAndType`.
308
308
* @param obj The `NodeAndType` object to use for `Style` lookup.
309
309
*/
310
- nodeAndTypeToStyle ( obj : NodeAndType ) : Style | null {
310
+ nodeAndTypeToStyle ( obj : NodeAndType ) : Styles | null {
311
311
switch ( obj . blockType ) {
312
312
case BlockType . root :
313
313
return this . rootClass ;
@@ -327,7 +327,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
327
327
}
328
328
}
329
329
330
- nodeAsStyle ( node : selectorParser . Node ) : [ Style , number ] | null {
330
+ nodeAsStyle ( node : selectorParser . Node ) : [ Styles , number ] | null {
331
331
if ( node . type === selectorParser . CLASS && node . value === ROOT_CLASS ) {
332
332
return [ this . rootClass , 0 ] ;
333
333
} else if ( node . type === selectorParser . TAG ) {
@@ -444,7 +444,7 @@ export class Block extends SourceContainer<Block, BlockClass> {
444
444
let sortedNames = [ ...sourceNames ] . sort ( ) ;
445
445
for ( let n of sortedNames ) {
446
446
if ( n !== `.${ ROOT_CLASS } ` ) {
447
- let o = this . find ( n ) as Style ;
447
+ let o = this . find ( n ) as Styles ;
448
448
result . push ( o . asDebug ( opts ) ) ;
449
449
}
450
450
}
0 commit comments